1

我想改变一条线的坐标并用新的坐标动态绘制它。虽然可以更改值,但我没有成功用新坐标重新绘制。
我的示例代码和跟踪输出在这里..

TRACE-1:SimpleFeatureImpl:OSB_Line=[SimpleFeatureImpl.Attribute:the_geom=MULTILINESTRING ((32.56891053280672 39.98170079260158, 32.56195765663663 39.98391357917568)),

TRACE-2:SimpleFeatureImpl:OSB_Line=[SimpleFeatureImpl.Attribute:the_geom=MULTILINESTRING ((132.5689105328067 39.98170079260158,

public void modifySelectedFeatures(Set<FeatureId> idSet) {
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
    MapContent mapContent = mapFrame.getMapContent();
    FeatureLayer layer = (FeatureLayer) mapContent.layers().get(0);
    Filter filter = ff.id(idSet);
    try {
        SimpleFeatureCollection fColl = (SimpleFeatureCollection) layer.getFeatureSource().getFeatures(filter);
        if (!fColl.isEmpty()) {
            SimpleFeatureIterator iterator = fColl.features();
            while (iterator.hasNext()) {
                SimpleFeature simpleFeature = iterator.next();
                System.out.println("TRACE-1:" + simpleFeature);
                Geometry geom = (MultiLineString) simpleFeature.getDefaultGeometry();
                Coordinate c = geom.getCoordinates()[0];
                c.setCoordinate(new Coordinate(c.x + 100.0, c.y, c.z));
                simpleFeature.setDefaultGeometry(geom);
                System.out.println("TRACE-2:" + simpleFeature);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();  
    }
    mapFrame.getMapPane().repaint();
}
4

0 回答 0