【问题标题】:Geojson file is not imported correctly if there is geometry in the properties如果属性中有几何图形,则无法正确导入 Geojson 文件
【发布时间】:2019-03-21 11:44:13
【问题描述】:

输入文件:

{
  "type": "FeatureCollection",
  "name": "smth_name",
  "crs": {
    "type": "name",
    "properties": {
      "name": "urn:ogc:def:crs:EPSG::4326"
    }
  },
  "features": [
    {
      "type": "Feature",
      "properties": {
        "testid": 2,
        "other_geom": {
          "type": "Point", "coordinates": [44.3, 33.3] 
        }
      },      
      "geometry":{"type":"MultiPolygon",
          "coordinates":[[[[33.5461,33.44],[33.441,33.447],[33.6718,33.448],[33.0188,33.441],[33.5461,33.44]]]]}
    }
  ]
}

因此,我得到了一个点几何形状(44.3、33.3)的对象,而不是多边形对象。

如何忽略特征属性或其他复杂字段中的几何?

使用geotools gt-geojsondatastore 19.0 版本。

GeoJSONDataStore geoJSONDataStore = new GeoJSONDataStore(jsonFile.toURI().toURL());
SimpleFeature simpleFeature = geoJSONDataStore.getFeatures()...next();
Point geometry = simpleFeature.getDefaultGeometry()

【问题讨论】:

    标签: java geojson geotools


    【解决方案1】:

    在您的构建器中,您已将默认几何图形设置为指向other_geom,即。 Point 对象类型。将其设置为MultiPolygongeometry)类型。

    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.setDefaultGeometry("geometry");
    

    在你的提取中

    MultiPolygon geometry = simpleFeature.getDefaultGeometry();
    

    【讨论】:

    • 输入文件是在外面生成的,我不能影响它的结构。
    猜你喜欢
    • 2023-03-10
    • 2015-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多