private static IPolygon GML2Polygon(XmlNode polygonNode, ISpatialReference sRef) { if (polygonNode == null) { return(null); } Polygon polygon = new Polygon(); if (polygonNode.Name == "Polygon") { foreach (XmlNode coordintes in polygonNode.SelectNodes("outerBoundaryIs/LinearRing/coordinates")) { Ring ring = new Ring(); CoordinatesToPointCollection(coordintes, ring, sRef); if (ring.PointCount > 0) { polygon.AddRing(ring); } } foreach (XmlNode coordintes in polygonNode.SelectNodes("innerBoundaryIs/LinearRing/coordinates")) { Hole hole = new Hole(); CoordinatesToPointCollection(coordintes, hole, sRef); if (hole.PointCount > 0) { polygon.AddRing(hole); } } } else if (polygonNode.Name == "PolygonPatch") { foreach (XmlNode coordintes in polygonNode.SelectNodes("exterior/LinearRing/posList")) { Ring ring = new Ring(); PosListToPointCollection(coordintes, ring, sRef); if (ring.PointCount > 0) { polygon.AddRing(ring); } } foreach (XmlNode coordintes in polygonNode.SelectNodes("interior/LinearRing/posList")) { Hole hole = new Hole(); PosListToPointCollection(coordintes, hole, sRef); if (hole.PointCount > 0) { polygon.AddRing(hole); } } } return(polygon); }
public void Draw(IDisplay display, IGeometry geometry) { Polygon p = new Polygon(); p.AddRing(display.Envelope.ToPolygon(0)[0]); if (geometry is IPolygon) { for (int i = 0; i < ((IPolygon)geometry).RingCount; i++) { var ring = ((IPolygon)geometry)[i]; if (SpatialAlgorithms.Algorithm.Intersects(display.Envelope, new Polygon(ring))) { p.AddRing(ring); } } } else if (geometry is IAggregateGeometry) { for (int g = 0; g < ((IAggregateGeometry)geometry).GeometryCount; g++) { if (((IAggregateGeometry)geometry)[g] is IPolygon) { IPolygon poly = (IPolygon)((IAggregateGeometry)geometry)[g]; for (int i = 0; i < poly.RingCount; i++) { var ring = poly[i]; if (SpatialAlgorithms.Algorithm.Intersects(display.Envelope, new Polygon(ring))) { p.AddRing(ring); } } } else { return; } } } var gp = DisplayOperations.Geometry2GraphicsPath(display, p); if (gp != null) { this.FillPath(display, gp); gp.Dispose(); gp = null; } }
private static IPolygon Clip_polygon_ToPolygon(Clip_polygon Clip_polygon) { Polygon polygon = new Polygon(); if (Clip_polygon.num_contours == 0) { return(new Polygon()); } short[] holeShort = new short[Clip_polygon.num_contours]; Marshal.Copy(Clip_polygon.hole, holeShort, 0, Clip_polygon.num_contours); IntPtr ptr = Clip_polygon.contour; for (int i = 0; i < Clip_polygon.num_contours; i++) { Clip_vertex_list Clip_vtx_lst = (Clip_vertex_list)Marshal.PtrToStructure(ptr, typeof(Clip_vertex_list)); IRing ring = ((holeShort[i] == 0) ? new Ring() : new Hole()); IntPtr ptr2 = Clip_vtx_lst.vertex; for (int j = 0; j < Clip_vtx_lst.num_vertices; j++) { Clip_vertex Clip_vtx = (Clip_vertex)Marshal.PtrToStructure(ptr2, typeof(Clip_vertex)); ring.AddPoint(new gView.Framework.Geometry.Point( Clip_vtx.x, Clip_vtx.y)); ptr2 = IntPtrPlus(ptr2, Marshal.SizeOf(Clip_vtx)); //(IntPtr)(((int)ptr2) + Marshal.SizeOf(Clip_vtx)); } polygon.AddRing(ring); ptr = IntPtrPlus(ptr, Marshal.SizeOf(Clip_vtx_lst)); //(IntPtr)(((int)ptr) + Marshal.SizeOf(Clip_vtx_lst)); } return(polygon); }
public GeomPolygon(IEnvelope envelope) { Polygon polygon = new Polygon(); Ring ring = new Ring(); ring.AddPoint(new gView.Framework.Geometry.Point(envelope.minx, envelope.miny)); ring.AddPoint(new gView.Framework.Geometry.Point(envelope.minx, envelope.maxy)); ring.AddPoint(new gView.Framework.Geometry.Point(envelope.maxx, envelope.maxy)); ring.AddPoint(new gView.Framework.Geometry.Point(envelope.maxx, envelope.miny)); ring.AddPoint(new gView.Framework.Geometry.Point(envelope.minx, envelope.miny)); polygon.AddRing(ring); NofContours = polygon.RingCount; ContourIsHole = new bool[NofContours]; Contour = new GeomVertexList[NofContours]; for (int i = 0; i < NofContours; i++) { ContourIsHole[i] = (i != 0); } for (int i = 0; i < polygon.RingCount; i++) { Contour[i] = new GeomVertexList(polygon[i]); } }
public Text() { _symbol = new SimpleTextSymbol(); _symbol.Font = Current.Engine.CreateFont("Arial", 20); _symbol.Text = _text; _symbol.TextSymbolAlignment = TextSymbolAlignment.leftAlignOver; //this.Symbol = _symbol; AggregateGeometry aGeometry = new AggregateGeometry(); Polygon polygon = new Polygon(); Ring ring = new Ring(); ring.AddPoint(new Point(0, 0)); ring.AddPoint(new Point(1, 0)); ring.AddPoint(new Point(1, 1)); ring.AddPoint(new Point(0, 1)); polygon.AddRing(ring); aGeometry.AddGeometry(polygon); aGeometry.AddGeometry(new Point(0, 0)); this.Template = aGeometry; RemoveAllGrabbers(); AddGrabber(GrabberIDs.rotation); AddGrabber(GrabberIDs.move); }
private void writeFDB_FC_Index_nodes(DualTreeNode dnode, List <SpatialIndexNode> nodes, int NID, int PID) { SpatialIndexNode node = new SpatialIndexNode(); Polygon p = new Polygon(); Ring ring = new Ring(); ring.AddPoint(new Point(dnode.Bounds.minx, dnode.Bounds.miny)); //ring.AddPoint(new Point(node.Bounds.maxx,node.Bounds.miny)); ring.AddPoint(new Point(dnode.Bounds.maxx, dnode.Bounds.maxy)); //ring.AddPoint(new Point(node.Bounds.minx,node.Bounds.maxy)); //ring.AddPoint(new Point(node.Bounds.minx,node.Bounds.miny)); p.AddRing(ring); node.Rectangle = p; node.NID = NID; node.PID = PID; node.Page = dnode.page; node.IDs = dnode.ShapeIds; nodes.Add(node); foreach (DualTreeNode subNode in dnode.SubNodes) { writeFDB_FC_Index_nodes(subNode, nodes, _NID++, NID); } }
static public Polygon ToPolygon(this GeoJSON.Net.Geometry.MultiPolygon geoJsonMultiPolygon) { var polygon = new Polygon(); if (geoJsonMultiPolygon?.Coordinates != null) { foreach (var geoJsonPolygon in geoJsonMultiPolygon.Coordinates) { if (geoJsonPolygon?.Coordinates != null) { foreach (var geoJsonLineString in geoJsonPolygon.Coordinates) { if (geoJsonLineString?.Coordinates != null) { var ring = new Ring(); polygon.AddRing(ring); foreach (var position in geoJsonLineString.Coordinates) { ring.AddPoint(new Point(position.Longitude, position.Latitude)); } } } } } } return(polygon); }
protected override object ShapeParameterValue(OgcSpatialFeatureclass fClass, gView.Framework.Geometry.IGeometry shape, int srid, out bool AsSqlParameter) { if (shape is IPolygon) { #region Check Polygon Rings IPolygon p = new Polygon(); for (int i = 0; i < ((IPolygon)shape).RingCount; i++) { IRing ring = ((IPolygon)shape)[i]; if (ring != null && ring.Area > 0D) { p.AddRing(ring); } } if (p.RingCount == 0) { AsSqlParameter = true; return(null); } shape = p; #endregion } else if (shape is IPolyline) { #region Check Polyline Paths IPolyline l = new Polyline(); for (int i = 0; i < ((IPolyline)shape).PathCount; i++) { IPath path = ((IPolyline)shape)[i]; if (path != null && path.Length > 0D) { l.AddPath(path); } } if (l.PathCount == 0) { AsSqlParameter = true; return(null); } shape = l; #endregion } AsSqlParameter = false; //return gView.Framework.OGC.OGC.GeometryToWKB(shape, gView.Framework.OGC.OGC.WkbByteOrder.Ndr); string geometryString = (shape is IPolygon) ? "geometry::STGeomFromText('" + gView.Framework.OGC.WKT.ToWKT(shape) + "'," + srid + ").MakeValid()" : "geometry::STGeomFromText('" + gView.Framework.OGC.WKT.ToWKT(shape) + "'," + srid + ")"; return(geometryString); //return "geometry::STGeomFromText('" + geometryString + "',0)"; }
public IPolygon ToPolygon() { Polygon polygon = new Polygon(); for (int i = 0; i < NofContours; i++) { polygon.AddRing(Contour[i].ToRing()); } return(polygon); }
public void ThrowsErrorOnLessThanThreePointsInRingOnAdd() { var rings = new List <RingPoint[]> { new[] { new RingPoint(0, 0), new RingPoint(1, 0) } }; var polygon = new Polygon(); Assert.Throws <ArgumentException>(() => polygon.AddRing(rings)); }
public void ThrowsErrorOnLessThanThreePointsInRingOnAdd() { var rings = new List <RingPoint[]> { new[] { new RingPoint(0, 0), new RingPoint(1, 0) } }; var polygon = new Polygon(); polygon.AddRing(rings); }
private static Polygon CreatePolygon(BinaryReader reader, WkbByteOrder byteOrder, bool hasZ, bool hasM) { // Get the Number of rings in this Polygon. int numRings = (int)ReadUInt32(reader, byteOrder); Polygon polygon = new Polygon(); for (int i = 0; i < numRings; i++) { Ring ring = new Ring(); ReadPointCollection(reader, byteOrder, ring, hasZ, hasM); polygon.AddRing(ring); } return(polygon); }
public void CanAddRing() { var polygon = new Polygon(); var rings = new List <RingPoint[]> { new[] { new RingPoint(0, 0), new RingPoint(1, 0), new RingPoint(2, 0), new RingPoint(0, 0) } }; polygon.AddRing(rings); Assert.That(polygon.Rings, Is.EquivalentTo(rings)); }
public Polygon CreatePolygon(int width, int height) { Polygon polygon = new Polygon(); Ring ring = new Ring(); gView.Framework.Geometry.Point p1 = new gView.Framework.Geometry.Point( X - dx_X / 2.0 - dy_X / 2.0, Y - dx_Y / 2.0 - dy_Y / 2.0); ring.AddPoint(p1); ring.AddPoint(new gView.Framework.Geometry.Point(p1.X + dx_X * width, p1.Y + dx_Y * width)); ring.AddPoint(new gView.Framework.Geometry.Point(p1.X + dx_X * width + dy_X * height, p1.Y + dx_Y * width + dy_Y * height)); ring.AddPoint(new gView.Framework.Geometry.Point(p1.X + dy_X * height, p1.Y + dy_Y * height)); polygon.AddRing(ring); return(polygon); }
public Polygon CreatePolygon() { Polygon polygon = new Polygon(); Ring ring = new Ring(); gView.Framework.Geometry.Point p1 = new gView.Framework.Geometry.Point( X - dx1 / 2.0 - dy1 / 2.0, Y - dx2 / 2.0 - dy2 / 2.0); ring.AddPoint(p1); ring.AddPoint(new gView.Framework.Geometry.Point(p1.X + dx1 * iWidth, p1.Y + dx2 * iWidth)); ring.AddPoint(new gView.Framework.Geometry.Point(p1.X + dx1 * iWidth + dy1 * iHeight, p1.Y + dx2 * iWidth + dy2 * iHeight)); ring.AddPoint(new gView.Framework.Geometry.Point(p1.X + dy1 * iHeight, p1.Y + dy2 * iHeight)); polygon.AddRing(ring); return(polygon); }
static public Polygon ToPolygon(this ClipperPolygons clipperPolygons) { Polygon result = new Polygon(); foreach (var clipperRing in clipperPolygons) { var ring = new Ring(); foreach (var clipperPoint in clipperRing) { ring.AddPoint(clipperPoint.ToPoint()); } result.AddRing(ring); } return result; }
public Rectangle() { SimpleFillSymbol fillSymbol = new SimpleFillSymbol(); fillSymbol.Color = ArgbColor.FromArgb(40, 255, 255, 100); SimpleLineSymbol lineSymbol = new SimpleLineSymbol(); fillSymbol.OutlineSymbol = lineSymbol; this.Symbol = fillSymbol; Polygon polygon = new Polygon(); Ring ring = new Ring(); ring.AddPoint(new Point(0, 0)); ring.AddPoint(new Point(1, 0)); ring.AddPoint(new Point(1, 1)); ring.AddPoint(new Point(0, 1)); polygon.AddRing(ring); this.Template = polygon; }
public Ellipse() { SimpleFillSymbol fillSymbol = new SimpleFillSymbol(); fillSymbol.Color = ArgbColor.FromArgb(60, 255, 255, 100); SimpleLineSymbol lineSymbol = new SimpleLineSymbol(); fillSymbol.OutlineSymbol = lineSymbol; this.Symbol = fillSymbol; Polygon polygon = new Polygon(); Ring ring = new Ring(); for (double w = 0; w < 2.0 * Math.PI; w += 2.0 * Math.PI / 50) { ring.AddPoint(new Point(0.5 + 0.5 * Math.Cos(w), 0.5 + 0.5 * Math.Sin(w))); } polygon.AddRing(ring); this.Template = polygon; }
private static IGeometry GeometryFromSymbol(ISymbol symbol, IEnvelope env) { IGeometry geometry = null; if (symbol is ISymbolCollection) { if (((ISymbolCollection)symbol).Symbols.Count > 0) { geometry = GeometryFromSymbol(((ISymbolCollection)symbol).Symbols[0].Symbol, env); } } else if (symbol is IPointSymbol || symbol is ITextSymbol) { geometry = new gView.Framework.Geometry.Point((env.minx + env.maxx) / 2, Math.Abs(env.miny - env.maxy) / 2); } else if (symbol is ILineSymbol) { IPoint p1 = new gView.Framework.Geometry.Point(env.minx + 5, Math.Abs(env.miny - env.maxy) / 2); IPoint p2 = new gView.Framework.Geometry.Point(env.maxx - 5, Math.Abs(env.miny - env.maxy) / 2); IPath path = new Path(); path.AddPoint(p1); path.AddPoint(p2); IPolyline line = new Polyline(); line.AddPath(path); geometry = line; } else if (symbol is IFillSymbol) { IPoint p1 = new gView.Framework.Geometry.Point(env.minx + 5, 5); IPoint p2 = new gView.Framework.Geometry.Point(env.maxx - 5, 5); IPoint p3 = new gView.Framework.Geometry.Point(env.maxx - 5, Math.Abs(env.miny - env.maxy) - 5); IPoint p4 = new gView.Framework.Geometry.Point(env.minx + 5, Math.Abs(env.miny - env.maxy) - 5); IRing ring = new Ring(); ring.AddPoint(p1); ring.AddPoint(p2); ring.AddPoint(p3); ring.AddPoint(p4); IPolygon polygon = new Polygon(); polygon.AddRing(ring); geometry = polygon; } return(geometry); }
public void TristripToPolyons(ref List <IPolygon> polygons) { if (polygons == null) { return; } for (int i = 0; i < NofVertices - 2; i++) { Polygon poly = new Polygon(); Ring ring = new Ring(); ring.AddPoint(new gView.Framework.Geometry.Point( Vertex[i].X, Vertex[i].Y)); ring.AddPoint(new gView.Framework.Geometry.Point( Vertex[i + 1].X, Vertex[i + 1].Y)); ring.AddPoint(new gView.Framework.Geometry.Point( Vertex[i + 2].X, Vertex[i + 2].Y)); poly.AddRing(ring); polygons.Add(poly); } }
private static Polygon CreateMultiPolygon(BinaryReader reader, WkbByteOrder byteOrder, bool hasZ, bool hasM) { int numPolygons = (int)ReadUInt32(reader, byteOrder); // Create a new array for the Polygons. Polygon polygon = new Polygon(); // Loop on the number of polygons. for (int i = 0; i < numPolygons; i++) { // read polygon header reader.ReadByte(); ReadUInt32(reader, byteOrder); // TODO: Validate type Polygon p = CreatePolygon(reader, byteOrder, hasZ, hasM); for (int r = 0; r < p.RingCount; r++) { polygon.AddRing(p[r]); } } return(polygon); }
public Arrow() { SimpleFillSymbol fillSymbol = new SimpleFillSymbol(); fillSymbol.Color = System.Drawing.Color.FromArgb(60, 255, 255, 100); SimpleLineSymbol lineSymbol = new SimpleLineSymbol(); fillSymbol.OutlineSymbol = lineSymbol; this.Symbol = fillSymbol; Polygon polygon = new Polygon(); Ring ring = new Ring(); ring.AddPoint(new Point(0, 0.33)); ring.AddPoint(new Point(0.66, 0.33)); ring.AddPoint(new Point(0.66, 0)); ring.AddPoint(new Point(1, 0.5)); ring.AddPoint(new Point(0.66, 1)); ring.AddPoint(new Point(0.66, 0.66)); ring.AddPoint(new Point(0, 0.66)); polygon.AddRing(ring); this.Template = polygon; }
static public IGeometry ToGeometry(this JObject jObject) { if (jObject != null) { var type = jObject["type"].Value <string>()?.ToLower(); if (type == "point") { var coordinates = (JArray)jObject["coordinates"]; return(new Point( coordinates[0].Value <double>(), coordinates[1].Value <double>())); } if (type == "polygon") { var polygon = new Polygon(); var jsonRings = (JArray)jObject["coordinates"]; foreach (JArray jsonRing in jsonRings) { var ring = new Ring(); foreach (JArray jsonPoint in jsonRing) { ring.AddPoint(new Point( jsonPoint[0].Value <double>(), jsonPoint[1].Value <double>())); } if (ring.PointCount > 0) { polygon.AddRing(ring); } } return(polygon); } } return(null); }
private IGeometry ReadGeometry(ShapeType sType) { int numPoints = 0, numParts = 0; int[] parts; IGeometry geometry = null; switch (sType) { case ShapeType.NullShape: break; case ShapeType.Point: geometry = new Point(_shp.ReadDouble(), _shp.ReadDouble()); break; case ShapeType.PointM: geometry = new Point(_shp.ReadDouble(), _shp.ReadDouble()); //double m = _shp.ReadDouble(); break; case ShapeType.PointZ: geometry = new Point(_shp.ReadDouble(), _shp.ReadDouble(), _shp.ReadDouble()); //double m=_shp.ReadDouble(); break; case ShapeType.MultiPointZ: case ShapeType.MultiPointM: case ShapeType.MultiPoint: MultiPoint mPoint = new MultiPoint(); _shp.BaseStream.Position += 32; // BoundingBox numPoints = _shp.ReadInt32(); ReadPoints(numPoints, (PointCollection)mPoint); if (sType == ShapeType.MultiPointZ) { ReadZRange(); ReadZ(mPoint); } if (sType == ShapeType.MultiPointM || sType == ShapeType.MultiPointZ) { ReadMRange(); ReadM(mPoint); } geometry = mPoint; break; case ShapeType.PolyLineM: case ShapeType.PolyLineZ: case ShapeType.PolyLine: _shp.BaseStream.Position += 32; // BoundingBox numParts = _shp.ReadInt32(); numPoints = _shp.ReadInt32(); parts = ReadParts(numParts); Polyline polyline = new Polyline(); for (int i = 0; i < numParts; i++) { gView.Framework.Geometry.Path path = new gView.Framework.Geometry.Path(); ReadPart(i, parts, numPoints, path); polyline.AddPath(path); } if (sType == ShapeType.PolyLineZ) { ReadZRange(); for (int i = 0; i < polyline.PathCount; i++) { ReadZ(polyline[i]); } } if (sType == ShapeType.PolyLineM /* || sType == ShapeType.PolyLineZ*/) { ReadMRange(); for (int i = 0; i < polyline.PathCount; i++) { ReadM(polyline[i]); } } geometry = polyline; break; case ShapeType.PolygonM: case ShapeType.PolygonZ: case ShapeType.Polygon: _shp.BaseStream.Position += 32; // BoundingBox numParts = _shp.ReadInt32(); numPoints = _shp.ReadInt32(); parts = ReadParts(numParts); Polygon polygon = new Polygon(); for (int i = 0; i < numParts; i++) { Ring ring = new Ring(); ReadPart(i, parts, numPoints, ring); polygon.AddRing(ring); } if (sType == ShapeType.PolygonZ) { ReadZRange(); for (int i = 0; i < polygon.RingCount; i++) { ReadZ(polygon[i]); } } if (sType == ShapeType.PolygonM || sType == ShapeType.PolygonZ) { ReadMRange(); for (int i = 0; i < polygon.RingCount; i++) { ReadM(polygon[i]); } } geometry = polygon; break; } return(geometry); }
virtual public void DrawGrabbers(IDisplay display) { IMultiPoint grabbers = Grabbers(display, true); if (grabbers == null) { return; } System.Drawing.Drawing2D.SmoothingMode smode = display.GraphicsContext.SmoothingMode; display.GraphicsContext.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; SimplePointSymbol pointSymbol = new SimplePointSymbol(); pointSymbol.Color = System.Drawing.Color.White; pointSymbol.OutlineColor = System.Drawing.Color.Black; pointSymbol.OutlineWidth = 1; pointSymbol.Size = 8; if (display.GraphicsContainer.EditMode == GrabberMode.Pointer) { Ring ring = new Ring(); for (int i = 0; i < Math.Min(grabbers.PointCount, 4); i++) { ring.AddPoint(grabbers[i]); } Polygon polygon = new Polygon(); polygon.AddRing(ring); SimpleLineSymbol lSymbol = new SimpleLineSymbol(); lSymbol.Color = System.Drawing.Color.Gray; lSymbol.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; display.Draw(lSymbol, polygon); lSymbol.Release(); for (int i = 0; i < grabbers.PointCount; i++) { if (!UseGrabber((GrabberIDs)i)) { continue; } if (i > 7 && pointSymbol.Color == System.Drawing.Color.White) { pointSymbol.Color = System.Drawing.Color.Yellow; DrawRotationGrabberline(display); } display.Draw(pointSymbol, grabbers[i]); } } else if (display.GraphicsContainer.EditMode == GrabberMode.Vertex) { pointSymbol.Marker = SimplePointSymbol.MarkerType.Square; pointSymbol.Size = 5; for (int i = 0; i < grabbers.PointCount; i++) { display.Draw(pointSymbol, grabbers[i]); } } display.GraphicsContext.SmoothingMode = smode; }
public static IGeometry GetGeometry2D(ShapeLib.SHPObject obj) { if (obj == null) { return(null); } int parts = obj.nParts; int verts = obj.nVertices; int part = 0, nextp = 0; double[] X = new double[verts]; double[] Y = new double[verts]; int[] pStart = new int[parts]; unsafe { int *pstart = (int *)obj.paPartStart.ToPointer(); //ShapeLib.PartType * pType =(ShapeLib.PartType *)obj.paPartType.ToPointer(); double *x = (double *)obj.padfX; double *y = (double *)obj.padfY; for (int i = 0; i < verts; i++) { X[i] = x[i]; Y[i] = y[i]; } for (int i = 0; i < parts; i++) { pStart[i] = pstart[i]; } } switch (obj.shpType) { case ShapeLib.ShapeType.Point: case ShapeLib.ShapeType.PointM: case ShapeLib.ShapeType.PointZ: return(new Point(X[0], Y[0])); case ShapeLib.ShapeType.PolyLine: case ShapeLib.ShapeType.PolyLineM: case ShapeLib.ShapeType.PolyLineZ: IPolyline polyline = new Polyline(); IPath path = null; for (int v = 0; v < verts; v++) { if (path != null && nextp == v) { polyline.AddPath(path); path = null; } if (path == null) { if (parts <= part + 1) { nextp = verts; } else { nextp = pStart[part + 1]; part++; } path = new gView.Framework.Geometry.Path(); } path.AddPoint(new Point(X[v], Y[v])); } polyline.AddPath(path); X = Y = null; return(polyline); case ShapeLib.ShapeType.Polygon: case ShapeLib.ShapeType.PolygonM: case ShapeLib.ShapeType.PolygonZ: IPolygon polygon = new Polygon(); IRing ring = null; for (int v = 0; v < verts; v++) { if (ring != null && nextp == v) { polygon.AddRing(ring); ring = null; } if (ring == null) { if (parts <= part + 1) { nextp = verts; } else { nextp = pStart[part + 1]; part++; } ring = new Ring(); } ring.AddPoint(new Point(X[v], Y[v])); } polygon.AddRing(ring); X = Y = null; return(polygon); } return(null); }
private IGeometry FetchShape(System.Int16 index) { unsafe { System.Int32 err_no = 0; SE_SHAPE shape_val = new SE_SHAPE(); System.Int32 *part_offsets = null; System.Int32 *subp_offsets = null; SE_POINT * points = null; try { err_no = Wrapper10.SE_shape_create(new SE_COORDREF(), ref shape_val); if (err_no != 0) { return(null); } err_no = Wrapper10.SE_stream_get_shape(_stream.SeStream, index, shape_val); if (err_no != 0) { return(null); } Int32 shapeType = 0, numPoints = 0, numParts = 0, numSubparts = 0; err_no = Wrapper10.SE_shape_get_type(shape_val, ref shapeType); if (err_no != 0 || shapeType == CONST.SG_NIL_SHAPE) { return(null); } err_no = Wrapper10.SE_shape_get_num_points(shape_val, 0, 0, ref numPoints); if (err_no != 0) { return(null); } err_no = Wrapper10.SE_shape_get_num_parts(shape_val, ref numParts, ref numSubparts); if (err_no != 0) { return(null); } part_offsets = (System.Int32 *)Marshal.AllocHGlobal(((int)numParts + 1) * sizeof(System.Int32)); subp_offsets = (System.Int32 *)Marshal.AllocHGlobal(((int)numSubparts + 1) * sizeof(System.Int32)); points = (SE_POINT *)Marshal.AllocHGlobal((int)numPoints * sizeof(SE_POINT)); part_offsets[numParts] = (int)numSubparts; subp_offsets[numSubparts] = (int)numPoints; err_no = Wrapper10.SE_shape_get_all_points( shape_val, SE_ROTATION_TYPE.SE_DEFAULT_ROTATION, (IntPtr)part_offsets, (IntPtr)subp_offsets, (IntPtr)points, (IntPtr)null, (IntPtr)null); if (err_no != 0) { return(null); } IGeometry ret = null; switch (shapeType) { case CONST.SG_POINT_SHAPE: if (numPoints == 1) { ret = new Point(points[0].x, points[0].y); } else if (numPoints > 1) { MultiPoint mPoint_ = new MultiPoint(); for (int i = 0; i < numPoints; i++) { mPoint_.AddPoint(new Point(points[i].x, points[i].y)); } ret = mPoint_; } break; case CONST.SG_MULTI_POINT_SHAPE: MultiPoint mPoint = new MultiPoint(); for (int i = 0; i < numPoints; i++) { mPoint.AddPoint(new Point(points[i].x, points[i].y)); } ret = mPoint; break; case CONST.SG_LINE_SHAPE: case CONST.SG_SIMPLE_LINE_SHAPE: case CONST.SG_MULTI_LINE_SHAPE: case CONST.SG_MULTI_SIMPLE_LINE_SHAPE: Polyline polyline = new Polyline(); for (int s = 0; s < numSubparts; s++) { Path path = new Path(); int to = subp_offsets[s + 1]; for (int i = subp_offsets[s]; i < to; i++) { path.AddPoint(new Point(points[i].x, points[i].y)); } polyline.AddPath(path); } ret = polyline; break; case CONST.SG_AREA_SHAPE: case CONST.SG_MULTI_AREA_SHAPE: Polygon polygon = new Polygon(); for (int s = 0; s < numSubparts; s++) { Ring ring = new Ring(); int to = subp_offsets[s + 1]; for (int i = subp_offsets[s]; i < to; i++) { ring.AddPoint(new Point(points[i].x, points[i].y)); } polygon.AddRing(ring); } ret = polygon; break; } return(ret); } catch { return(null); } finally { if (part_offsets != null) { Marshal.FreeHGlobal((System.IntPtr)part_offsets); } if (subp_offsets != null) { Marshal.FreeHGlobal((System.IntPtr)subp_offsets); } if (points != null) { Marshal.FreeHGlobal((System.IntPtr)points); } if (shape_val.handle != IntPtr.Zero) { Wrapper10.SE_shape_free(shape_val); } } } }
private void Run() { if (_targetDataset == null || _fdb == null || _sourceDataset == null) { return; } //if (_targetDataset[_name] != null) //{ // MessageBox.Show("Featureclass '" + _name + "' already exists!"); // return; //} bool succeeded = false; try { Envelope bounds = new Envelope(_spatialIndexDef.SpatialIndexBounds); Envelope iBounds = new Envelope(bounds.minx - _tileSizeX, bounds.miny - _tileSizeY, bounds.maxx + _tileSizeX, bounds.maxy + _tileSizeY); _cacheDirectory += @"\" + _name; if (!String.IsNullOrEmpty(_cacheDirectory)) { DirectoryInfo di = new DirectoryInfo(_cacheDirectory); if (!di.Exists) { di.Create(); } StringBuilder sb = new StringBuilder(); sb.Append("<TileCacheDefinition>\r\n"); sb.Append(" <General levels='" + _levels + "' origin='lowerleft' />\r\n"); sb.Append(" <Envelope minx='" + bounds.minx.ToString(_nhi) + "' miny='" + bounds.miny.ToString(_nhi) + "' maxx='" + bounds.maxx.ToString(_nhi) + "' maxy='" + bounds.maxy.ToString(_nhi) + "' />\r\n"); sb.Append(" <TileSize x='" + _tileSizeX.ToString(_nhi) + "' y='" + _tileSizeY.ToString(_nhi) + "' />\r\n"); sb.Append(" <TileResolution x='" + _resX.ToString(_nhi) + "' y='" + _resY.ToString(_nhi) + "' />\r\n"); sb.Append("</TileCacheDefinition>"); StreamWriter sw = new StreamWriter(di.FullName + @"\tilecache.xml"); sw.WriteLine(sb.ToString()); sw.Close(); } ProgressReport report = new ProgressReport(); int datasetId = _fdb.DatasetID(_targetDataset.DatasetName); if (datasetId == -1) { return; } IClass cls = null; try { cls = _sourceDataset.Elements[0].Class; } catch { cls = null; } IMultiGridIdentify gridClass = cls as IMultiGridIdentify; if (_gridType == TileGridType.binary_float && gridClass == null) { return; } IFeatureClass sourceFc = cls as IFeatureClass; Map map = null; if (_gridType == TileGridType.image_jpg || _gridType == TileGridType.image_png) { map = new Map(); ILayer layer = LayerFactory.Create(cls); map.AddLayer(layer); //map.iWidth = (int)(_tileSizeX / _resX); //map.iHeight = (int)(_tileSizeY / _resY); } #region Create Featureclass IFeatureClass fc = null; IDatasetElement element = _targetDataset[_name]; if (element != null && element.Class is IFeatureClass) { fc = (IFeatureClass)element.Class; if (fc.GeometryType == geometryType.Polygon && fc.FindField("GRID_LEVEL") != null && fc.FindField("GRID_ROW") != null && fc.FindField("GRID_COLUMN") != null && fc.FindField("FILE") != null) { if (MessageBox.Show("TileGridClass already exists. Do you wan't to append to this Grid?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) != DialogResult.Yes) { return; } } else { _fdb.DeleteFeatureClass(_name); fc = null; } } if (fc == null) { Fields fields = new Fields(); fields.Add(new Field("GRID_LEVEL", FieldType.integer)); fields.Add(new Field("GRID_ROW", FieldType.integer)); fields.Add(new Field("GRID_COLUMN", FieldType.integer)); fields.Add(new Field("FILE", FieldType.String, 512)); _fdb.CreateFeatureClass(_targetDataset.DatasetName, _name, new GeometryDef(geometryType.Polygon), fields); element = _targetDataset[_name]; if (element == null || !(element.Class is IFeatureClass)) { return; } _fdb.SetSpatialIndexBounds(_name, "BinaryTree2", iBounds, _spatialIndexDef.SplitRatio, _spatialIndexDef.MaxPerNode, _spatialIndexDef.Levels); fc = (IFeatureClass)element.Class; } #endregion #region Create Tiles #region Report double tx = _tileSizeX, ty = _tileSizeY; if (ReportProgress != null) { report.featureMax = 0; for (int i = 0; i < _levels; i++) { if (_createLevels.Contains(i)) { for (double y = bounds.miny; y < bounds.maxy; y += ty) { for (double x = bounds.minx; x < bounds.maxx; x += tx) { report.featureMax++; } } } if (_levelType == TileLevelType.ConstantImagesize) { tx *= 2; ty *= 2; } } report.Message = "Create Tiles"; report.featurePos = 0; ReportProgress(report); } int reportInterval = (_createTiles ? 10 : 1000); #endregion List <IFeature> features = new List <IFeature>(); for (int level = 0; level < _levels; level++) { if (map != null) { map.iWidth = (int)(_tileSizeX / _resX); map.iHeight = (int)(_tileSizeY / _resY); } if (_createLevels.Contains(level)) { int row = 0; for (double y = bounds.miny; y < bounds.maxy; y += _tileSizeY) { DirectoryInfo di = new DirectoryInfo(_cacheDirectory + @"\" + level + @"\" + row); if (!di.Exists) { di.Create(); } int column = 0; for (double x = bounds.minx; x < bounds.maxx; x += _tileSizeX) { #region Polygon Polygon polygon = new Polygon(); Ring ring = new Ring(); ring.AddPoint(new Point(x, y)); ring.AddPoint(new Point(Math.Min(x + _tileSizeX, bounds.maxx), y)); ring.AddPoint(new Point(Math.Min(x + _tileSizeX, bounds.maxx), Math.Min(y + _tileSizeY, bounds.maxy))); ring.AddPoint(new Point(x, Math.Min(y + _tileSizeY, bounds.maxy))); ring.Close(); polygon.AddRing(ring); #endregion if (sourceFc != null) { SpatialFilter filter = new SpatialFilter(); filter.AddField(sourceFc.IDFieldName); filter.Geometry = polygon; filter.FilterSpatialReference = fc.SpatialReference; using (IFeatureCursor cursor = sourceFc.GetFeatures(filter)) { if (cursor.NextFeature == null) { column++; report.featurePos++; if (ReportProgress != null && report.featurePos % reportInterval == 0) { ReportProgress(report); } continue; } } } string relFilename = level + "/" + row + "/" + column + ".bin"; if (_createTiles) { string filename = di.FullName + @"\" + column; if (_gridType == TileGridType.binary_float) { float[] vals = gridClass.MultiGridQuery( null, new IPoint[] { ring[0], ring[1], ring[3] }, _resX, _resY, fc.SpatialReference, null); if (!HasFloatArrayData(vals)) { column++; report.featurePos++; if (ReportProgress != null && report.featurePos % reportInterval == 0) { ReportProgress(report); } continue; } StoreFloatArray(filename + ".bin", x, y, _resX, _resY, vals); } else if (map != null) { map.ZoomTo(new Envelope(x, y, x + _tileSizeX, y + _tileSizeY)); map.RefreshMap(DrawPhase.All, _cancelTracker); if (_gridType == TileGridType.image_png) { map.Bitmap.Save(filename + ".png", System.Drawing.Imaging.ImageFormat.Png); } else if (_gridType == TileGridType.image_jpg) { map.Bitmap.Save(filename + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); } } } Feature feature = new Feature(); feature.Shape = polygon; feature.Fields.Add(new FieldValue("GRID_LEVEL", level)); feature.Fields.Add(new FieldValue("GRID_ROW", row)); feature.Fields.Add(new FieldValue("GRID_COLUMN", column)); feature.Fields.Add(new FieldValue("FILE", relFilename)); features.Add(feature); column++; report.featurePos++; if (features.Count >= reportInterval) { if (ReportProgress != null) { ReportProgress(report); } if (!_fdb.Insert(fc, features)) { MessageBox.Show(_fdb.lastErrorMsg, "DB Insert Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } features.Clear(); if (!_cancelTracker.Continue) { succeeded = true; return; } } } row++; } } if (_levelType == TileLevelType.ConstantImagesize) { _tileSizeX *= 2; _tileSizeY *= 2; } _resX *= 2; _resY *= 2; } if (features.Count > 0) { if (ReportProgress != null) { ReportProgress(report); } _fdb.Insert(fc, features); } _fdb.CalculateExtent(fc); #endregion succeeded = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (!succeeded) { _fdb.DeleteFeatureClass(_name); } } }
private object Transform2D_(object geometry, bool inverse) { if (_projectionPipeline == null) { return(geometry); } CoordinateReferenceSystem from = _fromSrs, to = _toSrs; bool fromProjective = _fromProjective, toProjektive = _toProjective; if (geometry == null) { return(null); } if (from == null || to == null) { return(geometry); } if (geometry is PointCollection) { IPointCollection pColl = (IPointCollection)geometry; int pointCount = pColl.PointCount; if (pointCount == 0) { return(geometry); } IPointCollection target = null; var basicTransformations = BasicTransformations(inverse); for (int b = 0, b_to = basicTransformations.Length; b < b_to; b++) { BasicCoordinateTransform t = basicTransformations[b]; if (pColl is IRing) { target = new Ring(); } else if (pColl is IPath) { target = new Path(); } else if (pColl is IMultiPoint) { target = new MultiPoint(); } else { target = new PointCollection(); } for (int i = 0; i < pointCount; i++) { ProjCoordinate cFrom = new ProjCoordinate(pColl[i].X, pColl[i].Y); var cTo = new ProjCoordinate(); t.Transform(cFrom, cTo); target.AddPoint(new Point(cTo.X, cTo.Y)); } pColl = target; } return(target); } if (geometry is IPoint) { IPoint target = null; var basicTransformations = BasicTransformations(inverse); for (int b = 0, b_to = basicTransformations.Length; b < b_to; b++) { BasicCoordinateTransform t = basicTransformations[b]; ProjCoordinate cFrom = new ProjCoordinate(((IPoint)geometry).X, ((IPoint)geometry).Y), cTo = new ProjCoordinate(); t.Transform(cFrom, cTo); target = new Point(cTo.X, cTo.Y); geometry = target; } return(target); } if (geometry is IEnvelope) { return(Transform2D_(((IEnvelope)geometry).ToPolygon(10), inverse)); } if (geometry is IPolyline) { int count = ((IPolyline)geometry).PathCount; IPolyline polyline = new Polyline(); for (int i = 0; i < count; i++) { polyline.AddPath((IPath)Transform2D_(((IPolyline)geometry)[i], inverse)); } return(polyline); } if (geometry is IPolygon) { int count = ((IPolygon)geometry).RingCount; IPolygon polygon = new Polygon(); for (int i = 0; i < count; i++) { polygon.AddRing((IRing)Transform2D_(((IPolygon)geometry)[i], inverse)); } return(polygon); } if (geometry is IAggregateGeometry) { int count = ((IAggregateGeometry)geometry).GeometryCount; IAggregateGeometry aGeom = new AggregateGeometry(); for (int i = 0; i < count; i++) { aGeom.AddGeometry((IGeometry)Transform2D_(((IAggregateGeometry)geometry)[i], inverse)); } return(aGeom); } return(null); }
static public IGeometry ToGeometry(this JsonGeometry geometry) { if (geometry == null) { return(null); } if (geometry.X.HasValue && geometry.Y.HasValue) { return(new Point(geometry.X.Value, geometry.Y.Value)); } if (geometry.XMin.HasValue && geometry.YMin.HasValue && geometry.XMax.HasValue && geometry.YMax.HasValue) { return(new Envelope(geometry.XMin.Value, geometry.YMin.Value, geometry.XMax.Value, geometry.YMax.Value)); } if (geometry.Paths != null && geometry.Paths.Length > 0) { var polyline = new Polyline(); for (int p = 0, pathCount = geometry.Paths.Length; p < pathCount; p++) { var jsonPath = geometry.Paths[p]; if (jsonPath.Length < 1) { continue; } var path = new Path(); for (int i = 0, pointCount = jsonPath.GetLength(0); i < pointCount; i++) { path.AddPoint(new Point(jsonPath[i, 0], jsonPath[i, 1])); } polyline.AddPath(path); } return(polyline); } if (geometry.Rings != null && geometry.Rings.Length > 0) { var polygon = new Polygon(); for (int p = 0, ringCount = geometry.Rings.Length; p < ringCount; p++) { var jsonRing = geometry.Rings[p]; if (jsonRing.Length < 1) { continue; } var ring = new Ring(); for (int i = 0, pointCount = jsonRing.GetLength(0); i < pointCount; i++) { ring.AddPoint(new Point(jsonRing[i, 0], jsonRing[i, 1])); } polygon.AddRing(ring); } return(polygon); } return(null); }