我有多边形形状,我想将其转换为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
?
答案 0 :(得分:5)
方法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();
}