private void RenderShapeOnLayer(Shape shape, MapLayer layer) { switch (shape.Type) { case ShapeType.Point: ShapePoint point = shape as ShapePoint; layer.Children.Add(new Pushpin() { Location = new Location(point.Point.Y, point.Point.X) }); break; case ShapeType.PolyLine: ShapePolyLine polyline = shape as ShapePolyLine; for (int i = 0; i < polyline.Parts.Count; i++) { layer.Children.Add(new MapPolyline() { Locations = PointDArrayToLocationCollection(polyline.Parts[i]), Stroke = new SolidColorBrush(Color.FromArgb(150, 255, 0, 0)) }); } break; case ShapeType.Polygon: ShapePolygon polygon = shape as ShapePolygon; if (polygon.Parts.Count > 0) { //Only render the exterior ring of polygons for now. for (int i = 0; i < polygon.Parts.Count; i++) { //Note that the exterior rings in a ShapePolygon have a Clockwise order if (!IsCCW(polygon.Parts[i])) { layer.Children.Add(new MapPolygon() { Locations = PointDArrayToLocationCollection(polygon.Parts[i]), Fill = new SolidColorBrush(Color.FromArgb(150, 0, 0, 255)), Stroke = new SolidColorBrush(Color.FromArgb(150, 255, 0, 0)) }); } } } break; case ShapeType.MultiPoint: ShapeMultiPoint multiPoint = shape as ShapeMultiPoint; for (int i = 0; i < multiPoint.Points.Length; i++) { layer.Children.Add(new Pushpin() { Location = new Location(multiPoint.Points[i].Y, multiPoint.Points[i].X) }); } break; default: break; } }
static void Main(string[] args) { Shapefile shapefile = new Shapefile("C:/Users/Austin Spurlin/Downloads/tl_2019_29097_roads.shp"); file = new System.IO.StreamWriter("C:/Users/Austin Spurlin/Downloads/output.txt"); Console.WriteLine(); // a shapefile contains one type of shape (and possibly null shapes) Console.WriteLine("Type: {0}, Shapes: {1:n0}", shapefile.Type, shapefile.Count); // a shapefile also defines a bounding box for all shapes in the file Console.WriteLine("Bounds: {0},{1} -> {2},{3}", shapefile.BoundingBox.Left, shapefile.BoundingBox.Top, shapefile.BoundingBox.Right, shapefile.BoundingBox.Bottom); Console.WriteLine(); foreach (Shape shape in shapefile) { //Console.WriteLine("Shape {0:n0}, Type {1}", shape.RecordNumber, shape.Type); String roadType = ""; String name = ""; // each shape may have associated metadata string[] metadataNames = shape.GetMetadataNames(); if (metadataNames != null) { foreach (string metadataName in metadataNames) { if (metadataName.Equals("rttyp")) { roadType = shape.GetMetadata(metadataName); } if (metadataName.Equals("fullname")) { name = shape.GetMetadata(metadataName); } //Console.WriteLine("{0}={1} ({2})", metadataName, shape.GetMetadata(metadataName), shape.DataRecord.GetDataTypeName(shape.DataRecord.GetOrdinal(metadataName))); } } if (name == "") { name = "Unnamed"; } //If the road name ends with TRL, it is a walking trail and should not be included. if (!name.ToUpper().EndsWith("TRL")) { switch (shape.Type) { case ShapeType.PolyLine: ShapePolyLine line = shape as ShapePolyLine; if (line.Parts.Count > 0) { Point lastPoint = null; foreach (PointD coordinate in line.Parts[0]) { Point point = AddPoint(coordinate.Y, coordinate.X); if (lastPoint != null) { JoinPoints(lastPoint, point, name, roadType); } lastPoint = point; } } break; default: Console.WriteLine(name + " is a " + shape.Type); break; } } } List <Point> pointsToRemove = new List <Point>(); foreach (Point point in points) { if (point.paths.Count == 0) { pointsToRemove.Add(point); } file.WriteLine(point.lat + ", " + point.lon + ":"); foreach (Path path in point.paths) { if (path.pointA.Equals(point)) { file.WriteLine(path.name + " (" + path.roadType + ") " + path.pointB); } else { file.WriteLine(path.name + " (" + path.roadType + ") " + path.pointA); } } } while (pointsToRemove.Count > 0) { points.Remove(pointsToRemove[0]); pointsToRemove.RemoveAt(0); } Console.WriteLine("Checking for intersections..."); CheckForIntersections(); Console.WriteLine(); Console.WriteLine("Cleaing up..."); CleanUp(); file.Close(); Console.WriteLine(); Console.WriteLine("Exporting"); Export(); Console.WriteLine(); Console.WriteLine("Creating Diagram"); GenerateDiagram(); Console.WriteLine(); Console.WriteLine("Done"); }