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 static IAggregateGeometry CreateGeometryCollection(BinaryReader reader, WkbByteOrder byteOrder, bool hasZ, bool hasM) { // Get the Number of Geometries in this Collection. int numGeometries = (int)ReadUInt32(reader, byteOrder); AggregateGeometry aGeometry = new AggregateGeometry(); for (int g = 0; g < numGeometries; g++) { IGeometry geometry = WKBToGeometry(reader, byteOrder); if (geometry != null) { aGeometry.AddGeometry(geometry); } } return(aGeometry); }
public static IGeometry GML2Geometry(string gml, GmlVersion gmlVersion) { try { gml = gml.Replace("<gml:", "<").Replace("</gml:", "</"); XmlDocument doc = new XmlDocument(); doc.LoadXml(gml); XmlNode geomNode = doc.ChildNodes[0]; ISpatialReference sRef = null; if ((int)gmlVersion > 2 && geomNode.Attributes["srsName"] != null) { sRef = SpatialReference.FromID(geomNode.Attributes["srsName"].Value); } switch (geomNode.Name) { case "Point": return(GML2Point(geomNode, sRef)); case "pointProperty": return(GML2Point(geomNode.SelectSingleNode("Point"), sRef)); case "Box": case "Envelope": return(GML2Envelope(geomNode, sRef)); case "LineString": IPath path = GML2Path(geomNode, sRef); if (path == null) { return(null); } Polyline polyline = new Polyline(); polyline.AddPath(path); return(polyline); case "MultiLineString": return(GML2Polyline(geomNode, sRef)); case "curveProperty": return(GML2Polyline(geomNode, sRef)); case "Polygon": return(GML2Polygon(geomNode, sRef)); case "MultiPolygon": AggregateGeometry aGeom1 = new AggregateGeometry(); foreach (XmlNode polygonNode in geomNode.SelectNodes("polygonMember/Polygon")) { IPolygon polygon = GML2Polygon(polygonNode, sRef); if (polygon != null) { aGeom1.AddGeometry(polygon); } } if (aGeom1.GeometryCount == 0) { return(null); } IPolygon mpolygon1 = (IPolygon)aGeom1[0]; for (int i = 1; i < aGeom1.GeometryCount; i++) { IPolygon p = (IPolygon)aGeom1[i]; for (int r = 0; r < p.RingCount; r++) { mpolygon1.AddRing(p[r]); } } return(mpolygon1); case "surfaceProperty": AggregateGeometry aGeom2 = new AggregateGeometry(); foreach (XmlNode polygonNode in geomNode.SelectNodes("Surface/patches/PolygonPatch")) { IPolygon polygon = GML2Polygon(polygonNode, sRef); if (polygon != null) { aGeom2.AddGeometry(polygon); } } if (aGeom2.GeometryCount == 0) { return(null); } IPolygon mpolygon2 = (IPolygon)aGeom2[0]; for (int i = 1; i < aGeom2.GeometryCount; i++) { IPolygon p = (IPolygon)aGeom2[i]; for (int r = 0; r < p.RingCount; r++) { mpolygon2.AddRing(p[r]); } } return(mpolygon2); default: return(null); } } catch (Exception ex) { string err = ex.Message; return(null); } }
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 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); } }
private object Transform2D_(object geometry, IntPtr from, IntPtr to, bool fromProjective, bool toProjektive) { if (geometry == null) { return(null); } if (from == IntPtr.Zero || to == IntPtr.Zero) { return(geometry); } if (geometry is PointCollection) { PointCollection pColl = (PointCollection)geometry; int pointCount = pColl.PointCount; if (pointCount == 0) { return(geometry); } IntPtr buffer = Marshal.AllocHGlobal(pointCount * 2 * sizeof(double)); lock (LockThis1) { try { IntPtr xPtr = IntPtr.Zero, yPtr = IntPtr.Zero; unsafe { double *b = (double *)buffer; for (int i = 0; i < pointCount; i++) { b[i] = pColl[i].X; b[pointCount + i] = pColl[i].Y; } if (!fromProjective) { ToRad(buffer, pointCount * 2); } xPtr = (IntPtr)(&b[0]); yPtr = (IntPtr)(&b[pointCount]); } if (from != IntPtr.Zero && to != IntPtr.Zero) { //if (preTo > 0) //{ // Proj4Wrapper.pj_transform(from, preTo, pointCount, 0, xPtr, yPtr, (IntPtr)0); // Proj4Wrapper.pj_transform(preTo, to, pointCount, 0, xPtr, yPtr, (IntPtr)0); //} //else //{ Proj4Wrapper.pj_transform(from, to, pointCount, 0, xPtr, yPtr, IntPtr.Zero); //} } if (!toProjektive) { ToDeg(buffer, pointCount * 2); } IPointCollection target = null; 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(); } unsafe { double *b = (double *)buffer; for (int i = 0; i < pointCount; i++) { target.AddPoint(new Point(b[i], b[pointCount + i])); } return(target); } } finally { Marshal.FreeHGlobal(buffer); } } //double [] x; //double [] y; //((PointCollection)geometry).getXY(out x,out y); //if (!fromProjective) ToRad(x, y); //if(from>0 && to>0) // Proj4Wrapper.pj_transform(from,to,x.Length,0,x,y,null); //if (!toProjektive) ToDeg(x, y); //if(geometry is Ring) //{ // Ring ring=new Ring(); // ring.setXYZ(x,y,null); // return ring; //} //if(geometry is Path) //{ // Path path=new Path(); // path.setXYZ(x,y,null); // return path; //} //if (geometry is MultiPoint) //{ // MultiPoint multiPoint = new MultiPoint(); // multiPoint.setXYZ(x, y, null); // return multiPoint; //} //return new PointCollection(x,y,null); } if (geometry is IPoint) { double[] x = { ((IPoint)geometry).X }; double[] y = { ((IPoint)geometry).Y }; if (!fromProjective) { ToRad(x, y); } lock (LockThis1) { if (from != IntPtr.Zero && to != IntPtr.Zero) { unsafe { fixed(double *xx = x) fixed(double *yy = y) { IntPtr xPtr = (IntPtr)(xx); IntPtr yPtr = (IntPtr)(yy); //if (preTo > 0) //{ // Proj4Wrapper.pj_transform(from, preTo, x.Length, 0, xPtr, yPtr, (IntPtr)0); // Proj4Wrapper.pj_transform(preTo, to, x.Length, 0, xPtr, yPtr, (IntPtr)0); //} //else //{ Proj4Wrapper.pj_transform(from, to, x.Length, 0, xPtr, yPtr, IntPtr.Zero); //} } } } } if (!toProjektive) { ToDeg(x, y); } return(new Point(x[0], y[0])); } if (geometry is IEnvelope) { return(Transform2D_(((IEnvelope)geometry).ToPolygon(10), from, to, fromProjective, toProjektive)); } 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], from, to, fromProjective, toProjektive)); } 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], from, to, fromProjective, toProjektive)); } 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], from, to, fromProjective, toProjektive)); } return(aGeom); } return(null); }