Created
December 24, 2022 15:36
-
-
Save lansalot/bc2a0da7bee786269ff5950fb13a065e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rivate void btnSelectShapeFile_Click(object sender, EventArgs e) | |
{ | |
if (dlgShapefile.ShowDialog(this) == DialogResult.OK) | |
{ | |
shapeFileName = dlgShapefile.FileName; | |
if (shapeFileName != null) | |
{ | |
using (Shapefile shapefile = new Shapefile(shapeFileName)) | |
foreach (Shape shape in shapefile) | |
{ | |
switch (shape.Type) | |
{ | |
case ShapeType.Point: | |
// a point is just a single x/y point | |
ShapePoint shapePoint = shape as ShapePoint; | |
//Console.WriteLine("Point={0},{1}", shapePoint.Point.X, shapePoint.Point.Y); | |
break; | |
case ShapeType.Polygon: | |
// a polygon contains one or more parts - each part is a list of points which | |
// are clockwise for boundaries and anti-clockwise for holes | |
// see http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf | |
ShapePolygon shapePolygon = shape as ShapePolygon; | |
foreach (PointD[] part in shapePolygon.Parts) | |
{ | |
var points = new List<GeoPoint>(); | |
var polygon = new Polygon(PolygonStyle.Default); | |
foreach (PointD point in part) | |
{ | |
points.Add(new GeoPoint((float)point.X, (float)point.Y)); | |
} | |
polygon.AddRange(points); | |
mapControl.Polygons.Add(polygon); | |
} | |
break; | |
default: | |
// and so on for other types... | |
break; | |
} | |
mapControl.Refresh(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment