【问题标题】:create geojson using simple json java使用简单的json java创建geojson
【发布时间】:2016-10-25 12:05:18
【问题描述】:

我想使用 simple-json-1.1.1 jar 创建以下 geojson。

{"type": "FeatureCollection",
"crs": {
    "type": "name",
    "properties": {
            "name": "ESPG:4326"
            }
    },
    "features":[

    {
        "type":"Feature",
        "geometry":{
                "type":"Point",
                "coordinates":[55,55]
                },
        "properties":{
                "desc":"something"}
                }
    ]
}

关于如何做到这一点的任何想法?谢谢!

【问题讨论】:

    标签: java json eclipse geojson


    【解决方案1】:

    上述创建geojson的代码如下:

    JSONObject featureCollection = new JSONObject();
    featureCollection.put("type", "FeatureCollection");
    JSONObject properties = new JSONObject();
    properties.put("name", "ESPG:4326");
    JSONObject crs = new JSONObject();
    crs.put("type", "name");
    crs.put("properties", properties);
    featureCollection.put("crs", crs);
    
    JSONArray features = new JSONArray();
    JSONObject feature = new JSONObject();
    feature.put("type", "Feature");
    JSONObject geometry = new JSONObject();
    
    JSONAray JSONArrayCoord = new JSONArray();
    
    JSONArrayCoord.add(0, 55);
    JSONArrayCoord.add(1, 55);
    geometry.put("type", "Point");
    geometry.put("coordinates", JSONArrayCoord);
    feature.put("geometry", geometry);
    
    features.add(feature);
    featureCollection.put("features", features);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-14
      • 2012-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-09
      • 2017-02-19
      相关资源
      最近更新 更多