// 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 MCTArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(()=>{// accelerate the geometry to testvaracceleratedPoly=GeometryEngine.Instance.AccelerateForRelationalOperations(polygon);// loop through all the geometries to test againstforeach(vartestPolygonintestPolygons){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(newCoordinate2D(10.0,10.0));outerPts.Add(newCoordinate2D(10.0,20.0));outerPts.Add(newCoordinate2D(20.0,20.0));outerPts.Add(newCoordinate2D(20.0,10.0));List<Coordinate2D>innerPts=newList<Coordinate2D>();innerPts.Add(newCoordinate2D(13.0,13.0));innerPts.Add(newCoordinate2D(17.0,13.0));innerPts.Add(newCoordinate2D(17.0,17.0));innerPts.Add(newCoordinate2D(13.0,17.0));Polygondonut=null;// add the outer pointsPolygonBuilderExpb=newPolygonBuilderEx(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=gasPolyline;
Buffer a MapPoint
// buffer a pointMapPointpt=MapPointBuilderEx.CreateMapPoint(1.0,1.0,SpatialReferences.WGS84);GeometryptBuffer=GeometryEngine.Instance.Buffer(pt,5.0);Polygonbuffer=ptBufferasPolygon;
Buffer a Circular Arc
// create the circular arcMapPointfromPt=MapPointBuilderEx.CreateMapPoint(2,1);MapPointtoPt=MapPointBuilderEx.CreateMapPoint(1,2);Coordinate2DinteriorPt=newCoordinate2D(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=ptsBufferasPolygon;// bufferResult will have 4 parts
// clip a polyline by an envelopeEnvelopeenv=EnvelopeBuilderEx.CreateEnvelope(2.0,2.0,4.0,4.0);LineSegmentline=LineBuilderEx.CreateLineSegment(newCoordinate2D(0,3),newCoordinate2D(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(newCoordinate2D(1.0,1.0));list.Add(newCoordinate2D(1.0,4.0));list.Add(newCoordinate2D(4.0,4.0));list.Add(newCoordinate2D(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
varsr=SpatialReferenceBuilder.CreateSpatialReference(4326);varpt1=MapPointBuilderEx.CreateMapPoint(60,180,sr);varpt2=MapPointBuilderEx.CreateMapPoint(60,0,sr);// densify by lengthvargl=GeometryEngine.Instance.ConstructGeodeticLineFromPoints(GeodeticCurveType.Geodesic,pt1,pt2,null,CurveDensifyMethod.ByLength,-3.356);// densify by deviationgl=GeometryEngine.Instance.ConstructGeodeticLineFromPoints(GeodeticCurveType.Geodesic,pt1,pt2,null,CurveDensifyMethod.ByDeviation,-0.0026);
Construct a Point at a distance and angle from an existing Point
List<Coordinate2D>firstLinePts=newList<Coordinate2D>();firstLinePts.Add(newCoordinate2D(1.0,1.0));firstLinePts.Add(newCoordinate2D(1.0,4.0));List<Coordinate2D>secondLinePts=newList<Coordinate2D>();secondLinePts.Add(newCoordinate2D(4.0,4.0));secondLinePts.Add(newCoordinate2D(4.0,1.0));List<Coordinate2D>thirdLinePts=newList<Coordinate2D>();thirdLinePts.Add(newCoordinate2D(0.0,2.0));thirdLinePts.Add(newCoordinate2D(5.0,2.0));List<Coordinate2D>fourthLinePts=newList<Coordinate2D>();fourthLinePts.Add(newCoordinate2D(0.0,3.0));fourthLinePts.Add(newCoordinate2D(5.0,3.0));// build the polylinesList<Polyline>polylines=newList<Polyline>();polylines.Add(PolylineBuilderEx.CreatePolyline(firstLinePts));polylines.Add(PolylineBuilderEx.CreatePolyline(secondLinePts));polylines.Add(PolylineBuilderEx.CreatePolyline(thirdLinePts));polylines.Add(PolylineBuilderEx.CreatePolyline(fourthLinePts));// construct polygons from the polylinesvarpolygons=GeometryEngine.Instance.ConstructPolygonsFromPolylines(polylines);// polygons.Count = 1// polygon coordinates are (1.0, 2.0), (1.0, 3.0), (4.0, 3.0), (4.0, 2.0)
Polygon contains MapPoints, Polylines, Polygons
// 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=hullasMapPoint;// 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=hullasPolygon;// 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=hullasPolyline;// hullPolyline.Length = Math.Sqrt(2)// hullPolyline.PointCount = 2// 3 point angular linepolylineList.Add(MapPointBuilderEx.CreateMapPoint(2.0,1.0));polyline=PolylineBuilderEx.CreatePolyline(polylineList);hull=GeometryEngine.Instance.ConvexHull(polyline);hullPoly=hullasPolygon;// 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=hullasPolygon;// 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=hullasPolygon;// 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=geomasPolyline;// densify a circular arcMapPointfromPt=MapPointBuilderEx.CreateMapPoint(2,1);MapPointtoPt=MapPointBuilderEx.CreateMapPoint(1,2);Coordinate2DinteriorPt=newCoordinate2D(1+Math.Sqrt(2)/2,1+Math.Sqrt(2)/2);EllipticArcBuilderExcab=newEllipticArcBuilderEx(fromPt,toPt,interiorPt);EllipticArcSegmentcircularArc=cab.ToSegment();polyline=PolylineBuilderEx.CreatePolyline(circularArc);geom=GeometryEngine.Instance.DensifyByLength(polyline,2);result=geomasPolyline;
//// 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=newMultipointBuilderEx();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=newMultipointBuilderEx();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)asPolyline;// generalizedPolyline.HasZ = truePolygongeneralized3DPolyline=GeometryEngine.Instance.Generalize3D(polylineWithZ,200)asPolygon;// 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)asPolygon;doubledelta=SpatialReferences.WGS84.XYTolerance*2*Math.Sqrt(2);ReadOnlyPointCollectionpoints=outPolygon.Points;foreach(MapPointpinpoints){doubled=GeometryEngine.Instance.GeodesicDistance(pt,p);// d = 5 (+- delta)}// specify a unit for the distanceoutPolygon=GeometryEngine.Instance.GeodesicBuffer(pt,5000,LinearUnit.Millimeters)asPolygon;// 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)asPolygon;// outPolygon.PartCount = 4// buffer different geometry typesList<Coordinate2D>coords=newList<Coordinate2D>(){newCoordinate2D(1,2),newCoordinate2D(10,20),newCoordinate2D(20,30),newCoordinate2D(50,60),newCoordinate2D(70,80),newCoordinate2D(80,40),newCoordinate2D(90,10),newCoordinate2D(110,15),newCoordinate2D(120,30),newCoordinate2D(10,40),newCoordinate2D(-10,40),newCoordinate2D(-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)asPolygon;// specify unit typesoutPolygon=GeometryEngine.Instance.GeodesicBuffer(manyGeometries,20,LinearUnit.Miles)asPolygon;
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>(){newCoordinate2D(-80,0),newCoordinate2D(-20,60),newCoordinate2D(40,20),newCoordinate2D(0,-20),newCoordinate2D(-80,0)};SpatialReferencesr=SpatialReferences.WGS84;// create a polylinePolylinepolyline=PolylineBuilderEx.CreatePolyline(coords,sr);// densify in kmPolylinegeodesicPolyline=GeometryEngine.Instance.GeodeticDensifyByDeviation(polyline,200,LinearUnit.Kilometers,GeodeticCurveType.Geodesic)asPolyline;// densify in mgeodesicPolyline=GeometryEngine.Instance.GeodeticDensifyByDeviation(polyline,200,LinearUnit.Meters,GeodeticCurveType.Geodesic)asPolyline;// Change curve type to LoxodromePolylineloxodromePolyline=GeometryEngine.Instance.GeodeticDensifyByDeviation(polyline,200,LinearUnit.Meters,GeodeticCurveType.Loxodrome)asPolyline;
GeodeticDensifyByLength - polygon
List<Coordinate2D>coords=newList<Coordinate2D>(){newCoordinate2D(-80,0),newCoordinate2D(-20,60),newCoordinate2D(40,20),newCoordinate2D(0,-20),newCoordinate2D(-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(Segmentsinsegments){Polylineline=PolylineBuilderEx.CreatePolyline(s,sr);doublegeoLen=GeometryEngine.Instance.GeodesicLength(line);geoLengths.Add(geoLen);}// find the max lengthgeoLengths.Sort();doublemaxLen=geoLengths[geoLengths.Count-1];// densify the polygon (in meters)PolygondensifiedPoly=GeometryEngine.Instance.GeodeticDensifyByLength(polygon,maxLen,LinearUnit.Meters,GeodeticCurveType.Geodesic)asPolygon;// densify the polygon (in km)doublemaxSegmentLength=maxLen/10000;densifiedPoly=GeometryEngine.Instance.GeodeticDensifyByLength(polygon,maxSegmentLength,LinearUnit.Kilometers,GeodeticCurveType.Geodesic)asPolygon;
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;
// mitered join and butt capsSpatialReferencesr=SpatialReferenceBuilder.CreateSpatialReference(102010);List<Coordinate2D>coords=newList<Coordinate2D>(){newCoordinate2D(1400,6200),newCoordinate2D(1600,6300),newCoordinate2D(1800,6200)};Polylinepolyline=PolylineBuilderEx.CreatePolyline(coords,sr);Polygonpolygon=GeometryEngine.Instance.GraphicBuffer(polyline,50,LineJoinType.Miter,LineCapType.Butt,10,0,-1)asPolygon;// bevelled join and round capsEnvelopeenvelope=EnvelopeBuilderEx.CreateEnvelope(0,0,10000,10000,SpatialReferences.WebMercator);PolygonoutPolygon=GeometryEngine.Instance.GraphicBuffer(envelope,1000,LineJoinType.Bevel,LineCapType.Round,4,0,96)asPolygon;
GraphicBuffer Many
// round join and round capsMapPointpoint1=MapPointBuilderEx.CreateMapPoint(0,0);MapPointpoint2=MapPointBuilderEx.CreateMapPoint(1,1,SpatialReferences.WGS84);MapPointpoint3=MapPointBuilderEx.CreateMapPoint(1000000,1200000,SpatialReferences.WebMercator);List<MapPoint>points=newList<MapPoint>(){point1,point2,point3};IReadOnlyList<Geometry>geometries=GeometryEngine.Instance.GraphicBuffer(points,5,LineJoinType.Round,LineCapType.Round,0,0,3000);
Intersection between two Polylines
// 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=gasMultipoint;// result is a multiPoint that intersects at (2,2) and (4,2)
Intersection between two Polygons
// determine intersection between two polygonsEnvelopeenv1=EnvelopeBuilderEx.CreateEnvelope(newCoordinate2D(3.0,2.0),newCoordinate2D(6.0,6.0));Polygonpoly1=PolygonBuilderEx.CreatePolygon(env1);Envelopeenv2=EnvelopeBuilderEx.CreateEnvelope(newCoordinate2D(1.0,1.0),newCoordinate2D(4.0,4.0));Polygonpoly2=PolygonBuilderEx.CreatePolygon(env2);PolygonpolyResult=GeometryEngine.Instance.Intersection(poly1,poly2)asPolygon;
Determine label point for a Polygon
// create a polygonList<Coordinate2D>list2D=newList<Coordinate2D>();list2D.Add(newCoordinate2D(1.0,1.0));list2D.Add(newCoordinate2D(1.0,2.0));list2D.Add(newCoordinate2D(2.0,2.0));list2D.Add(newCoordinate2D(2.0,1.0));Polygonpolygon=PolygonBuilderEx.CreatePolygon(list2D);boolisSimple=GeometryEngine.Instance.IsSimpleAsFeature(polygon);MapPointpt=GeometryEngine.Instance.LabelPoint(polygon);
Determine Length, Length3D of line
MapPointc1=MapPointBuilderEx.CreateMapPoint(1,2,3);MapPointc2=MapPointBuilderEx.CreateMapPoint(4,2,4);// line segmentLineSegmentline=LineBuilderEx.CreateLineSegment(c1,c2);doublelen=line.Length;// = 3doublelen3D=line.Length3D;// = Math.Sqrt(10)// polylinePolylinep=PolylineBuilderEx.CreatePolyline(line);doublep_len=p.Length;// = len = 3doublep_len3D=p.Length3D;// = len3D = Math.Sqrt(10)doublege_len=GeometryEngine.Instance.Length(p);// = p_len = len = 3doublege_len3d=GeometryEngine.Instance.Length3D(p);// = p_len3D = len3D = Math.Sqrt(10)
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,outm1,outm2);// m1 = -3// m2 = NaNGeometryEngine.Instance.GetMsAtDistance(polyline,500,AsRatioOrLength.AsLength,outm1,outm2);// m1 = -2.5// m2 = NaNGeometryEngine.Instance.GetMsAtDistance(polyline,1000,AsRatioOrLength.AsLength,outm1,outm2);// 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,outsplitHappened,outpartIndex,outsegmentIndex)asPolyline;// 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,outsplitHappened,outpartIndex,outsegmentIndex)asPolyline;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,outsplitHappened,outpartIndex,outsegmentIndex)asPolyline;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\":[[[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 using points (0, 0, 17), (1, 0, 42), (7, 6, 18) List<MapPoint>updatePoints=newList<MapPoint>(3);MapPointBuilderExbuilder=newMapPointBuilderEx(0,0);builder.M=17;updatePoints.Add(builder.ToGeometry()asMapPoint);builder.X=1;builder.M=42;updatePoints.Add(builder.ToGeometry()asMapPoint);builder.X=7;builder.Y=6;builder.M=18;updatePoints.Add(builder.ToGeometry()asMapPoint);// Calibrate all the points in the polylinedoublecutOffDistance=polyline.Length;PolylineupdatedPolyline=GeometryEngine.Instance.CalibrateByMs(polyline,updatePoints,UpdateMMethod.Interpolate,cutOffDistance)asPolyline;// The points in the updated polyline are// (0, 0, 17 ), ( 1, 0, 42 ), ( 1, 1, 38 ), ( 1, 2, 34 ), ( 3, 1, 30 ), ( 5, 3, 26 ), ( 9, 5, 22 ), ( 7, 6, 18 )// ExtrapolateBefore using points (1, 2, 42), (9, 5, 18)builder.X=1;builder.Y=2;builder.M=42;updatePoints[0]=builder.ToGeometry()asMapPoint;builder.X=9;builder.Y=5;builder.M=18;updatePoints[1]=builder.ToGeometry()asMapPoint;updatePoints.RemoveAt(2);updatedPolyline=GeometryEngine.Instance.CalibrateByMs(polyline,updatePoints,UpdateMMethod.ExtrapolateBefore,cutOffDistance)asPolyline;// The points in the updated polyline are// ( 0, 0, 66 ), ( 1, 0, 58 ), ( 1, 1, 50 ), ( 1, 2, 42 ), ( 3, 1, 3 ), ( 5, 3, 4 ), ( 9, 5, 18 ), ( 7, 6, 6 )// ExtrapolateAfter using points (0, 0, 17), (1, 2, 42)builder.X=0;builder.Y=0;builder.M=17;updatePoints.Insert(0,builder.ToGeometry()asMapPoint);updatePoints.RemoveAt(2);updatedPolyline=GeometryEngine.Instance.CalibrateByMs(polyline,updatePoints,UpdateMMethod.ExtrapolateAfter,cutOffDistance)asPolyline;// The points in the updated polyline are// ( 0, 0, 17 ), ( 1, 0, 0 ), ( 1, 1, 1 ), ( 1, 2, 42 ), ( 3, 1, 50.333333333333333 ), ( 5, 3, 58.666666666666671 ), ( 9, 5, 67 ), ( 7, 6, 75.333333333333343 )// ExtrapolateAfter and Interpolate using points (0, 0, 17), (1, 2, 42)updatedPolyline=GeometryEngine.Instance.CalibrateByMs(polyline,updatePoints,UpdateMMethod.ExtrapolateAfter|UpdateMMethod.Interpolate,cutOffDistance)asPolyline;// The points in the updated polyline are// (0,0,17),(1,0,25.333333333333336),(1,1,33.666666666666671),(1,2,42),(3,1,50.333333333333336),(5,3,58.666666666666671),(9,5,67),(7,6,75.333333333333343)
Calibrate M-values using segment lengths and M values from input points - CalibrateMsByDistance
List<MapPoint>points=newList<MapPoint>();MapPointBuilderExpointBuilder=newMapPointBuilderEx(0,0);pointBuilder.HasM=true;pointBuilder.M=0;points.Add(pointBuilder.ToGeometry());pointBuilder.SetValues(0,8);pointBuilder.M=12;points.Add(pointBuilder.ToGeometry());pointBuilder.SetValues(0,18);pointBuilder.M=10;points.Add(pointBuilder.ToGeometry());pointBuilder.SetValues(0,28);pointBuilder.M=14;points.Add(pointBuilder.ToGeometry());pointBuilder.SetValues(0,32);pointBuilder.M=20;points.Add(pointBuilder.ToGeometry());pointBuilder.SetValues(0,38);pointBuilder.M=26;points.Add(pointBuilder.ToGeometry());pointBuilder.SetValues(0,50);pointBuilder.M=30;points.Add(pointBuilder.ToGeometry());Polylinepolyline=PolylineBuilderEx.CreatePolyline(points,AttributeFlags.HasM);// The points in the polyline are (0, 0, 0), (0, 8, 12), (0, 18, 10), (0, 28, 14), (0, 32, 20), (0, 38, 26), (0, 50, 30)// Calibrate Ms using points (0, 8, 15), (0, 28, 30), (0, 38, 20)points.Clear();pointBuilder.SetValues(0,8);pointBuilder.M=15;points.Add(pointBuilder.ToGeometry());pointBuilder.SetValues(0,28);pointBuilder.M=30;points.Add(pointBuilder.ToGeometry());pointBuilder.SetValues(0,38);pointBuilder.M=20;points.Add(pointBuilder.ToGeometry());doublecutOffDistance=polyline.Length;// ExtrapolateBeforePolylineupdatedPolyline=GeometryEngine.Instance.CalibrateMsByDistance(polyline,points,UpdateMMethod.ExtrapolateBefore,true,cutOffDistance)asPolyline;// The points in the updated polyline are// (0, 0, 9), (0, 8, 15), (0, 18, 10), (0, 28, 30), (0, 32, 20), (0, 38, 20), (0, 50, 30)// InterpolateupdatedPolyline=GeometryEngine.Instance.CalibrateMsByDistance(polyline,points,UpdateMMethod.Interpolate,true,cutOffDistance)asPolyline;// The points in the updated polyline are// (0, 0, 0), (0, 8, 15), (0, 18, 22.5), (0, 28, 30), (0, 32, 26), (0, 38, 20), (0, 50, 30)// ExtrapolateAfterupdatedPolyline=GeometryEngine.Instance.CalibrateMsByDistance(polyline,points,UpdateMMethod.ExtrapolateAfter,true,cutOffDistance)asPolyline;// The points in the updated polyline are// (0, 0, 0), (0, 8, 15), (0, 18, 10), (0, 28, 30), (0, 32, 20), (0, 38, 20), (0, 50, 8)// ExtrapolateBefore and Interpolate and ExtrapolateAfterupdatedPolyline=GeometryEngine.Instance.CalibrateMsByDistance(polyline,points,UpdateMMethod.ExtrapolateAfter,true,cutOffDistance)asPolyline;// The points in the updated polyline are// (0, 0, 9), (0, 8, 15), (0, 18, 22.5), (0, 28, 30), (0, 32, 26), (0, 38, 20), (0, 50, 8)
Set all the M-values to NaN - DropMs
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)asPolyline;// 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)asPolyline;// 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)asPolyline;// 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,outfromDetail,outtoDetail);// 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,outfromDetail,outtoDetail);// 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)asPolyline;// 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 6Coordinate2D[]coords=newCoordinate2D[]{newCoordinate2D(-4,4),newCoordinate2D(-1,1),newCoordinate2D(2,6),newCoordinate2D(-8,2),newCoordinate2D(5,-3),newCoordinate2D(7,2),newCoordinate2D(5,3),newCoordinate2D(3,-1)};double[]ms=newdouble[]{1,2,3,4,5,6,7,8};MultipointBuilderExbuilder=newMultipointBuilderEx(coords);builder.Ms=ms;builder.HasM=true;Multipointmultipoint=builder.ToGeometry();MultipointoutMultipoint=GeometryEngine.Instance.MultiplyMs(multipoint,6)asMultipoint;// 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=newMapPointBuilderEx(0,0);pointBuilder.M=1;MapPointpoint1=pointBuilder.ToGeometry();pointBuilder.SetValues(2,2);pointBuilder.M=3;MapPointpoint2=pointBuilder.ToGeometry();Polylinepolyline=PolylineBuilderEx.CreatePolyline(newMapPoint[]{point1,point2},AttributeFlags.HasM);;PolylineoutPolyline=GeometryEngine.Instance.OffsetMs(polyline,2)asPolyline;// 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=newEnvelopeBuilderEx(-5,1,2,4);envelopeBuilder.MMin=10;envelopeBuilder.MMax=20;Envelopeenvelope=envelopeBuilder.ToGeometry();EnvelopeoutEnvelope=GeometryEngine.Instance.OffsetMs(envelope,25)asEnvelope;// 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)asEnvelope;// 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,outfirstM,outlastM);// 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,outfirstM,outlastM);// 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,outfirstM,outlastM);// firstM and lastM are NaNjson="{\"hasM\":true,\"paths\":[]}";polyline=PolylineBuilderEx.FromJson(json);GeometryEngine.Instance.QueryFirstLastM(polyline,outfirstM,outlastM);// 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)asPolyline;// 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)asPolyline;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)asPolyline;// 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)asPolygon;// 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=newCoordinate2D(0,0);PolylineoutputPolyline=GeometryEngine.Instance.SetMsAsDistance(polyline,origin,0.5,1,true)asPolyline;// 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=newCoordinate2D(4,6);outputPolyline=GeometryEngine.Instance.SetMsAsDistance(polyline,origin,0.5,1,true)asPolyline;// 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=newMapPointBuilderEx(3,4,sr);pointBuilder.M=5.00006;MapPointpoint=pointBuilder.ToGeometry();MapPointoutputPoint=GeometryEngine.Instance.SnapMsToSpatialReference(point)asMapPoint;// outputPoint.M = 5.0001// MultipointpointBuilder=newMapPointBuilderEx(-3,-4,sr);pointBuilder.M=-5.000007;MapPointpoint2=pointBuilder.ToGeometry();Multipointmultipoint=MultipointBuilderEx.CreateMultipoint(newMapPoint[]{point,point2},AttributeFlags.HasM,sr);MultipointoutputMultipoint=GeometryEngine.Instance.SnapMsToSpatialReference(multipoint)asMultipoint;// 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)asPolyline;// 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=newCoordinate2D(-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)asMapPoint;// 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)asMapPoint;// 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>{newCoordinate3D(0,0,0),newCoordinate3D(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>(){newCoordinate2D(0,0),newCoordinate2D(1,4),newCoordinate2D(2,7),newCoordinate2D(-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>(){newCoordinate2D(10,1),newCoordinate2D(10,-4),newCoordinate2D(0,-4),newCoordinate2D(0,1),newCoordinate2D(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
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
// 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);
QueryNormal
stringjson="{\"curvePaths\":[[[-13046586.8335,4036570.6796000004],"+"{\"c\":[[-13046645.107099999,4037152.5873000026],"+"[-13046132.776277589,4036932.1325614937]]}]],\"spatialReference\":{\"wkid\":3857}}";Polylinepolyline=PolylineBuilderEx.FromJson(json);EllipticArcSegmentarc=polyline.Parts[0][0]asEllipticArcSegment;// No extension, distanceAlongCurve = 0.5// use the polylinePolylinepoly_normal=GeometryEngine.Instance.QueryNormal(polyline,SegmentExtensionType.NoExtension,0.5,AsRatioOrLength.AsRatio,1000);// or a segmentLineSegmentseg_normal=GeometryEngine.Instance.QueryNormal(arc,SegmentExtensionType.NoExtension,0.5,AsRatioOrLength.AsRatio,1000);// TangentAtFrom, distanceAlongCurve = -1.2poly_normal=GeometryEngine.Instance.QueryNormal(polyline,SegmentExtensionType.ExtendTangentAtFrom,-1.2,AsRatioOrLength.AsRatio,1000);seg_normal=GeometryEngine.Instance.QueryNormal(arc,SegmentExtensionType.ExtendTangentAtFrom,-1.2,AsRatioOrLength.AsRatio,1000);// TangentAtTo (ignored because distanceAlongCurve < 0), distanceAlongCurve = -1.2poly_normal=GeometryEngine.Instance.QueryNormal(polyline,SegmentExtensionType.ExtendTangentAtTo,-1.2,AsRatioOrLength.AsRatio,1000);seg_normal=GeometryEngine.Instance.QueryNormal(arc,SegmentExtensionType.ExtendTangentAtTo,-1.2,AsRatioOrLength.AsRatio,1000);// TangentAtTo, distanceAlongCurve = 1.2poly_normal=GeometryEngine.Instance.QueryNormal(polyline,SegmentExtensionType.ExtendTangentAtTo,1.2,AsRatioOrLength.AsRatio,1000);seg_normal=GeometryEngine.Instance.QueryNormal(arc,SegmentExtensionType.ExtendTangentAtTo,1.2,AsRatioOrLength.AsRatio,1000);// TangentAtFrom (ignored because distanceAlongCurve > 0), distanceAlongCurve = 1.2poly_normal=GeometryEngine.Instance.QueryNormal(polyline,SegmentExtensionType.ExtendTangentAtFrom,1.2,AsRatioOrLength.AsRatio,1000);seg_normal=GeometryEngine.Instance.QueryNormal(arc,SegmentExtensionType.ExtendTangentAtFrom,1.2,AsRatioOrLength.AsRatio,1000);// EmbeddedAtTo, distanceAlongCurve = 1.2poly_normal=GeometryEngine.Instance.QueryNormal(polyline,SegmentExtensionType.ExtendEmbeddedAtTo,1.2,AsRatioOrLength.AsRatio,1000);seg_normal=GeometryEngine.Instance.QueryNormal(arc,SegmentExtensionType.ExtendEmbeddedAtTo,1.2,AsRatioOrLength.AsRatio,1000);// EmbeddedAtFrom, distanceAlongCurve = -0.2poly_normal=GeometryEngine.Instance.QueryNormal(polyline,SegmentExtensionType.ExtendEmbeddedAtFrom,-0.2,AsRatioOrLength.AsRatio,1000);seg_normal=GeometryEngine.Instance.QueryNormal(arc,SegmentExtensionType.ExtendEmbeddedAtFrom,-0.2,AsRatioOrLength.AsRatio,1000);
QueryPoint
SpatialReferencesr=SpatialReferences.WGS84;// Horizontal line segmentCoordinate2Dstart=newCoordinate2D(1,1);Coordinate2Dend=newCoordinate2D(11,1);LineSegmentline=LineBuilderEx.CreateLineSegment(start,end,sr);Polylinepolyline=PolylineBuilderEx.CreatePolyline(line);// Don't extend the segmentMapPointoutPoint=GeometryEngine.Instance.QueryPoint(polyline,SegmentExtensionType.NoExtension,1.0,AsRatioOrLength.AsLength);// outPoint = (2, 1)// or the segmentMapPointoutPoint_seg=GeometryEngine.Instance.QueryPoint(line,SegmentExtensionType.NoExtension,1.0,AsRatioOrLength.AsLength);// outPoint_seg = (2, 1)// Extend infinitely in both directionsoutPoint=GeometryEngine.Instance.QueryPoint(polyline,SegmentExtensionType.ExtendTangents,1.5,AsRatioOrLength.AsRatio);// outPoint = (16, 1)outPoint_seg=GeometryEngine.Instance.QueryPoint(line,SegmentExtensionType.ExtendTangents,1.5,AsRatioOrLength.AsRatio);// outPoint_seg = (16, 1)
QueryPointAndDistance
// Horizontal line segmentList<MapPoint>linePts=newList<MapPoint>();linePts.Add(MapPointBuilderEx.CreateMapPoint(1.0,1.0,SpatialReferences.WGS84));linePts.Add(MapPointBuilderEx.CreateMapPoint(11.0,1.0,SpatialReferences.WGS84));Polylinepolyline=PolylineBuilderEx.CreatePolyline(linePts);boolisSimple=GeometryEngine.Instance.IsSimpleAsFeature(polyline);// Don't extent the segmentSegmentExtensionTypeextension=SegmentExtensionType.NoExtension;// A point on the line segmentMapPointinPoint=MapPointBuilderEx.CreateMapPoint(2,1,SpatialReferences.WGS84);doubledistanceAlongCurve,distanceFromCurve;LeftOrRightSidewhichSide;AsRatioOrLengthasRatioOrLength=AsRatioOrLength.AsLength;MapPointoutPoint=GeometryEngine.Instance.QueryPointAndDistance(polyline,extension,inPoint,asRatioOrLength,outdistanceAlongCurve,outdistanceFromCurve,outwhichSide);// outPoint = 2, 1// distanceAlongCurve = 1// distanceFromCurve = 0// whichSide = GeometryEngine.Instance.LeftOrRightSide.LeftSide// Extend infinitely in both directionsextension=SegmentExtensionType.ExtendTangents;// A point on the left sideinPoint=MapPointBuilderEx.CreateMapPoint(16,6,SpatialReferences.WGS84);asRatioOrLength=AsRatioOrLength.AsRatio;outPoint=GeometryEngine.Instance.QueryPointAndDistance(polyline,extension,inPoint,asRatioOrLength,outdistanceAlongCurve,outdistanceFromCurve,outwhichSide);// outPoint = 16, 1// distanceAlongCurve = 1.5// distanceFromCurve = 5// whichSide = GeometryEngine.Instance.LeftOrRightSide.LeftSide
SpatialReferencesr=SpatialReferences.WGS84;Coordinate2Dstart=newCoordinate2D(0,0);Coordinate2Dend=newCoordinate2D(4,4);LineSegmentline=LineBuilderEx.CreateLineSegment(start,end,sr);Coordinate2D[]coords=newCoordinate2D[]{newCoordinate2D(-1,2),newCoordinate2D(-1,4),newCoordinate2D(1,4),newCoordinate2D(-1,2)};Polygonpolygon=PolygonBuilderEx.CreatePolygon(coords,sr);// reflect a polygon about the linePolygonreflectedPolygon=GeometryEngine.Instance.ReflectAboutLine(polygon,line)asPolygon;// reflectedPolygon points are // (2, -1), (4, -1), (4, 1), (2, -1)
Determine relationship between two geometries
// set up some geometries// pointsMapPointpoint0=MapPointBuilderEx.CreateMapPoint(0,0,SpatialReferences.WGS84);MapPointpoint1=MapPointBuilderEx.CreateMapPoint(1,1,SpatialReferences.WGS84);MapPointpoint2=MapPointBuilderEx.CreateMapPoint(-5,5,SpatialReferences.WGS84);// multipointList<MapPoint>points=newList<MapPoint>(){point0,point1,point2};Multipointmultipoint=MultipointBuilderEx.CreateMultipoint(points,SpatialReferences.WGS84);// polygon List<Coordinate2D>polygonCoords=newList<Coordinate2D>(){newCoordinate2D(-10,0),newCoordinate2D(0,10),newCoordinate2D(10,0),newCoordinate2D(-10,0)};Polygonpolygon=PolygonBuilderEx.CreatePolygon(polygonCoords,SpatialReferences.WGS84);// polylinesPolylinepolyline1=PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(newCoordinate2D(-9.1,0.1),newCoordinate2D(0,9)),SpatialReferences.WGS84);Polylinepolyline2=PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(newCoordinate2D(-5,5),newCoordinate2D(0,5)),SpatialReferences.WGS84);Polylinepolyline3=PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(newCoordinate2D(2.09,-2.04),newCoordinate2D(5,10)),SpatialReferences.WGS84);Polylinepolyline4=PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(newCoordinate2D(10,-5),newCoordinate2D(10,5)),SpatialReferences.WGS84);List<Segment>segments=newList<Segment>(){LineBuilderEx.CreateLineSegment(newCoordinate2D(5.05,-2.87),newCoordinate2D(6.35,1.57)),LineBuilderEx.CreateLineSegment(newCoordinate2D(6.35,1.57),newCoordinate2D(4.13,2.59)),LineBuilderEx.CreateLineSegment(newCoordinate2D(4.13,2.59),newCoordinate2D(5,5))};Polylinepolyline5=PolylineBuilderEx.CreatePolyline(segments,SpatialReferences.WGS84);segments.Add(LineBuilderEx.CreateLineSegment(newCoordinate2D(5,5),newCoordinate2D(10,10)));Polylinepolyline6=PolylineBuilderEx.CreatePolyline(segments,SpatialReferences.WGS84);Polylinepolyline7=PolylineBuilderEx.CreatePolyline(polyline5);Polylinepolyline8=PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(newCoordinate2D(5,5),newCoordinate2D(10,10)),SpatialReferences.WGS84);segments.Clear();segments.Add(LineBuilderEx.CreateLineSegment(newCoordinate2D(0.6,3.5),newCoordinate2D(0.7,7)));segments.Add(LineBuilderEx.CreateLineSegment(newCoordinate2D(0.7,7),newCoordinate2D(3,9)));Polylinepolyline9=PolylineBuilderEx.CreatePolyline(segments,SpatialReferences.WGS84);// now do the Related tests// Interior/Interior Intersectsstringscl="T********";boolrelated=GeometryEngine.Instance.Relate(polygon,polyline1,scl);// related = truerelated=GeometryEngine.Instance.Relate(point0,point1,scl);// related = falserelated=GeometryEngine.Instance.Relate(point0,multipoint,scl);// related = truerelated=GeometryEngine.Instance.Relate(multipoint,polygon,scl);// related = truerelated=GeometryEngine.Instance.Relate(multipoint,polyline1,scl);// related = falserelated=GeometryEngine.Instance.Relate(polyline2,point2,scl);// related = falserelated=GeometryEngine.Instance.Relate(point1,polygon,scl);// related = true// Interior/Boundary Intersectsscl="*T*******";related=GeometryEngine.Instance.Relate(polygon,polyline2,scl);// related = truerelated=GeometryEngine.Instance.Relate(polygon,polyline3,scl);// related = falserelated=GeometryEngine.Instance.Relate(point1,polygon,scl);// related = false// Boundary/Boundary Interior intersectsscl="***T*****";related=GeometryEngine.Instance.Relate(polygon,polyline4,scl);// related = true// Overlaps Dim1scl="1*T***T**";related=GeometryEngine.Instance.Relate(polygon,polyline5,scl);// related = true// Crosses Area/Line (LineB crosses PolygonA)scl="1020F1102";related=GeometryEngine.Instance.Relate(polygon,polyline6,scl);// related = falserelated=GeometryEngine.Instance.Relate(polygon,polyline9,scl);// related = true// Boundary/Boundary Touchesscl="F***T****";related=GeometryEngine.Instance.Relate(polygon,polyline7,scl);// related = falserelated=GeometryEngine.Instance.Relate(polygon,polyline8,scl);// related = true
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)
Rotate a Polyline
// rotate a polylineMapPointfixedPt=MapPointBuilderEx.CreateMapPoint(3.0,3.0);List<MapPoint>pts=newList<MapPoint>();pts.Add(MapPointBuilderEx.CreateMapPoint(1.0,1.0));pts.Add(MapPointBuilderEx.CreateMapPoint(1.0,5.0));pts.Add(MapPointBuilderEx.CreateMapPoint(5,5));pts.Add(MapPointBuilderEx.CreateMapPoint(5.0,1.0));Polylinepolyline=PolylineBuilderEx.CreatePolyline(pts);Polylinerotated=GeometryEngine.Instance.Rotate(polyline,fixedPt,Math.PI/4)asPolyline;// rotate 45 deg
Calculate area of geometry on surface of Earth's ellipsoid - ShapePreservingArea
// ptMapPointpt=MapPointBuilderEx.CreateMapPoint(1.0,3.0,SpatialReferences.WebMercator);doublearea=GeometryEngine.Instance.ShapePreservingArea(pt);// area = 0List<MapPoint>pts=newList<MapPoint>();pts.Add(MapPointBuilderEx.CreateMapPoint(1.0,1.0,3.0));pts.Add(MapPointBuilderEx.CreateMapPoint(1.0,3.0,3.0));pts.Add(MapPointBuilderEx.CreateMapPoint(3,3,3.0));pts.Add(MapPointBuilderEx.CreateMapPoint(3.0,1.0,3.0));// multipointMultipointmPt=MultipointBuilderEx.CreateMultipoint(pts);area=GeometryEngine.Instance.ShapePreservingArea(mPt);// area = 0// polylinePolylinepolyline=PolylineBuilderEx.CreatePolyline(pts);area=GeometryEngine.Instance.ShapePreservingArea(polyline);// area = 0// polygonPolygonpolygon=PolygonBuilderEx.CreatePolygon(pts,SpatialReferences.WGS84);area=GeometryEngine.Instance.ShapePreservingArea(polygon);polygon=PolygonBuilderEx.CreatePolygon(pts,SpatialReferences.WebMercator);area=GeometryEngine.Instance.ShapePreservingArea(polygon);polygon=PolygonBuilderEx.CreatePolygon(new[]{MapPointBuilderEx.CreateMapPoint(-170,45),MapPointBuilderEx.CreateMapPoint(170,45),MapPointBuilderEx.CreateMapPoint(170,-45),MapPointBuilderEx.CreateMapPoint(-170,-54)},SpatialReferences.WGS84);vararea_meters=GeometryEngine.Instance.ShapePreservingArea(polygon);// , AreaUnits.SquareMeters);vararea_miles=GeometryEngine.Instance.ShapePreservingArea(polygon,AreaUnit.SquareMiles);// area_meters - 352556425383104.37// area_miles - 136122796.848425
Calculate length of geometry on surface of Earth's ellipsoid - ShapePreservingLength
// ptMapPointpt=MapPointBuilderEx.CreateMapPoint(1.0,3.0,SpatialReferences.WebMercator);doublelen=GeometryEngine.Instance.ShapePreservingLength(pt);// len = 0List<MapPoint>pts=newList<MapPoint>();pts.Add(MapPointBuilderEx.CreateMapPoint(1.0,1.0,3.0));pts.Add(MapPointBuilderEx.CreateMapPoint(1.0,3.0,3.0));pts.Add(MapPointBuilderEx.CreateMapPoint(3,3,3.0));pts.Add(MapPointBuilderEx.CreateMapPoint(3.0,1.0,3.0));// multipointMultipointmPt=MultipointBuilderEx.CreateMultipoint(pts);len=GeometryEngine.Instance.ShapePreservingLength(mPt);// len = 0// polylinePolylinepolyline=PolylineBuilderEx.CreatePolyline(pts,SpatialReferences.WGS84);len=GeometryEngine.Instance.ShapePreservingLength(polyline);// polygonPolygonpolygon=PolygonBuilderEx.CreatePolygon(pts,SpatialReferences.WGS84);len=GeometryEngine.Instance.ShapePreservingLength(polygon);polyline=PolylineBuilderEx.CreatePolyline(new[]{MapPointBuilderEx.CreateMapPoint(-170,0),MapPointBuilderEx.CreateMapPoint(170,0)},SpatialReferences.WGS84);varlength_meters=GeometryEngine.Instance.ShapePreservingLength(polyline);// , LinearUnits.Meters);varlength_miles=GeometryEngine.Instance.ShapePreservingLength(polyline,LinearUnit.Miles);// length_meters - 37848626.869713023// length_miles - 23518.046402579574
SideBuffer
// right side, round capsSpatialReferencesr=SpatialReferenceBuilder.CreateSpatialReference(102010);List<Coordinate2D>coords=newList<Coordinate2D>(){newCoordinate2D(1200,5800),newCoordinate2D(1400,5800),newCoordinate2D(1400,6000),newCoordinate2D(1300,6000),newCoordinate2D(1300,5700)};Polylinepolyline=PolylineBuilderEx.CreatePolyline(coords,sr);Polygonoutput=GeometryEngine.Instance.SideBuffer(polyline,20,LeftOrRightSide.RightSide,LineCapType.Round)asPolygon;
List<Coordinate2D>coords=newList<Coordinate2D>(){newCoordinate2D(8,0),newCoordinate2D(8,4),newCoordinate2D(6,4),newCoordinate2D(8,4),newCoordinate2D(10,4),newCoordinate2D(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,outsplitOccurred,outpartIndex,outsegmentIndex);// 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,outsplitOccurred,outpartIndex,outsegmentIndex);// 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,outsplitOccurred,outpartIndex,outsegmentIndex);// 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,outsplitOccurred,outpartIndex,outsegmentIndex);// 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,outsplitOccurred,outpartIndex,outsegmentIndex);// splitOccurred = false// ignore partIndex, sgementIndex// splitPolyline is the same as polylineZ////// multipart polygon///List<Coordinate3D>coordsZ=newList<Coordinate3D>(){newCoordinate3D(10,10,5),newCoordinate3D(10,20,5),newCoordinate3D(20,20,5),newCoordinate3D(20,10,5)};List<Coordinate3D>coordsZ_2ndPart=newList<Coordinate3D>(){newCoordinate3D(30,20,10),newCoordinate3D(30,30,10),newCoordinate3D(35,28,10),newCoordinate3D(40,30,10),newCoordinate3D(40,20,10),};varbuilder=newPolygonBuilderEx();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,outsplitOccurred,outpartIndex,outsegmentIndex);// 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,outsplitOccurred,outpartIndex,outsegmentIndex);// 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=newCoordinate2D[]{newCoordinate2D(-1,-1),newCoordinate2D(-2,-5),newCoordinate2D(-5,-11),newCoordinate2D(-10,-19),newCoordinate2D(-17,-29),newCoordinate2D(-26,-41),newCoordinate2D(-37,-5),newCoordinate2D(-50,-21),newCoordinate2D(-65,-39),newCoordinate2D(-82,-9)};intarraySize=inCoords2D.Length;ProjectionTransformationprojTrans=ProjectionTransformation.Create(SpatialReferences.WGS84,SpatialReferenceBuilder.CreateSpatialReference(24891));Coordinate2D[]outCoords2D=newCoordinate2D[arraySize];// transform and choose to remove the clipped coordinatesintnumPointsTransformed=GeometryEngine.Instance.Transform2D(inCoords2D,projTrans,refoutCoords2D,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,refoutCoords2D,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=newCoordinate3D[]{newCoordinate3D(-1,-1,0),newCoordinate3D(-2,-5,1),newCoordinate3D(-5,-11,2),newCoordinate3D(-10,-19,3),newCoordinate3D(-17,-29,4),newCoordinate3D(-26,-41,5),newCoordinate3D(-37,-5,6),newCoordinate3D(-50,-21,7),newCoordinate3D(-65,-39,8),newCoordinate3D(-82,-9,9)};intarraySize=inCoords3D.Length;ProjectionTransformationprojTrans=ProjectionTransformation.Create(SpatialReferences.WGS84,SpatialReferenceBuilder.CreateSpatialReference(24891));Coordinate3D[]outCoords3D=newCoordinate3D[arraySize];// transform and choose to remove the clipped coordinatesintnumPointsTransformed=GeometryEngine.Instance.Transform3D(inCoords3D,projTrans,refoutCoords3D);// 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=geometryasMultipoint;// 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=gasPolygon;
Union many Polylines
// union many polylinesList<Coordinate2D>coords=newList<Coordinate2D>(){newCoordinate2D(1,2),newCoordinate2D(3,4),newCoordinate2D(4,2),newCoordinate2D(5,6),newCoordinate2D(7,8),newCoordinate2D(8,4),newCoordinate2D(9,10),newCoordinate2D(11,12),newCoordinate2D(12,8),newCoordinate2D(10,8),newCoordinate2D(12,12),newCoordinate2D(14,10)};// create Disjoint linesList<Polyline>manyLines=newList<Polyline>{PolylineBuilderEx.CreatePolyline(newList<Coordinate2D>(){coords[0],coords[1],coords[2]},SpatialReferences.WGS84),PolylineBuilderEx.CreatePolyline(newList<Coordinate2D>(){coords[3],coords[4],coords[5]}),PolylineBuilderEx.CreatePolyline(newList<Coordinate2D>(){coords[6],coords[7],coords[8]})};Polylinepolyline=GeometryEngine.Instance.Union(manyLines)asPolyline;
Union many Polygons
// union many polygonsList<Coordinate3D>coordsZ=newList<Coordinate3D>(){newCoordinate3D(1,2,0),newCoordinate3D(3,4,1),newCoordinate3D(4,2,2),newCoordinate3D(5,6,3),newCoordinate3D(7,8,4),newCoordinate3D(8,4,5),newCoordinate3D(9,10,6),newCoordinate3D(11,12,7),newCoordinate3D(12,8,8),newCoordinate3D(10,8,9),newCoordinate3D(12,12,10),newCoordinate3D(14,10,11)};// create polygonsList<Polygon>manyPolygonsZ=newList<Polygon>{PolygonBuilderEx.CreatePolygon(newList<Coordinate3D>(){coordsZ[0],coordsZ[1],coordsZ[2]},SpatialReferences.WGS84),PolygonBuilderEx.CreatePolygon(newList<Coordinate3D>(){coordsZ[3],coordsZ[4],coordsZ[5]}),PolygonBuilderEx.CreatePolygon(newList<Coordinate3D>(){coordsZ[6],coordsZ[7],coordsZ[8]})};Polygonpolygon=GeometryEngine.Instance.Union(manyPolygonsZ)asPolygon;
MapPoints, Polylines, Polygons within 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