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.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('\\', '/')); }
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(); }
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 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 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 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(); }
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 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 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(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 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.GetFeatureByOid(i); try { var res = ToSqlServerAndBack(fdr.Geometry); Assert.AreEqual(fdr.Geometry, res); Console.WriteLine(string.Format("Feature {0} ({1}) converted!", i, fdr.Attributes[0])); } catch (SqlGeometryConverterException) { Console.WriteLine(string.Format("Feature {0} ({1}) conversion failed!", i, fdr.Attributes[0])); } } } }
// Phuong thuc public int UpdateToDB() { try { GeometryServiceProvider.Instance = new NetTopologySuite.NtsGeometryServices(); // Mo tep tin SharpMap.Data.Providers.ShapeFile map = new SharpMap.Data.Providers.ShapeFile(FileName); map.Open(); String dsCot = ""; int demKQ = 0; // Doc cau truc cua tep tin var feature = map.GetFeature(0); String query = "CREATE TABLE " + SQLTableName + "(ID int Identity(1,1) PRIMARY KEY, "; foreach (DataColumn col in feature.Table.Columns) { if (col.ColumnName.ToLower().Equals("id") || col.ColumnName.ToLower().Equals("oid")) { continue; } dsCot += col.ColumnName + ", "; String type = col.DataType.ToString().ToLower().Split('.')[1]; if (type.Equals("string")) { query += col.ColumnName + " nvarchar(max), "; } else if (type.Equals("int16") || type.Equals("int32") || type.Equals("int64") || type.Equals("uint16") || type.Equals("uint32") || type.Equals("uint64")) { query += col.ColumnName + " int, "; } else if (type.Equals("float") || type.Equals("double")) { query += col.ColumnName + " float, "; } } dsCot += "geom"; query += "geom Geometry)"; da.Write(query); // Doc du lieu tren ban do va cap nhat vao CSDL // INSERT INTO tenBang(ds cot) VALUES(ds gia tri) for (int i = 0; i < map.GetFeatureCount(); i++) { var featurei = map.GetFeature((uint)i); String insertQuery = "INSERT INTO " + SQLTableName + "(" + dsCot + ") VALUES("; String values = ""; foreach (DataColumn col in featurei.Table.Columns) { if (col.ColumnName.ToLower().Equals("oid") || col.ColumnName.ToLower().Equals("id")) { continue; } String type = col.DataType.ToString().ToLower().Split('.')[1]; if (type.ToLower().Equals("string")) { values += "N'" + cv.TCVN3ToUnicode(featurei.ItemArray[col.Ordinal].ToString()) + "', "; } else { if (featurei.ItemArray[col.Ordinal].ToString().Length > 0) { values += featurei.ItemArray[col.Ordinal].ToString() + ", "; } else { values += "0, "; } } } String polygon = featurei.Geometry.ToString(); values += "Geometry::STPolyFromText('" + polygon + "', 4326)"; insertQuery += values + ")"; demKQ += da.Write(insertQuery); } return(demKQ); } catch { return(0); } }
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('\\', '/')); }