我在空间数据库中有几何图形。在 jts 拓扑套件的帮助下,我设法在谷歌地图 v2 上绘制了一些简单的多边形,将 WKT 转换为坐标数组。但我不知道如何正确绘制多面体。各个较小的形状是相连的,它们不应该是相连的。
正确的多边形:
错误的多面体:
应该如何:
我在空间数据库中有几何图形。在 jts 拓扑套件的帮助下,我设法在谷歌地图 v2 上绘制了一些简单的多边形,将 WKT 转换为坐标数组。但我不知道如何正确绘制多面体。各个较小的形状是相连的,它们不应该是相连的。
正确的多边形:
错误的多面体:
应该如何:
所以经过几天的尝试,我让它像这样工作。我希望它可以帮助某人。
private void test(){
GeometryFactory geometryFactory = new GeometryFactory();
WKTReader reader=new WKTReader(geometryFactory);
PolygonOptions polyOptions = null;
ArrayList<String> featureList = new ArrayList<String>();
MultiPolygon multipolygon = null;
Polygon polygon = null;
Coordinate[] outerCoordinates = null;
Coordinate[] innerCoordinates = null;
ArrayList<LatLng> outer = null;
ArrayList<LatLng> inner = null;
try {
//Gets a list of features in WKT format
featureList = HtmlActivity.mDbHelper.getFeatureList();
//Iterates the feature list
for (String feature : featureList) {
multipolygon = (MultiPolygon) reader.read(feature);
//Gets each polygon of a multipolygon
for(int i = 0; i < multipolygon.getNumGeometries(); i++)
{
outer = new ArrayList<LatLng>();
polyOptions = new PolygonOptions();
polygon = (Polygon) multipolygon.getGeometryN(i);
//Gets each polygon outer coordinates
outerCoordinates = polygon.getExteriorRing().getCoordinates();
for (Coordinate outerCoordinate : outerCoordinates){
outer.add(new LatLng(outerCoordinate.y, outerCoordinate.x));
}
polyOptions.addAll(outer);
//Getting each polygon interior coordinates (hole) if they exist
if(polygon.getNumInteriorRing() > 0){
for(int j = 0; j < polygon.getNumInteriorRing(); j++){
inner = new ArrayList<LatLng>();
innerCoordinates = polygon.getInteriorRingN(j).getCoordinates();
for (Coordinate innerCoordinate : innerCoordinates){
inner.add(new LatLng(innerCoordinate.y, innerCoordinate.x));
}
polyOptions.addHole(inner);
}
}
polyOptions.strokeColor(Color.rgb(30, 30, 30));
polyOptions.strokeWidth(2);
polyOptions.fillColor(Color.argb(255, 255, 0, 0));
googleMap.addPolygon(polyOptions);
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}