输入文件:
{
"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()
最佳答案
在您的构建器中,您已将默认几何图形设置为指向 other_geom
,即。 Point
对象类型。将其设置为 MultiPolygon
类型(geometry
)。
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setDefaultGeometry("geometry");
在你的提取中
MultiPolygon geometry = simpleFeature.getDefaultGeometry();
关于java - 如果属性中有几何图形,则 Geojson 文件无法正确导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55279726/