将EsriGeometry转为GeoJson

        public static string ConvertEsriGeometryToGeoJson(IGeometry esriGeometry)
        {
            byte[] b = ConvertGeometryToWKB(esriGeometry);
            WKBReader reader = new WKBReader();
            NetTopologySuite.Geometries.Geometry geometry = reader.Read(b);
            GeoJsonWriter geoJsonWriter = new GeoJsonWriter();
            return geoJsonWriter.Write(geometry);
        }

        public static byte[] ConvertGeometryToWKB(IGeometry geometry)
        {
            IWkb wkb = geometry as IWkb;
            ITopologicalOperator oper = geometry as ITopologicalOperator;
            oper.Simplify();
            IGeometryFactory3 factory = new GeometryEnvironment() as IGeometryFactory3;
            byte[] b = factory.CreateWkbVariantFromGeometry(geometry) as byte[];
            return b;
        }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
JSON(JavaScript Object Notation)是一种常用的数据格式,而GeoJSON是一种基于JSON的地理空间数据格式。将JSON转为GeoJSON可以通过以下步骤实现: 1. 确保你的JSON数据包含地理空间信息,例如经纬度坐标或几何对象。 2. 解析JSON数据,将其转换为程序中的对象或数据结构。 3. 创建一个新的GeoJSON对象,并设置其类型为"FeatureCollection"。 4. 遍历解析后的JSON数据,对每个地理空间对象进行处理。 5. 对于每个地理空间对象,创建一个新的GeoJSON Feature对象,并设置其几何属性为对应的几何对象。 6. 将其他属性(如名称、描述等)添加到GeoJSON Feature对象中。 7. 将每个GeoJSON Feature对象添加到GeoJSON FeatureCollection对象中。 8. 将GeoJSON FeatureCollection对象转换为字符串形式,即可得到转换后的GeoJSON数据。 下面是一个示例代码,演示了如何将包含经纬度坐标的JSON数据转换为GeoJSON: ```python import json # 假设原始的JSON数据 json_data = ''' { "points": [ { "name": "Point 1", "latitude": 40.7128, "longitude": -74.0060 }, { "name": "Point 2", "latitude": 34.0522, "longitude": -118.2437 } ] } ''' # 解析JSON数据 data = json.loads(json_data) # 创建GeoJSON FeatureCollection对象 geojson = { "type": "FeatureCollection", "features": [] } # 遍历解析后的JSON数据 for point in data["points"]: # 创建GeoJSON Feature对象 feature = { "type": "Feature", "geometry": { "type": "Point", "coordinates": [point["longitude"], point["latitude"]] }, "properties": { "name": point["name"] } } # 将GeoJSON Feature对象添加到FeatureCollection中 geojson["features"].append(feature) # 将GeoJSON转换为字符串形式 geojson_str = json.dumps(geojson) print(geojson_str) ``` 这样,你就可以将JSON数据转换为GeoJSON格式了。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值