public PointShapefile( Shapefile shapefile, Context context, Ellipsoid globeShape, ShapefileAppearance appearance) { Verify.ThrowIfNull(shapefile); Verify.ThrowIfNull(context); Verify.ThrowIfNull(globeShape); Verify.ThrowIfNull(appearance); _billboards = new BillboardCollection(context); _billboards.Texture = Device.CreateTexture2D(appearance.Bitmap, TextureFormat.RedGreenBlueAlpha8, false); foreach (Shape shape in shapefile) { if (shape.ShapeType != ShapeType.Point) { throw new NotSupportedException("The type of an individual shape does not match the Shapefile type."); } Vector2D point = ((PointShape)shape).Position; Vector3D position = globeShape.ToVector3D(Trig.ToRadians(new Geodetic3D(point.X, point.Y))); Billboard billboard = new Billboard(); billboard.Position = position; _billboards.Add(billboard); } }
public static void ThrowIfNull(Shapefile shapefile) { if (shapefile == null) { throw new ArgumentNullException("shapefile"); } }
private static void PolylineCapacities(Shapefile shapefile, out int positionsCount, out int indicesCount) { int numberOfPositions = 0; int numberOfIndices = 0; foreach (Shape shape in shapefile) { if (shape.ShapeType != ShapeType.Polyline) { throw new NotSupportedException("The type of an individual shape does not match the Shapefile type."); } PolylineShape polylineShape = (PolylineShape)shape; for (int j = 0; j < polylineShape.Count; ++j) { ShapePart part = polylineShape[j]; numberOfPositions += part.Count; numberOfIndices += (part.Count - 1) * 2; } } positionsCount = numberOfPositions; indicesCount = numberOfIndices; }
public ShapefileRenderer( string filename, Context context, Ellipsoid globeShape, ShapefileAppearance appearance) { Shapefile shapefile = new Shapefile(filename); switch (shapefile.ShapeType) { case ShapeType.Point: PointShapefile pointShapefile = new PointShapefile(shapefile, context, globeShape, appearance); pointShapefile.DepthWrite = false; _shapefileGraphics = pointShapefile; break; case ShapeType.Polyline: PolylineShapefile polylineShapefile = new PolylineShapefile(shapefile, context, globeShape, appearance); polylineShapefile.DepthWrite = false; _shapefileGraphics = polylineShapefile; break; case ShapeType.Polygon: PolygonShapefile polygonShapefile = new PolygonShapefile(shapefile, context, globeShape, appearance); polygonShapefile.DepthWrite = false; _shapefileGraphics = polygonShapefile; break; default: throw new NotSupportedException("Rendering is not supported for " + shapefile.ShapeType.ToString() + " shapefiles."); } }
public void Polygon() { Shapefile sf = new Shapefile(@"110m_admin_0_countries.shp"); Assert.AreEqual(ShapeType.Polygon, sf.ShapeType); Assert.AreEqual(177, sf.Count); foreach (Shape shape in sf) { Assert.AreEqual(ShapeType.Polygon, shape.ShapeType); PolygonShape polygonShape = (PolygonShape)shape; Assert.Greater(polygonShape.Count, 0); foreach (ShapePart part in polygonShape) { Assert.GreaterOrEqual(part.Count, 4); Assert.AreEqual(part[0], part[part.Count - 1]); } } }
public void PointShape() { Shapefile sf = new Shapefile("amtrakx020.shp"); // // Verify header // Assert.AreEqual(ShapeType.Point, sf.ShapeType); Assert.AreEqual(-124.21199, sf.Extent.LowerLeft.X, 1e-4); Assert.AreEqual(24.5559350038636, sf.Extent.LowerLeft.Y, 1e-13); Assert.AreEqual(-70.290492990603, sf.Extent.UpperRight.X, 1e-13); Assert.AreEqual(50.3315320102401, sf.Extent.UpperRight.Y, 1e-13); // // Verify records // Assert.AreEqual(823, sf.Count); Vector2D[] positions = new Vector2D[sf.Count]; for (int i = 0; i < sf.Count; ++i) { // // This first assert would not hold if the shapefile // contains null shapes, which are filtered out. // Assert.AreEqual(i + 1, sf[i].RecordNumber); Assert.AreEqual(ShapeType.Point, sf[i].ShapeType); positions[i] = ((PointShape)sf[i]).Position; } int j = 0; foreach (Shape shape in sf) { Assert.AreEqual(positions[j++], ((PointShape)shape).Position); } }
public void Polyline() { Shapefile sf = new Shapefile("50m-rivers-lake-centerlines.shp"); // // Verify header // Assert.AreEqual(ShapeType.Polyline, sf.ShapeType); Assert.AreEqual(458, sf.Count); foreach (Shape shape in sf) { Assert.AreEqual(ShapeType.Polyline, shape.ShapeType); PolylineShape polylineShape = (PolylineShape)shape; Assert.Greater(polylineShape.Count, 0); foreach (ShapePart part in polylineShape) { Assert.Greater(part.Count, 0); } } }
public PolygonShapefile( Shapefile shapefile, Context context, Ellipsoid globeShape, ShapefileAppearance appearance) { Verify.ThrowIfNull(shapefile); Verify.ThrowIfNull(context); Verify.ThrowIfNull(globeShape); _polyline = new OutlinedPolylineTexture(); _polygons = new List<Polygon>(); VertexAttributeDoubleVector3 positionAttribute = new VertexAttributeDoubleVector3("position"); VertexAttributeRGBA colorAttribute = new VertexAttributeRGBA("color"); VertexAttributeRGBA outlineColorAttribute = new VertexAttributeRGBA("outlineColor"); IndicesUnsignedInt indices = new IndicesUnsignedInt(); Random r = new Random(3); IList<Vector3D> positions = new List<Vector3D>(); foreach (Shape shape in shapefile) { if (shape.ShapeType != ShapeType.Polygon) { throw new NotSupportedException("The type of an individual shape does not match the Shapefile type."); } PolygonShape polygonShape = (PolygonShape)shape; for (int j = 0; j < polygonShape.Count; ++j) { Color color = Color.FromArgb(127, r.Next(256), r.Next(256), r.Next(256)); positions.Clear(); ShapePart part = polygonShape[j]; for (int i = 0; i < part.Count; ++i) { Vector2D point = part[i]; positions.Add(globeShape.ToVector3D(Trig.ToRadians(new Geodetic3D(point.X, point.Y)))); // // For polyline // positionAttribute.Values.Add(globeShape.ToVector3D(Trig.ToRadians(new Geodetic3D(point.X, point.Y)))); colorAttribute.AddColor(color); outlineColorAttribute.AddColor(Color.Black); if (i != 0) { indices.Values.Add((uint)positionAttribute.Values.Count - 2); indices.Values.Add((uint)positionAttribute.Values.Count - 1); } } try { Polygon p = new Polygon(context, globeShape, positions); p.Color = color; _polygons.Add(p); } catch (ArgumentOutOfRangeException) // Not enough positions after cleaning { } } } Mesh mesh = new Mesh(); mesh.PrimitiveType = PrimitiveType.Lines; mesh.Attributes.Add(positionAttribute); mesh.Attributes.Add(colorAttribute); mesh.Attributes.Add(outlineColorAttribute); mesh.Indices = indices; _polyline.Set(context, mesh); }
public PolylineShapefile( Shapefile shapefile, Context context, Ellipsoid globeShape, ShapefileAppearance appearance) { Verify.ThrowIfNull(shapefile); Verify.ThrowIfNull(context); Verify.ThrowIfNull(globeShape); Verify.ThrowIfNull(appearance); _polyline = new OutlinedPolylineTexture(); int positionsCount = 0; int indicesCount = 0; PolylineCapacities(shapefile, out positionsCount, out indicesCount); VertexAttributeDoubleVector3 positionAttribute = new VertexAttributeDoubleVector3("position", positionsCount); VertexAttributeRGBA colorAttribute = new VertexAttributeRGBA("color", positionsCount); VertexAttributeRGBA outlineColorAttribute = new VertexAttributeRGBA("outlineColor", positionsCount); IndicesUnsignedInt indices = new IndicesUnsignedInt(indicesCount); foreach (Shape shape in shapefile) { if (shape.ShapeType != ShapeType.Polyline) { throw new NotSupportedException("The type of an individual shape does not match the Shapefile type."); } PolylineShape polylineShape = (PolylineShape)shape; for (int j = 0; j < polylineShape.Count; ++j) { ShapePart part = polylineShape[j]; for (int i = 0; i < part.Count; ++i) { Vector2D point = part[i]; positionAttribute.Values.Add(globeShape.ToVector3D(Trig.ToRadians(new Geodetic3D(point.X, point.Y)))); colorAttribute.AddColor(appearance.PolylineColor); outlineColorAttribute.AddColor(appearance.PolylineOutlineColor); if (i != 0) { indices.Values.Add((uint)positionAttribute.Values.Count - 2); indices.Values.Add((uint)positionAttribute.Values.Count - 1); } } } } Mesh mesh = new Mesh(); mesh.PrimitiveType = PrimitiveType.Lines; mesh.Attributes.Add(positionAttribute); mesh.Attributes.Add(colorAttribute); mesh.Attributes.Add(outlineColorAttribute); mesh.Indices = indices; _polyline.Set(context, mesh); _polyline.Width = appearance.PolylineWidth; _polyline.OutlineWidth = appearance.PolylineOutlineWidth; }