public static SpatialReference WGS84 {get;}
Public Shared ReadOnly Property WGS84 As SpatialReference
public static SpatialReference WGS84 {get;}
Public Shared ReadOnly Property WGS84 As SpatialReference
SpatialReference wgs84 = SpatialReferences.WGS84; bool isProjected = wgs84.IsProjected; // false bool isGeographic = wgs84.IsGeographic; // true
// Get datum of a spatial reference SpatialReference srWgs84 = SpatialReferences.WGS84; Datum datum = srWgs84.Datum; // datum.Name = "D_WGS_1984" // datum.Wkid = 6326 // datum.SpheroidName = "WGS_1984" // datum.SpheroidWkid = 7030 // datum.SpheroidFlattening = 0.0033528106647474805 // datum.SpheroidSemiMajorAxis = 6378137.0 // datum.SpheroidSemiMinorAxis = 6356752.3142451793 // Custom WKT string wyomingWkt = "PROJCS[\"Wyoming_State_Pl_NAD_1927\",GEOGCS[\"GCS_North_American_1927\",DATUM[\"D_North_American_1927_Perry\",SPHEROID[\"Clarke_1866_Chase\",6378210.0,250.0]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"false_easting\",500000.0],PARAMETER[\"false_northing\",0.0],PARAMETER[\"central_meridian\",-107.3333333],PARAMETER[\"scale_factor\",0.9999412],PARAMETER[\"latitude_of_origin\",40.66666667],UNIT[\"Foot_US\",0.3048006096012192]]"; SpatialReference srFromWkt = SpatialReferenceBuilder.CreateSpatialReference(wyomingWkt); datum = srWgs84.Datum; // datum.Name = "D_North_American_1927_Perry" // datum.Wkid = 0 // datum.SpheroidName = "Clarke_1866_Chase" // datum.SpheroidWkid = 0 // datum.SpheroidFlattening = 0.004 // datum.SpheroidSemiMajorAxis = 6378210.0 // datum.SpheroidSemiMinorAxis = 6352697.16
// Use a builderEx convenience method or a builderEx constructor. // neither need to run on the MCT MapPoint startPt = MapPointBuilderEx.CreateMapPoint(1.0, 1.0); MapPoint endPt = MapPointBuilderEx.CreateMapPoint(2.0, 1.0); List<MapPoint> list = new List<MapPoint>(); list.Add(startPt); list.Add(endPt); Polyline polyline = PolylineBuilderEx.CreatePolyline(list, SpatialReferences.WGS84); // use AttributeFlags.None since we only have 2D points in the list PolylineBuilderEx pb = new PolylineBuilderEx(list, AttributeFlags.None); pb.SpatialReference = SpatialReferences.WGS84; Polyline polyline2 = pb.ToGeometry(); // use AttributeFlags.NoAttributes because we only have 2d points in the list Polyline polyline4 = PolylineBuilderEx.CreatePolyline(list, AttributeFlags.None);
// create a polyline List<Coordinate2D> coords = new List<Coordinate2D> { new Coordinate2D(0, 0), new Coordinate2D(0, 1), new Coordinate2D(1, 1), new Coordinate2D(1, 0) }; Polyline polyline = PolylineBuilderEx.CreatePolyline( coords, SpatialReferences.WGS84); WkbExportFlags wkbExportFlags = WkbExportFlags.WkbExportDefaults; WkbImportFlags wkbImportFlags = WkbImportFlags.WkbImportDefaults; // export and import byte[] buffer = GeometryEngine.Instance.ExportToWKB(wkbExportFlags, polyline); Geometry geometry = GeometryEngine.Instance.ImportFromWKB( wkbImportFlags, buffer, SpatialReferences.WGS84); Polyline importPolyline = geometry as Polyline; // alternatively, determine the size for the buffer int bufferSize = GeometryEngine.Instance.GetWKBSize(wkbExportFlags, polyline); buffer = new byte[bufferSize]; // export bufferSize = GeometryEngine.Instance.ExportToWKB( wkbExportFlags, polyline, ref buffer); // import importPolyline = GeometryEngine.Instance.ImportFromWKB( wkbImportFlags, buffer, SpatialReferences.WGS84) as Polyline;
// create an envelope List<MapPoint> coordsZM = new List<MapPoint> { MapPointBuilderEx.CreateMapPoint(1001, 1002, 1003, 1004), MapPointBuilderEx.CreateMapPoint(2001, 2002, Double.NaN, 2004), MapPointBuilderEx.CreateMapPoint(3001, -3002, 3003, 3004), MapPointBuilderEx.CreateMapPoint(1001, -4002, 4003, 4004) }; Envelope envelope = EnvelopeBuilderEx.CreateEnvelope( coordsZM[0], coordsZM[2], SpatialReferences.WGS84); // export and import EsriShapeExportFlags exportFlags = EsriShapeExportFlags.EsriShapeExportDefaults; EsriShapeImportFlags importFlags = EsriShapeImportFlags.EsriShapeImportDefaults; byte[] buffer = GeometryEngine.Instance.ExportToEsriShape(exportFlags, envelope); Polygon importedPolygon = GeometryEngine.Instance.ImportFromEsriShape( importFlags, buffer, envelope.SpatialReference) as Polygon; Envelope importedEnvelope = importedPolygon.Extent; // export without z,m buffer = GeometryEngine.Instance.ExportToEsriShape( EsriShapeExportFlags.EsriShapeExportStripZs | EsriShapeExportFlags.EsriShapeExportStripMs, envelope); importedPolygon = GeometryEngine.Instance.ImportFromEsriShape( importFlags, buffer, SpatialReferences.WGS84) as Polygon; importedEnvelope = importedPolygon.Extent; bool hasZ = importedEnvelope.HasZ; // hasZ = false bool hasM = importedEnvelope.HasM; // hasM = false // export with shapeSize int bufferSize = GeometryEngine.Instance.GetEsriShapeSize( exportFlags, envelope); buffer = new byte[bufferSize]; bufferSize = GeometryEngine.Instance.ExportToEsriShape( exportFlags, envelope, ref buffer); importedPolygon = GeometryEngine.Instance.ImportFromEsriShape( importFlags, buffer, envelope.SpatialReference) as Polygon; importedEnvelope = importedPolygon.Extent; // or use the envelope and envelopeBuilderEx classes buffer = envelope.ToEsriShape(); // buffer represents a polygon as there is not an envelope Esri shape buffer // EnvelopeBuilderEx.FromEsriShape takes a polygon Esri shape buffer and returns the extent of the polygon. importedEnvelope = EnvelopeBuilderEx.FromEsriShape(buffer);
Target Platforms: Windows 11, Windows 10, Windows 8.1