【发布时间】:2013-12-10 09:09:48
【问题描述】:
我是 Java GeoTools 库的新手,我只是想在地图上绘制一个多边形。我使用 GPS 坐标来绘制点,绘制得很好,但我就是不知道如何在它们之间绘制 LineString 以挽救我的生命。
我查看了 geotools.org 和 this posting 上的所有教程,但无济于事。 这应该这么复杂吗?任何人都可以发布绘制 LineString 所需的代码片段吗?这是我上次尝试过的:
SimpleFeatureType lineType = DataUtilities.createType("LINE", "geom:LineString,name:String");
SimpleFeatureBuilder featureBuilderLines = new SimpleFeatureBuilder(lineType);
SimpleFeatureCollection collectionLines = FeatureCollections.newCollection();
LineString line = builder.createLineString(listOfPoints);
featureBuilderLines.add(line);
SimpleFeature featureLine = featureBuilderLines.buildFeature(null);
((DefaultFeatureCollection)collectionLines).add(featureLine);
Style lineStyle = SLD.createLineStyle(Color.RED, 2.0f);
map.addLayer(new FeatureLayer(collectionLines, lineStyle));
谢谢,提前和最好的问候
【问题讨论】:
-
请添加一些代码,以便我们看到您尝试吃的东西。
-
如果你检查行它包含什么?
-
我放在那里的 10 个元素,带有一个合理的信封。但是 .showMap() 函数会抛出以下异常: org.geotools.geometry.iso.coordinate.LineStringImpl 不能转换为 com.vividsolutions.jts.geom.Geometry
-
早点提一下错误可能是值得的 :-) 听起来您的构建器正在构建错误类型的 LineString,您使用的是 GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
-
是的,我是。我之前没有提到这个错误,因为感觉好像我只是在黑暗中摸索,不知道自己在做什么。我尝试了其他也不起作用的变体,但显然出现了不同的错误。