private static Polyline CreateLineString(BinaryReader reader, WkbByteOrder byteOrder, bool hasZ, bool hasM) { Polyline pline = new Polyline(); gView.Framework.Geometry.Path path = new gView.Framework.Geometry.Path(); ReadPointCollection(reader, byteOrder, path, hasZ, hasM); pline.AddPath(path); return(pline); }
public void AddPoint(IPoint point) { if (point == null) { return; } if (_geometry is IPoint && _actPartNr == 0) { ((IPoint)_geometry).X = point.X; ((IPoint)_geometry).Y = point.Y; ((IPoint)_geometry).Z = point.Z; } else if (_geometry is IMultiPoint) { IMultiPoint mPoint = (IMultiPoint)_geometry; mPoint.AddPoint(point); } else if (_geometry is IPolyline) { IPolyline pLine = (IPolyline)_geometry; if (_actPartNr >= pLine.PathCount) { gView.Framework.Geometry.Path path = new gView.Framework.Geometry.Path(); path.AddPoint(point); pLine.AddPath(path); _actPartNr = pLine.PathCount - 1; } else { pLine[_actPartNr].AddPoint(point); } } else if (_geometry is IPolygon) { IPolygon poly = (IPolygon)_geometry; if (_actPartNr >= poly.RingCount) { Ring ring = new Ring(); ring.AddPoint(point); poly.AddRing(ring); _actPartNr = poly.RingCount - 1; } else { poly[_actPartNr].AddPoint(point); } } }
private void ReadMultiLine(BinaryReader br) { geometry = new Polyline(); for (int i = 0; i < parts; i++) { gView.Framework.Geometry.Path path = new gView.Framework.Geometry.Path(); int vertices = (int)CBF.SwapWord(br.ReadUInt32()); double x = 0.0, y = 0.0; for (int v = 0; v < vertices; v++) { x += (double)br.ReadDecimal(); y += (double)br.ReadDecimal(); path.AddPoint(new Point(x, y)); } ((Polyline)geometry).AddPath(path); } }
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); }
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); }
static public IGeometry AXL2Geometry(string axl, bool ignoreBuffer) { try { XmlDocument doc = new XmlDocument(); doc.LoadXml("<g>" + axl + "</g>"); AggregateGeometry aGeom = new AggregateGeometry(); IPoint point; XmlNode bufferNode = null; foreach (XmlNode node in doc.ChildNodes[0].ChildNodes) { switch (node.Name) { case "BUFFER": if (!ignoreBuffer) { bufferNode = node; } break; case "POINT": point = PointFromAxl(node); AddSrs(node, point); aGeom.AddGeometry(point); break; case "MULTIPOINT": IMultiPoint mpoint = new MultiPoint(); AddSrs(node, mpoint); foreach (XmlNode pointnode in node.SelectNodes("POINT")) { point = PointFromAxl(pointnode); mpoint.AddPoint(point); } if (mpoint.PointCount == 0) { PointsFromCoords(mpoint, node.SelectSingleNode("COORDS")); } aGeom.AddGeometry(mpoint); break; case "ENVELOPE": IEnvelope envelope = new Envelope( Convert.ToDouble(node.Attributes["minx"].Value.Replace(".", ",")), Convert.ToDouble(node.Attributes["miny"].Value.Replace(".", ",")), Convert.ToDouble(node.Attributes["maxx"].Value.Replace(".", ",")), Convert.ToDouble(node.Attributes["maxy"].Value.Replace(".", ","))); AddSrs(node, envelope); aGeom.AddGeometry(envelope); break; case "POLYLINE": IPolyline pline = new Polyline(); AddSrs(node, pline); foreach (XmlNode pathnode in node.SelectNodes("PATH")) { IPath path = new gView.Framework.Geometry.Path(); foreach (XmlNode pointnode in pathnode.SelectNodes("POINT")) { point = PointFromAxl(pointnode); path.AddPoint(point); } foreach (XmlNode coordnode in pathnode.SelectNodes("COORDS")) { PointsFromCoords(path, coordnode); } pline.AddPath(path); } aGeom.AddGeometry(pline); break; case "POLYGON": IPolygon pgon = new Polygon(); AddSrs(node, pgon); foreach (XmlNode ringnode in node.SelectNodes("RING")) { IRing ring = new gView.Framework.Geometry.Ring(); foreach (XmlNode pointnode in ringnode.SelectNodes("POINT")) { point = PointFromAxl(pointnode); ring.AddPoint(point); } foreach (XmlNode coordnode in ringnode.SelectNodes("COORDS")) { PointsFromCoords(ring, coordnode); } pgon.AddRing(ring); foreach (XmlNode holenode in ringnode.SelectNodes("HOLE")) { IRing hole = new gView.Framework.Geometry.Ring(); foreach (XmlNode pointnode in holenode.SelectNodes("POINT")) { point = PointFromAxl(pointnode); hole.AddPoint(point); } foreach (XmlNode coordnode in holenode.SelectNodes("COORDS")) { PointsFromCoords(hole, coordnode); } pgon.AddRing(hole); } } foreach (XmlNode ringnode in node.SelectNodes("HOLE")) { IRing ring = new gView.Framework.Geometry.Ring(); foreach (XmlNode pointnode in ringnode.SelectNodes("POINT")) { point = PointFromAxl(pointnode); ring.AddPoint(point); } foreach (XmlNode coordnode in ringnode.SelectNodes("COORDS")) { PointsFromCoords(ring, coordnode); } pgon.AddRing(ring); } aGeom.AddGeometry(pgon); break; } } if (aGeom.GeometryCount == 0) { return(null); } if (!ignoreBuffer && bufferNode != null && bufferNode.Attributes["distance"] != null) { try { double dist = Convert.ToDouble(bufferNode.Attributes["distance"].Value); IPolygon polygon = aGeom.Buffer(dist); return(polygon); } catch { } } if (aGeom.GeometryCount == 1) { return(aGeom[0]); } return(aGeom); } catch { return(null); } }