gpt4 book ai didi

java - 将要素添加到 Geotools 中的现有图层

转载 作者:搜寻专家 更新时间:2023-11-01 03:22:24 25 4
gpt4 key购买 nike

我向 Geotools MapPane 添加了一个图层,其中包含各种 WKT 字符串功能。图层显示正确。现在,在 UI 上单击一个按钮,我想向该层添加另一个功能。

最初,我创建图层并使用以下内容显示它:

List<SimpleFeature> list  = featuresFromWkt(wktString, name); //method name explains what it does..
ListFeatureCollection col = new ListFeatureCollection(getFeatureType(), list);
Color color = Color.BLUE;
Style style = SLD.createPolygonStyle(color, color.brighter(), 0.5f);
FeatureLayer layer = new FeatureLayer(col, style);
layer.setVisible(true);
layer.setTitle(name);
mapContent.layers().add(layer)

现在,要向图层添加内容,我从内容中获取图层,使用:

FeatureLayer layer = (FeatureLayer) mapContent.layers().get(0);

我现在可以使用 layer.getSimpleFeatureSource() 来检索源,但似乎无法将此源转换回我可以调用 .addFeature(someNewFeature) 以向 map 添加内容的内容。

我可以保留对 ListFeatureCollection 的引用并使用它来添加新功能,但我更愿意仅使用 mapConent.layers.get(layerNumber) 方法,然后使用图层添加内容。

到目前为止,我看到的所有示例都只是添加了具有新功能的另一层。我不想添加另一层,而只是向现有层添加一些内容,其内容位于内存中。我在这里错过了什么吗?有没有我不知道的 GeoTools 类?

最佳答案

看看http://osgeo-org.1560.x6.nabble.com/Adding-geometry-to-layer-td4324729.html .这听起来与您的问题非常相似,不久前在 GeoTools 邮件列表中被问到。

基本思路,以防上面链接的邮件列表存档在某个时间点变得不可用:

  • 创建包含您的特征的特征集合(最初可能为空)
  • 将此要素集合添加到 map 层
  • 稍后将特征添加到特征集合中。

根据邮件列表上的声明:“当您将要素添加到集合中时, map Pane 应该自动重新绘制(从要素集合到 map 图层到图层列表再到 map Pane 有一系列事件发送)”

关于java - 将要素添加到 Geotools 中的现有图层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26882297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com