public void TestCachedLineSymbolizerInTheme() { var p = new SharpMap.Data.Providers.ShapeFile(GetTestFile(), false); var l = new SharpMap.Layers.VectorLayer("roads", p); var theme = new ClsTheme(l.Style); l.Theme = theme; var m = new SharpMap.Map(new System.Drawing.Size(720, 540)) { BackColor = System.Drawing.Color.Cornsilk }; m.Layers.Add(l); m.ZoomToExtents(); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var bmp = m.GetMap(); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("AurichRoads1Theme.bmp"); }
public void TestCachedLineSymbolizerInTheme() { var p = new SharpMap.Data.Providers.ShapeFile(TestUtility.GetPathToTestFile("roads_aur.shp"), false); var l = new SharpMap.Layers.VectorLayer("roads", p); var theme = new ClsTheme(l.Style); l.Theme = theme; var m = new SharpMap.Map(new System.Drawing.Size(720, 540)) { BackColor = System.Drawing.Color.Cornsilk }; m.Layers.Add(l); m.ZoomToExtents(); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var bmp = m.GetMap(); sw.Stop(); System.Diagnostics.Trace.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save(System.IO.Path.Combine(UnitTestsFixture.GetImageDirectory(this), "AurichRoads1Theme.bmp")); }
public void TestPerformanceLinealLayer() { NUnit.Framework.Assert.IsTrue(System.IO.File.Exists(GetTestDataFilePath("roads_ugl.shp")), "Specified shapefile is not present!"); var map = new SharpMap.Map(new System.Drawing.Size(1024, 768)); var shp = new SharpMap.Data.Providers.ShapeFile(GetTestDataFilePath("roads_ugl.shp"), false, false); var lyr = new SharpMap.Layers.Symbolizer.LinealVectorLayer("Roads", shp) { Symbolizer = new SharpMap.Rendering.Symbolizer.BasicLineSymbolizer { Line = new System.Drawing.Pen(System.Drawing.Color.Black) } }; map.Layers.Add(lyr); map.ZoomToExtents(); RepeatedRendering(map, shp.GetFeatureCount(), NumberOfRenderCycles, out _msLineal); System.Diagnostics.Trace.WriteLine("\nWith testing if record is deleted "); shp.CheckIfRecordIsDeleted = true; long tmp; RepeatedRendering(map, shp.GetFeatureCount(), 1, out tmp); var res = map.GetMap(); var path = System.IO.Path.ChangeExtension(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp"), "lineal.png"); res.Save(path, System.Drawing.Imaging.ImageFormat.Png); System.Diagnostics.Trace.WriteLine("\nResult saved at file://" + path.Replace('\\', '/')); }
public void TestReadValueZFromPointZShapeFile() { var file = GetTestDataFilePath("Point_With_Z.shp"); var sh = new SharpMap.Data.Providers.ShapeFile(file, true); sh.Open(); var fc = sh.GetFeatureCount(); NUnit.Framework.Assert.AreEqual(1149, fc); NUnit.Framework.Assert.AreEqual(0, sh.GetObjectIDsInView(sh.GetExtents())[0]); var featsInView = sh.GetGeometriesInView(new GeoAPI.Geometries.Envelope(sh.GetExtents())); NUnit.Framework.Assert.AreEqual(1149, featsInView.Count); foreach (var item in featsInView) { NUnit.Framework.Assert.IsNotNull(item.Coordinate.Z); } NUnit.Framework.Assert.AreEqual(featsInView[0].Coordinate.Z, 146.473); NUnit.Framework.Assert.AreEqual(featsInView[1].Coordinate.Z, 181.374); NUnit.Framework.Assert.AreEqual(featsInView[2].Coordinate.Z, 146.676); NUnit.Framework.Assert.AreEqual(featsInView[3].Coordinate.Z, 181.087); NUnit.Framework.Assert.AreEqual(featsInView[4].Coordinate.Z, 169.948); NUnit.Framework.Assert.AreEqual(featsInView[5].Coordinate.Z, 169.916); sh.Close(); }
public void TestExecuteIntersectionQuery() { NUnit.Framework.Assert.IsTrue(System.IO.File.Exists(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp")), "Specified shapefile is not present!"); var shp = new SharpMap.Data.Providers.ShapeFile(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp"), false, false); shp.Open(); var fds = new SharpMap.Data.FeatureDataSet(); var bbox = shp.GetExtents(); //narrow it down bbox.ExpandBy(-0.425*bbox.Width, -0.425*bbox.Height); //Just to avoid that initial query does not impose performance penalty shp.DoTrueIntersectionQuery = false; shp.ExecuteIntersectionQuery(bbox, fds); fds.Tables.RemoveAt(0); //Perform query once more var sw = new System.Diagnostics.Stopwatch(); sw.Start(); shp.ExecuteIntersectionQuery(bbox, fds); sw.Stop(); System.Console.WriteLine("Queried using just envelopes:\n" + fds.Tables[0].Rows.Count + " in " + sw.ElapsedMilliseconds + "ms."); fds.Tables.RemoveAt(0); shp.DoTrueIntersectionQuery = true; sw.Reset(); sw.Start(); shp.ExecuteIntersectionQuery(bbox, fds); sw.Stop(); System.Console.WriteLine("Queried using prepared geometries:\n" + fds.Tables[0].Rows.Count + " in " + sw.ElapsedMilliseconds + "ms."); }
public void TestReadValueZFromLineStringZShapeFile() { var file = GetTestDataFilePath("LineString_With_Z.shp"); var sh = new SharpMap.Data.Providers.ShapeFile(file, true); sh.Open(); var fc = sh.GetFeatureCount(); NUnit.Framework.Assert.AreEqual(1221, fc); NUnit.Framework.Assert.AreEqual(0, sh.GetObjectIDsInView(sh.GetExtents())[0]); var featsInView = sh.GetGeometriesInView(new GeoAPI.Geometries.Envelope(sh.GetExtents())); NUnit.Framework.Assert.AreEqual(1221, featsInView.Count); foreach (var item in featsInView) { NUnit.Framework.Assert.IsNotNull(item.Coordinate.Z); } NUnit.Framework.Assert.AreEqual(featsInView[0].Coordinates[0].Z, 35.865); NUnit.Framework.Assert.AreEqual(featsInView[0].Coordinates[1].Z, 35.743); NUnit.Framework.Assert.AreEqual(featsInView[1].Coordinates[0].Z, 35.518); NUnit.Framework.Assert.AreEqual(featsInView[1].Coordinates[1].Z, 35.518); NUnit.Framework.Assert.AreEqual(featsInView[2].Coordinates[0].Z, 37.438); NUnit.Framework.Assert.AreEqual(featsInView[2].Coordinates[1].Z, 37.441); NUnit.Framework.Assert.AreEqual(featsInView[3].Coordinates[0].Z, 37.441); NUnit.Framework.Assert.AreEqual(featsInView[3].Coordinates[1].Z, 37.441); sh.Close(); }
private void AddShapeLayer_OnClick(object sender, RoutedEventArgs e) { var ofd = new OpenFileDialog(); ofd.Filter = @"Shapefiles (*.shp)|*.shp"; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var ds = new SharpMap.Data.Providers.ShapeFile(ofd.FileName); var lay = new SharpMap.Layers.VectorLayer(System.IO.Path.GetFileNameWithoutExtension(ofd.FileName), ds); if (ds.CoordinateSystem != null) { GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformationFactory fact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); lay.CoordinateTransformation = fact.CreateFromCoordinateSystems(ds.CoordinateSystem, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator); lay.ReverseCoordinateTransformation = fact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator, ds.CoordinateSystem); } WpfMap.MapLayers.Add(lay); if (WpfMap.MapLayers.Count == 1) { Envelope env = lay.Envelope; WpfMap.ZoomToEnvelope(env); } } e.Handled = true; }
public void TestDeleteAfterClose() { string test; CopyShapeFile(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp"), out test); var shp = new SharpMap.Data.Providers.ShapeFile(test); shp.Open(); shp.Close(); var succeeded = true; foreach (var file in System.IO.Directory.GetFiles(System.IO.Path.GetDirectoryName(test), System.IO.Path.GetFileNameWithoutExtension(test) + ".*")) { try { System.IO.File.Delete(file); } catch (System.Exception) { System.Diagnostics.Trace.WriteLine("Failed to delete '{0}'", file); succeeded = false; } } NUnit.Framework.Assert.IsTrue(succeeded); }
public void TestStreetDirectionSymbolizer() { var p = new SharpMap.Data.Providers.ShapeFile(@"d:\\daten\GeoFabrik\\Aurich\\roads.shp", false); var l = new SharpMap.Layers.VectorLayer("roads", p); l.Style.Outline = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 7); l.Style.Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 3); l.Style.EnableOutline = true; var sd = new SharpMap.Layers.Symbolizer.LinealVectorLayer("streetd", p, new StreetDirectionSymbolizer() { ArrowLength = 100, RepeatInterval = 500 }); var m = new SharpMap.Map(new System.Drawing.Size(1440, 1080)) { BackColor = System.Drawing.Color.Cornsilk }; m.Layers.Add(l); m.Layers.Add(sd); m.ZoomToExtents(); m.Zoom *= 0.3; var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var bmp = m.GetMap(); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("NDSRoadsSD.bmp"); }
private void AddShapeLayer_OnClick(object sender, RoutedEventArgs e) { var ofd = new OpenFileDialog(); ofd.Filter = "Shapefiles (*.shp)|*.shp"; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var ds = new SharpMap.Data.Providers.ShapeFile(ofd.FileName); var lay = new SharpMap.Layers.VectorLayer(System.IO.Path.GetFileNameWithoutExtension(ofd.FileName), ds); if (ds.CoordinateSystem != null) { GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformationFactory fact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); lay.CoordinateTransformation = fact.CreateFromCoordinateSystems(ds.CoordinateSystem, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator); lay.ReverseCoordinateTransformation = fact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator, ds.CoordinateSystem); } WpfMap.MapLayers.Add(lay); if (WpfMap.MapLayers.Count == 1) { Envelope env = lay.Envelope; WpfMap.ZoomToEnvelope(env); } } e.Handled = true; }
public static void Example2() { var map = new SharpMap.Map(new Size(1280, 1084)); SharpMap.Data.Providers.IProvider provider = new SharpMap.Data.Providers.ShapeFile( @"C:\temp\Data\niedersachsen.shp\railways.shp"); var style = new SharpMap.Styles.VectorStyle(); style.Line.Brush = Brushes.White; style.Line.DashPattern = new float[] { 4f, 4f }; style.Line.Width = 4; style.EnableOutline = true; style.Outline.Brush = Brushes.Black; style.Outline.Width = 6; var vl = new SharpMap.Layers.VectorLayer("Railways", provider) {Style = style}; map.Layers.Add(vl); var env = vl.Envelope; env.ExpandBy(-0.45f *env.Width, -0.45 * env.Height); map.ZoomToBox(env); var mapImage = map.GetMap(); mapImage.Save("Example2.png", System.Drawing.Imaging.ImageFormat.Png); }
public void TestCachedLineSymbolizerInTheme() { if (!System.IO.File.Exists("d:\\daten\\GeoFabrik\\Aurich\\roads.shp")) { throw new NUnit.Framework.IgnoreException(""); } var p = new SharpMap.Data.Providers.ShapeFile(@"d:\\daten\\GeoFabrik\\Aurich\\roads.shp", false); var l = new SharpMap.Layers.VectorLayer("roads", p); var theme = new ClsTheme(l.Style); l.Theme = theme; var m = new SharpMap.Map(new System.Drawing.Size(720, 540)) { BackColor = System.Drawing.Color.Cornsilk }; m.Layers.Add(l); m.ZoomToExtents(); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var bmp = m.GetMap(); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("AurichRoads1Theme.bmp"); }
public void TestWarpedLineSymbolizer() { var p = new SharpMap.Data.Providers.ShapeFile(@"d:\\daten\GeoFabrik\\Aurich\\roads.shp", false); var l = new SharpMap.Layers.VectorLayer("roads", p); var cls = new SharpMap.Rendering.Symbolizer.CachedLineSymbolizer(); cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 2) }); cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander { Pattern = SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.GetGreaterSeries(3, 3), Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1) }); l.Style.LineSymbolizer = cls; var m = new SharpMap.Map(new System.Drawing.Size(720, 540)) { BackColor = System.Drawing.Color.Cornsilk }; m.Layers.Add(l); m.ZoomToExtents(); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var bmp = m.GetMap(); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("AurichRoads1.bmp"); cls.LineSymbolizeHandlers[1] = new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander { Pattern = SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.GetTriangleSeries(4, 7), Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1), Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Firebrick) }; sw.Start(); bmp = m.GetMap(); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("AurichRoads2.bmp"); //cls.LineSymbolizeHandlers[0] = cls.LineSymbolizeHandlers[1]; cls.LineSymbolizeHandlers[1] = new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander { Pattern = SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.GetZigZag(4, 4), Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1), //Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Firebrick) }; sw.Start(); bmp = m.GetMap(); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("AurichRoads3.bmp"); }
public void SetupFixture() { SqlConnectionStringBuilder connStrBuilder = new SqlConnectionStringBuilder(UnitTests.Properties.Settings.Default.SqlServer2008); if (string.IsNullOrEmpty(connStrBuilder.DataSource) || string.IsNullOrEmpty(connStrBuilder.InitialCatalog)) { Assert.Ignore("Requires SQL Server connectionstring"); } GeoAPI.GeometryServiceProvider.Instance = new NetTopologySuite.NtsGeometryServices(); // Set up sample table using (SqlConnection conn = new SqlConnection(UnitTests.Properties.Settings.Default.SqlServer2008)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { // The ID column cannot simply be int, because that would cause GetObjectIDsInView to fail. The provider internally works with uint cmd.CommandText = "CREATE TABLE roads_ugl(ID decimal(10,0) identity(1,1) PRIMARY KEY, NAME nvarchar(100), GEOM geometry)"; cmd.ExecuteNonQuery(); } // Load data using (SharpMap.Data.Providers.ShapeFile shapeFile = new SharpMap.Data.Providers.ShapeFile(GetTestFile())) { shapeFile.Open(); IEnumerable <uint> indexes = shapeFile.GetObjectIDsInView(shapeFile.GetExtents()); indexes = indexes.Take(100); foreach (uint idx in indexes) { SharpMap.Data.FeatureDataRow feature = shapeFile.GetFeature(idx); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "INSERT INTO roads_ugl(NAME, GEOM) VALUES (@Name, geometry::STGeomFromText(@Geom, @Srid))"; cmd.Parameters.AddWithValue("@Geom", feature.Geometry.AsText()); cmd.Parameters.AddWithValue("@Name", feature["NAME"]); cmd.Parameters.AddWithValue("@Srid", shapeFile.SRID); cmd.ExecuteNonQuery(); } } } // Create spatial index using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "CREATE SPATIAL INDEX [IX_roads_ugl_GEOM] ON [dbo].[roads_ugl](GEOM)USING GEOMETRY_GRID WITH (BOUNDING_BOX =(-98, 40, -82, 50), GRIDS =(LEVEL_1 = MEDIUM,LEVEL_2 = MEDIUM,LEVEL_3 = MEDIUM,LEVEL_4 = MEDIUM))"; cmd.ExecuteNonQuery(); } } }
public void TestSetUp() { using (var sf = new SharpMap.Data.Providers.ShapeFile(GetTestDataFilePath("roads_ugl.shp"))) { sf.Open(); var fds = new SharpMap.Data.FeatureDataSet(); sf.ExecuteIntersectionQuery(sf.GetExtents(), fds); _provider = new SharpMap.Data.Providers.GeometryFeatureProvider(fds.Tables[0]); } }
public void TestSetUp() { using (var sf = new SharpMap.Data.Providers.ShapeFile(GetTestDataFilePath("roads_ugl.shp"))) { sf.Open(); var fds = new SharpMap.Data.FeatureDataSet(); sf.ExecuteIntersectionQuery(sf.GetExtents(), fds); _provider = new SharpMap.Data.Providers.GeometryFeatureProvider(fds.Tables[0]); } }
public void TestPlainPolygonSymbolizer(string filePath) { filePath = filePath.Replace("\\", new string(System.IO.Path.DirectorySeparatorChar, 1)); if (!System.IO.File.Exists(filePath)) { throw new NUnit.Framework.IgnoreException($"'{filePath}' not found"); } var provider = new SharpMap.Data.Providers.ShapeFile(filePath, true); var l = new SharpMap.Layers.Symbolizer.PolygonalVectorLayer("Countries", provider); l.Symbolizer = new ModifiedBasicPolygonSymbolizer { Fill = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.WideDownwardDiagonal, System.Drawing.Color.Red /*, * System.Drawing.Color.LightPink*/), UseClipping = false, //Outline = System.Drawing.Pens.AliceBlue }; var m = new SharpMap.Map(new System.Drawing.Size(1440, 1080)) { BackColor = System.Drawing.Color.Cornsilk }; m.Layers.Add(l); m.ZoomToExtents(); var sw = new System.Diagnostics.Stopwatch(); var img = m.GetMap(); sw.Start(); img = m.GetMap(); img.Save(System.IO.Path.Combine(UnitTestsFixture.GetImageDirectory(this), "PolygonSymbolizer-1.bmp"), System.Drawing.Imaging.ImageFormat.Bmp); sw.Stop(); System.Diagnostics.Trace.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds)); l.Symbolizer = new SharpMap.Rendering.Symbolizer.BasicPolygonSymbolizer() { Fill = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.WideDownwardDiagonal, System.Drawing.Color.Red /*, * System.Drawing.Color.LightPink*/), UseClipping = false, //Outline = System.Drawing.Pens.AliceBlue }; sw.Reset(); sw.Start(); img = m.GetMap(); img.Save(System.IO.Path.Combine(UnitTestsFixture.GetImageDirectory(this), "PolygonSymbolizer-2.bmp"), System.Drawing.Imaging.ImageFormat.Bmp); sw.Stop(); System.Diagnostics.Trace.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds)); }
public void SetupFixture() { SqlConnectionStringBuilder connStrBuilder = new SqlConnectionStringBuilder(UnitTests.Properties.Settings.Default.SqlServer2008); if (string.IsNullOrEmpty(connStrBuilder.DataSource) || string.IsNullOrEmpty(connStrBuilder.InitialCatalog)) { Assert.Ignore("Requires SQL Server connectionstring"); } GeoAPI.GeometryServiceProvider.Instance = new NetTopologySuite.NtsGeometryServices(); // Set up sample table using (SqlConnection conn = new SqlConnection(UnitTests.Properties.Settings.Default.SqlServer2008)) { conn.Open(); using(SqlCommand cmd = conn.CreateCommand()) { // The ID column cannot simply be int, because that would cause GetOidsInView to fail. The provider internally works with uint cmd.CommandText = "CREATE TABLE roads_ugl(ID decimal(10,0) identity(1,1) PRIMARY KEY, NAME nvarchar(100), GEOM geometry)"; cmd.ExecuteNonQuery(); } // Load data using (SharpMap.Data.Providers.ShapeFile shapeFile = new SharpMap.Data.Providers.ShapeFile(GetTestFile())) { shapeFile.Open(); IEnumerable<uint> indexes = shapeFile.GetOidsInView(shapeFile.GetExtents()); indexes = indexes.Take(100); foreach (uint idx in indexes) { var feature = shapeFile.GetFeatureByOid(idx); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "INSERT INTO roads_ugl(NAME, GEOM) VALUES (@Name, geometry::STGeomFromText(@Geom, @Srid))"; cmd.Parameters.AddWithValue("@Geom", feature.Geometry.AsText()); cmd.Parameters.AddWithValue("@Name", feature.Attributes["NAME"]); cmd.Parameters.AddWithValue("@Srid", shapeFile.SRID); cmd.ExecuteNonQuery(); } } } // Create spatial index using(SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "CREATE SPATIAL INDEX [IX_roads_ugl_GEOM] ON [dbo].[roads_ugl](GEOM)USING GEOMETRY_GRID WITH (BOUNDING_BOX =(-98, 40, -82, 50), GRIDS =(LEVEL_1 = MEDIUM,LEVEL_2 = MEDIUM,LEVEL_3 = MEDIUM,LEVEL_4 = MEDIUM))"; cmd.ExecuteNonQuery(); } } }
public void TestReadPointZShapeFile() { var file = GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp"); var sh = new SharpMap.Data.Providers.ShapeFile(file, true); sh.Open(); var fc = sh.GetFeatureCount(); NUnit.Framework.Assert.AreEqual(4342, fc); NUnit.Framework.Assert.AreEqual(0, sh.GetObjectIDsInView(sh.GetExtents())[0]); var featsInView = sh.GetGeometriesInView(new GeoAPI.Geometries.Envelope(sh.GetExtents())); NUnit.Framework.Assert.AreEqual(4342, featsInView.Count); sh.Close(); }
public void TestBasicLineSymbolizer() { if (!System.IO.File.Exists("d:\\daten\\GeoFabrik\\roads.shp")) { throw new NUnit.Framework.IgnoreException(""); } var p = new SharpMap.Data.Providers.ShapeFile(@"d:\\daten\\GeoFabrik\\roads.shp", false); var l = new SharpMap.Layers.VectorLayer("roads", p); //l.Style.Outline = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 5); l.Style.Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 1); l.Style.EnableOutline = false; var m = new SharpMap.Map(new System.Drawing.Size(1440, 1080)) { BackColor = System.Drawing.Color.Cornsilk }; m.Layers.Add(l); m.ZoomToExtents(); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); m.GetMap(); sw.Stop(); System.Console.WriteLine(string.Format("Rendering old method: {0}ms", sw.ElapsedMilliseconds)); sw.Reset(); sw.Start(); var bmp = m.GetMap(); sw.Stop(); System.Console.WriteLine(string.Format("Rendering old method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("NDSRoads1.bmp"); var cls = new SharpMap.Rendering.Symbolizer.CachedLineSymbolizer(); //cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 5) }); cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 1) }); l.Style.LineSymbolizer = cls; sw.Reset(); sw.Start(); bmp = m.GetMap(); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("NDSRoads2.bmp"); }
public void DoTest() { SharpMap.Data.Providers.ShapeFile sf = new SharpMap.Data.Providers.ShapeFile("cities.shp"); SharpMap.Data.FeatureDataSet fds = new SharpMap.Data.FeatureDataSet(); sf.ExecuteIntersectionQuery(sf.GetExtents(), fds); SharpMap.Data.Providers.FeatureProvider gfp = new SharpMap.Data.Providers.FeatureProvider(fds.Tables[0]); System.Data.DataTable dt = new System.Data.DataTable("external"); dt.Columns.Add("city", typeof(string)); dt.Columns.Add("males", typeof(int)); dt.Columns.Add("females", typeof(int)); }
public void TestGetFeature() { NUnit.Framework.Assert.IsTrue(System.IO.File.Exists(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp")), "Specified shapefile is not present!"); var shp = new SharpMap.Data.Providers.ShapeFile(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp"), false, false); shp.Open(); var feat = shp.GetFeature(0); NUnit.Framework.Assert.IsNotNull(feat); shp.Close(); }
public void TestReadPointZShapeFile() { var file = GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp"); var sh = new SharpMap.Data.Providers.ShapeFile(file, true); var fc = sh.GetFeatureCount(); NUnit.Framework.Assert.AreEqual(4342, fc); sh.Open(); var featsInView = sh.GetGeometriesInView(new GeoAPI.Geometries.Envelope(sh.GetExtents())); NUnit.Framework.Assert.AreEqual(4342, featsInView.Count); sh.Close(); }
public void TestPlainPolygonSymbolizer() { var provider = new SharpMap.Data.Providers.ShapeFile( "..\\..\\..\\WinFormSamples\\GeoData\\World\\countries.shp", true); var l = new SharpMap.Layers.Symbolizer.PolygonalVectorLayer("Countries", provider); l.Symbolizer = new ModifiedBasicPolygonSymbolizer { Fill = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.WideDownwardDiagonal, System.Drawing.Color.Red /*, * System.Drawing.Color.LightPink*/), UseClipping = false, //Outline = System.Drawing.Pens.AliceBlue }; var m = new SharpMap.Map(new System.Drawing.Size(1440, 1080)) { BackColor = System.Drawing.Color.Cornsilk }; m.Layers.Add(l); m.ZoomToExtents(); var sw = new System.Diagnostics.Stopwatch(); var img = m.GetMap(); sw.Start(); img = m.GetMap(); img.Save("PolygonSymbolizer-1.bmp", System.Drawing.Imaging.ImageFormat.Bmp); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds)); l.Symbolizer = new SharpMap.Rendering.Symbolizer.BasicPolygonSymbolizer() { Fill = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.WideDownwardDiagonal, System.Drawing.Color.Red /*, * System.Drawing.Color.LightPink*/), UseClipping = false, //Outline = System.Drawing.Pens.AliceBlue }; sw.Restart(); img = m.GetMap(); img.Save("PolygonSymbolizer-2.bmp", System.Drawing.Imaging.ImageFormat.Bmp); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds)); }
public void TestWarpedLineSymbolizer() { var p = new SharpMap.Data.Providers.ShapeFile(@"d:\\daten\GeoFabrik\\Aurich\\roads.shp", false); var l = new SharpMap.Layers.VectorLayer("roads", p); var cls = new SharpMap.Rendering.Symbolizer.CachedLineSymbolizer(); cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 2) }); cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander { Pattern = SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.GetGreaterSeries(3, 3), Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1) }); l.Style.LineSymbolizer = cls; var m = new SharpMap.Map(new System.Drawing.Size(720, 540)) {BackColor = System.Drawing.Color.Cornsilk}; m.Layers.Add(l); m.ZoomToExtents(); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var bmp = m.GetMap(); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("AurichRoads1.bmp"); cls.LineSymbolizeHandlers[1] = new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander { Pattern = SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.GetTriangleSeries(4, 7), Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1), Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Firebrick) }; sw.Start(); bmp = m.GetMap(); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("AurichRoads2.bmp"); //cls.LineSymbolizeHandlers[0] = cls.LineSymbolizeHandlers[1]; cls.LineSymbolizeHandlers[1] = new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander { Pattern = SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.GetZigZag(4, 4), Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1), //Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Firebrick) }; sw.Start(); bmp = m.GetMap(); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("AurichRoads3.bmp"); }
public void TestReadPointZShapeFile() { string file = TestUtility.GetPathToTestFile("SPATIAL_F_SKARVMUFF.shp"); var sh = new SharpMap.Data.Providers.ShapeFile(file, true); sh.Open(); int fc = sh.GetFeatureCount(); NUnit.Framework.Assert.AreEqual(4342, fc); NUnit.Framework.Assert.AreEqual(0, sh.GetObjectIDsInView(sh.GetExtents())[0]); var featsInView = sh.GetGeometriesInView(new GeoAPI.Geometries.Envelope(sh.GetExtents())); NUnit.Framework.Assert.AreEqual(4342, featsInView.Count); sh.Close(); }
public void TestBasicLineSymbolizer() { var p = new SharpMap.Data.Providers.ShapeFile(GetTestFile(), false); var l = new SharpMap.Layers.VectorLayer("roads", p); //l.Style.Outline = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 5); l.Style.Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 1); l.Style.EnableOutline = false; var m = new SharpMap.Map(new System.Drawing.Size(1440, 1080)) { BackColor = System.Drawing.Color.Cornsilk }; m.Layers.Add(l); m.ZoomToExtents(); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); m.GetMap(); sw.Stop(); System.Diagnostics.Trace.WriteLine(string.Format("Rendering old method: {0}ms", sw.ElapsedMilliseconds)); sw.Reset(); sw.Start(); var bmp = m.GetMap(); sw.Stop(); System.Diagnostics.Trace.WriteLine(string.Format("Rendering old method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save(System.IO.Path.Combine(UnitTestsFixture.GetImageDirectory(this), "NDSRoads1.bmp")); var cls = new SharpMap.Rendering.Symbolizer.CachedLineSymbolizer(); //cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 5) }); cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 1) }); l.Style.LineSymbolizer = cls; sw.Reset(); sw.Start(); bmp = m.GetMap(); sw.Stop(); System.Diagnostics.Trace.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save(System.IO.Path.Combine(UnitTestsFixture.GetImageDirectory(this), "NDSRoads2.bmp")); }
private void transform_Click(object sender, EventArgs e) { if (vlay == null) { return; } if (vlay.DataSource == null) { MessageBox.Show("请先载入shp文件"); } else { if (!vlay.DataSource.IsOpen) { vlay.DataSource.Open(); } SharpMap.Data.Providers.ShapeFile shapefile = (SharpMap.Data.Providers.ShapeFile)vlay.DataSource; int geoCount = shapefile.GetFeatureCount(); string writefile = null; saveFileDialog1.Filter = "(*.txt*)|*.txt"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { writefile = saveFileDialog1.FileName; } if (writefile == null) { MessageBox.Show("输出文件不能为空,请正确选择"); return; } FileStream fs = new FileStream(writefile, FileMode.Append); StreamWriter sw = new StreamWriter(fs, Encoding.Default); for (int i = 0; i < geoCount; i++) { GeoAPI.Geometries.IGeometry geo = shapefile.GetGeometryByID(Convert.ToUInt32(i)); sw.Write(geo + "\n"); } // Console.WriteLine(geo); vlay.DataSource.Close(); sw.Close(); fs.Close(); MessageBox.Show("文件已转换完毕!"); } }
public void TestPlainPolygonSymbolizer() { var provider = new SharpMap.Data.Providers.ShapeFile( "..\\..\\..\\WinFormSamples\\GeoData\\World\\countries.shp", true); var l = new SharpMap.Layers.Symbolizer.PolygonalVectorLayer("Countries", provider); l.Symbolizer = new ModifiedBasicPolygonSymbolizer { Fill = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.WideDownwardDiagonal, System.Drawing.Color.Red /*, System.Drawing.Color.LightPink*/), UseClipping = false, //Outline = System.Drawing.Pens.AliceBlue }; var m = new SharpMap.Map(new System.Drawing.Size(1440, 1080)) { BackColor = System.Drawing.Color.Cornsilk }; m.Layers.Add(l); m.ZoomToExtents(); var sw = new System.Diagnostics.Stopwatch(); var img = m.GetMap(); sw.Start(); img = m.GetMap(); img.Save("PolygonSymbolizer-1.bmp", System.Drawing.Imaging.ImageFormat.Bmp); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds)); l.Symbolizer = new SharpMap.Rendering.Symbolizer.BasicPolygonSymbolizer() { Fill = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.WideDownwardDiagonal, System.Drawing.Color.Red/*, System.Drawing.Color.LightPink*/), UseClipping = false, //Outline = System.Drawing.Pens.AliceBlue }; sw.Reset(); sw.Start(); img = m.GetMap(); img.Save("PolygonSymbolizer-2.bmp", System.Drawing.Imaging.ImageFormat.Bmp); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds)); }
public static void Example1() { var map = new SharpMap.Map(new Size(1280, 1084)); SharpMap.Data.Providers.IProvider provider = new SharpMap.Data.Providers.ShapeFile( @"C:\temp\Data\niedersachsen.shp\railways.shp"); var vl = new SharpMap.Layers.VectorLayer("Railways", provider); map.Layers.Add(vl); map.ZoomToBox(vl.Envelope); var mapImage = map.GetMap(); mapImage.Save("Example1.png", System.Drawing.Imaging.ImageFormat.Png); }
public static void Example3() { var map = new SharpMap.Map(new Size(1280, 1084)); SharpMap.Data.Providers.IProvider provider = new SharpMap.Data.Providers.ShapeFile( @"C:\temp\Data\niedersachsen.shp\railways.shp"); var cls = new SharpMap.Rendering.Symbolizer.CachedLineSymbolizer(); cls.LineSymbolizeHandlers.Add( new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 2) }); var wls = new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander { Pattern = SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer. GetGreaterSeries(3, 3), Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1), Interval = 20 }; cls.LineSymbolizeHandlers.Add(wls); var vl = new SharpMap.Layers.Symbolizer.LinealVectorLayer( "Railways", provider); vl.Symbolizer = cls; map.Layers.Add(vl); var env = vl.Envelope; env.ExpandBy(-0.45f * env.Width, -0.45 * env.Height); map.ZoomToBox(env); var mapImage = map.GetMap(); mapImage.Save("Example3.png", System.Drawing.Imaging.ImageFormat.Png); }
public static void Example1() { var map = new SharpMap.Map(new Size(1280, 1084)); SharpMap.Data.Providers.IProvider provider = new SharpMap.Data.Providers.ShapeFile( @"C:\temp\Data\niedersachsen.shp\railways.shp"); var vl = new SharpMap.Layers.VectorLayer("Railways", provider); map.Layers.Add(vl); map.ZoomToBox(vl.Envelope); var mapImage = map.GetMap(); mapImage.Save("Example1.png", System.Drawing.Imaging.ImageFormat.Png); }
public void TestPerformanceVectorLayer() { NUnit.Framework.Assert.IsTrue(System.IO.File.Exists(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp")), "Specified shapefile is not present!"); var map = new SharpMap.Map(new System.Drawing.Size(1024, 768)); var shp = new SharpMap.Data.Providers.ShapeFile(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp")); var lyr = new SharpMap.Layers.VectorLayer("Roads", shp); map.Layers.Add(lyr); map.ZoomToExtents(); RepeatedRendering(map, shp.GetFeatureCount(), NumberOfRenderCycles, out _msVector); var res = map.GetMap(); var path = System.IO.Path.ChangeExtension(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp"), ".vector.png"); res.Save(path, System.Drawing.Imaging.ImageFormat.Png); System.Console.WriteLine("\nResult saved at file://" + path.Replace('\\', '/')); }
public void TestPerformanceVectorLayer() { NUnit.Framework.Assert.IsTrue(System.IO.File.Exists(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp")), "Specified shapefile is not present!"); var map = new SharpMap.Map(new System.Drawing.Size(1024, 768)); var shp = new SharpMap.Data.Providers.ShapeFile(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp"), false, false); var lyr = new SharpMap.Layers.VectorLayer("Roads", shp); map.Layers.Add(lyr); map.ZoomToExtents(); RepeatedRendering(map, shp.GetFeatureCount(), NumberOfRenderCycles, out _msVector); var res = map.GetMap(); var path = System.IO.Path.ChangeExtension(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp"), ".vector.png"); res.Save(path, System.Drawing.Imaging.ImageFormat.Png); System.Console.WriteLine("\nResult saved at file://" + path.Replace('\\', '/')); }
public void TestCachedLineSymbolizerInTheme() { var p = new SharpMap.Data.Providers.ShapeFile(@"d:\\daten\GeoFabrik\\Aurich\\roads.shp", false); var l = new SharpMap.Layers.VectorLayer("roads", p); var theme = new ClsTheme(l.Style); l.Theme = theme; var m = new SharpMap.Map(new System.Drawing.Size(720, 540)) { BackColor = System.Drawing.Color.Cornsilk }; m.Layers.Add(l); m.ZoomToExtents(); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var bmp = m.GetMap(); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("AurichRoads1Theme.bmp"); }
public void TestExecuteIntersectionQueryWithFilterDelegate() { NUnit.Framework.Assert.IsTrue(System.IO.File.Exists(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp")), "Specified shapefile is not present!"); var shp = new SharpMap.Data.Providers.ShapeFile(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp"), false, false); shp.Open(); var fds = new SharpMap.Data.FeatureDataSet(); var bbox = shp.GetExtents(); //narrow it down bbox.ExpandBy(-0.425 * bbox.Width, -0.425 * bbox.Height); //Just to avoid that initial query does not impose performance penalty shp.DoTrueIntersectionQuery = false; shp.FilterDelegate = JustTracks; shp.ExecuteIntersectionQuery(bbox, fds); fds.Tables.RemoveAt(0); //Perform query once more var sw = new System.Diagnostics.Stopwatch(); sw.Start(); shp.ExecuteIntersectionQuery(bbox, fds); sw.Stop(); System.Console.WriteLine("Queried using just envelopes:\n" + fds.Tables[0].Rows.Count + " in " + sw.ElapsedMilliseconds + "ms."); fds.Tables.RemoveAt(0); shp.DoTrueIntersectionQuery = true; sw.Reset(); sw.Start(); shp.ExecuteIntersectionQuery(bbox, fds); sw.Stop(); System.Console.WriteLine("Queried using prepared geometries:\n" + fds.Tables[0].Rows.Count + " in " + sw.ElapsedMilliseconds + "ms."); }
public static List <Area> Parse(string shapeFilePath) { var gss = new NtsGeometryServices(); var pcs = (ProjectedCoordinateSystem)ProjectedCoordinateSystem.WebMercator; GeoAPI.GeometryServiceProvider.Instance = gss; var shapeFile = new SharpMap.Data.Providers.ShapeFile(shapeFilePath, true); var areas = new List <Area>(); for (var i = 0; i < shapeFile.GetFeatureCount(); i++) { var feature = shapeFile.GetFeature((uint)i); var area = new Area(feature.ItemArray); IEnumerable <IGeometry> geometries = feature.Geometry.GetType() == typeof(MultiPolygon) ? ((MultiPolygon)feature.Geometry).Geometries : feature.Geometry.GetType() == typeof(NetTopologySuite.Geometries.Polygon) ? new IGeometry[] { feature.Geometry } : null; if (geometries == null) { throw new Exception("Don't know geometry type " + feature.Geometry.GetType().FullName); } foreach (var geometry in geometries) { area.polygons.Add(new Polygon() { borders = geometry.Coordinates.Select(CoordFormatter).ToArray() }); } areas.Add(area); } return(areas); }
public void TestShapeFile() { using (var p = new SharpMap.Data.Providers.ShapeFile(@"D:\Daten\kowg\shapefile\Police Authorities_region.shp", true)) { p.Open(); for (uint i = 0; i < p.GetFeatureCount(); i++ ) { var fdr = p.GetFeature(i); try { var res = ToSqlServerAndBack(fdr.Geometry); Assert.AreEqual(fdr.Geometry, res); Console.WriteLine(string.Format("Feature {0} ({1}) converted!", i, fdr[0])); } catch (SqlGeometryConverterException) { Console.WriteLine(string.Format("Feature {0} ({1}) conversion failed!", i, fdr[0])); } } } }
public void TestShapeFile() { using (var p = new SharpMap.Data.Providers.ShapeFile(@"D:\Daten\kowg\shapefile\Police Authorities_region.shp", true)) { p.Open(); for (uint i = 0; i < p.GetFeatureCount(); i++) { var fdr = p.GetFeature(i); try { var res = ToSqlServerAndBack(fdr.Geometry); Assert.AreEqual(fdr.Geometry, res); Console.WriteLine(string.Format("Feature {0} ({1}) converted!", i, fdr[0])); } catch (SqlGeometryConverterException) { Console.WriteLine(string.Format("Feature {0} ({1}) conversion failed!", i, fdr[0])); } } } }
public void TestBasicLineSymbolizer() { var p = new SharpMap.Data.Providers.ShapeFile(@"d:\\daten\GeoFabrik\\roads.shp", false); var l = new SharpMap.Layers.VectorLayer("roads", p); //l.Style.Outline = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 5); l.Style.Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 1); l.Style.EnableOutline = false; var m = new SharpMap.Map(new System.Drawing.Size(1440,1080)) {BackColor = System.Drawing.Color.Cornsilk}; m.Layers.Add(l); m.ZoomToExtents(); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); m.GetMap(); sw.Stop(); System.Console.WriteLine(string.Format("Rendering old method: {0}ms", sw.ElapsedMilliseconds)); sw.Reset(); sw.Start(); var bmp = m.GetMap(); sw.Stop(); System.Console.WriteLine(string.Format("Rendering old method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("NDSRoads1.bmp"); var cls = new SharpMap.Rendering.Symbolizer.CachedLineSymbolizer(); //cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 5) }); cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 1) }); l.Style.LineSymbolizer = cls; sw.Reset(); sw.Start(); bmp = m.GetMap(); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("NDSRoads2.bmp"); }
public static void Example3() { var map = new SharpMap.Map(new Size(1280, 1084)); SharpMap.Data.Providers.IProvider provider = new SharpMap.Data.Providers.ShapeFile( @"C:\temp\Data\niedersachsen.shp\railways.shp"); var cls = new SharpMap.Rendering.Symbolizer.CachedLineSymbolizer(); cls.LineSymbolizeHandlers.Add( new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 2) }); var wls = new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander { Pattern = SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer. GetGreaterSeries(3, 3), Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1), Interval = 20 }; cls.LineSymbolizeHandlers.Add(wls); var vl = new SharpMap.Layers.Symbolizer.LinealVectorLayer( "Railways", provider); vl.Symbolizer = cls; map.Layers.Add(vl); var env = vl.Envelope; env.ExpandBy(-0.45f * env.Width, -0.45 * env.Height); map.ZoomToBox(env); var mapImage = map.GetMap(); mapImage.Save("Example3.png", System.Drawing.Imaging.ImageFormat.Png); }
public void TestDeleteAfterClose() { string test; CopyShapeFile(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp"), out test); var shp = new SharpMap.Data.Providers.ShapeFile(test); shp.Open(); shp.Close(); var succeeded = true; foreach (var file in System.IO.Directory.GetFiles(System.IO.Path.GetDirectoryName(test), System.IO.Path.GetFileNameWithoutExtension(test) + ".*")) { try { System.IO.File.Delete(file); } catch (System.Exception) { System.Console.WriteLine("Failed to delete '{0}'", file); succeeded = false; } } NUnit.Framework.Assert.IsTrue(succeeded); }
public void TestShapeFile() { using (var p = new SharpMap.Data.Providers.ShapeFile(GetTestFile(), true)) { p.Open(); for (uint i = 0; i < p.GetFeatureCount(); i++) { var fdr = p.GetFeature(i); try { fdr.Geometry.SRID = -1; var res = ToSqlServerAndBack(fdr.Geometry); Assert.AreEqual(fdr.Geometry, res); System.Diagnostics.Trace.WriteLine(string.Format("Feature {0} ({1}) converted!", i, fdr[0])); } catch (SqlGeometryConverterException) { System.Diagnostics.Trace.WriteLine(string.Format("Feature {0} ({1}) conversion failed!", i, fdr[0])); } } } }
public static SharpMap.Map InitializeMap(float angle) { var dataSource = new SharpMap.Data.Providers.ShapeFile( string.Format("{0}/roads.shp", ShapefileSample.PathOsm), true); var fds = new SharpMap.Data.FeatureDataSet(); dataSource.Open(); dataSource.ExecuteIntersectionQuery(dataSource.GetExtents(), fds); dataSource.Close(); var gfp = new SharpMap.Data.Providers.GeometryFeatureProvider(fds.Tables[0]); var vl = new SharpMap.Layers.VectorLayer("roads", gfp) { CoordinateTransformation = LayerTools.Dhdn2ToWgs84 }; var ll = new SharpMap.Layers.LabelLayer("labels") { DataSource = gfp, CoordinateTransformation = LayerTools.Dhdn2ToWgs84, LabelColumn = "name", MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest, }; ll.Style.Halo = new System.Drawing.Pen(System.Drawing.Color.Red); //ll.Style.IgnoreLength = true; var map = new SharpMap.Map(); map.Layers.Add(vl); map.Layers.Add(ll); map.Layers.Add(vl); map.ZoomToExtents(); return(map); }
public static void Example2() { var map = new SharpMap.Map(new Size(1280, 1084)); SharpMap.Data.Providers.IProvider provider = new SharpMap.Data.Providers.ShapeFile( @"C:\temp\Data\niedersachsen.shp\railways.shp"); var style = new SharpMap.Styles.VectorStyle(); style.Line.Brush = Brushes.White; style.Line.DashPattern = new float[] { 4f, 4f }; style.Line.Width = 4; style.EnableOutline = true; style.Outline.Brush = Brushes.Black; style.Outline.Width = 6; var vl = new SharpMap.Layers.VectorLayer("Railways", provider) { Style = style }; map.Layers.Add(vl); var env = vl.Envelope; env.ExpandBy(-0.45f * env.Width, -0.45 * env.Height); map.ZoomToBox(env); var mapImage = map.GetMap(); mapImage.Save("Example2.png", System.Drawing.Imaging.ImageFormat.Png); }
public void TestGetFeature() { NUnit.Framework.Assert.IsTrue(System.IO.File.Exists(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp")), "Specified shapefile is not present!"); var shp = new SharpMap.Data.Providers.ShapeFile(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp"), false, false); shp.Open(); var feat = shp.GetFeature(0); NUnit.Framework.Assert.IsNotNull(feat); shp.Close(); }
public void TestStreetDirectionSymbolizer() { var p = new SharpMap.Data.Providers.ShapeFile(@"d:\\daten\GeoFabrik\\Aurich\\roads.shp", false); var l = new SharpMap.Layers.VectorLayer("roads", p); l.Style.Outline = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 7); l.Style.Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 3); l.Style.EnableOutline = true; var sd = new SharpMap.Layers.Symbolizer.LinealVectorLayer("streetd", p, new StreetDirectionSymbolizer() { ArrowLength = 100, RepeatInterval = 500 }); var m = new SharpMap.Map(new System.Drawing.Size(1440, 1080)) { BackColor = System.Drawing.Color.Cornsilk }; m.Layers.Add(l); m.Layers.Add(sd); m.ZoomToExtents(); m.Zoom *= 0.3; var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var bmp = m.GetMap(); sw.Stop(); System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("NDSRoadsSD.bmp"); }
public void DoTest() { SharpMap.Data.Providers.ShapeFile sf = new SharpMap.Data.Providers.ShapeFile("cities.shp"); SharpMap.Data.FeatureDataSet fds = new SharpMap.Data.FeatureDataSet(); sf.ExecuteIntersectionQuery(sf.GetExtents(), fds); SharpMap.Data.Providers.FeatureProvider gfp = new SharpMap.Data.Providers.FeatureProvider(fds.Tables[0]); System.Data.DataTable dt = new System.Data.DataTable("external"); dt.Columns.Add("city", typeof (string)); dt.Columns.Add("males", typeof (int)); dt.Columns.Add("females", typeof (int)); }
public void FixtureSetup() { var connStrBuilder = new NpgsqlConnectionStringBuilder(Properties.Settings.Default.PostGis); if (string.IsNullOrEmpty(connStrBuilder.Host) || string.IsNullOrEmpty(connStrBuilder.Database)) { Assert.Ignore("Requires PostgreSQL connectionstring"); } GeoAPI.GeometryServiceProvider.Instance = new NetTopologySuite.NtsGeometryServices(); try { // Set up sample table using (var conn = new NpgsqlConnection(Properties.Settings.Default.PostGis)) { conn.Open(); // Load data using (var shapeFile = new SharpMap.Data.Providers.ShapeFile(GetTestFile(), false, false, 4326)) { shapeFile.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "SELECT COUNT(*) FROM \"geometry_columns\" WHERE \"f_table_name\" = 'roads_ugl_g' AND \"f_geometry_column\"='geom';"; var count = cmd.ExecuteScalar(); if (Convert.ToInt32(count) > 0) { cmd.CommandText = "SELECT DropGeometryColumn('roads_ugl_g', 'geom');"; cmd.ExecuteNonQuery(); cmd.CommandText = "DROP TABLE roads_ugl_g"; cmd.ExecuteNonQuery(); } // The ID column cannot simply be int, because that would cause GetOidsInView to fail. The provider internally works with uint cmd.CommandText = "CREATE TABLE roads_ugl_g(id integer primary key, name character varying(100));"; cmd.ExecuteNonQuery(); cmd.CommandText = "SELECT AddGeometryColumn('roads_ugl_g', 'geom', " + shapeFile.SRID + ", 'GEOMETRY', 2);"; cmd.ExecuteNonQuery(); } IEnumerable<uint> indexes = shapeFile.GetOidsInView(shapeFile.GetExtents()); _insertedIds = new List<uint>(indexes.Take(100)); using (NpgsqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "INSERT INTO roads_ugl_g(id, name, geom) VALUES (@PId, @PName, @PGeom);"; var @params = cmd.Parameters; @params.AddRange( new[] { new NpgsqlParameter("PId", NpgsqlDbType.Integer), new NpgsqlParameter("PName", NpgsqlDbType.Varchar, 100), new NpgsqlParameter("PGeom", NpgsqlDbType.Bytea) }); var writer = new PostGisWriter(); foreach (var idx in _insertedIds) { var feature = shapeFile.GetFeatureByOid(idx); @params["PId"].NpgsqlValue = (int) idx; @params["PName"].NpgsqlValue = feature.Attributes["NAME"]; @params["PGeom"].NpgsqlValue = writer.Write(feature.Geometry); cmd.ExecuteNonQuery(); } } } } } catch { Assert.Ignore("Failed to connect to PostgreSQL/PostGIS Server"); } }
private void SHP2KML(string shpFile, string kmlFile) { SharpMap.Data.Providers.ShapeFile shp = new SharpMap.Data.Providers.ShapeFile(shpFile); SharpMap.Data.FeatureDataSet fds = new SharpMap.Data.FeatureDataSet(); shp.Open(); shp.ExecuteIntersectionQuery(shp.GetExtents(), fds); System.Data.DataTable dt = fds.Tables[0]; KMLib.KMLRoot kml = new KMLib.KMLRoot(); for (int i = 0; i < dt.Rows.Count; i++ ) { SharpMap.Data.FeatureDataRow row = dt.Rows[i] as SharpMap.Data.FeatureDataRow; StringBuilder description = new StringBuilder(); for (int j = 0; j < dt.Columns.Count; j++) { description.Append("<p><b>" + capitalize(dt.Columns[j].ToString()) + "</b>: " + row[j] + "</p>\n"); } if (row.Geometry is SharpMap.Geometries.Point) { var pointGeom = row.Geometry as SharpMap.Geometries.Point; var placemark = new KMLib.Feature.Placemark(); placemark.Point = new KMLib.Geometry.KmlPoint((float) pointGeom.X, (float) pointGeom.Y); placemark.description = description.ToString(); kml.Document.Add(placemark); } else if (row.Geometry is SharpMap.Geometries.Polygon) { var polygonGeom = row.Geometry as SharpMap.Geometries.Polygon; var placemark = new KMLib.Feature.Placemark(); var polygon = new KMLib.Polygon(); var boundary = new KMLib.BoundaryIs(); foreach (SharpMap.Geometries.Point vertex in polygonGeom.ExteriorRing.Vertices) { boundary.LinearRing.Coordinates.Add(new Core.Geometry.Point3D(vertex.X, vertex.Y)); } boundary.LinearRing.CloseRing(); boundary.LinearRing.Extrude = true; polygon.OuterBoundaryIs = boundary; var interiorRing = new KMLib.BoundaryIs(); for (int j = 0; j < polygonGeom.NumInteriorRing; j++) { foreach (SharpMap.Geometries.Point point in polygonGeom.InteriorRing(j).Vertices) { interiorRing.LinearRing.Coordinates.Add(new Core.Geometry.Point3D(point.X, point.Y)); } interiorRing.LinearRing.CloseRing(); } polygon.InnerBoundaryIs = interiorRing; placemark.Polygon = polygon; kml.Document.Add(placemark); } } kml.Save(kmlFile); shp.Close(); btnConvert.Content = "Done Converting"; }
public void FixtureSetup() { var connStrBuilder = new NpgsqlConnectionStringBuilder(Properties.Settings.Default.PostGis); if (string.IsNullOrEmpty(connStrBuilder.Host) || string.IsNullOrEmpty(connStrBuilder.Database)) { Assert.Ignore("Requires PostgreSQL connectionstring"); } GeoAPI.GeometryServiceProvider.Instance = new NetTopologySuite.NtsGeometryServices(); try { // Set up sample table using (var conn = new NpgsqlConnection(Properties.Settings.Default.PostGis)) { conn.Open(); // Load data using (var shapeFile = new SharpMap.Data.Providers.ShapeFile(GetTestFile())) { shapeFile.SRID = 4326; shapeFile.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "DROP TABLE IF EXISTS roads_ugl"; cmd.ExecuteNonQuery(); // The ID column cannot simply be int, because that would cause GetObjectIDsInView to fail. The provider internally works with uint cmd.CommandText = "CREATE TABLE roads_ugl(id integer primary key, name character varying(100), geog geography);"; cmd.ExecuteNonQuery(); } IEnumerable<uint> indexes = shapeFile.GetObjectIDsInView(shapeFile.GetExtents()); _insertedIds = new List<uint>(indexes.Take(100)); using (NpgsqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "INSERT INTO roads_ugl(id, name, geog) VALUES (@PId, @PName, ST_GeogFromWKB(@PGeom));"; var @params = cmd.Parameters; @params.AddRange( new[] { new NpgsqlParameter("PId", NpgsqlDbType.Integer), new NpgsqlParameter("PName", NpgsqlDbType.Varchar, 100), new NpgsqlParameter("PGeom", NpgsqlDbType.Bytea) }); var writer = new PostGisWriter(); foreach (var idx in _insertedIds) { var feature = shapeFile.GetFeature(idx); @params["PId"].NpgsqlValue = (int)idx; @params["PName"].NpgsqlValue = feature["NAME"]; @params["PGeom"].NpgsqlValue = writer.Write(feature.Geometry); cmd.ExecuteNonQuery(); } } // Verify foreach (var pgp in GetTestProvider()) { foreach (var idx in _insertedIds) { var g1 = pgp.GetGeometryByID(idx); var g2 = shapeFile.GetGeometryByID(idx); Assert.AreEqual(g1, g2); } } } } } catch (Exception ee) { Assert.Ignore("Failed to connect to PostgreSQL/PostGIS Server"); } }
public static SharpMap.Map InitializeMap(float angle) { var dataSource = new SharpMap.Data.Providers.ShapeFile( string.Format("{0}/roads.shp", ShapefileSample.PathOsm), true); var fds = new SharpMap.Data.FeatureDataSet(); dataSource.Open(); dataSource.ExecuteIntersectionQuery(dataSource.GetExtents(), fds); dataSource.Close(); var gfp = new SharpMap.Data.Providers.GeometryFeatureProvider(fds.Tables[0]); var vl = new SharpMap.Layers.VectorLayer("roads", gfp) { CoordinateTransformation = LayerTools.Dhdn2ToWgs84 }; var ll = new SharpMap.Layers.LabelLayer("labels") { DataSource = gfp, CoordinateTransformation = LayerTools.Dhdn2ToWgs84, LabelColumn = "name", MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest, }; ll.Style.Halo = new System.Drawing.Pen(System.Drawing.Color.Red); //ll.Style.IgnoreLength = true; var map = new SharpMap.Map(); map.Layers.Add(vl); map.Layers.Add(ll); map.Layers.Add(vl); map.ZoomToExtents(); return map; }
public void TestPerformanceLinealLayer() { NUnit.Framework.Assert.IsTrue(System.IO.File.Exists(GetTestDataFilePath("roads_ugl.shp")), "Specified shapefile is not present!"); var map = new SharpMap.Map(new System.Drawing.Size(1024, 768)); var shp = new SharpMap.Data.Providers.ShapeFile(GetTestDataFilePath("roads_ugl.shp")); var lyr = new SharpMap.Layers.Symbolizer.LinealVectorLayer("Roads", shp) { Symbolizer = new SharpMap.Rendering.Symbolizer.BasicLineSymbolizer {Line = new System.Drawing.Pen(System.Drawing.Color.Black)} }; map.Layers.Add(lyr); map.ZoomToExtents(); RepeatedRendering(map, shp.GetFeatureCount(), NumberOfRenderCycles, out _msLineal); System.Console.WriteLine("\nWith testing if record is deleted "); shp.CheckIfRecordIsDeleted = true; long tmp; RepeatedRendering(map, shp.GetFeatureCount(), 1, out tmp); var res = map.GetMap(); var path = System.IO.Path.ChangeExtension(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp"), "lineal.png"); res.Save(path, System.Drawing.Imaging.ImageFormat.Png); System.Console.WriteLine("\nResult saved at file://" + path.Replace('\\', '/')); }