public List<List<double>> getDataAlongLine( datacontract.geojsonLine profileLine, int nrSamples = 30, CRS srs = CRS.WGS84) { client.Headers[HttpRequestHeader.ContentType] = "application/json"; Uri dhmUri = new Uri(baseUri + "DHMVMIXED/request/"); datacontract.dhmRequest dhmMsg = new datacontract.dhmRequest() { Samples = nrSamples, LineString = profileLine, SrsIn= (int)srs , SrsOut= (int)srs }; string postData = JsonConvert.SerializeObject(dhmMsg); byte[] byteArray = System.Text.Encoding.ASCII.GetBytes(postData); byte[] byteResult = client.UploadData(dhmUri, "POST", byteArray); string json = Encoding.ASCII.GetString(byteResult); List<List<double>> response = JsonConvert.DeserializeObject<List<List<double>>>(json); return response; }
private void createGrapicAndZoomTo(string capakeyResponse, datacontract.geojson Geom) { IRgbColor inClr = new RgbColorClass() { Red = 0, Blue = 100, Green = 0 }; ; IRgbColor outLine = new RgbColorClass() { Red = 0, Blue = 200, Green = 0, Transparency = 240 }; if (Geom.type == "MultiPolygon") { datacontract.geojsonMultiPolygon muniPolygons = JsonConvert.DeserializeObject<datacontract.geojsonMultiPolygon>(capakeyResponse); IGeometryCollection multiPoly = new GeometryBagClass(); clearGraphics(); foreach (datacontract.geojsonPolygon poly in muniPolygons.toPolygonList()) { IPolygon lbPoly = geopuntHelper.geojson2esriPolygon(poly, (int)dataHandler.CRS.Lambert72); lbPoly.SimplifyPreserveFromTo(); IGeometry prjGeom = geopuntHelper.Transform((IGeometry)lbPoly, map.SpatialReference); IElement muniGrapic = geopuntHelper.AddGraphicToMap(map, prjGeom, inClr, outLine, 2, true); graphics.Add(muniGrapic); multiPoly.AddGeometry(prjGeom); } view.Extent = ((IGeometryBag)multiPoly).Envelope; view.Refresh(); } else if (Geom.type == "Polygon") { datacontract.geojsonPolygon municipalityPolygon = JsonConvert.DeserializeObject<datacontract.geojsonPolygon>(capakeyResponse); IPolygon lbPoly = geopuntHelper.geojson2esriPolygon(municipalityPolygon, (int)dataHandler.CRS.Lambert72); lbPoly.SimplifyPreserveFromTo(); IPolygon prjPoly = (IPolygon)geopuntHelper.Transform((IGeometry)lbPoly, map.SpatialReference); view.Extent = prjPoly.Envelope; clearGraphics(); IElement muniGrapic = geopuntHelper.AddGraphicToMap(map, (IGeometry)prjPoly, inClr, outLine, 3, true); graphics.Add(muniGrapic); view.Refresh(); } }
/// <summary>Convert a GeoJSON Polygon geometry to Arcgis Geometry </summary> /// <param name="JSpoint">The deserialised GeoJson Object</param> /// <param name="epsg">The EPSG-code of the spatial reference, -1 is unknown</param> /// <returns>A Arcgis Polygon goemetry</returns> public static IPolygon geojson2esriPolygon(datacontract.geojsonPolygon JSPolygon, int epsg = -1) { Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment"); System.Object obj = Activator.CreateInstance(factoryType); ISpatialReferenceFactory3 spatialReferenceFactory = obj as ISpatialReferenceFactory3; IGeometryBridge2 pGeoBrg = new GeometryEnvironment() as IGeometryBridge2; IGeometryCollection esriGeometryCol = new PolygonClass(); for (int n = 0; n < JSPolygon.coordinates.Count; n++) { List<List<double>> JSring = JSPolygon.coordinates[n]; IPointCollection4 ring = new RingClass(); ESRI.ArcGIS.esriSystem.WKSPoint[] aWKSPointBuffer = new ESRI.ArcGIS.esriSystem.WKSPoint[JSring.Count]; for (int i = 0; i < JSring.Count; i++) { double[] xy = JSring[i].ToArray(); aWKSPointBuffer[i].X = xy[0]; aWKSPointBuffer[i].Y = xy[1]; } pGeoBrg.SetWKSPoints(ring , aWKSPointBuffer); esriGeometryCol.AddGeometry(ring as IGeometry, Type.Missing, Type.Missing); } IPolygon esriPolygon = esriGeometryCol as IPolygon; if (epsg != -1) { ISpatialReference srs = spatialReferenceFactory.CreateSpatialReference(epsg); esriPolygon.SpatialReference = srs; } return esriPolygon; }
/// <summary>Convert a GoeJSON point geometry to Arcgis Geometry </summary> /// <param name="JSpoint">The deserialised GeoJson Object</param> /// <param name="epsg">The EPSG-code of the spatial reference, -1 is unknown</param> /// <returns>A Arcgis Point goemetry</returns> public static IPoint geojson2esriPoint(datacontract.geojsonPoint JSpoint, int epsg = -1) { Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment"); System.Object obj = Activator.CreateInstance(factoryType); ISpatialReferenceFactory3 spatialReferenceFactory = obj as ISpatialReferenceFactory3; IPoint esriPnt = new PointClass() { X = JSpoint.coordinates[0], Y = JSpoint.coordinates[1] }; if (epsg != -1) { ISpatialReference srs = spatialReferenceFactory.CreateSpatialReference(epsg); esriPnt.SpatialReference = srs; } return esriPnt; }
/// <summary>Convert a GeoJSON Line geometry to Arcgis Geometry </summary> /// <param name="JSpoint">The deserialised GeoJson Object</param> /// <param name="epsg">The EPSG-code of the spatial reference, -1 is unknown</param> /// <returns>A Arcgis PolyLine goemetry</returns> public static IPolyline geojson2esriLine(datacontract.geojsonLine JSline, int epsg = -1) { Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment"); System.Object obj = Activator.CreateInstance(factoryType); ISpatialReferenceFactory3 spatialReferenceFactory = obj as ISpatialReferenceFactory3; IGeometryBridge2 pGeoBrg = new GeometryEnvironment() as IGeometryBridge2; ESRI.ArcGIS.esriSystem.WKSPoint[] aWKSPointBuffer = new ESRI.ArcGIS.esriSystem.WKSPoint[ JSline.coordinates.Count ]; for (int n = 0; n < JSline.coordinates.Count; n++) { double[] xy = JSline.coordinates[n].ToArray(); aWKSPointBuffer[n].X = xy[0]; aWKSPointBuffer[n].Y = xy[1]; } IPolyline esriLine = new PolylineClass(); pGeoBrg.SetWKSPoints(esriLine as IPointCollection4, aWKSPointBuffer); if (epsg != -1) { ISpatialReference srs = spatialReferenceFactory.CreateSpatialReference(epsg); esriLine.SpatialReference = srs; } return esriLine; }