/// <summary>Convert a ESRI geometry to geojson </summary> /// <param name="esriPoint">A ESRI point object</param> /// <returns>A geojson Object</returns> public static datacontract.geojsonPoint esri2geojsonPoint(IPoint esriPoint) { int epsg; string epsgUri; if (esriPoint.SpatialReference == null) { epsgUri = ""; } else if (esriPoint.SpatialReference.FactoryCode == 900913 || esriPoint.SpatialReference.FactoryCode == 102100) { epsg = 3857;//google mercator epsgUri = string.Format("http://www.opengis.net/def/crs/EPSG/0/{0}", epsg); } else { epsg = esriPoint.SpatialReference.FactoryCode; epsgUri = string.Format("http://www.opengis.net/def/crs/EPSG/0/{0}", epsg); } datacontract.geojsonCRS JScrs = new datacontract.geojsonCRS(){ type= "link", properties = new Dictionary<string, string>() { { "href", epsgUri } } }; datacontract.geojsonPoint JSpoint = new datacontract.geojsonPoint() { type = "Point", coordinates = new List<double>() { esriPoint.X, esriPoint.Y }, crs = JScrs }; return JSpoint; }
/// <summary>Convert a ESRI geometry to geojson </summary> /// <param name="esriPoint">A ESRI polygon object</param> /// <returns>A geojson Object</returns> public static datacontract.geojsonPolygon esri2geojsonPolygon(IPolygon esriPolygon) { int epsg; string epsgUri; if (esriPolygon.SpatialReference == null) { epsgUri = ""; } else if (esriPolygon.SpatialReference.FactoryCode == 900913 || esriPolygon.SpatialReference.FactoryCode == 102100) { epsg = 3857;//google mercator epsgUri = string.Format("http://www.opengis.net/def/crs/EPSG/0/{0}", epsg); } else { epsg = esriPolygon.SpatialReference.FactoryCode; epsgUri = string.Format("http://www.opengis.net/def/crs/EPSG/0/{0}", epsg); } datacontract.geojsonCRS JScrs = new datacontract.geojsonCRS() { type = "link", properties = new Dictionary<string, string>() { { "href", epsgUri } } }; datacontract.geojsonPolygon JSpolygon = new datacontract.geojsonPolygon() { type = "Polygon", crs = JScrs }; List<List<List<double>>> coords = new List<List<List<double>>>(); IGeometryCollection rings = esriPolygon as IGeometryCollection; for (int n = 0; n < rings.GeometryCount; n++) { IPointCollection4 ring = rings.get_Geometry(n) as IPointCollection4; List<List<double>> JSring = new List<List<double>>(); for (int i = 0; i < ring.PointCount; i++) { IPoint pt = ring.get_Point(i); List<double> JSpt = new List<double>() {pt.X, pt.Y }; JSring.Add(JSpt); } coords.Add(JSring); } JSpolygon.coordinates = coords; return JSpolygon; }
/// <summary>Convert a ESRI geometry to geojson </summary> /// <param name="esriPoint">A ESRI polyline object</param> /// <returns>A geojson Object</returns> public static datacontract.geojsonLine esri2geojsonLine(IPolyline esriLine) { int epsg; string epsgUri; if (esriLine.SpatialReference == null) { epsgUri = ""; } else if (esriLine.SpatialReference.FactoryCode == 900913 || esriLine.SpatialReference.FactoryCode == 102100) { epsg = 3857;//google mercator epsgUri = string.Format("http://www.opengis.net/def/crs/EPSG/0/{0}", epsg); } else { epsg = esriLine.SpatialReference.FactoryCode; epsgUri = string.Format("http://www.opengis.net/def/crs/EPSG/0/{0}", epsg); } datacontract.geojsonCRS JScrs = new datacontract.geojsonCRS() { type = "link", properties = new Dictionary<string, string>() { { "href", epsgUri } } }; datacontract.geojsonLine JSline = new datacontract.geojsonLine() {type = "Polyline", crs = JScrs }; List<List<double>> coords = new List<List<double>>(); IPointCollection4 nodes = esriLine as IPointCollection4; for (int n = 0; n < nodes.PointCount; n++) { IPoint node = nodes.get_Point(n); List<double> pt = new List<double>() {node.X, node.Y }; coords.Add(pt); } JSline.coordinates = coords; return JSline; }