我正在实施轨迹点的插值。所以,基本上,我需要沿着方位角从起点到目的点创建几个点。问题是,我无法在集合中添加创建的点:
SimpleFeatureType featureType = featureSource.getSchema();
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
SimpleFeatureCollection collection = featureSource.getFeatures();
/* Irrelevant code here
-----------------------
*/
Point2D newPt = setPointByAzimuth(startingPointCoords, azimuth, distance_to_next_point);
Point pointToCollection = geometryFactory.createPoint(new Coordinate(newPt.getX(), newPt.getY()));
featureBuilder.add(pointToCollection); //not quite sure what this does
SimpleFeature feature = featureBuilder.buildFeature(null);
collection.add(feature);
但是,当我运行它时,集合大小不会更改,也不会向此集合添加任何内容。 我不知道这里有什么问题。
谢谢,
答案 0 :(得分:2)
Not every implementation of SimpleFeatureCollection
is mutable
尝试另一种方式:
new DefaultFeatureCollection
并添加您的积分; addLayer
将其添加到MapContent
。