3

我有多边形形状,我想将其转换为 MultiLineString。请注意,通常方向是不同的:从点、坐标、线等使用GeometryFactory构建多边形。我开始考虑GeometryTransformer但很难理解那里的文档......所以我有这个:

import com.vividsolutions.jts.geom.*;
...
GeometryFactory gFactory = new GeometryFactory();
GeometryTransformer gTransform = new GeometryTransformer();
Polygon polygon = gFactory.createPolygon(someLinearRing, null);
MultiLineString mlString = polygon.TODO?

如何继续中TODO

4

1 回答 1

6

该方法Polygon.getBoundary()计算多边形的边界。如果多边形没有孔(也只有一个边界),则返回 LinearRing 类型的对象。如果多边形有孔 - 也有多个边界 - 则返回 MultiLineString 类型的对象。

使用方法 Polygon.getNumInteriorRing() 检查多边形是否有孔,然后构建多线串是必要的:

GeometryFactory gFactory = new GeometryFactory();
if (polygon.getNumInteriorRing() == 0){
  // polygon has not holes, so extract the exterior ring
  // and build a multilinestring
  return gFactory.createMultiLineString(polygon.getExteriorRing());
}

else{
  // Polygon has holes, also several boundaries. 
  // Simply run getBoundary(), it will return a multilinestring
  return polygon.getBoundary();
}
于 2015-09-28T07:58:51.377 回答