public static Polyline FromJson( string jsonString )
Public Shared Function FromJson( _ ByVal jsonString As String _ ) As Polyline
Parameters
- jsonString
- JSON string representation of a Polyline.
Return Value
A Polyline.
public static Polyline FromJson( string jsonString )
Public Shared Function FromJson( _ ByVal jsonString As String _ ) As Polyline
Exception | Description |
---|---|
System.ArgumentNullException | The jsonString is empty or null. |
ArcGIS.Core.Geometry.Exceptions.GeometryObjectException | JSON string is invalid or does not represent a polyline string. |
// MapPoint string inputString = "{\"x\":1,\"y\":2,\"spatialReference\":{\"wkid\":4326,\"latestWkid\":4326}}"; Geometry geometry = GeometryEngine.Instance.ImportFromJson( JsonImportFlags.JsonImportDefaults, inputString); MapPoint importPoint = geometry 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 multipoint = 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 points = 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, multipoint); // outputString = inputString // or use the multipoint itself outputString2 = multipoint.ToJson(); // // Polyline // Polyline polyline = PolylineBuilderEx.CreatePolyline( coords, SpatialReferences.WebMercator); // export without the spatial reference outputString = GeometryEngine.Instance.ExportToJson( JsonExportFlags.JsonExportSkipCRS, polyline); // import geometry = GeometryEngine.Instance.ImportFromJson( JsonImportFlags.JsonImportDefaults, outputString); Polyline importPolyline = geometry as Polyline; // importPolyline.SpatialReference = null points = 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 polygon = PolygonBuilderEx.CreatePolygon( coords, SpatialReferences.WebMercator); // export without the spatial reference outputString = GeometryEngine.Instance.ExportToJson( JsonExportFlags.JsonExportSkipCRS, polygon); // import geometry = GeometryEngine.Instance.ImportFromJson( JsonImportFlags.JsonImportDefaults, outputString); Polygon importPolygon = geometry as Polygon; // importPolygon.SpatialReference = null points = 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
Target Platforms: Windows 11, Windows 10