【发布时间】:2017-08-09 17:12:39
【问题描述】:
我正在使用 geotools 17.2 来解析 GeoJSON 文件,如下所示:
try (FileInputStream is = new FileInputStream(routeFile)) {
FeatureJSON io = new FeatureJSON();
return io.readFeatureCollection(is);
}
我使用的 GeoJSON 文件如下:
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": { },
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
}
}, {
"type": "Feature",
"properties": { "name": "test" },
"geometry": {
"type": "Point",
"coordinates": [44.912109375, 53.64463782485651]
}
}
]
}
解析失败并显示以下错误消息/堆栈跟踪:
Caused by: java.lang.IllegalArgumentException: No such attribute:name
at org.geotools.feature.simple.SimpleFeatureBuilder.set(SimpleFeatureBuilder.java:288)
at org.geotools.geojson.feature.FeatureHandler.endObject(FeatureHandler.java:176)
at org.geotools.geojson.DelegatingHandler.endObject(DelegatingHandler.java:81)
at org.geotools.geojson.feature.FeatureCollectionHandler.endObject(FeatureCollectionHandler.java:121)
at org.json.simple.parser.JSONParser.parse(Unknown Source)
at org.geotools.geojson.feature.FeatureJSON$FeatureCollectionIterator.readNext(FeatureJSON.java:746)
但是,如果我将 name 属性移动到第一点,则解析成功。有没有办法让 geotools 在自定义属性方面更加灵活? (或者这是库中的错误?)
【问题讨论】: