英语不是我的母语;请原谅打字错误。
我有两个问题
Q1:ForceCooperativeSystemIterator.class next()方法为什么不返回原始的SimpleFeature而是重新输入SimpleFeature?
Q2:当使用 ForceCooperativeSystemIterator 时,我无法检索原始对象来更新此默认几何图形。最好的方法是什么?
FeatureJSON featureJSON = new FeatureJSON(new GeometryJSON(15));
InputStream is = Files.newInputStream(Paths.get("/arjen_data/rust/2.geojson"));
SimpleFeatureIterator simpleFeatureCollection2 = (SimpleFeatureCollection) featureJSON.readFeatureCollection(is);
try (SimpleFeatureIterator fit = simpleFeatureCollection2.features()) {
while (fit.hasNext()) {
// fit is ForceCoordinateSystemIterator.class
SimpleFeature next = fit.next(); // is retype object
Geometry defaultGeometry = (Geometry) next.getDefaultGeometry();
Geometry intersection = defaultGeometry.difference(union);
// update default Geometry
next.setDefaultGeometry(intersection);
}
}
我阅读了ForceCooperativeSystemIterator.class next()方法源代码。我现在有上面提到的两个问题。
@Override
public SimpleFeature next() throws NoSuchElementException {
if (reader == null) {
throw new IllegalStateException("Reader has already been closed");
}
SimpleFeature next = reader.next();
if (builder == null) return next;
try {
// why retype? original object is bad?
return SimpleFeatureBuilder.retype(next, builder);
} catch (IllegalAttributeException eep) {
throw (IllegalStateException)
new IllegalStateException(eep.getMessage()).initCause(eep);
}
}
我怀疑答案与库中的可变和不可变对象有关,
FeatureType
(模式)是不可变的,Feature
的模式包含有关Geometry
对象的CRS的信息,所以如果你改变您必须更改该功能的架构。
我怀疑,如果您使用
gt-geojson-store
来获取“正确的”GeoJSON 数据存储,而不是使用 gt-geojson
,您的生活会更轻松,后者(也)不受支持,但支持程度更低。但是,这也不会让您修改默认几何图形来更新集合(我认为)。您可能想查看本教程。