public static SpatialReference WebMercator {get;}
Public Shared ReadOnly Property WebMercator As SpatialReference
public static SpatialReference WebMercator {get;}
Public Shared ReadOnly Property WebMercator As SpatialReference
{
SpatialReference sr = SpatialReferences.WebMercator;
// Get Esri WKT
string wkt = sr.Wkt;
/*
PROJCS["WGS_1984_Web_Mercator_Auxiliary_Sphere",
GEOGCS["GCS_WGS_1984",
DATUM["D_WGS_1984",
SPHEROID["WGS_1984", 6378137.0, 298.257223563]],
PRIMEM["Greenwich", 0.0],
UNIT["Degree", 0.0174532925199433]],
PROJECTION["Mercator_Auxiliary_Sphere"],
PARAMETER["False_Easting", 0.0],
PARAMETER["False_Northing", 0.0],
PARAMETER["Central_Meridian", 0.0],
PARAMETER["Standard_Parallel_1", 0.0],
PARAMETER["Auxiliary_Sphere_Type", 0.0],
UNIT["Meter", 1.0]]
*/
// Get OGC WKT2
string wkt2 = sr.GetWkt2(WktFormatMode.None);
/*
PROJCRS["WGS_1984_Web_Mercator_Auxiliary_Sphere",
BASEGEOGCRS["GCS_WGS_1984",
DYNAMIC[FRAMEEPOCH[1990.5], MODEL["AM0-2"]],
DATUM["D_WGS_1984",
ELLIPSOID["WGS_1984", 6378137.0, 298.257223563, LENGTHUNIT["Meter", 1.0]]],
PRIMEM["Greenwich", 0.0, ANGLEUNIT["Degree", 0.0174532925199433]],
CS[ellipsoidal, 2],
AXIS["Latitude (lat)", north, ORDER[1]],
AXIS["Longitude (lon)", east, ORDER[2]],
ANGLEUNIT["Degree", 0.0174532925199433]],
CONVERSION["Mercator_Auxiliary_Sphere",
METHOD["Mercator_Auxiliary_Sphere"],
PARAMETER["False_Easting", 0.0, LENGTHUNIT["Meter", 1.0]],
PARAMETER["False_Northing", 0.0, LENGTHUNIT["Meter", 1.0]],
PARAMETER["Central_Meridian", 0.0, ANGLEUNIT["Degree", 0.0174532925199433]],
PARAMETER["Standard_Parallel_1", 0.0, ANGLEUNIT["Degree", 0.0174532925199433]],
PARAMETER["Auxiliary_Sphere_Type", 0.0]],
CS[Cartesian, 2],
AXIS["Easting (X)", east, ORDER[1]],
AXIS["Northing (Y)", north, ORDER[2]],
LENGTHUNIT["Meter", 1.0]]
*/
// You can create a spatial reference with the Esri WKT string or the OCG WKT2 string
sr = SpatialReferenceBuilder.CreateSpatialReference(wkt2);
// Get OGC WKT2 including authority in top-level objects
// In this case the authority is written as ID["EPSG",3857]
wkt2 = sr.GetWkt2(WktFormatMode.AuthorityTop);
/*
PROJCRS["WGS_1984_Web_Mercator_Auxiliary_Sphere",
BASEGEOGCRS["GCS_WGS_1984",
DYNAMIC[FRAMEEPOCH[1990.5],MODEL["AM0-2"]],
DATUM["D_WGS_1984",
ELLIPSOID["WGS_1984",6378137.0,298.257223563,LENGTHUNIT["Meter",1.0]]],
PRIMEM["Greenwich",0.0,ANGLEUNIT["Degree",0.017453292519943295]],
CS[ellipsoidal,2],
AXIS["Latitude (lat)",north,ORDER[1]],
AXIS["Longitude(lon)",east,ORDER[2]],
ANGLEUNIT["Degree",0.017453292519943295]],
CONVERSION["Mercator_Auxiliary_Sphere",
METHOD["Mercator_Auxiliary_Sphere"],
PARAMETER["False_Easting",0.0,LENGTHUNIT["Meter",1.0]],
PARAMETER["False_Northing",0.0,LENGTHUNIT["Meter",1.0]],
PARAMETER["Central_Meridian",0.0,ANGLEUNIT["Degree",0.017453292519943295]],
PARAMETER["Standard_Parallel_1",0.0,ANGLEUNIT["Degree",0.017453292519943295]],
PARAMETER["Auxiliary_Sphere_Type",0.0]],
CS[Cartesian,2],
AXIS["Easting (X)",east,ORDER[1]],
AXIS["Northing (Y)",north,ORDER[2]],
LENGTHUNIT["Meter",1.0],
ID["EPSG",3857]]
*/
// Get OGC WKT2 including authority in all objects
// Authority is written as ID["ESPG",<id>] or ID["Esri",<id>]
wkt2 = sr.GetWkt2(WktFormatMode.AuthorityAll);
/*
PROJCRS["WGS_1984_Web_Mercator_Auxiliary_Sphere",
BASEGEOGCRS["GCS_WGS_1984",
DYNAMIC[FRAMEEPOCH[1990.5],MODEL["AM0-2"]],
DATUM["D_WGS_1984",
ELLIPSOID["WGS_1984",6378137.0,298.257223563,LENGTHUNIT["Meter",1.0,ID["EPSG",9001]],ID["EPSG",7030]],
ID["EPSG",6326]],
PRIMEM["Greenwich",0.0,ANGLEUNIT["Degree",0.017453292519943295,ID["EPSG",9102]],ID["EPSG",8901]],
CS[ellipsoidal,2],
AXIS["Latitude (lat)",north,ORDER[1]],
AXIS["Longitude(lon)",east,ORDER[2]],
ANGLEUNIT["Degree",0.017453292519943295,ID["EPSG",9102]],ID["EPSG",4326]],
CONVERSION["Mercator_Auxiliary_Sphere",
METHOD["Mercator_Auxiliary_Sphere",ID["Esri",43104]],
PARAMETER["False_Easting",0.0,LENGTHUNIT["Meter",1.0,ID["EPSG",9001]],ID["Esri",100001]],
PARAMETER["False_Northing",0.0,LENGTHUNIT["Meter",1.0,ID["EPSG",9001]],ID["Esri",100002]],
PARAMETER["Central_Meridian",0.0,ANGLEUNIT["Degree",0.017453292519943295,ID["EPSG",9102]],ID["Esri",100010]],
PARAMETER["Standard_Parallel_1",0.0,ANGLEUNIT["Degree",0.017453292519943295,ID["EPSG",9102]],ID["Esri",100025]],
PARAMETER["Auxiliary_Sphere_Type",0.0,ID["Esri",100035]]],
CS[Cartesian,2],
AXIS["Easting(X)",east,ORDER[1]],
AXIS["Northing (Y)",north,ORDER[2]],
LENGTHUNIT["Meter",1.0,ID["EPSG",9001]],
ID["EPSG",3857]]
*/
}
{
MapPoint point = MapPointBuilderEx.CreateMapPoint(1, 2, SpatialReferences.WebMercator);
List<Coordinate2D> coords2DToUse = new List<Coordinate2D>()
{
new Coordinate2D(0, 0),
new Coordinate2D(0, 1),
new Coordinate2D(1, 1),
new Coordinate2D(1, 0)
};
Multipoint multipointNew = MultipointBuilderEx.CreateMultipoint(coords2DToUse, SpatialReferences.WGS84);
Polyline polylineNew = PolylineBuilderEx.CreatePolyline(coords2DToUse, SpatialReferences.WebMercator);
GeometryBagBuilderEx builder = new GeometryBagBuilderEx(SpatialReferences.WGS84);
GeometryBag emptyBag = builder.ToGeometry();
// emptyBag.IsEmpty = true
builder.AddGeometry(point);
// builder.GeometryCount = 1
GeometryBag geometryBag = builder.ToGeometry();
// geometryBag.PartCount = 1
// geometryBag.PointCount = 1
// geometryBag.IsEmpty = false
IReadOnlyList<ArcGIS.Core.Geometry.Geometry> geometries = geometryBag.Geometries;
// geometries.Count = 1
// geometries[0] is MapPoint with a sr of WGS84
bool isEqual = geometryBag.IsEqual(emptyBag); // isEqual = false
builder.InsertGeometry(0, multipoint);
geometryBag = builder.ToGeometry();
// geometryBag.PartCount = 2
geometries = geometryBag.Geometries;
// geometries.Count = 2
// geometries[0] is Multipoint
// geometries[1] is MapPoint
builder.AddGeometry(polyline);
builder.RemoveGeometry(1);
geometryBag = builder.ToGeometry();
// geometryBag.PartCount = 2
geometries = geometryBag.Geometries;
// geometries.Count = 2
// geometries[0] is Multipoint
// geometries[1] is Polyline
}
{
// Use a builder convenience method or use a builder constructor.
MapPoint point = MapPointBuilderEx.CreateMapPoint(10, 20);
List<Coordinate2D> coords = new List<Coordinate2D>() { new Coordinate2D(50, 60), new Coordinate2D(-120, -70), new Coordinate2D(40, 60) };
Multipoint multipointNew = MultipointBuilderEx.CreateMultipoint(coords, SpatialReferences.WebMercator);
Polyline polylineNew = PolylineBuilderEx.CreatePolyline(coords);
string json = "{\"rings\":[[[0,0],[0,1],[1,1],[1,0],[0,0]],[[3,0],[3,1],[4,1],[4,0],[3,0]]]}";
Polygon polygonNew = PolygonBuilderEx.FromJson(json);
var geometries = new List<Geometry>() { point, multipoint, polyline, polygon };
// Builder convenience methods don't need to run on the MCT.
var bag = GeometryBagBuilderEx.CreateGeometryBag(geometries, SpatialReferences.WGS84);
var builder = new GeometryBagBuilderEx(geometries, SpatialReferences.WGS84);
// do something with the builder
bag = builder.ToGeometry();
}
{
MapPoint point = MapPointBuilderEx.CreateMapPoint(10, 20);
List<Coordinate2D> coords = new List<Coordinate2D>() { new Coordinate2D(50, 60), new Coordinate2D(-120, -70), new Coordinate2D(40, 60) };
Multipoint multipointNew = MultipointBuilderEx.CreateMultipoint(coords, SpatialReferences.WebMercator);
Polyline polylineNew = PolylineBuilderEx.CreatePolyline(coords);
string json = "{\"rings\":[[[0,0],[0,1],[1,1],[1,0],[0,0]],[[3,0],[3,1],[4,1],[4,0],[3,0]]]}";
Polygon polygonNew = PolygonBuilderEx.FromJson(json);
var geometries = new List<Geometry>() { point, multipoint, polyline, polygon };
var builder = new GeometryBagBuilderEx(SpatialReferences.WGS84);
builder.AddGeometries(geometries);
GeometryBag geomBag = builder.ToGeometry();
// geomBag.PartCount == 4 (point, multipoint, polyline, polygon)
geometries = new List<Geometry>() { point, polyline };
builder.InsertGeometries(1, geometries);
// builder.GeometryCount == 6
geomBag = builder.ToGeometry();
// geomBag.PartCount == 6 (point, point, polyline, multipoint, polyline, polygon)
}
{
// create a point with z, m
MapPoint point = MapPointBuilderEx.CreateMapPoint(
100, 200, 300, 400, SpatialReferences.WebMercator);
// set the flags
WktExportFlags wktExportFlags = WktExportFlags.WktExportDefaults;
WktImportFlags wktImportFlags = WktImportFlags.WktImportDefaults;
// export and import
string wktString = GeometryEngine.Instance.ExportToWKT(wktExportFlags, point);
MapPoint importPointGeom = GeometryEngine.Instance.ImportFromWKT(
wktImportFlags, wktString, SpatialReferences.WebMercator) as MapPoint;
double x = importPointGeom.X; // x = 100
double y = importPointGeom.Y; // y = 200
bool hasZ = importPointGeom.HasZ; // hasZ = true
double z = importPointGeom.Z; // z = 300
bool hasM = importPointGeom.HasM; // hasM = true
double m = importPointGeom.M; // m = 400
// export without z
WktExportFlags exportFlagsNoZ = WktExportFlags.WktExportStripZs;
wktString = GeometryEngine.Instance.ExportToWKT(exportFlagsNoZ, point);
importPointGeom = GeometryEngine.Instance.ImportFromWKT(
wktImportFlags, wktString, SpatialReferences.WebMercator) as MapPoint;
x = importPointGeom.X; // x = 100
y = importPointGeom.Y; // y = 200
hasZ = importPointGeom.HasZ; // hasZ = false
z = importPointGeom.Z; // z = 0
hasM = importPointGeom.HasM; // hasM = true
m = importPointGeom.M; // m = 400
// export without m
WktExportFlags exportFlagsNoM = WktExportFlags.WktExportStripMs;
wktString = GeometryEngine.Instance.ExportToWKT(exportFlagsNoM, point);
importPointGeom = GeometryEngine.Instance.ImportFromWKT(
wktImportFlags, wktString, SpatialReferences.WebMercator) as MapPoint;
x = importPointGeom.X; // x = 100
y = importPointGeom.Y; // y = 200
hasZ = importPointGeom.HasZ; // hasZ = true
z = importPointGeom.Z; // z = 300
hasM = importPointGeom.HasM; // hasM = false
m = importPointGeom.M; // m = Nan
// export without z, m
wktString = GeometryEngine.Instance.ExportToWKT(
exportFlagsNoZ | exportFlagsNoM, point);
importPointGeom = GeometryEngine.Instance.ImportFromWKT(
wktImportFlags, wktString, SpatialReferences.WebMercator) as MapPoint;
x = importPointGeom.X; // x = 100
y = importPointGeom.Y; // y = 200
hasZ = importPointGeom.HasZ; // hasZ = false
z = importPointGeom.Z; // z = 0
hasM = importPointGeom.HasM; // hasM = false
m = importPointGeom.M; // m = Nan
}
{
// MapPoint
string inputString =
"{\"x\":1,\"y\":2,\"spatialReference\":{\"wkid\":4326,\"latestWkid\":4326}}";
Geometry geometryFromJson = GeometryEngine.Instance.ImportFromJson(
JsonImportFlags.JsonImportDefaults, inputString);
MapPoint importPoint = geometryFromJson as MapPoint;
// importPoint = 1, 2
// importPoint.SpatialReference.WKid = 4326
// use the MapPointBuilderEx convenience method
MapPoint importPoint2 = MapPointBuilderEx.FromJson(inputString);
// importPoint2 = 1, 2
// impointPoint2.SpatialReference.Wkid = 4326
string outputString = GeometryEngine.Instance.ExportToJson(
JsonExportFlags.JsonExportDefaults, importPoint);
// outputString =
// "{\"x\":1,\"y\":2,\"spatialReference\":{\"wkid\":4326,\"latestWkid\":4326}}"
string outputString2 = importPoint.ToJson();
inputString =
"{\"spatialReference\":{\"wkid\":4326},\"z\":3,\"m\":4,\"x\":1,\"y\":2}";
importPoint = GeometryEngine.Instance.ImportFromJson(
JsonImportFlags.JsonImportDefaults, inputString) as MapPoint;
// importPoint.HasM = true
// importPoint.HasZ = true
// importPoint.X = 1
// importPoint.Y = 2
// importPoint.M = 4
// importPoint.Z = 3
importPoint2 = MapPointBuilderEx.FromJson(inputString);
// export to json - skip spatial reference
outputString = GeometryEngine.Instance.ExportToJson(
JsonExportFlags.JsonExportSkipCRS, importPoint);
// outputString = "{\"x\":1,\"y\":2,\"z\":3,\"m\":4}"
// export from mappoint, skipping the sr - same as GeometryEngine.Instance.ExportToJson w JsonExportFlags.JsonExportSkipCRS
outputString2 = importPoint.ToJson(true);
//
// Multipoint
//
List<Coordinate2D> coords = new List<Coordinate2D>()
{
new Coordinate2D(100, 200),
new Coordinate2D(201, 300),
new Coordinate2D(301, 400),
new Coordinate2D(401, 500)
};
Multipoint multipointFromCoords = MultipointBuilderEx.CreateMultipoint(
coords, SpatialReferences.WebMercator);
inputString =
"{\"points\":[[100,200],[201,300],[301,400],[401,500]],\"spatialReference\":{\"wkid\":3857}}";
Multipoint importMultipoint =
GeometryEngine.Instance.ImportFromJson(
JsonImportFlags.JsonImportDefaults, inputString) as Multipoint;
// importMultipoint.IsEqual(multipoint) = true
ReadOnlyPointCollection pointsFromMultipoint = importMultipoint.Points;
// points.Count = 4
// points[0] = 100, 200
// points[1] = 201, 300
// points[2] = 301, 400
// points[3] = 401, 500
// use the MultipointbuilderEx convenience method
Multipoint importMultipoint2 = MultipointBuilderEx.FromJson(inputString);
// importMultipoint2.IsEqual(multipoint) = true
// export to json
outputString = GeometryEngine.Instance.ExportToJson(
JsonExportFlags.JsonExportDefaults, multipointFromCoords);
// outputString = inputString
// or use the multipoint itself
outputString2 = multipointFromCoords.ToJson();
//
// Polyline
//
Polyline polylineFromCoords = PolylineBuilderEx.CreatePolyline(
coords, SpatialReferences.WebMercator);
// export without the spatial reference
outputString = GeometryEngine.Instance.ExportToJson(
JsonExportFlags.JsonExportSkipCRS, polylineFromCoords);
// import
geometry = GeometryEngine.Instance.ImportFromJson(
JsonImportFlags.JsonImportDefaults, outputString);
Polyline importPolyline = geometryFromJson as Polyline;
// importPolyline.SpatialReference = null
pointsFromMultipoint = importPolyline.Points;
// points.Count = 4
// points[0] = 100, 200
// points[1] = 201, 300
// points[2] = 301, 400
// points[3] = 401, 500
// use the polylineBuilderEx convenience method
Polyline importPolyline2 = PolylineBuilderEx.FromJson(outputString);
// importPolyline2 = importPolyline
outputString2 = importPolyline2.ToJson();
// outputString2 = outputString
//
// Polygon
//
Polygon polygonFromCoords = PolygonBuilderEx.CreatePolygon(
coords, SpatialReferences.WebMercator);
// export without the spatial reference
outputString = GeometryEngine.Instance.ExportToJson(
JsonExportFlags.JsonExportSkipCRS, polygonFromCoords);
// import
geometryFromJson = GeometryEngine.Instance.ImportFromJson(
JsonImportFlags.JsonImportDefaults, outputString);
Polygon importPolygon = geometry as Polygon;
// importPolygon.SpatialReference = null
pointsFromMultipoint = importPolygon.Points;
// points.Count = 5
// polygonBuilderEx convenience method
Polygon importPolyon2 = PolygonBuilderEx.FromJson(outputString);
// importPolygon2 = importPolygon
// export from the polygon
outputString2 = importPolyon2.ToJson(true);
// Empty polygon
polygon = PolygonBuilderEx.CreatePolygon(SpatialReferences.WebMercator);
outputString = GeometryEngine.Instance.ExportToJson(
JsonExportFlags.JsonExportDefaults, polygon);
importPolygon = GeometryEngine.Instance.ImportFromJson(
JsonImportFlags.JsonImportDefaults, outputString) as Polygon;
// importPolygon.IsEmpty = true
// importPolygon.SpatialReference.Wkid = 3857
}
{
// methods need to be on the MCT
await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
SpatialReference sr4267 = SpatialReferenceBuilder.CreateSpatialReference(4267);
SpatialReference sr4326 = SpatialReferences.WGS84;
SpatialReference sr3857 = SpatialReferences.WebMercator;
// Create transformation from 4267 -> 3857
ProjectionTransformation projTransFromSRs =
ArcGIS.Core.Geometry.ProjectionTransformation.Create(sr4267, sr3857);
// create an envelope
Envelope env = EnvelopeBuilderEx.CreateEnvelope(
new Coordinate2D(2, 2), new Coordinate2D(3, 3), sr4267);
// Project with one geo transform 4267 -> 3857
Envelope projectedEnvEx = GeometryEngine.Instance.ProjectEx(
env, projTransFromSRs) as Envelope;
// Create inverse transformation, 3857 -> 4267
ProjectionTransformation projTransFromSRsInverse =
ArcGIS.Core.Geometry.ProjectionTransformation.Create(sr3857, sr4267);
// Project the projected envelope back using the inverse transformation
Envelope projectedEnvBack =
GeometryEngine.Instance.ProjectEx(
projectedEnvEx, projTransFromSRsInverse) as Envelope;
bool isEqual = env.IsEqual(projectedEnvBack);
});
}
{
SpatialReference sr = SpatialReferences.WGS84;
SpatialReference sr2 = SpatialReferences.WebMercator;
// create some points
MapPoint point0 = MapPointBuilderEx.CreateMapPoint(0, 0, sr);
MapPoint point1 = MapPointBuilderEx.CreateMapPoint(10, 20, sr);
MapPoint point2 = GeometryEngine.Instance.Project(point1, sr2) as MapPoint;
MapPoint pointEmpty = MapPointBuilderEx.CreateMapPoint(sr);
MapPoint pointwithNoSR = MapPointBuilderEx.CreateMapPoint(1, 1);
MapPoint pointZM = MapPointBuilderEx.CreateMapPoint(1, 2, 3, 4, sr);
// convert to MGRS
ToGeoCoordinateParameter mgrsParam =
new ToGeoCoordinateParameter(GeoCoordinateType.MGRS);
// 31NAA6602100000
string geoCoordString = point0.ToGeoCoordinateString(mgrsParam);
// use the builder to create a new point from the string.
// Coordinates are the same
// outPoint.x = 0; outPoint.Y = 0
MapPoint outPoint =
MapPointBuilderEx.FromGeoCoordinateString(
geoCoordString, sr, GeoCoordinateType.MGRS);
// 32QPH0460911794
// outPoint.X = 10; outPoint.Y = 20
geoCoordString = point1.ToGeoCoordinateString(mgrsParam);
outPoint = MapPointBuilderEx.FromGeoCoordinateString(
geoCoordString, sr, GeoCoordinateType.MGRS);
// z, m are not transformed
// outPoint.X = 1; outPoint.Y = 2; outPoint.Z = Nan; outPoint.M = Nan;
geoCoordString = pointZM.ToGeoCoordinateString(mgrsParam);
outPoint = MapPointBuilderEx.FromGeoCoordinateString(
geoCoordString, sr, GeoCoordinateType.MGRS);
// set the number of digits to 2 and convert
// 32QPH0512
// outPoint.X = 10; outPoint.Y = 20
mgrsParam.NumDigits = 2;
geoCoordString = point1.ToGeoCoordinateString(mgrsParam);
outPoint = MapPointBuilderEx.FromGeoCoordinateString(
geoCoordString, sr, GeoCoordinateType.MGRS);
// convert to UTM
ToGeoCoordinateParameter utmParam =
new ToGeoCoordinateParameter(GeoCoordinateType.UTM);
// 31N 166021 0000000
geoCoordString = point0.ToGeoCoordinateString(utmParam);
// 32Q 604609 2211793
geoCoordString = point1.ToGeoCoordinateString(utmParam);
// convert to DMS
ToGeoCoordinateParameter dmsParam =
new ToGeoCoordinateParameter(GeoCoordinateType.DMS);
// 00 00 00.00N 000 00 00.00E
geoCoordString = point0.ToGeoCoordinateString(dmsParam);
// 20 00 00.00N 010 00 00.00E
geoCoordString = point1.ToGeoCoordinateString(dmsParam);
// convert to DDM
ToGeoCoordinateParameter ddmParam =
new ToGeoCoordinateParameter(GeoCoordinateType.DDM);
// 00 00.0000N 000 00.0000E
geoCoordString = point0.ToGeoCoordinateString(ddmParam);
// 20 00.0000N 010 00.0000E
geoCoordString = point1.ToGeoCoordinateString(ddmParam);
// convert to DD
ToGeoCoordinateParameter ddParam =
new ToGeoCoordinateParameter(GeoCoordinateType.DD);
// 00.000000N 000.000000E
geoCoordString = point0.ToGeoCoordinateString(ddParam);
// 20.000000N 010.000000E
geoCoordString = point1.ToGeoCoordinateString(ddParam);
}
{
List<Coordinate3D> coords2 =
[
new Coordinate3D(0, 0, 0),
new Coordinate3D(0, 1000, double.NaN),
new Coordinate3D(1000, 1000, 50),
new Coordinate3D(1000, 1000, 76),
new Coordinate3D(0, 1000, double.NaN),
new Coordinate3D(0, 0, 0)
];
SpatialReference sr = SpatialReferences.WebMercator;
polyline = PolylineBuilderEx.CreatePolyline(coords2, sr);
// polyline.HasZ = true
// polyline.Points[1].HasZ = true
// polyline.Points[1].Z = NaN
// polyline.Points[4].HasZ = true
// polyline.Points[4].Z = NaN
Polyline polylineNoNaNZs = GeometryEngine.Instance.CalculateNonSimpleZs(polyline, 0) as Polyline;
// polylineNoNaNZs.Points[1].HasZ = true
// polylineNoNaNZs.Points[1].Z = 25 (halfway between 0 and 50)
// polylineNoNaNZs.Points[4].HasZ = true
// polylineNoNaNZs.Points[4].Z = 38 (halfway between 76 and 0)
}
{
List<MapPoint> coords =
[
MapPointBuilderEx.CreateMapPoint(0, 0, 0, 0),
MapPointBuilderEx.CreateMapPoint(0, 1000),
MapPointBuilderEx.CreateMapPoint(1000, 1000, 10, 50)
];
SpatialReference sr = SpatialReferences.WebMercator;
polygon = PolygonBuilderEx.CreatePolygon(coords, sr);
// polygon.HasM = true
// polygon.Points[1].HasM = true
// polygon.Points[1].M = NaN
Polygon polygonNoNaNMs = GeometryEngine.Instance.CalculateNonSimpleMs(polygon, 0) as Polygon;
// polygonNoNaNMs.Points[1].HasM = true
// polygonNoNaNMs.Points[1].M = 25 (halfway between 0 and 50)
}
{
polygon = PolygonBuilderEx.CreatePolygon(
[
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);
var area = GeometryEngine.Instance.GeodesicArea(polygon);
// area is close to 255032810857732.31
area = GeometryEngine.Instance.GeodesicArea(polygon, AreaUnit.SquareKilometers);
// area is close to 255032810.85953,
}
{
polyline = PolylineBuilderEx.CreatePolyline(
[
MapPointBuilderEx.CreateMapPoint(-10018754.1713946, 10018754.1713946),
MapPointBuilderEx.CreateMapPoint(10018754.1713946, 10018754.1713946)
], SpatialReferences.WebMercator);
var length = GeometryEngine.Instance.GeodesicLength(polyline);
// length is approx 5243784.5551844323 in meters
length = GeometryEngine.Instance.GeodesicLength(polyline, LinearUnit.Miles);
// length is approx 3258.33666089067 in miles
var polyline2 = GeometryEngine.Instance.Project(polyline, SpatialReferences.WGS84);
length = GeometryEngine.Instance.GeodesicLength(polyline2);
// length is approx 5243784.55518443 in meters after projecting
}
{
SpatialReference sr = SpatialReferences.WebMercator;
var points = new[] { MapPointBuilderEx.CreateMapPoint(0, 0, sr) };
double distance = 10;
double azimuth = Math.PI / 2;
var resultPoints = GeometryEngine.Instance.GeodeticMove(points, sr, distance, LinearUnit.Meters, azimuth, GeodeticCurveType.Geodesic);
// resultPoints.First().X = 10
// resultPoints.First().Y = 0
// resultPoints.First().SpatialReference.Wkid = sr.Wkid
// Change LinearUnit to Miles
resultPoints = GeometryEngine.Instance.GeodeticMove(points, sr, distance, LinearUnit.Miles, azimuth, GeodeticCurveType.Geodesic);
// resultPoints.First().X = 16093.44
// resultPoints.First().Y = 0
// Change curve type
resultPoints = GeometryEngine.Instance.GeodeticMove(points, sr, distance, LinearUnit.Miles, azimuth, GeodeticCurveType.Loxodrome);
// resultPoints.First().X = 16093.44
// resultPoints.First().Y = 0
}
{
// mitered join and butt caps
SpatialReference sr = SpatialReferenceBuilder.CreateSpatialReference(102010);
List<Coordinate2D> coords =
[
new Coordinate2D(1400,6200),
new Coordinate2D(1600,6300),
new Coordinate2D(1800,6200)
];
polyline = PolylineBuilderEx.CreatePolyline(coords, sr);
polygon = GeometryEngine.Instance.GraphicBuffer(polyline, 50, LineJoinType.Miter, LineCapType.Butt, 10, 0, -1) as Polygon;
// bevelled join and round caps
Envelope envelope = EnvelopeBuilderEx.CreateEnvelope(0, 0, 10000, 10000, SpatialReferences.WebMercator);
Polygon outPolygon = GeometryEngine.Instance.GraphicBuffer(envelope, 1000, LineJoinType.Bevel, LineCapType.Round, 4, 0, 96) as Polygon;
}
{
// round join and round caps
MapPoint point1 = MapPointBuilderEx.CreateMapPoint(0, 0);
MapPoint point2 = MapPointBuilderEx.CreateMapPoint(1, 1, SpatialReferences.WGS84);
MapPoint point3 = MapPointBuilderEx.CreateMapPoint(1000000, 1200000, SpatialReferences.WebMercator);
List<MapPoint> points = [point1, point2, point3];
IReadOnlyList<Geometry> geometries = GeometryEngine.Instance.GraphicBuffer(points, 5, LineJoinType.Round, LineCapType.Round, 0, 0, 3000);
}
{
SpatialReference sr = SpatialReferences.WebMercator; // precision = 1 / MScale = 0.0001
// MapPoint
MapPointBuilderEx pointBuilder = new(3, 4, sr)
{
M = 5.00006
};
MapPoint point = pointBuilder.ToGeometry();
MapPoint outputPoint = GeometryEngine.Instance.SnapMsToSpatialReference(point) as MapPoint;
// outputPoint.M = 5.0001
// Multipoint
MapPointBuilderEx mapPointBuilderEx = new(-3, -4, sr)
{
M = -5.000007
};
pointBuilder = mapPointBuilderEx;
MapPoint point2 = pointBuilder.ToGeometry();
Multipoint multipoint = MultipointBuilderEx.CreateMultipoint([point, point2], AttributeFlags.HasM, sr);
Multipoint outputMultipoint = GeometryEngine.Instance.SnapMsToSpatialReference(multipoint) as Multipoint;
// outputMultipoint.Points[0].M = 5.0001, outputMultipoint.Points[1].M = -5
// Polyline
string json = "{\"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}}";
polyline = PolylineBuilderEx.FromJson(json);
Polyline outputPolyline = GeometryEngine.Instance.SnapMsToSpatialReference(polyline) as Polyline;
// The M-values for the vertices in outputPolyline are { 10.0007, 15.0003, 20, 15.0003, 10.0007 }
}
{
LineSegment line = LineBuilderEx.CreateLineSegment(MapPointBuilderEx.CreateMapPoint(0, 3), MapPointBuilderEx.CreateMapPoint(5.0, 3.0));
polyline = PolylineBuilderEx.CreatePolyline(line);
bool simple = GeometryEngine.Instance.IsSimpleAsFeature(polyline);
// ratio = false
MapPoint pt = GeometryEngine.Instance.MovePointAlongLine(polyline, 1.0, false, 0.0, SegmentExtensionType.NoExtension);
// pt = 1.0, 3.0
pt = GeometryEngine.Instance.MovePointAlongLine(polyline, 1.0, false, -1.0, SegmentExtensionType.NoExtension);
// pt = 1.0, 4.0
pt = GeometryEngine.Instance.MovePointAlongLine(polyline, 1.0, false, 2.0, SegmentExtensionType.NoExtension);
// pt = 1.0, 1.0
// ratio = true
pt = GeometryEngine.Instance.MovePointAlongLine(polyline, 0.5, true, 0, SegmentExtensionType.NoExtension);
// pt = 2.5, 3.0
// move past the line
pt = GeometryEngine.Instance.MovePointAlongLine(polyline, 7, false, 0, SegmentExtensionType.NoExtension);
// pt = 5.0, 3.0
// move past the line with extension at "to" point
pt = GeometryEngine.Instance.MovePointAlongLine(polyline, 7, false, 0, SegmentExtensionType.ExtendEmbeddedAtTo);
// pt = 7.0, 3.0
// negative distance with extension at "from" point
pt = GeometryEngine.Instance.MovePointAlongLine(polyline, -2, false, 0, SegmentExtensionType.ExtendEmbeddedAtFrom);
// pt = -2.0, 3.0
// ratio = true
pt = GeometryEngine.Instance.MovePointAlongLine(polyline, 0.5, true, 0, SegmentExtensionType.NoExtension);
// pt = 2.5, 3.0
// line with Z
List<Coordinate3D> coords3D = [new Coordinate3D(0, 0, 0), new Coordinate3D(1113195, 1118890, 5000)];
Polyline polylineZ = PolylineBuilderEx.CreatePolyline(coords3D, SpatialReferences.WebMercator);
// polylineZ.HasZ = true
// ratio = true, no offset
pt = 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 offset
pt = 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 offset
pt = 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 = 0
MapPoint pt3 = MapPointBuilderEx.CreateMapPoint(5, 5, 0);
MapPoint pt4 = MapPointBuilderEx.CreateMapPoint(5, 5, 10);
List<MapPoint> pts = [pt3, pt4];
polyline = PolylineBuilderEx.CreatePolyline(pts);
// polyline.HasZ = true
// polyline.Length3D = 10
// polyline.Length = 0
MapPoint result = GeometryEngine.Instance.MovePointAlongLine(polyline, 2, false, 0, SegmentExtensionType.NoExtension);
// result = 5, 5, 2
// polyline with length2d = 0 and length3d = 0
MapPoint pt5 = MapPointBuilderEx.CreateMapPoint(5, 5, 10);
MapPoint pt6 = 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 = 0
result = GeometryEngine.Instance.MovePointAlongLine(polyline, 3, true, 0, SegmentExtensionType.NoExtension);
// result = 5, 5, 10
result = GeometryEngine.Instance.MovePointAlongLine(polyline, 3, true, 0, SegmentExtensionType.ExtendEmbeddedAtFrom);
// result = 5, 5, 10
// polyline with Z and M
List<MapPoint> inputPoints =
[
MapPointBuilderEx.CreateMapPoint(1, 2, 3, 4),
MapPointBuilderEx.CreateMapPoint(1, 2, 33, 44),
];
Polyline polylineZM = PolylineBuilderEx.CreatePolyline(inputPoints, SpatialReferences.WGS84);
// polylineZM.HasZ = true
// polylineZM.HasM = true
// ratio = true, no offset
MapPoint pointAlong = GeometryEngine.Instance.MovePointAlongLine(polylineZM, 0.5, true, 0, SegmentExtensionType.NoExtension);
// pointAlong = 1, 2, 18, 24
// ratio = true with offset
pointAlong = GeometryEngine.Instance.MovePointAlongLine(polylineZM, 0.2, true, 2.23606797749979, SegmentExtensionType.NoExtension);
// pointAlong = 1, 2, 9, 12
}
{
MapPoint pt = MapPointBuilderEx.CreateMapPoint(1.0, 3.0, SpatialReferences.WGS84);
Geometry result = GeometryEngine.Instance.Project(pt, SpatialReferences.WebMercator);
MapPoint projectedPt = result as MapPoint;
}
{
// pt
MapPoint pt = MapPointBuilderEx.CreateMapPoint(1.0, 3.0, SpatialReferences.WebMercator);
double area = GeometryEngine.Instance.ShapePreservingArea(pt); // area = 0
List<MapPoint> pts =
[
MapPointBuilderEx.CreateMapPoint(1.0, 1.0, 3.0),
MapPointBuilderEx.CreateMapPoint(1.0, 3.0, 3.0),
MapPointBuilderEx.CreateMapPoint(3, 3, 3.0),
MapPointBuilderEx.CreateMapPoint(3.0, 1.0, 3.0),
];
// multipoint
Multipoint mPt = MultipointBuilderEx.CreateMultipoint(pts);
area = GeometryEngine.Instance.ShapePreservingArea(mPt); // area = 0
// polyline
polyline = PolylineBuilderEx.CreatePolyline(pts);
area = GeometryEngine.Instance.ShapePreservingArea(polyline); // area = 0
// polygon
polygon = PolygonBuilderEx.CreatePolygon(pts, SpatialReferences.WGS84);
area = GeometryEngine.Instance.ShapePreservingArea(polygon);
polygon = PolygonBuilderEx.CreatePolygon(pts, SpatialReferences.WebMercator);
area = GeometryEngine.Instance.ShapePreservingArea(polygon);
polygon = PolygonBuilderEx.CreatePolygon(
[
MapPointBuilderEx.CreateMapPoint( -170, 45),
MapPointBuilderEx.CreateMapPoint( 170, 45),
MapPointBuilderEx.CreateMapPoint( 170, -45),
MapPointBuilderEx.CreateMapPoint( -170, -54)
], SpatialReferences.WGS84);
var area_meters = GeometryEngine.Instance.ShapePreservingArea(polygon);// , AreaUnits.SquareMeters);
var area_miles = GeometryEngine.Instance.ShapePreservingArea(polygon, AreaUnit.SquareMiles);
// area_meters - 352556425383104.37
// area_miles - 136122796.848425
}
{
// pt
MapPoint pt = MapPointBuilderEx.CreateMapPoint(1.0, 3.0, SpatialReferences.WebMercator);
double len = GeometryEngine.Instance.ShapePreservingLength(pt); // len = 0
List<MapPoint> pts =
[
MapPointBuilderEx.CreateMapPoint(1.0, 1.0, 3.0),
MapPointBuilderEx.CreateMapPoint(1.0, 3.0, 3.0),
MapPointBuilderEx.CreateMapPoint(3, 3, 3.0),
MapPointBuilderEx.CreateMapPoint(3.0, 1.0, 3.0),
];
// multipoint
Multipoint mPt = MultipointBuilderEx.CreateMultipoint(pts);
len = GeometryEngine.Instance.ShapePreservingLength(mPt); // len = 0
// polyline
polyline = PolylineBuilderEx.CreatePolyline(pts, SpatialReferences.WGS84);
len = GeometryEngine.Instance.ShapePreservingLength(polyline);
// polygon
polygon = PolygonBuilderEx.CreatePolygon(pts, SpatialReferences.WGS84);
len = GeometryEngine.Instance.ShapePreservingLength(polygon);
polyline = PolylineBuilderEx.CreatePolyline(
[
MapPointBuilderEx.CreateMapPoint( -170, 0),
MapPointBuilderEx.CreateMapPoint( 170, 0)
], SpatialReferences.WGS84);
var length_meters = GeometryEngine.Instance.ShapePreservingLength(polyline); // , LinearUnits.Meters);
var length_miles = GeometryEngine.Instance.ShapePreservingLength(polyline, LinearUnit.Miles);
// length_meters - 37848626.869713023
// length_miles - 23518.046402579574
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)