Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Map applications like DotSpatial will attempt to render all the vectors on the screen for your loaded shapefile. They do not attempt to draw any lines that are not in the current extent. But when you are zoomed out, they will try to draw all the lines exactly, which is slow. One strategy that might help is to set the visibility scale so that you only draw the layer once you zoom in. The Layer class in DotSpatial allows you to set dynamic visibility for the layer so that you only draw the full shapefile when you zoom in beyond a certain point.</p> <pre><code>myLayer.UseDynamicVisiblity = true; myLayer.DynamicVisibilityMode = DynamicVisibilityMode.ZoomedIn; myLayer.DynamicVisibiltyWidth = .2; // eg. .2 degrees of longitude in WGS84 </code></pre> <p>The only down side to this strategy is that you won't see any roads at all until you zoom in to the specified extent. So one option would be to create a low resolution version of your road shapes that looks ok when you are zoomed out, but doesn't contain any "duplicate" points for a much larger grid size. You can do this either by using another line shapefile or by creating an image, or creating image tiles. The first example below uses a grid size of 1000 x 1000 so that it reduces the redundant points to a minimum representation. Using a combination of different grid sizes and the dynamic visibility, you should be able to render your large line shapefiles more efficiently. Rasters typically have overviews, but vectors typically do not, so this is one way to create an artificial overview for a vector. The second example will use DP line simplification, which keeps all the shapes, but uses fewer points to represent each shape. </p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using DotSpatial.Data; using DotSpatial.Projections; using DotSpatial.Topology; namespace WindowsFormsApplication3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Shapefile source = new Shapefile(); source = Shapefile.OpenFile(@"C:\Data\Rivers\River.shp"); bool[,] pointRepresented = new bool[1000, 1000]; double width = source.Extent.Width; double height = source.Extent.Height; double dx = width / 1000; double dy = height / 1000; FeatureSet result = new FeatureSet(FeatureType.Line); result.Projection = KnownCoordinateSystems.Geographic.World.WGS1984; // lat lon in WGS84 result.DataTable.Columns.Add("Index", typeof(int)); int index = 0; foreach (ShapeRange shape in source.ShapeIndices) { bool started = false; List&lt;LineString&gt; linestrings = new List&lt;LineString&gt;(); foreach (PartRange part in shape.Parts) { List&lt;Coordinate&gt; coords = new List&lt;Coordinate&gt;(); foreach (Vertex vert in part) { int i = (int)((vert.X - source.Extent.MinX) / dx); int j = (int)((vert.Y - source.Extent.MinY) / dy); if (i &gt; 999) { i = 999; } if (j &gt; 999) { j = 999; } if (pointRepresented[i, j] == true) continue; coords.Add(new Coordinate(vert.X, vert.Y)); pointRepresented[i, j] = true; } if (coords.Count &gt; 0) { if (coords.Count == 1) { coords.Add(coords[0]); // add a duplicate "endpoint" to the line if we only have one point. } linestrings.Add(new LineString(coords)); } } if (linestrings.Count &gt; 0) { IFeature feature; if (linestrings.Count &gt; 1) { feature = result.AddFeature(new MultiLineString(linestrings)); } else { feature = result.AddFeature(linestrings[0]); } feature.DataRow["Index"] = index; index++; } result.SaveAs(@"C:\Data\Rivers\RiverPreview.shp", true); } MessageBox.Show(@"Finished creating file: C:\Data\Rivers\RiverPreview.shp"); } } } </code></pre> <p>The second approach uses DP Line simplification, and will not remove shapes, but simply reduces the number of points used to represent each shape. The tolerance will have to be adjusted to match your dataset and coordinates.</p> <pre><code> /// &lt;summary&gt; /// This alternative uses DP line simplification, which keeps every shape, but "simplifies" the shape, simply reducing /// the number of points. This will not accomplish the goal of reducing the number of shapes, but will /// give you a reduced representation that matches the original features in cases where slowness is caused /// by too much detail, which can be useful if you still want to keep all your features. /// &lt;/summary&gt; private void button2_Click(object sender, EventArgs e) { Shapefile source = new Shapefile(); source = Shapefile.OpenFile(@"C:\Data\Rivers\River.shp"); FeatureSet result = new FeatureSet(FeatureType.Line); result.Projection = source.Projection; result.CopyTableSchema(source); foreach (IFeature feature in source.Features) { LineString linestring = feature.BasicGeometry as LineString; if (linestring != null) { IList&lt;Coordinate&gt; points = linestring.Coordinates; IList&lt;Coordinate&gt; simplified = DouglasPeuckerLineSimplifier.Simplify(points, .00002); IFeature resultFeature = result.AddFeature(new LineString(simplified)); resultFeature.CopyAttributes(feature); } else { MultiLineString multipleLines = feature.BasicGeometry as MultiLineString; if (multipleLines != null) { List&lt;LineString&gt; resultLines = new List&lt;LineString&gt;(); foreach (IGeometry line in multipleLines.Geometries) { IList&lt;Coordinate&gt; points = line.Coordinates; IList&lt;Coordinate&gt; simplified = DouglasPeuckerLineSimplifier.Simplify(points, .00002); resultLines.Add(new LineString(simplified)); } IFeature resultFeature = result.AddFeature(new MultiLineString(resultLines)); resultFeature.CopyAttributes(feature); } } } result.SaveAs(@"C:\Data\Rivers\RiverSimplified.shp", true); MessageBox.Show(@"Finished creating file: C:\Data\Rivers\RiverSimplified.shp"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload