// Use acceleration to speed up relational operations. Accelerate your source geometry only if you are going to test many other geometries against it. // Acceleration is applicable for polylines and polygons only. Note that accelerated geometries take more memory so if you aren't going to get any// benefit from accelerating it, don't do it. // The performance of the following GeometryEngine functions are the only ones which can be improved with an accelerated geometry.// GeometryEngine.Instance.Contains// GeometryEngine.Instance.Crosses// GeometryEngine.Instance.Disjoint// GeometryEngine.Instance.Disjoint3D// GeometryEngine.Instance.Equals// GeometryEngine.Instance.Intersects// GeometryEngine.Instance.Relate// GeometryEngine.Instance.Touches// GeometryEngine.Instance.Within// methods need to run on the MCT
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(()=>{// accelerate the geometry to testvaracceleratedPoly= GeometryEngine.Instance.AccelerateForRelationalOperations(polygon);// loop through all the geometries to test againstforeach(var testPolygon in testPolygons){boolcontains= GeometryEngine.Instance.Contains(acceleratedPoly, testPolygon);boolwithin= GeometryEngine.Instance.Within(acceleratedPoly, testPolygon);boolcrosses= GeometryEngine.Instance.Crosses(acceleratedPoly, testPolygon);}});
Determine area of a polygon
varg1= PolygonBuilderEx.FromJson("{\"rings\": [ [ [0, 0], [10, 0], [10, 10], [0, 10] ] ] }");doubled= GeometryEngine.Instance.Area(g1);// d = -100.0 //negative due to wrong ring orientationd= GeometryEngine.Instance.Area(GeometryEngine.Instance.SimplifyAsFeature(g1));// d = 100.0 // feature has been simplifed; ring orientation is correct
Determine the boundary of a multi-part Polygon
// create a donut polygon. Must use the PolygonBuilderEx objectList<Coordinate2D>outerPts=newList<Coordinate2D>();
outerPts.Add(new Coordinate2D(10.0,10.0));
outerPts.Add(new Coordinate2D(10.0,20.0));
outerPts.Add(new Coordinate2D(20.0,20.0));
outerPts.Add(new Coordinate2D(20.0,10.0));List<Coordinate2D>innerPts=newList<Coordinate2D>();
innerPts.Add(new Coordinate2D(13.0,13.0));
innerPts.Add(new Coordinate2D(17.0,13.0));
innerPts.Add(new Coordinate2D(17.0,17.0));
innerPts.Add(new Coordinate2D(13.0,17.0));Polygondonut=null;// add the outer pointsPolygonBuilderExpb=new PolygonBuilderEx(outerPts);// add the inner points (note they are defined anticlockwise)
pb.AddPart(innerPts);// get the polygondonut= pb.ToGeometry();// get the boundary Geometryg= GeometryEngine.Instance.Boundary(donut);Polylineboundary= g as Polyline;
Buffer a MapPoint
// buffer a pointMapPointpt= MapPointBuilderEx.CreateMapPoint(1.0,1.0, SpatialReferences.WGS84);GeometryptBuffer= GeometryEngine.Instance.Buffer(pt,5.0);Polygonbuffer= ptBuffer as Polygon;
Buffer a Circular Arc
// create the circular arcMapPointfromPt= MapPointBuilderEx.CreateMapPoint(2,1);MapPointtoPt= MapPointBuilderEx.CreateMapPoint(1,2);Coordinate2DinteriorPt=new Coordinate2D(1+ Math.Sqrt(2)/2,1+ Math.Sqrt(2)/2);EllipticArcSegmentcircularArc= EllipticArcBuilderEx.CreateCircularArc(fromPt, toPt, interiorPt);// buffer the arcPolylinepolyline= PolylineBuilderEx.CreatePolyline(circularArc);GeometrylineBuffer= GeometryEngine.Instance.Buffer(polyline,10);
Buffer multiple MapPoints
// creates a buffer around each MapPointList<MapPoint>pts=newList<MapPoint>();
pts.Add(MapPointBuilderEx.CreateMapPoint(1.0,1.0));
pts.Add(MapPointBuilderEx.CreateMapPoint(1.0,2.0));
pts.Add(MapPointBuilderEx.CreateMapPoint(2.0,2.0));
pts.Add(MapPointBuilderEx.CreateMapPoint(2.0,1.0));GeometryptsBuffer= GeometryEngine.Instance.Buffer(pts,0.25);PolygonbufferResult= ptsBuffer as Polygon;// bufferResult will have 4 parts
// clip a polyline by an envelopeEnvelopeenv= EnvelopeBuilderEx.CreateEnvelope(2.0,2.0,4.0,4.0);LineSegmentline= LineBuilderEx.CreateLineSegment(new Coordinate2D(0,3),new Coordinate2D(5.0,3.0));Polylinepolyline= PolylineBuilderEx.CreatePolyline(line);GeometryclipGeom= GeometryEngine.Instance.Clip(polyline, env);
Clip a Polyline by a Polygon
// clip a polyline by a polygonList<Coordinate2D>list=newList<Coordinate2D>();
list.Add(new Coordinate2D(1.0,1.0));
list.Add(new Coordinate2D(1.0,4.0));
list.Add(new Coordinate2D(4.0,4.0));
list.Add(new Coordinate2D(4.0,1.0));Polygonpolygon= PolygonBuilderEx.CreatePolygon(list, SpatialReferences.WGS84);LineSegmentcrossingLine= LineBuilderEx.CreateLineSegment(MapPointBuilderEx.CreateMapPoint(0,3), MapPointBuilderEx.CreateMapPoint(5.0,3.0));Polylinep= PolylineBuilderEx.CreatePolyline(crossingLine);Geometrygeometry= GeometryEngine.Instance.Clip(p, polygon.Extent);
Construct a geodetic line with specified distance and azimuth
// build a polygon List<MapPoint>pts=newList<MapPoint>();
pts.Add(MapPointBuilderEx.CreateMapPoint(1.0,1.0));
pts.Add(MapPointBuilderEx.CreateMapPoint(1.0,2.0));
pts.Add(MapPointBuilderEx.CreateMapPoint(2.0,2.0));
pts.Add(MapPointBuilderEx.CreateMapPoint(2.0,1.0));Polygonpoly= PolygonBuilderEx.CreatePolygon(pts);// test if an inner point is containedMapPointinnerPt= MapPointBuilderEx.CreateMapPoint(1.5,1.5);boolcontains= GeometryEngine.Instance.Contains(poly, innerPt);// contains = true// test a point on a boundarycontains= GeometryEngine.Instance.Contains(poly, poly.Points[0]);// contains = false// test an interior lineMapPointinnerPt2= MapPointBuilderEx.CreateMapPoint(1.25,1.75);List<MapPoint>innerLinePts=newList<MapPoint>();
innerLinePts.Add(innerPt);
innerLinePts.Add(innerPt2);// test an inner polylinePolylinepolyline= PolylineBuilderEx.CreatePolyline(innerLinePts);contains= GeometryEngine.Instance.Contains(poly, polyline);// contains = true// test a line that crosses the boundaryMapPointouterPt= MapPointBuilderEx.CreateMapPoint(3,1.5);List<MapPoint>crossingLinePts=newList<MapPoint>();
crossingLinePts.Add(innerPt);
crossingLinePts.Add(outerPt);polyline= PolylineBuilderEx.CreatePolyline(crossingLinePts);contains= GeometryEngine.Instance.Contains(poly, polyline);// contains = false// test a polygon in polygonEnvelopeenv= EnvelopeBuilderEx.CreateEnvelope(innerPt, innerPt2);contains= GeometryEngine.Instance.Contains(poly, env);// contains = true
Determine convex hull
//// convex hull around a point - returns a point//MapPointpt= MapPointBuilderEx.CreateMapPoint(2.0,2.0);Geometryhull= GeometryEngine.Instance.ConvexHull(pt);MapPointhullPt= hull as MapPoint;// nullPt.X = 2// hullPt.Y = 2List<MapPoint>list=newList<MapPoint>();
list.Add(MapPointBuilderEx.CreateMapPoint(1.0,1.0));
list.Add(MapPointBuilderEx.CreateMapPoint(1.0,2.0));
list.Add(MapPointBuilderEx.CreateMapPoint(2.0,2.0));
list.Add(MapPointBuilderEx.CreateMapPoint(2.0,1.0));//// convex hull around a multipoint - returns a polygon//// build a multiPointMultipointmultiPoint= MultipointBuilderEx.CreateMultipoint(list);hull= GeometryEngine.Instance.ConvexHull(multiPoint);PolygonhullPoly= hull as Polygon;// hullPoly.Area = 1// hullPoly.PointCount = 5// // convex hull around a line - returns a polyline or polygon// List<MapPoint>polylineList=newList<MapPoint>();
polylineList.Add(MapPointBuilderEx.CreateMapPoint(1.0,1.0));
polylineList.Add(MapPointBuilderEx.CreateMapPoint(2.0,2.0));// 2 point straight linePolylinepolyline= PolylineBuilderEx.CreatePolyline(polylineList);hull= GeometryEngine.Instance.ConvexHull(polyline);PolylinehullPolyline= hull as Polyline;// hullPolyline.Length = Math.Sqrt(2)// hullPolyline.PointCount = 2// 3 point angular line
polylineList.Add(MapPointBuilderEx.CreateMapPoint(2.0,1.0));polyline= PolylineBuilderEx.CreatePolyline(polylineList);hull= GeometryEngine.Instance.ConvexHull(polyline);hullPoly= hull as Polygon;// hullPoly.Length = 2 + Math.Sqrt(2)// hullPoly.Area = 0.5// hullPoly.PointCount = 4//// convex hull around a polygon - returns a polygon//// simple polygonPolygonpoly= PolygonBuilderEx.CreatePolygon(list);hull= GeometryEngine.Instance.ConvexHull(poly);hullPoly= hull as Polygon;// hullPoly.Length = 4.0// hullPoly.Area = 1.0// hullPoly.PointCount = 5// polygon with concave anglesList<MapPoint>funkyList=newList<MapPoint>();
funkyList.Add(MapPointBuilderEx.CreateMapPoint(1.0,1.0));
funkyList.Add(MapPointBuilderEx.CreateMapPoint(1.5,1.5));
funkyList.Add(MapPointBuilderEx.CreateMapPoint(1.0,2.0));
funkyList.Add(MapPointBuilderEx.CreateMapPoint(2.0,2.0));
funkyList.Add(MapPointBuilderEx.CreateMapPoint(1.5,1.5));
funkyList.Add(MapPointBuilderEx.CreateMapPoint(2.0,1.0));
funkyList.Add(MapPointBuilderEx.CreateMapPoint(1.0,1.0));PolygonfunkyPoly= PolygonBuilderEx.CreatePolygon(funkyList);hull= GeometryEngine.Instance.ConvexHull(funkyPoly);hullPoly= hull as Polygon;// hullPoly.Length = 4.0// hullPoly.Area = 1.0// hullPoly.PointCount = 5// hullPoly.Points[0] = 1.0, 1.0// hullPoly.Points[1] = 1.0, 2.0// hullPoly.Points[2] = 2.0, 2.0// hullPoly.Points[3] = 2.0, 1.0// hullPoly.Points[4] = 1.0, 1.0
Determine if two geometries cross
//// pt on pt//MapPointpt= MapPointBuilderEx.CreateMapPoint(1.0,1.0);MapPointpt2= MapPointBuilderEx.CreateMapPoint(2.0,2.0);boolcrosses= GeometryEngine.Instance.Crosses(pt, pt2);// crosses = falsecrosses= GeometryEngine.Instance.Crosses(pt, pt);// crosses = false// // pt and line// List<MapPoint>list=newList<MapPoint>();
list.Add(MapPointBuilderEx.CreateMapPoint(1.0,1.0));
list.Add(MapPointBuilderEx.CreateMapPoint(3.0,3.0));
list.Add(MapPointBuilderEx.CreateMapPoint(5.0,1.0));Polylineline1= PolylineBuilderEx.CreatePolyline(list);crosses= GeometryEngine.Instance.Crosses(line1, pt2);// crosses = falsecrosses= GeometryEngine.Instance.Crosses(pt2, line1);// crosses = false// end pt of linecrosses= GeometryEngine.Instance.Crosses(line1, pt);// crosses = false//// pt and polygon//List<MapPoint>polyPts=newList<MapPoint>();
polyPts.Add(MapPointBuilderEx.CreateMapPoint(3.0,2.0));
polyPts.Add(MapPointBuilderEx.CreateMapPoint(3.0,6.0));
polyPts.Add(MapPointBuilderEx.CreateMapPoint(6.0,6.0));
polyPts.Add(MapPointBuilderEx.CreateMapPoint(6.0,2.0));Polygonpoly1= PolygonBuilderEx.CreatePolygon(polyPts);crosses= GeometryEngine.Instance.Crosses(poly1, pt);// crosses = falsecrosses= GeometryEngine.Instance.Crosses(pt, poly1);// crosses = false// // line and line//List<MapPoint>list2=newList<MapPoint>();
list2.Add(MapPointBuilderEx.CreateMapPoint(1.0,3.0));
list2.Add(MapPointBuilderEx.CreateMapPoint(3.0,1.0));
list2.Add(MapPointBuilderEx.CreateMapPoint(5.0,3.0));Polylineline2= PolylineBuilderEx.CreatePolyline(list2);crosses= GeometryEngine.Instance.Crosses(line1, line2);// crosses = true//// line and polygon//crosses= GeometryEngine.Instance.Crosses(poly1, line1);// crosses = true//// polygon and polygon//Envelopeenv= EnvelopeBuilderEx.CreateEnvelope(MapPointBuilderEx.CreateMapPoint(1.0,1.0), MapPointBuilderEx.CreateMapPoint(4,4));Polygonpoly2= PolygonBuilderEx.CreatePolygon(env);crosses= GeometryEngine.Instance.Crosses(poly1, poly2);// crosses = false
// densify a line segmentMapPointstartPt= MapPointBuilderEx.CreateMapPoint(1.0,1.0);MapPointendPt= MapPointBuilderEx.CreateMapPoint(1,21);LineSegmentline= LineBuilderEx.CreateLineSegment(startPt, endPt);Polylinepolyline= PolylineBuilderEx.CreatePolyline(line);Geometrygeom= GeometryEngine.Instance.DensifyByLength(polyline,2);Polylineresult= geom as Polyline;// densify a circular arcMapPointfromPt= MapPointBuilderEx.CreateMapPoint(2,1);MapPointtoPt= MapPointBuilderEx.CreateMapPoint(1,2);Coordinate2DinteriorPt=new Coordinate2D(1+ Math.Sqrt(2)/2,1+ Math.Sqrt(2)/2);EllipticArcBuilderExcab=new EllipticArcBuilderEx(fromPt, toPt, interiorPt);EllipticArcSegmentcircularArc= cab.ToSegment();polyline= PolylineBuilderEx.CreatePolyline(circularArc);geom= GeometryEngine.Instance.DensifyByLength(polyline,2);result= geom as Polyline;
Difference between two Polygons
List<MapPoint>polyPts=newList<MapPoint>();
polyPts.Add(MapPointBuilderEx.CreateMapPoint(3.0,2.0));
polyPts.Add(MapPointBuilderEx.CreateMapPoint(3.0,6.0));
polyPts.Add(MapPointBuilderEx.CreateMapPoint(6.0,6.0));
polyPts.Add(MapPointBuilderEx.CreateMapPoint(6.0,2.0));Polygonpoly1= PolygonBuilderEx.CreatePolygon(polyPts);Envelopeenv= EnvelopeBuilderEx.CreateEnvelope(MapPointBuilderEx.CreateMapPoint(1.0,1.0), MapPointBuilderEx.CreateMapPoint(4,4));Polygonpoly2= PolygonBuilderEx.CreatePolygon(env);Geometryresult= GeometryEngine.Instance.Difference(poly1, poly2);PolygonpolyResult= result as Polygon;// polyResult.Area = 10.0result= GeometryEngine.Instance.Difference(poly2, poly1);polyResult= result as Polygon;// polyResult.Area = 7.0
Determine if two Geometries are disjoint
//// pt on pt//MapPointpt= MapPointBuilderEx.CreateMapPoint(1.0,1.0);MapPointpt2= MapPointBuilderEx.CreateMapPoint(2.0,2.5);booldisjoint= GeometryEngine.Instance.Disjoint(pt, pt2);// result is trueMultipointBuilderExmpb=new MultipointBuilderEx();
mpb.AddPoint(pt);
mpb.AddPoint(pt2);MultipointmultiPoint= mpb.ToGeometry();disjoint= GeometryEngine.Instance.Disjoint(multiPoint, pt);// result is false// // pt and line// List<MapPoint>list=newList<MapPoint>();
list.Add(MapPointBuilderEx.CreateMapPoint(1.0,1.0));
list.Add(MapPointBuilderEx.CreateMapPoint(3.0,3.0));
list.Add(MapPointBuilderEx.CreateMapPoint(5.0,1.0));Polylineline1= PolylineBuilderEx.CreatePolyline(list);disjoint= GeometryEngine.Instance.Disjoint(line1, pt2);// result is truedisjoint= GeometryEngine.Instance.Disjoint(pt2, line1);// result is true// end pt of linedisjoint= GeometryEngine.Instance.Disjoint(line1, pt);// result is false//// pt and polygon//List<MapPoint>polyPts=newList<MapPoint>();
polyPts.Add(MapPointBuilderEx.CreateMapPoint(3.0,2.0));
polyPts.Add(MapPointBuilderEx.CreateMapPoint(3.0,6.0));
polyPts.Add(MapPointBuilderEx.CreateMapPoint(6.0,6.0));
polyPts.Add(MapPointBuilderEx.CreateMapPoint(6.0,2.0));Polygonpoly1= PolygonBuilderEx.CreatePolygon(polyPts);disjoint= GeometryEngine.Instance.Disjoint(poly1, pt);// result is truedisjoint= GeometryEngine.Instance.Disjoint(pt, poly1);// result is true// // line and line//List<MapPoint>list2=newList<MapPoint>();
list2.Add(MapPointBuilderEx.CreateMapPoint(1.0,3.0));
list2.Add(MapPointBuilderEx.CreateMapPoint(3.0,1.0));
list2.Add(MapPointBuilderEx.CreateMapPoint(5.0,3.0));Polylineline2= PolylineBuilderEx.CreatePolyline(list2);disjoint= GeometryEngine.Instance.Disjoint(line1, line2);// result is false//// line and polygon//disjoint= GeometryEngine.Instance.Disjoint(poly1, line1);// result is falsedisjoint= GeometryEngine.Instance.Disjoint(line1, poly1);// result is false//// polygon and polygon//Envelopeenv= EnvelopeBuilderEx.CreateEnvelope(MapPointBuilderEx.CreateMapPoint(1.0,1.0), MapPointBuilderEx.CreateMapPoint(4,4));Polygonpoly2= PolygonBuilderEx.CreatePolygon(env);disjoint= GeometryEngine.Instance.Disjoint(poly1, poly2);// result is false// disjoint3DSpatialReferencesr= SpatialReferences.WGS84;MapPointpt3D_1= MapPointBuilderEx.CreateMapPoint(1,1,1, sr);MapPointpt3D_2= MapPointBuilderEx.CreateMapPoint(2,2,2, sr);MapPointpt3D_3= MapPointBuilderEx.CreateMapPoint(1,1,2, sr);MultipointBuilderExmpbEx=new MultipointBuilderEx();
mpbEx.AddPoint(pt3D_1);
mpbEx.AddPoint(pt3D_2);
mpbEx.HasZ =true;multiPoint= mpbEx.ToGeometry();disjoint= GeometryEngine.Instance.Disjoint3D(multiPoint, pt3D_2);// disjoint = falsedisjoint= GeometryEngine.Instance.Disjoint3D(multiPoint, pt3D_3);// disjoint = true
Determine distance between two Geometries
MapPointpt1= MapPointBuilderEx.CreateMapPoint(1.0,1.0);MapPointpt2= MapPointBuilderEx.CreateMapPoint(2.0,2.0);MapPointpt3= MapPointBuilderEx.CreateMapPoint(4.0,2.0);//// pt and pt //doubled= GeometryEngine.Instance.Distance(pt1, pt2);// d = Math.Sqrt(2)//// pt and multipoint//List<MapPoint>multiPts=newList<MapPoint>();
multiPts.Add(pt2);
multiPts.Add(pt3);MultipointmultiPoint= MultipointBuilderEx.CreateMultipoint(multiPts);d= GeometryEngine.Instance.Distance(pt1, multiPoint);// d = Math.Sqrt(2)//// pt and envelope//Envelopeenv= EnvelopeBuilderEx.CreateEnvelope(pt1, pt2);d= GeometryEngine.Instance.Distance(pt1, env);// d = 0//// pt and polyline//List<MapPoint>polylinePts=newList<MapPoint>();
polylinePts.Add(MapPointBuilderEx.CreateMapPoint(2.0,1.0));
polylinePts.Add(pt2);Polylinepolyline= PolylineBuilderEx.CreatePolyline(polylinePts);d= GeometryEngine.Instance.Distance(pt1, polyline);// d = 1.0//// pt and polygon//Envelopeenv2= EnvelopeBuilderEx.CreateEnvelope(MapPointBuilderEx.CreateMapPoint(3.0,3.0), MapPointBuilderEx.CreateMapPoint(5.0,5.0));Polygonpoly= PolygonBuilderEx.CreatePolygon(env2);d= GeometryEngine.Instance.Distance(pt1, poly);// d = Math.Sqrt(8)//// envelope and polyline//d= GeometryEngine.Instance.Distance(env, polyline);// d = 0//// polyline and polyline//List<MapPoint>polylineList=newList<MapPoint>();
polylineList.Add(MapPointBuilderEx.CreateMapPoint(4,3));
polylineList.Add(MapPointBuilderEx.CreateMapPoint(4,4));Polylinepolyline2= PolylineBuilderEx.CreatePolyline(polylineList);d= GeometryEngine.Instance.Distance(polyline, polyline2);// d = Math.Sqrt(5)//// polygon and polygon//Polygonpoly2= PolygonBuilderEx.CreatePolygon(env);d= GeometryEngine.Instance.Distance(poly, poly2);// d = Math.Sqrt(2)
Determine 3D distance between two Geometries
// between points MapPointpt1= MapPointBuilderEx.CreateMapPoint(1,1,1);MapPointpt2= MapPointBuilderEx.CreateMapPoint(2,2,2);MapPointpt3= MapPointBuilderEx.CreateMapPoint(10,2,1);// pt1 to pt2doubled= GeometryEngine.Instance.Distance3D(pt1, pt2);// d = Math.Sqrt(3)// pt1 to pt3d= GeometryEngine.Instance.Distance3D(pt1, pt3);// d = Math.Sqrt(82)// pt2 to pt3d= GeometryEngine.Instance.Distance3D(pt2, pt3);// d = Math.Sqrt(65)// intersecting linesList<MapPoint>list=newList<MapPoint>();
list.Add(MapPointBuilderEx.CreateMapPoint(1.0,1.0,1.0));
list.Add(MapPointBuilderEx.CreateMapPoint(3.0,3.0,1.0));
list.Add(MapPointBuilderEx.CreateMapPoint(5.0,1.0,1.0));Polylineline1= PolylineBuilderEx.CreatePolyline(list);List<MapPoint>list2=newList<MapPoint>();
list2.Add(MapPointBuilderEx.CreateMapPoint(1.0,3.0,1.0));
list2.Add(MapPointBuilderEx.CreateMapPoint(3.0,1.0,1.0));
list2.Add(MapPointBuilderEx.CreateMapPoint(5.0,3.0,1.0));Polylineline2= PolylineBuilderEx.CreatePolyline(list2);boolintersects= GeometryEngine.Instance.Intersects(line1, line2);// intersects = trued= GeometryEngine.Instance.Distance3D(line1, line2);// d = 0 (distance is 0 when geomtries intersect)
PolylinegeneralizedPolyline= GeometryEngine.Instance.Generalize(polylineWithZ,200)as Polyline;// generalizedPolyline.HasZ = truePolygongeneralized3DPolyline= GeometryEngine.Instance.Generalize3D(polylineWithZ,200)as Polygon;// generalized3DPolyline.HasZ = true// note that generalized3DPolyline and generalizedPolyline will have different definitions// ie generalizedPolyline.IsEqual(generalized3DPolyline) = false
Calculate the Geodesic Area of a polygon
varpolygon= PolygonBuilderEx.CreatePolygon(new[]{
MapPointBuilderEx.CreateMapPoint(-10018754.1713946,10018754.1713946),
MapPointBuilderEx.CreateMapPoint(10018754.1713946,10018754.1713946),
MapPointBuilderEx.CreateMapPoint(10018754.1713946,-10018754.1713946),
MapPointBuilderEx.CreateMapPoint(-10018754.1713946,-10018754.1713946)}, SpatialReferences.WebMercator);vararea= GeometryEngine.Instance.GeodesicArea(polygon);// area is close to 255032810857732.31area= GeometryEngine.Instance.GeodesicArea(polygon, AreaUnit.SquareKilometers);// area is close to 255032810.85953,
Create a buffer polygon at the specified geodesic distance
// buffer a pointMapPointpt= MapPointBuilderEx.CreateMapPoint(1.0,1.0, SpatialReferences.WGS84);PolygonoutPolygon= GeometryEngine.Instance.GeodesicBuffer(pt,5)as Polygon;doubledelta= SpatialReferences.WGS84.XYTolerance *2* Math.Sqrt(2);ReadOnlyPointCollectionpoints= outPolygon.Points;foreach(MapPoint p in points){doubled= GeometryEngine.Instance.GeodesicDistance(pt, p);// d = 5 (+- delta)}// specify a unit for the distanceoutPolygon= GeometryEngine.Instance.GeodesicBuffer(pt,5000, LinearUnit.Millimeters)as Polygon;// buffer of 0 distance produces an empty geometryGeometryg= GeometryEngine.Instance.GeodesicBuffer(pt,0);// g.IsEmpty = true// buffer many pointsList<MapPoint>list=newList<MapPoint>();
list.Add(MapPointBuilderEx.CreateMapPoint(1.0,1.0, SpatialReferences.WGS84));
list.Add(MapPointBuilderEx.CreateMapPoint(10.0,20.0));
list.Add(MapPointBuilderEx.CreateMapPoint(40.0,40.0));
list.Add(MapPointBuilderEx.CreateMapPoint(60.0,60.0));outPolygon= GeometryEngine.Instance.GeodesicBuffer(list,10000)as Polygon;// outPolygon.PartCount = 4// buffer different geometry typesList<Coordinate2D>coords=newList<Coordinate2D>(){new Coordinate2D(1,2),new Coordinate2D(10,20),new Coordinate2D(20,30),new Coordinate2D(50,60),new Coordinate2D(70,80),new Coordinate2D(80,40),new Coordinate2D(90,10),new Coordinate2D(110,15),new Coordinate2D(120,30),new Coordinate2D(10,40),new Coordinate2D(-10,40),new Coordinate2D(-10,50)};List<Geometry>manyGeometries=newList<Geometry>{
MapPointBuilderEx.CreateMapPoint(1.0,1.0, SpatialReferences.WGS84),
PolylineBuilderEx.CreatePolyline(newList<Coordinate2D>(){coords[0], coords[1], coords[2]}, SpatialReferences.WGS84),
PolylineBuilderEx.CreatePolyline(newList<Coordinate2D>(){coords[3], coords[4], coords[5]}),
PolygonBuilderEx.CreatePolygon(newList<Coordinate2D>(){coords[9], coords[10], coords[11]})};outPolygon= GeometryEngine.Instance.GeodesicBuffer(manyGeometries,20000)as Polygon;// specify unit typesoutPolygon= GeometryEngine.Instance.GeodesicBuffer(manyGeometries,20, LinearUnit.Miles)as Polygon;
Determine geodesic distance between two Geometries
varpoint1= MapPointBuilderEx.CreateMapPoint(-170,45, SpatialReferences.WGS84);varpoint2= MapPointBuilderEx.CreateMapPoint(170,45, SpatialReferences.WGS84);vardistances_meters= GeometryEngine.Instance.GeodesicDistance(point1, point2);// distance is approximately 1572912.2066940258 in metersvardistance_feet= GeometryEngine.Instance.GeodesicDistance(point1, point2, LinearUnit.Feet);// distance is approximately 5160473.11904786 in feet
varpolyline= PolylineBuilderEx.CreatePolyline(new[]{
MapPointBuilderEx.CreateMapPoint(-10018754.1713946,10018754.1713946),
MapPointBuilderEx.CreateMapPoint(10018754.1713946,10018754.1713946)}, SpatialReferences.WebMercator);varlength= GeometryEngine.Instance.GeodesicLength(polyline);// length is approx 5243784.5551844323 in meterslength= GeometryEngine.Instance.GeodesicLength(polyline, LinearUnit.Miles);// length is approx 3258.33666089067 in milesvarpolyline2= GeometryEngine.Instance.Project(polyline, SpatialReferences.WGS84);length= GeometryEngine.Instance.GeodesicLength(polyline2);// length is approx 5243784.55518443 in meters after projecting
List<Coordinate2D>coords=newList<Coordinate2D>(){new Coordinate2D(-80,0),new Coordinate2D(-20,60),new Coordinate2D(40,20),new Coordinate2D(0,-20),new Coordinate2D(-80,0)};SpatialReferencesr= SpatialReferences.WGS84;// create a polylinePolylinepolyline= PolylineBuilderEx.CreatePolyline(coords, sr);// densify in kmPolylinegeodesicPolyline= GeometryEngine.Instance.GeodeticDensifyByDeviation(polyline,200, LinearUnit.Kilometers, GeodeticCurveType.Geodesic)as Polyline;// densify in mgeodesicPolyline= GeometryEngine.Instance.GeodeticDensifyByDeviation(polyline,200, LinearUnit.Meters, GeodeticCurveType.Geodesic)as Polyline;// Change curve type to LoxodromePolylineloxodromePolyline= GeometryEngine.Instance.GeodeticDensifyByDeviation(polyline,200, LinearUnit.Meters, GeodeticCurveType.Loxodrome)as Polyline;
GeodeticDensifyByLength - polygon
List<Coordinate2D>coords=newList<Coordinate2D>(){new Coordinate2D(-80,0),new Coordinate2D(-20,60),new Coordinate2D(40,20),new Coordinate2D(0,-20),new Coordinate2D(-80,0)};SpatialReferencesr= SpatialReferences.WGS84;// create a polygonPolygonpolygon= PolygonBuilderEx.CreatePolygon(coords, sr);// get the geodesic lengths of the polygon segmentsReadOnlySegmentCollectionsegments= polygon.Parts[0];List<Double>geoLengths=newList<Double>(segments.Count);foreach(Segment s in segments){Polylineline= PolylineBuilderEx.CreatePolyline(s, sr);doublegeoLen= GeometryEngine.Instance.GeodesicLength(line);
geoLengths.Add(geoLen);}// find the max length
geoLengths.Sort();doublemaxLen= geoLengths[geoLengths.Count -1];// densify the polygon (in meters)PolygondensifiedPoly= GeometryEngine.Instance.GeodeticDensifyByLength(polygon, maxLen, LinearUnit.Meters, GeodeticCurveType.Geodesic)as Polygon;// densify the polygon (in km)doublemaxSegmentLength=maxLen/10000;densifiedPoly= GeometryEngine.Instance.GeodeticDensifyByLength(polygon, maxSegmentLength, LinearUnit.Kilometers, GeodeticCurveType.Geodesic)as Polygon;
Calculate geodetic distance, azimuth between two points
// get all the geographic coordinate systemsIReadOnlyList<CoordinateSystemListEntry>gcs_list= GeometryEngine.Instance.GetPredefinedCoordinateSystemList(CoordinateSystemFilter.GeographicCoordinateSystem);// get the projected coordinate systemsIReadOnlyList<CoordinateSystemListEntry>proj_list= GeometryEngine.Instance.GetPredefinedCoordinateSystemList(CoordinateSystemFilter.ProjectedCoordinateSystem);// get the vertical coordinate systemsIReadOnlyList<CoordinateSystemListEntry>vert_list= GeometryEngine.Instance.GetPredefinedCoordinateSystemList(CoordinateSystemFilter.VerticalCoordinateSystem);// get geographic and projected coordinate systemsIReadOnlyList<CoordinateSystemListEntry>combined_list= GeometryEngine.Instance.GetPredefinedCoordinateSystemList(CoordinateSystemFilter.GeographicCoordinateSystem | CoordinateSystemFilter.ProjectedCoordinateSystem);// investigate one of the entriesCoordinateSystemListEntryentry= gcs_list[0];intwkid= entry.Wkid;stringcategory= entry.Category;stringname= entry.Name;
Retrieve system geographic transformations
// a geographic transformation is the definition of how to project from one spatial reference to anotherIReadOnlyList<GeographicTransformationListEntry>list= GeometryEngine.Instance.GetPredefinedGeographicTransformationList();// a GeographicTransformationListEntry consists of Name, Wkid, the From SpatialReference Wkid, the To SpatialReference WkidGeographicTransformationListEntryentry= list[0];intfromWkid= entry.FromSRWkid;inttoWkid= entry.ToSRWkid;intwkid= entry.Wkid;stringname= entry.Name;
// determine intersection between two polylinesList<MapPoint>pts=newList<MapPoint>();
pts.Add(MapPointBuilderEx.CreateMapPoint(1.0,1.0));
pts.Add(MapPointBuilderEx.CreateMapPoint(3.0,3.0));
pts.Add(MapPointBuilderEx.CreateMapPoint(5.0,1.0));Polylineline1= PolylineBuilderEx.CreatePolyline(pts);List<MapPoint>pts2=newList<MapPoint>();
pts2.Add(MapPointBuilderEx.CreateMapPoint(1.0,3.0));
pts2.Add(MapPointBuilderEx.CreateMapPoint(3.0,1.0));
pts2.Add(MapPointBuilderEx.CreateMapPoint(5.0,3.0));Polylineline2= PolylineBuilderEx.CreatePolyline(pts2);boolintersects= GeometryEngine.Instance.Intersects(line1, line2);// intersects = trueGeometryg= GeometryEngine.Instance.Intersection(line1, line2, GeometryDimensionType.EsriGeometry0Dimension);MultipointresultMultipoint= g as Multipoint;// result is a multiPoint that intersects at (2,2) and (4,2)
Intersection between two Polygons
// determine intersection between two polygonsEnvelopeenv1= EnvelopeBuilderEx.CreateEnvelope(new Coordinate2D(3.0,2.0),new Coordinate2D(6.0,6.0));Polygonpoly1= PolygonBuilderEx.CreatePolygon(env1);Envelopeenv2= EnvelopeBuilderEx.CreateEnvelope(new Coordinate2D(1.0,1.0),new Coordinate2D(4.0,4.0));Polygonpoly2= PolygonBuilderEx.CreatePolygon(env2);PolygonpolyResult= GeometryEngine.Instance.Intersection(poly1, poly2)as Polygon;
Get the M values at the specified distance along the multipart
stringjson="{\"hasM\":true,\"paths\":[[[-3000,-2000,-3],[-2000,-2000,-2]],[[-2000,-2000,1],[-2000,1000,2]]],\"spatialReference\":{\"wkid\":3857}}";Polylinepolyline= PolylineBuilderEx.FromJson(json);// polyline has 2 partsdoublem1,m2;
GeometryEngine.Instance.GetMsAtDistance(polyline,0, AsRatioOrLength.AsLength,out m1,out m2);// m1 = -3// m2 = NaN
GeometryEngine.Instance.GetMsAtDistance(polyline,500, AsRatioOrLength.AsLength,out m1,out m2);// m1 = -2.5// m2 = NaN
GeometryEngine.Instance.GetMsAtDistance(polyline,1000, AsRatioOrLength.AsLength,out m1,out m2);// m1 = -2// m2 = 1 // m2 has a value because distance 1000 is at the end of the first part, beginning of the second part
Insert M value at the given distance - InsertMAtDistance
stringjson="{\"hasM\":true,\"paths\":[[[-3000,-2000,-3],[-2000,-2000,-2],[-1000,-2000,null]]]}";Polylinepolyline= PolylineBuilderEx.FromJson(json);boolsplitHappened;intpartIndex,segmentIndex;// A point already exists at the given distancedoublem=-1;doubledistance=2000;boolcreateNewPart=false;PolylineoutputPolyline= GeometryEngine.Instance.InsertMAtDistance(polyline, m, distance, AsRatioOrLength.AsLength, createNewPart,out splitHappened,out partIndex,out segmentIndex)as Polyline;// splitHappened = false, partIndex = 0, segmentIndex = 2// outputPolyline.Points[2].M = -1json="{\"hasM\":true,\"paths\":[[[-3000,-2000,-3],[-2000,-2000,-2],[-1000,-2000,-1]],[[0,0,0],[0,1000,0],[0,2000,2]]],\"spatialReference\":{\"wkid\":3857}}";polyline= PolylineBuilderEx.FromJson(json);// A point already exists at the given distance, but createNewPart = truem=1;distance=3000;createNewPart=true;outputPolyline= GeometryEngine.Instance.InsertMAtDistance(polyline, m, distance, AsRatioOrLength.AsLength, createNewPart,out splitHappened,out partIndex,out segmentIndex)as Polyline;stringoutputJson= outputPolyline.ToJson();// splitHappened = true, partIndex = 2, segmentIndex = 0// outputJson = {"hasM":true,"paths":[[[-3000,-2000,-3],[-2000,-2000,-2],[-1000,-2000,-1]],[[0,0,0],[0,1000,1]],[[0,1000,1],[0,2000,2]]]}}// A new part has been created and the M values for outputPolyline.Points[4] and outputPolyline.Points[5] have been modified// A point does not exist at the given distancem=1;distance=3500;createNewPart=false;outputPolyline= GeometryEngine.Instance.InsertMAtDistance(polyline, m, distance, AsRatioOrLength.AsLength, createNewPart,out splitHappened,out partIndex,out segmentIndex)as Polyline;outputJson= outputPolyline.ToJson();// splitHappened = true even though createNewPart = false because a new point was created// partIndex = 1, segmentIndex = 2// outputJson = {"hasM":true,"paths":[[[-3000,-2000,-3],[-2000,-2000,-2],[-1000,-2000,-1]],[[0,0,0],[0,1000,0],[0,1500,1],[0,2000,2]]]}// A new point has been inserted (0, 1500, 1) by interpolating the X and Y coordinates and M value set to the input M value.
Calibrate M values using M values from input points - CalibrateByMs
stringjson="{\"hasM\":true,\"paths\":[[[-4,2,1],[-4,5,2],[-2,5,3],[-2,7,4],[2,7,5]],[[4,1,-1],[2,1,-2],[2,-2,-3],[-3,-2,-4],[-3,0,-5]]]}}";Polylinepolyline= PolylineBuilderEx.FromJson(json);PolylineoutputPolyline= GeometryEngine.Instance.DropMs(polyline)as Polyline;// outputPolyline.HasM = true. Every M-value is NaN.// outputPolyline.ToJson() = {"hasM":true,"paths":[[[-4,2,null],[-4,5,null],[-2,5,null],[-2,7,null],[2,7,null]],[[4,1,-null],[2,1,null],[2,-2,null],[-3,-2,null],[-3,0,null]]]}
Extrapolate M-values based on a range defined by part and vertex indices - ExtrapolateMs
stringjson="{\"hasM\":true,\"paths\":[[[2,0,50],[2,1,40],[3,1,30],[3,5,60],[7,5,12],[7,1,20],[9,1,28],[9,3,10]]],\"spatialReference\":{\"wkid\":4326}}";Polylinepolyline= PolylineBuilderEx.FromJson(json);// Extrapolate M-values from part 0, point 3 to part 0, point 5PolylineoutPolyline= GeometryEngine.Instance.ExtrapolateMs(polyline, ExtrapolateMMethod.ExtrapolateBefore,0,3,0,5)as Polyline;// The points in outPolyline are (x, y, m):// ( 2, 0, 90 ), ( 2, 1, 85 ), ( 3, 1, 80 ), ( 3, 5, 60 ), ( 7, 5, 12 ), ( 7, 1, 20 ), ( 9, 1, 28 ), ( 9, 3, 10 )json="{\"hasM\":true,\"paths\":[[[2,0,50],[2,1,40],[3,1,30],[3,5,60],[7,5,12],[7,1,20],[9,1,28],[9,3,10]],[[5,-4,-10],[5,-2,-40],[10,-2,-60],[10,-6,-50],[8,-6,-40],[8,-4,-80],[6,-4,-90]]],\"spatialReference\":{\"wkid\":4326}}";polyline= PolylineBuilderEx.FromJson(json);// Extrapolate M-values from part 0, point 5 to part1, point 1outPolyline= GeometryEngine.Instance.ExtrapolateMs(polyline, ExtrapolateMMethod.ExtrapolateAfter,0,5,1,1)as Polyline;// The points in part 0 of outPolyline don't change. They are (x, y, m):// ( 2, 0, 50 ), ( 2, 1, 40 ), ( 3, 1, 30 ), ( 3, 5, 60 ), ( 7, 5, 12 ), ( 7, 1, 20 ), ( 9, 1, 28 ), ( 9, 3, 10 )// The points in part 1 of outPolyline are (x, y, m):// ( 5, -4, -10 ), ( 5, -2, -40 ), ( 10, -2, -90 ), ( 10, -6, -130 ), ( 8, -6, -150 ), ( 8, -4, -170 ), ( 6, -4, -190 )
Get a list of distances along the multipart at points with the specified M-value - GetDistancesAtM
stringjson="{\"hasM\":true,\"paths\":[[[-4,1,1],[-4,3,2],[-2,3,3],[-2,5,1]],[[3,5,1],[3,2,2],[6,2,3],[6,-2,2]]]}";Polylinepolyline= PolylineBuilderEx.FromJson(json);// Get the distances as length measured from the start of the multipartIReadOnlyList<double>distances= GeometryEngine.Instance.GetDistancesAtM(polyline, AsRatioOrLength.AsLength,2);// distances.Count = 4// distances[0] = 2 measured to the point (-4, 3, 2)// distances[1] = 5 measured to the point (-2, 4, 2). Its M-value is interpolated from the segment (-2, 3, 3) -> (-2, 5, 1)// distances[2] = 9 measured to the point (3, 2, 2) // distances[3] = 16 measured to the point (6, -2, 2)// Get the distances as a ratio of the distance measured from the start of the multipart and the total length of the multipartdistances= GeometryEngine.Instance.GetDistancesAtM(polyline, AsRatioOrLength.AsRatio,2);// distances.Count = 4;// distances are { 0.125, 0.3125, 0.5625, 1 }
Get a polyline and other details corresponding to the subcurve(s) between the specified M-values - GetSubCurveBetweenMsEx
stringjson="{\"hasM\":true,\"paths\":[[[-2000,0,1],[-1000,1000,-1],[-1000,0,3],[1000,1000,4],[2000,1000,5],[2000,2000,6],[3000,2000,7],[4000,0,8]]],\"spatialReference\":{\"wkid\":3857}}";Polylinepolyline= PolylineBuilderEx.FromJson(json);// Get the subcurve between M-values 2 and 6MSubCurveRelationfromDetail,toDetail;PolylinesubCurve= GeometryEngine.Instance.GetSubCurveBetweenMsEx(polyline,2,6,out fromDetail,out toDetail);// The subcurve has one part and five points. The subcurve points are (x, y, m):// (-1000, 250, 2), (-1000, 0, 3), (1000, 1000, 4), (2000, 1000, 5), (2000, 2000, 6)// fromDetail = toDetail = MSubCurveRelation.MBetweenMinMax// Get the subcurve between M-values -2 and 3.5subCurve= GeometryEngine.Instance.GetSubCurveBetweenMsEx(polyline,-2,3.5,out fromDetail,out toDetail);// The subcurve has two parts and five points.// The subcurve points in part 0 are (x, y, m): (-1000, 1000, -1), (-2000, 0, 1)// The subcurve points in part 1 are (x, y, m): (-1000, 1000, -1), (-1000, 0, 3), (0, 500, 3.5)// fromDetail = MSubCurveRelation.MBelowMin, toDetail = MSubCurveRelation.MBetweenMinMax
Get a combination of monotonicity values that describes all trends in the M-values over the length of the multipart - GetMMonotonicity
stringjson="{\"hasM\":true,\"paths\":[[[-3000,-2000,10],[-2000,-2000,5],[-1000,-2000,0]]]}";Polylinepolyline= PolylineBuilderEx.FromJson(json);Monotonicitymonotonicity= GeometryEngine.Instance.GetMMonotonicity(polyline);// monotonicity = Monotonicity.ValueDecreases// Create a polygon from the polylinePolygonpolygon= PolygonBuilderEx.CreatePolygon(polyline);monotonicity= GeometryEngine.Instance.GetMMonotonicity(polygon);// monotonicity = ValueIncreases | ValueDecreasesjson="{\"hasM\":true,\"paths\":[[[-3000,-2000,10],[-2000,-2000,10],[-1000,-2000,10]]]}";polyline= PolylineBuilderEx.FromJson(json);monotonicity= GeometryEngine.Instance.GetMMonotonicity(polygon);// monotonicity = Monotonicity.ValueLeveljson="{\"hasM\":true,\"paths\":[[[-3000,-2000,null],[-2000,-2000,5],[-1000,-2000,10]]]}";polyline= PolylineBuilderEx.FromJson(json);monotonicity= GeometryEngine.Instance.GetMMonotonicity(polyline);// monotonicity = ValueIncreases | ValueEmpty// Create an empty polylinePolylineemptyPolyline= PolylineBuilderEx.FromJson("{\"hasM\":true,\"paths\":[]}");monotonicity= GeometryEngine.Instance.GetMMonotonicity(emptyPolyline);// monotonicity = Monotonicity.None
Generates M-values by linear interpolation over a range of points - InterpolateMsBetween
stringjson="{\"hasM\":true,\"paths\":[[[0,0,-1],[1,0,0],[1,1,1],[1,2,2],[3,1,3],[5,3,4],[9,5,5],[7,6,6]]],\"spatialReference\":{\"wkid\":4326}}";Polylinepolyline= PolylineBuilderEx.FromJson(json);// Interpolate between points 2 and 6PolylineoutPolyline= GeometryEngine.Instance.InterpolateMsBetween(polyline,0,2,0,6)as Polyline;// The points of the output polyline are// (0, 0, -1), (1, 0, 0), (1, 1, 1), (1, 2, 1.3796279833912741), (3, 1, 2.2285019604153242), (5, 3, 3.3022520459518998), (9, 5, 5), (7, 6, 6)
Determine if all the M-values are numbers - IsMSimple
// Create a multipoint and multiply M-values by 6
Coordinate2D[]coords=new Coordinate2D[]{new Coordinate2D(-4,4),new Coordinate2D(-1,1),new Coordinate2D(2,6),new Coordinate2D(-8,2),new Coordinate2D(5,-3),new Coordinate2D(7,2),new Coordinate2D(5,3),new Coordinate2D(3,-1)};double[]ms=newdouble[]{1,2,3,4,5,6,7,8};MultipointBuilderExbuilder=new MultipointBuilderEx(coords);
builder.Ms =ms;
builder.HasM =true;Multipointmultipoint= builder.ToGeometry();MultipointoutMultipoint= GeometryEngine.Instance.MultiplyMs(multipoint,6)as Multipoint;// The xy-values of the points in outMultipoint are the same as the points in the input multipoint.// The M-values in outMultipoint are { 6, 12, 18, 24, 30, 36, 42, 48 }
Add an offset value to each of the M-values - OffsetMs
// Create a polyline and add an offset of 2 to each of the M-valuesMapPointBuilderExpointBuilder=new MapPointBuilderEx(0,0);
pointBuilder.M =1;MapPointpoint1= pointBuilder.ToGeometry();
pointBuilder.SetValues(2,2);
pointBuilder.M =3;MapPointpoint2= pointBuilder.ToGeometry();Polylinepolyline= PolylineBuilderEx.CreatePolyline(new MapPoint[]{ point1, point2 }, AttributeFlags.HasM);;PolylineoutPolyline= GeometryEngine.Instance.OffsetMs(polyline,2)as Polyline;// The xy-values of the points in outPolyline are the same as the points in the input polyline.// The M-values in outPolyline are { 3, 5 }// Create an envelope and add an offset of 25 to each of the M-valuesEnvelopeBuilderExenvelopeBuilder=new EnvelopeBuilderEx(-5,1,2,4);
envelopeBuilder.MMin =10;
envelopeBuilder.MMax =20;Envelopeenvelope= envelopeBuilder.ToGeometry();EnvelopeoutEnvelope= GeometryEngine.Instance.OffsetMs(envelope,25)as Envelope;// The xy-values of the points in outEnvelope are the same as the points in the input envelope.// outEnvelope.MMin = 35, outEnvelope.MMax = 45// Add a negative offset to the M-values of the envelopeoutEnvelope= GeometryEngine.Instance.OffsetMs(envelope,-10)as Envelope;// The xy-values of the points in outEnvelope are the same as the points in the input envelope.// outEnvelope.MMin = 0, outEnvelope.MMax = 10
Reorient a polyine such that all M-values are non-decreasing, if possible - OrientByMs
stringjson="{\"hasM\":true,\"paths\":[[[0,0,1],[0,1,0],[1,1,-1],[1,0,-2]]]}";Polylinepolyline= PolylineBuilderEx.FromJson(json);PolylineoutputPolyline= GeometryEngine.Instance.OrientByMs(polyline);// The points of outputPolyline are (x, y, m): (1, 0, -2), (1, 1, -1), (0, 1, 0), (0, 0, 1)// M-values of second part is not monotonic, so it won't change. The first part will change.json="{\"hasM\":true,\"paths\":[[[0,0,1],[0,1,0],[1,1,-1],[1,0,-2]],[[5,4,6],[6,4,5],[8,6,7]]]}";polyline= PolylineBuilderEx.FromJson(json);outputPolyline= GeometryEngine.Instance.OrientByMs(polyline);// The points of part 0 of outputPolyline are (x, y, m): (1, 0, -2), (1, 1, -1), (0, 1, 0), (0, 0, 1)// The points of part 1 of outputPolyline are (x, y, m): (5, 4, 6), (6, 4, 5), (8, 6, 7)
Get the first and last defined M-values in a polyline - QueryFirstLastM
stringjson="{\"hasM\":true,\"paths\":[[[5,4,6],[6,4,5],[8,6,7]],[[0,0,1],[0,1,0],[1,1,-1],[1,0,-2]]]}";Polylinepolyline= PolylineBuilderEx.FromJson(json);doublefirstM,lastM;
GeometryEngine.Instance.QueryFirstLastM(polyline,out firstM,out lastM);// firstM = 6, lastM = -2json="{\"hasM\":true,\"paths\":[[[5,4,null],[6,4,5],[8,6,7]],[[0,0,1],[0,1,0],[1,1,-1],[1,0,null]]]}";polyline= PolylineBuilderEx.FromJson(json);
GeometryEngine.Instance.QueryFirstLastM(polyline,out firstM,out lastM);// firstM = 5, lastM = -1json="{\"hasM\":true,\"paths\":[[[5,4,null],[6,4,null],[8,6,null]],[[0,0,null],[0,1,null],[1,1,null],[1,0,null]]]}";polyline= PolylineBuilderEx.FromJson(json);
GeometryEngine.Instance.QueryFirstLastM(polyline,out firstM,out lastM);// firstM and lastM are NaNjson="{\"hasM\":true,\"paths\":[]}";polyline= PolylineBuilderEx.FromJson(json);
GeometryEngine.Instance.QueryFirstLastM(polyline,out firstM,out lastM);// firstM and lastM are NaN
Reverse the order of the M-values along a multipart - ReverseMs
stringjson="{\"hasM\":true,\"paths\":[[[5,4,6],[6,4,5],[8,6,7]]],\"spatialReference\":{\"wkid\":4326}}";Polylinepolyline= PolylineBuilderEx.FromJson(json);PolylineoutputPolyline= GeometryEngine.Instance.ReverseMs(polyline)as Polyline;// The xy-coordinates in outputPolyline are not changed. // The M-values in outputPolyline are: { 7, 5, 6 }
Set Ms at the beginning and end of the geometry and interpolate M-values between the two values - SetAndInterpolateMsBetween
stringjson="{\"hasM\":true,\"paths\":[[[-3000,-2000],[-2000,-2000],[-1000,-2000],[0,-2000],[1000,-2000],[2000,-2000],[3000,-2000],[4000,-2000]]],\"spatialReference\":{\"wkid\":3857}}";Polylinepolyline= PolylineBuilderEx.FromJson(json);PolylineoutPolyline= GeometryEngine.Instance.SetAndInterpolateMsBetween(polyline,100,800)as Polyline;ReadOnlyPointCollectionoutPoints= outPolyline.Points;// outPoints M values are { 100, 200, 300, 400, 500, 600, 700, 800 };
Set the M-values to the cumulative length of the start of the multipart - SetMsAtDistance
stringjson="{\"hasM\":true,\"paths\":[[[-3000,-2000,1],[-2000,-2000,2],[-1000,-2000,3],[0,-2000,null],[1000,-2000,4],[2000,-2000,5],[3000,-2000,10],[4000,-2000,11],[5000,-2000,12],[6000,-2000,13],[7000,-2000,14]]],\"spatialReference\":{\"wkid\":3857}}";Polylinepolyline= PolylineBuilderEx.FromJson(json);PolylineoutPolyline= GeometryEngine.Instance.SetMsAsDistance(polyline, AsRatioOrLength.AsLength)as Polyline;// The xy-coordinates don't change. // The M-values of the vertices in outPolyline are (x, y, m): // { 0, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000 }json="{\"hasM\":true,\"rings\":[[[0,0],[0,3000],[4000,3000],[4000,0],[0,0]]],\"spatialReference\":{\"wkid\":3857}}";Polygonpolygon= PolygonBuilderEx.FromJson(json);PolygonoutPolygon= GeometryEngine.Instance.SetMsAsDistance(polygon, AsRatioOrLength.AsLength)as Polygon;// The M-values of the vertices in outPolygon are (x, y, m): { 0, 3000, 7000, 10000, 14000 };
Set the M-values of the vertices as scaled and offset distances measured along a polyline - SetMsAsDistance
stringjson="{\"hasM\":true,\"paths\":[[[0,0,1],[3,0,2],[3,6,3],[7,6,4]]],\"spatialReference\":{\"wkid\":4326}}";Polylinepolyline= PolylineBuilderEx.FromJson(json);Coordinate2Dorigin=new Coordinate2D(0,0);PolylineoutputPolyline= GeometryEngine.Instance.SetMsAsDistance(polyline, origin,0.5,1,true)as Polyline;// The xy-coordinates of the polyline don't change.// The points of outputPolyline are (x, y, m): // (0, 0, 1), (3, 0, 2.5), (3, 6, 5.5), (7, 6, 7.5)// Measurements will start at the end of the polyline, point (7, 6)origin=new Coordinate2D(4,6);outputPolyline= GeometryEngine.Instance.SetMsAsDistance(polyline, origin,0.5,1,true)as Polyline;// The points of outputPolyline are (x, y, m): // (0, 0, 7.5), (3, 0, 6), (3, 6, 3), (7, 6, 1)
Snap the M-values to the M-precision of the spatial reference - SnapMsToSpatialReference
SpatialReferencesr= SpatialReferences.WebMercator;// precision = 1 / MScale = 0.0001// MapPointMapPointBuilderExpointBuilder=new MapPointBuilderEx(3,4, sr);
pointBuilder.M =5.00006;MapPointpoint= pointBuilder.ToGeometry();MapPointoutputPoint= GeometryEngine.Instance.SnapMsToSpatialReference(point)as MapPoint;// outputPoint.M = 5.0001// MultipointpointBuilder=new MapPointBuilderEx(-3,-4, sr);
pointBuilder.M =-5.000007;MapPointpoint2= pointBuilder.ToGeometry();Multipointmultipoint= MultipointBuilderEx.CreateMultipoint(new MapPoint[]{ point, point2 }, AttributeFlags.HasM, sr);MultipointoutputMultipoint= GeometryEngine.Instance.SnapMsToSpatialReference(multipoint)as Multipoint;// outputMultipoint.Points[0].M = 5.0001, outputMultipoint.Points[1].M = -5// Polylinestringjson="{\"hasM\":true,\"paths\":[[[3,2,10.00065],[3,4,15.000325],[5,4,20],[5,2,15.000325],[3,2,10.00065]]],\"spatialReference\":{\"wkid\":3857}}";Polylinepolyline= PolylineBuilderEx.FromJson(json);PolylineoutputPolyline= GeometryEngine.Instance.SnapMsToSpatialReference(polyline)as Polyline;// The M-values for the vertices in outputPolyline are { 10.0007, 15.0003, 20, 15.0003, 10.0007 }
Set the M-values of the vertices as scaled and offset M distances measured along a polyline - UpdateAllMsByMs
stringjson="{\"hasM\":true,\"paths\":[[[-8,2,1],[-8,5,8],[-5,5,0],[-5,7,12]],[[3,2,20],[7,2,30],[7,4,10],[13,4,5]]]}";Polylinepolyline= PolylineBuilderEx.FromJson(json);Coordinate2Dorigin=new Coordinate2D(-5,6);PolylineoutputPolyline= GeometryEngine.Instance.UpdateAllMsByMs(polyline, origin,1,0,true);// The xy-coordinates don't change. // The M-values of the vertices in part 0 of outputPolyline are { 27, 20, 12, 0 }// The M-values of the vertices in part 1 of outputPolyline are { 27, 37, 57, 62 }outputPolyline= GeometryEngine.Instance.UpdateAllMsByMs(polyline, origin,2,4,true);// The M-values of the vertices in part 0 of outputPolyline are { 58, 44, 28, 4 }// The M-values of the vertices in part 1 of outputPolyline are { 58, 78, 118, 128 }
Update M-values along the shortest path between the specified vertices - UpdateMsByDistance
stringjson="{\"hasM\":true,\"paths\":[[[-8,2,1],[-8,5,8],[-5,5,0],[-5,7,12]]],\"spatialReference\":{\"wkid\":4326}}";Polylinepolyline= PolylineBuilderEx.FromJson(json);PolylineoutputPolyline= GeometryEngine.Instance.UpdateMsByDistance(polyline,0,0,0,2,10,20, UpdateMMethod.Interpolate,true);// The xy-coordinates don't change.// The M-values of the vertices in outputPolyline are { 10, 15, 20, 12 }json="{\"hasM\":true,\"paths\":[[[-8,2,1],[-8,5,8],[-5,5,0],[-5,7,12]],[[3,2,20],[7,2,30],[7,4,10],[13,4,5]]]}";polyline= PolylineBuilderEx.FromJson(json);outputPolyline= GeometryEngine.Instance.UpdateMsByDistance(polyline,0,2,1,1,10,20, UpdateMMethod.ExtrapolateBefore,true);// The M-values of the vertices in part 0 of outputPolyline are { -5, 2.5, 10, 5 }// The M-values of the vertices in part 1 of outputPolyline are { 20, 20, 10, 5 }
Update M-values with the interpolation ratio determined by existing M-values and the input M-values - UpdateMsByMs
stringjson="{\"hasM\":true,\"paths\":[[[-8,2,1],[-8,5,8],[-5,5,0],[-5,7,12]]],\"spatialReference\":{\"wkid\":4326}}";Polylinepolyline= PolylineBuilderEx.FromJson(json);PolylineoutputPolyline= GeometryEngine.Instance.UpdateMsByMs(polyline,0,1,0,3,-2,14, UpdateMMethod.Interpolate);// The xy-coordinates don't change.// The M-values of the vertices in outputPolyline are (x, y, m): { 1, -2, 30, 14 }
Move a MapPoint
MapPointpt= MapPointBuilderEx.CreateMapPoint(1.0,3.0);MapPointptResult= GeometryEngine.Instance.Move(pt,-3.5,2.5)as MapPoint;// ptResult is (-2.5, 5.5)
Move a z-aware MapPoint
MapPointzPt= MapPointBuilderEx.CreateMapPoint(1.0,3.0,2.0);MapPointzPtResult= GeometryEngine.Instance.Move(zPt,4,0.25,0.5)as MapPoint;// zPtResult is (5.0, 3.25, 2.5);
LineSegmentline= LineBuilderEx.CreateLineSegment(MapPointBuilderEx.CreateMapPoint(0,3), MapPointBuilderEx.CreateMapPoint(5.0,3.0));Polylinepolyline= PolylineBuilderEx.CreatePolyline(line);boolsimple= GeometryEngine.Instance.IsSimpleAsFeature(polyline);// ratio = falseMapPointpt= GeometryEngine.Instance.MovePointAlongLine(polyline,1.0,false,0.0, SegmentExtensionType.NoExtension);// pt = 1.0, 3.0pt= GeometryEngine.Instance.MovePointAlongLine(polyline,1.0,false,-1.0, SegmentExtensionType.NoExtension);// pt = 1.0, 4.0pt= GeometryEngine.Instance.MovePointAlongLine(polyline,1.0,false,2.0, SegmentExtensionType.NoExtension);// pt = 1.0, 1.0// ratio = truept= GeometryEngine.Instance.MovePointAlongLine(polyline,0.5,true,0, SegmentExtensionType.NoExtension);// pt = 2.5, 3.0// move past the linept= GeometryEngine.Instance.MovePointAlongLine(polyline,7,false,0, SegmentExtensionType.NoExtension);// pt = 5.0, 3.0// move past the line with extension at "to" pointpt= GeometryEngine.Instance.MovePointAlongLine(polyline,7,false,0, SegmentExtensionType.ExtendEmbeddedAtTo);// pt = 7.0, 3.0// negative distance with extension at "from" pointpt= GeometryEngine.Instance.MovePointAlongLine(polyline,-2,false,0, SegmentExtensionType.ExtendEmbeddedAtFrom);// pt = -2.0, 3.0// ratio = truept= GeometryEngine.Instance.MovePointAlongLine(polyline,0.5,true,0, SegmentExtensionType.NoExtension);// pt = 2.5, 3.0// line with ZList<Coordinate3D>coords3D=newList<Coordinate3D>{new Coordinate3D(0,0,0),new Coordinate3D(1113195,1118890,5000)};PolylinepolylineZ= PolylineBuilderEx.CreatePolyline(coords3D, SpatialReferences.WebMercator);// polylineZ.HasZ = true// ratio = true, no offsetpt= GeometryEngine.Instance.MovePointAlongLine(polylineZ,0.5,true,0, SegmentExtensionType.NoExtension);// pt.X = 556597.5// pt.Y = 559445// pt.Z = 2500// ratio = true, past the line with "to" extension, no offsetpt= GeometryEngine.Instance.MovePointAlongLine(polylineZ,1.5,true,0, SegmentExtensionType.ExtendEmbeddedAtTo);// pt.X = 1669792.5// pt.Y = 1678335// pt.Z = 7500// ratio = true, negative distance past the line with no extension, no offsetpt= GeometryEngine.Instance.MovePointAlongLine(polylineZ,-1.5,true,0, SegmentExtensionType.NoExtension);// pt.X = 0// pt.Y = 0// pt.Z = -7500// polyline with Z but 2d distance = 0MapPointpt3= MapPointBuilderEx.CreateMapPoint(5,5,0);MapPointpt4= MapPointBuilderEx.CreateMapPoint(5,5,10);List<MapPoint>pts=newList<MapPoint>(){ pt3, pt4 };polyline= PolylineBuilderEx.CreatePolyline(pts);// polyline.HasZ = true// polyline.Length3D = 10// polyline.Length = 0MapPointresult= GeometryEngine.Instance.MovePointAlongLine(polyline,2,false,0, SegmentExtensionType.NoExtension);// result = 5, 5, 2// polyline with length2d = 0 and length3d = 0MapPointpt5= MapPointBuilderEx.CreateMapPoint(5,5,10);MapPointpt6= MapPointBuilderEx.CreateMapPoint(5,5,10);
pts.Clear();
pts.Add(pt5);
pts.Add(pt6);polyline= PolylineBuilderEx.CreatePolyline(pts);// polyline.HasZ = true// polyline.Length3D = 0// polyline.Length = 0result= GeometryEngine.Instance.MovePointAlongLine(polyline,3,true,0, SegmentExtensionType.NoExtension);// result = 5, 5, 10result= GeometryEngine.Instance.MovePointAlongLine(polyline,3,true,0, SegmentExtensionType.ExtendEmbeddedAtFrom);// result = 5, 5, 10// polyline with Z and MList<MapPoint>inputPoints=newList<MapPoint>(){
MapPointBuilderEx.CreateMapPoint(1,2,3,4),
MapPointBuilderEx.CreateMapPoint(1,2,33,44),};PolylinepolylineZM= PolylineBuilderEx.CreatePolyline(inputPoints, SpatialReferences.WGS84);// polylineZM.HasZ = true// polylineZM.HasM = true// ratio = true, no offsetMapPointpointAlong= GeometryEngine.Instance.MovePointAlongLine(polylineZM,0.5,true,0, SegmentExtensionType.NoExtension);// pointAlong = 1, 2, 18, 24// ratio = true with offsetpointAlong= GeometryEngine.Instance.MovePointAlongLine(polylineZM,0.2,true,2.23606797749979, SegmentExtensionType.NoExtension);// pointAlong = 1, 2, 9, 12
Separate components of a geometry into single component geometries
List<Coordinate2D>coords2D=newList<Coordinate2D>(){new Coordinate2D(0,0),new Coordinate2D(1,4),new Coordinate2D(2,7),new Coordinate2D(-10,3)};Multipointmultipoint= MultipointBuilderEx.CreateMultipoint(coords2D, SpatialReferences.WGS84);IReadOnlyList<Geometry>result= GeometryEngine.Instance.MultipartToSinglePart(multipoint);// result.Count = 4, // 'explode' a multipart polygonresult= GeometryEngine.Instance.MultipartToSinglePart(multipartPolygon);// create a bag of geometriesPolygonpolygon= PolygonBuilderEx.CreatePolygon(coords2D, SpatialReferences.WGS84);//At 2.x - GeometryBag bag = GeometryBagBuilder.CreateGeometryBag(new List<Geometry>() { multipoint, polygon });varbag= GeometryBagBuilderEx.CreateGeometryBag(newList<Geometry>(){ multipoint, polygon });// bag.PartCount = =2result= GeometryEngine.Instance.MultipartToSinglePart(bag);// result.Count == 2// result[0] is MultiPoint// result[1] is Polygon
Nearest Point versus Nearest Vertex
SpatialReferencesr= SpatialReferences.WGS84;MapPointpt= MapPointBuilderEx.CreateMapPoint(5,5, sr);List<Coordinate2D>coords=newList<Coordinate2D>(){new Coordinate2D(10,1),new Coordinate2D(10,-4),new Coordinate2D(0,-4),new Coordinate2D(0,1),new Coordinate2D(10,1)};Polygonpolygon= PolygonBuilderEx.CreatePolygon(coords);// find the nearest point in the polygon geomtry to the ptProximityResultresult= GeometryEngine.Instance.NearestPoint(polygon, pt);// result.Point = 5, 1// result.SegmentIndex = 3// result.PartIndex = 0// result.PointIndex = null//result.Distance = 4//result.RightSide = false// find the nearest vertex in the polgyon geometry to the ptresult= GeometryEngine.Instance.NearestVertex(polygon, pt);// result.Point = 10, 1// result.PointIndex = 0// result.SegmentIndex = null// result.PartIndex = 0// result.Distance = Math.Sqrt(41)// result.RightSide = false
Determine Nearest Point in 3D
MapPointpt1= MapPointBuilderEx.CreateMapPoint(1,1,1);MapPointpt2= MapPointBuilderEx.CreateMapPoint(2,2,2);MapPointpt3= MapPointBuilderEx.CreateMapPoint(10,2,1);//// test pt1 to pt2//ProximityResultresult= GeometryEngine.Instance.NearestPoint3D(pt1, pt2);// result.Point = 1,1,1// result.Distance = Math.Sqrt(3)// result.SegmentIndex = null// result.PartIndex = 0// result.PointIndex = 0// result.RightSide = false// // multipoint built from pt1, pt2. should be closer to pt2// Multipointmultipoint= MultipointBuilderEx.CreateMultipoint(newList<MapPoint>(){ pt1, pt2 });result= GeometryEngine.Instance.NearestPoint3D(multipoint, pt3);// result.Point = 2, 2, 2// result.Distance = Math.Sqrt(65)// result.SegmentIndex = null// result.PartIndex = 1// result.PointIndex = 1// result.RightSide = false
Calculate a geometry offset from the source
List<MapPoint>linePts=newList<MapPoint>();
linePts.Add(MapPointBuilderEx.CreateMapPoint(1.0,1.0, SpatialReferences.WGS84));
linePts.Add(MapPointBuilderEx.CreateMapPoint(10.0,1.0, SpatialReferences.WGS84));Polylinepolyline= PolylineBuilderEx.CreatePolyline(linePts);Geometryg= GeometryEngine.Instance.Offset(polyline,10, OffsetType.Square,0);PolylinegResult= g as Polyline;// gResult.PointCount = 2// gResult.Points[0] = (1, -9)// gResult.Points[1] = (10, -9)g= GeometryEngine.Instance.Offset(polyline,-10, OffsetType.Round,0.5);gResult= g as Polyline;// gResult.PointCount = 2// gResult.Points[0] = (1, -11// gResult.Points[1] = (10, 11)//// elliptic arc curve//Coordinate2DfromPt=new Coordinate2D(2,1);Coordinate2DtoPt=new Coordinate2D(1,2);Coordinate2DinteriorPt=new Coordinate2D(1+ Math.Sqrt(2)/2,1+ Math.Sqrt(2)/2);EllipticArcSegmentcircularArc= EllipticArcBuilderEx.CreateCircularArc(fromPt.ToMapPoint(), toPt.ToMapPoint(), interiorPt);polyline= PolylineBuilderEx.CreatePolyline(circularArc);g= GeometryEngine.Instance.Offset(polyline,-0.25, OffsetType.Miter,0.5);gResult= g as Polyline;g= GeometryEngine.Instance.Offset(polyline,0.25, OffsetType.Bevel,0.5);gResult= g as Polyline;//// offset for a polygon//List<MapPoint>list=newList<MapPoint>();
list.Add(MapPointBuilderEx.CreateMapPoint(10.0,10.0, SpatialReferences.WGS84));
list.Add(MapPointBuilderEx.CreateMapPoint(10.0,20.0, SpatialReferences.WGS84));
list.Add(MapPointBuilderEx.CreateMapPoint(20.0,20.0, SpatialReferences.WGS84));
list.Add(MapPointBuilderEx.CreateMapPoint(20.0,10.0, SpatialReferences.WGS84));Polygonpolygon= PolygonBuilderEx.CreatePolygon(list);g= GeometryEngine.Instance.Offset(polygon,2, OffsetType.Square,0);PolygongPolygon= g as Polygon;g= GeometryEngine.Instance.Offset(polygon,-2, OffsetType.Round,0.3);gPolygon= g as Polygon;g= GeometryEngine.Instance.Offset(polygon,-0.5, OffsetType.Miter,0.6);gPolygon= g as Polygon;
Determine if geometries overlap
MapPointpt1= MapPointBuilderEx.CreateMapPoint(1.5,1.5);MapPointpt2= MapPointBuilderEx.CreateMapPoint(1.25,1.75);MapPointpt3= MapPointBuilderEx.CreateMapPoint(3,1.5);MapPointpt4= MapPointBuilderEx.CreateMapPoint(1.5,2);//// point and point overlap//booloverlaps= GeometryEngine.Instance.Overlaps(pt1, pt2);// overlaps = falseoverlaps= GeometryEngine.Instance.Overlaps(pt1, pt1);// overlaps = false// Two geometries overlap if the region of their intersection is of the same dimension as the geometries involved and // is not equivalent to either of the geometries. List<MapPoint>pts=newList<MapPoint>();
pts.Add(pt1);
pts.Add(pt2);
pts.Add(pt3);List<MapPoint>pts2=newList<MapPoint>();
pts2.Add(pt2);
pts2.Add(pt3);
pts2.Add(pt4);//// pt and line overlap//Polylinepolyline= PolylineBuilderEx.CreatePolyline(pts);boolisSimple= GeometryEngine.Instance.IsSimpleAsFeature(polyline);// isSimple = trueoverlaps= GeometryEngine.Instance.Overlaps(polyline, pt1);// overlaps = false//// line and line//Polylinepolyline2= PolylineBuilderEx.CreatePolyline(pts2);isSimple= GeometryEngine.Instance.IsSimpleAsFeature(polyline2);// isSimple = trueoverlaps= GeometryEngine.Instance.Overlaps(polyline, polyline2);// overlaps = true
Project from WGS84 to WebMercator
MapPointpt= MapPointBuilderEx.CreateMapPoint(1.0,3.0, SpatialReferences.WGS84);Geometryresult= GeometryEngine.Instance.Project(pt, SpatialReferences.WebMercator);MapPointprojectedPt= result as MapPoint;
Project from WGS84
// create the polygonList<MapPoint>pts=newList<MapPoint>();
pts.Add(MapPointBuilderEx.CreateMapPoint(1.0,1.0, SpatialReferences.WGS84));
pts.Add(MapPointBuilderEx.CreateMapPoint(1.0,2.0, SpatialReferences.WGS84));
pts.Add(MapPointBuilderEx.CreateMapPoint(2.0,2.0, SpatialReferences.WGS84));
pts.Add(MapPointBuilderEx.CreateMapPoint(2.0,1.0, SpatialReferences.WGS84));Polygonpolygon= PolygonBuilderEx.CreatePolygon(pts);// ensure it is simpleboolisSimple= GeometryEngine.Instance.IsSimpleAsFeature(polygon);// create the spatial reference to project toSpatialReferencenorthPole= SpatialReferenceBuilder.CreateSpatialReference(102018);// north pole stereographic // projectGeometrygeometry= GeometryEngine.Instance.Project(polygon, northPole);
MapPointpt= MapPointBuilderEx.CreateMapPoint(1.0,3.0);MapPointrotatePt= MapPointBuilderEx.CreateMapPoint(3.0,3.0);Geometryresult= GeometryEngine.Instance.Rotate(pt, rotatePt, Math.PI /2);// result point is (3, 1)
List<Coordinate2D>coords=newList<Coordinate2D>(){new Coordinate2D(8,0),new Coordinate2D(8,4),new Coordinate2D(6,4),new Coordinate2D(8,4),new Coordinate2D(10,4),new Coordinate2D(8,4)};SpatialReferencesr= SpatialReferences.WGS84;// build a line that has segments that cross over each otherPolylinepolyline= PolylineBuilderEx.CreatePolyline(coords, sr);// polyline.PartCount = 1ReadOnlyPartCollectionparts= polyline.Parts;ReadOnlySegmentCollectionsegments= parts[0];// segments.Count = 5// note there is a difference between SimpleAsFeature (doesn't detect intersections and overlaps, determines if it's simple enough for gdb storage)// and SimplifyPolyline (does detect intersections etc)boolisSimple= GeometryEngine.Instance.IsSimpleAsFeature(polyline,false);// isSimple = true// simplify it (with force = false)// because it has already been deemed 'simple' (previous IsSimpleAsFeature call) no detection of intersections, overlaps occurPolylinesimplePolyline= GeometryEngine.Instance.SimplifyPolyline(polyline, SimplifyType.Planar,false);// simplePolyline.PartCount = 1ReadOnlyPartCollectionsimpleParts= simplePolyline.Parts;ReadOnlySegmentCollectionsimpleSegments= simpleParts[0];// simpleSegments.Count = 5// simplify it (with force = true)// detection of intersections, overlaps occur simplePolyline= GeometryEngine.Instance.SimplifyPolyline(polyline, SimplifyType.Planar,true);// simplePolyline.PartCount = 3simpleParts= simplePolyline.Parts;simpleSegments= simpleParts[0];// simpleSegments.Count = 1
// define a polylineMapPointstartPointZ= MapPointBuilderEx.CreateMapPoint(1,1,5);MapPointendPointZ= MapPointBuilderEx.CreateMapPoint(20,1,5);PolylinepolylineZ= PolylineBuilderEx.CreatePolyline(newList<MapPoint>(){ startPointZ, endPointZ });// define a split pointMapPointsplitPointAboveLine= MapPointBuilderEx.CreateMapPoint(10,10,10);boolsplitOccurred;intpartIndex;intsegmentIndex;// split the polyline at the point. dont project the split point onto the line, don't create a new partvarsplitPolyline= GeometryEngine.Instance.SplitAtPoint(polylineZ, splitPointAboveLine,false,false,out splitOccurred,out partIndex,out segmentIndex);// splitOccurred = true// partIndex = 0// segmentIndex = 1// splitPolyline.PointCount = 3// splitPolyline.PartCount = 1// splitPolyline coordinates are (1, 1, 5), (10, 10, 10), (20, 1, 5)// split the polyline at the point. dont project the split point onto the line, do create a new partsplitPolyline= GeometryEngine.Instance.SplitAtPoint(polylineZ, splitPointAboveLine,false,false,out splitOccurred,out partIndex,out segmentIndex);// splitOccurred = true// partIndex = 1// segmentIndex = 0// splitPolyline.PointCount = 4// splitPolyline.PartCount = 2// splitPolyline first part coordinates are (1, 1, 5), (10, 10, 10)// splitPolyline second part coordinates are (10, 10, 10), (20, 1, 5)// split the polyline at the point. do project the split point onto the line, don't create a new partsplitPolyline= GeometryEngine.Instance.SplitAtPoint(polylineZ, splitPointAboveLine,false,false,out splitOccurred,out partIndex,out segmentIndex);// splitOccurred = true// partIndex = 0// segmentIndex = 1// splitPolyline.PointCount = 3// splitPolyline.PartCount = 1// splitPolyline coordinates are (1, 1, 5), (10, 10, 5), (20, 1, 5)// split the polyline at the point. do project the split point onto the line, do create a new partsplitPolyline= GeometryEngine.Instance.SplitAtPoint(polylineZ, splitPointAboveLine,false,false,out splitOccurred,out partIndex,out segmentIndex);// splitOccurred = true// partIndex = 1// segmentIndex = 0// splitPolyline.PointCount = 4// splitPolyline.PartCount = 2// splitPolyline first part coordinates are (1, 1, 5), (10, 10, 5)// splitPolyline second part coordinates are (10, 10, 5), (20, 1, 5)//// try to split with a point that won't split the line - pt extends beyond the line//varpointAfterLine= MapPointBuilderEx.CreateMapPoint(50,1,10);splitPolyline= GeometryEngine.Instance.SplitAtPoint(polylineZ, pointAfterLine,false,false,out splitOccurred,out partIndex,out segmentIndex);// splitOccurred = false// ignore partIndex, sgementIndex// splitPolyline is the same as polylineZ////// multipart polygon///List<Coordinate3D>coordsZ=newList<Coordinate3D>(){new Coordinate3D(10,10,5),new Coordinate3D(10,20,5),new Coordinate3D(20,20,5),new Coordinate3D(20,10,5)};List<Coordinate3D>coordsZ_2ndPart=newList<Coordinate3D>(){new Coordinate3D(30,20,10),new Coordinate3D(30,30,10),new Coordinate3D(35,28,10),new Coordinate3D(40,30,10),new Coordinate3D(40,20,10),};varbuilder=new PolygonBuilderEx();
builder.HasZ =true;
builder.AddPart(coordsZ);
builder.AddPart(coordsZ_2ndPart);Polygonmultipart= builder.ToGeometry();// pointA is closer to the first part of the multipart - the split occurs in the first partvarpointA= MapPointBuilderEx.CreateMapPoint(22,18,7);varsplitPolygon= GeometryEngine.Instance.SplitAtPoint(multipart, pointA,false,false,out splitOccurred,out partIndex,out segmentIndex);// splitPolygon.PointCount = 12// splitPolygon.PartCount = 2// splitPolygon first part coordinates (10, 10, 5), (10, 20, 5), (20, 20, 5), (22, 18, 7), (20, 10, 5), (10, 10, 5)// pointB is midPoint between the 2 parts - no split will occurvarpointB= MapPointBuilderEx.CreateMapPoint(25,20,7);splitPolygon= GeometryEngine.Instance.SplitAtPoint(multipart, pointB,true,false,out splitOccurred,out partIndex,out segmentIndex);// splitOccurred = false// ignore partIndex, sgementIndex// splitPolyline is the same as polylineZ
Polygon touches another Polygon
// two disjoint polygonsEnvelopeenv= EnvelopeBuilderEx.CreateEnvelope(MapPointBuilderEx.CreateMapPoint(4.0,4.0), MapPointBuilderEx.CreateMapPoint(8,8));Polygonpoly1= PolygonBuilderEx.CreatePolygon(env);Envelopeenv2= EnvelopeBuilderEx.CreateEnvelope(MapPointBuilderEx.CreateMapPoint(1.0,1.0), MapPointBuilderEx.CreateMapPoint(5,5));Polygonpoly2= PolygonBuilderEx.CreatePolygon(env2);booltouches= GeometryEngine.Instance.Touches(poly1, poly2);// touches = false// another polygon that touches the firstEnvelopeenv3= EnvelopeBuilderEx.CreateEnvelope(MapPointBuilderEx.CreateMapPoint(1.0,1.0), MapPointBuilderEx.CreateMapPoint(4,4));Polygonpoly3= PolygonBuilderEx.CreatePolygon(env3);touches= GeometryEngine.Instance.Touches(poly1, poly3);// touches = true
Transform2D
// Not all of the input points are transformed as some of them are outside of the GCS horizon.
Coordinate2D[]inCoords2D=new Coordinate2D[]{new Coordinate2D(-1,-1),new Coordinate2D(-2,-5),new Coordinate2D(-5,-11),new Coordinate2D(-10,-19),new Coordinate2D(-17,-29),new Coordinate2D(-26,-41),new Coordinate2D(-37,-5),new Coordinate2D(-50,-21),new Coordinate2D(-65,-39),new Coordinate2D(-82,-9)};intarraySize= inCoords2D.Length;ProjectionTransformationprojTrans= ProjectionTransformation.Create(SpatialReferences.WGS84, SpatialReferenceBuilder.CreateSpatialReference(24891));
Coordinate2D[]outCoords2D=new Coordinate2D[arraySize];// transform and choose to remove the clipped coordinatesintnumPointsTransformed= GeometryEngine.Instance.Transform2D(inCoords2D, projTrans,ref outCoords2D,true);// numPointsTransformed = 4// outCoords2D.Length = 4// outCoords2D[0] = {5580417.6876455201, 1328841.2376554986}// outCoords2D[1] = {3508774.290814558, -568027.23444226268}// outCoords2D[2] = {1568096.0886155984, -2343435.4394415971}// outCoords2D[3] = {57325.827391741652, 1095146.8917508761}// transform and don't remove the clipped coordinatesnumPointsTransformed= GeometryEngine.Instance.Transform2D(inCoords2D, projTrans,ref outCoords2D,false);// numPointsTransformed = 4// outCoords2D.Length = 10// outCoords2D[0] = {double.Nan, double.Nan}// outCoords2D[1] = {double.Nan, double.Nan}// outCoords2D[2] = {double.Nan, double.Nan}// outCoords2D[3] = {double.Nan, double.Nan}// outCoords2D[4] = {double.Nan, double.Nan}// outCoords2D[5] = {double.Nan, double.Nan}// outCoords2D[6] = {5580417.6876455201, 1328841.2376554986}// outCoords2D[7] = {3508774.290814558, -568027.23444226268}// outCoords2D[8] = {1568096.0886155984, -2343435.4394415971}// outCoords2D[9] = {57325.827391741652, 1095146.8917508761}
Transform3D
// Not all of the input points are transformed as some of them are outside of the GCS horizon.
Coordinate3D[]inCoords3D=new Coordinate3D[]{new Coordinate3D(-1,-1,0),new Coordinate3D(-2,-5,1),new Coordinate3D(-5,-11,2),new Coordinate3D(-10,-19,3),new Coordinate3D(-17,-29,4),new Coordinate3D(-26,-41,5),new Coordinate3D(-37,-5,6),new Coordinate3D(-50,-21,7),new Coordinate3D(-65,-39,8),new Coordinate3D(-82,-9,9)};intarraySize= inCoords3D.Length;ProjectionTransformationprojTrans= ProjectionTransformation.Create(SpatialReferences.WGS84, SpatialReferenceBuilder.CreateSpatialReference(24891));
Coordinate3D[]outCoords3D=new Coordinate3D[arraySize];// transform and choose to remove the clipped coordinatesintnumPointsTransformed= GeometryEngine.Instance.Transform3D(inCoords3D, projTrans,ref outCoords3D);// numPointsTransformed = 4// outCoords2D.Length = 4// outCoords2D[0] = {5580417.6876455201, 1328841.2376554986, 7}// outCoords2D[1] = {3508774.290814558, -568027.23444226268, 8}// outCoords2D[2] = {1568096.0886155984, -2343435.4394415971, 9}// outCoords2D[3] = {57325.827391741652, 1095146.8917508761, 10}
Union two MapPoints - creates a Multipoint
MapPointpt1= MapPointBuilderEx.CreateMapPoint(1.0,1.0);MapPointpt2= MapPointBuilderEx.CreateMapPoint(2.0,2.5);Geometrygeometry= GeometryEngine.Instance.Union(pt1, pt2);Multipointmultipoint= geometry as Multipoint;// multipoint has point count of 2
Union two Polygons
// union two polygonsList<MapPoint>polyPts=newList<MapPoint>();
polyPts.Add(MapPointBuilderEx.CreateMapPoint(3.0,2.0));
polyPts.Add(MapPointBuilderEx.CreateMapPoint(3.0,6.0));
polyPts.Add(MapPointBuilderEx.CreateMapPoint(6.0,6.0));
polyPts.Add(MapPointBuilderEx.CreateMapPoint(6.0,2.0));Polygonpoly1= PolygonBuilderEx.CreatePolygon(polyPts);boolisSimple= GeometryEngine.Instance.IsSimpleAsFeature(poly1);Envelopeenv= EnvelopeBuilderEx.CreateEnvelope(MapPointBuilderEx.CreateMapPoint(4.0,4.0), MapPointBuilderEx.CreateMapPoint(8,8));Polygonpoly2= PolygonBuilderEx.CreatePolygon(env);isSimple= GeometryEngine.Instance.IsSimpleAsFeature(poly2);Geometryg= GeometryEngine.Instance.Union(poly1, poly2);PolygonpolyResult= g as Polygon;
// build a polygon List<MapPoint>pts=newList<MapPoint>();
pts.Add(MapPointBuilderEx.CreateMapPoint(1.0,1.0));
pts.Add(MapPointBuilderEx.CreateMapPoint(1.0,2.0));
pts.Add(MapPointBuilderEx.CreateMapPoint(2.0,2.0));
pts.Add(MapPointBuilderEx.CreateMapPoint(2.0,1.0));Polygonpoly= PolygonBuilderEx.CreatePolygon(pts);// an inner pointMapPointinnerPt= MapPointBuilderEx.CreateMapPoint(1.5,1.5);boolwithin= GeometryEngine.Instance.Within(innerPt, poly);// within = true// point on a boundarywithin= GeometryEngine.Instance.Within(pts[0], poly);// within = false// an interior lineMapPointinnerPt2= MapPointBuilderEx.CreateMapPoint(1.25,1.75);List<MapPoint>innerLinePts=newList<MapPoint>();
innerLinePts.Add(innerPt);
innerLinePts.Add(innerPt2);Polylinepolyline= PolylineBuilderEx.CreatePolyline(innerLinePts);within= GeometryEngine.Instance.Within(polyline, poly);// within = true// a line that crosses the boundaryMapPointouterPt= MapPointBuilderEx.CreateMapPoint(3,1.5);List<MapPoint>crossingLinePts=newList<MapPoint>();
crossingLinePts.Add(innerPt);
crossingLinePts.Add(outerPt);polyline= PolylineBuilderEx.CreatePolyline(crossingLinePts);within= GeometryEngine.Instance.Within(polyline, poly);// within = false// polygon in polygonEnvelopeenv= EnvelopeBuilderEx.CreateEnvelope(innerPt, innerPt2);within= GeometryEngine.Instance.Within(env, poly);// within = true