Esempio n. 1
0
        /// <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;
        }
Esempio n. 2
0
        /// <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;
        }