将MultiLineString转换为MultiPolygon

时间:2018-10-22 14:25:31

标签: java postgis

我正在使用postgres数据库和postgis扩展以及一个保存地理数据的Java应用程序。我有一个形状文件,其中包含一个MultiLineString,该文件由一个封闭的LineString组成。尽管从技术上讲它不是MultiPolygon,但我需要将其转换为MultiPolygon,以将其存储在定义为shape的{​​{1}}列中。

我已经阅读到postgis具有功能geometry(MultiPolygon,4326),并且使用了与Java等效的功能,如下所示:

ST_ConvexHull

对此的替代方案可能是

Geometry shape = ... // the shape, which happens to be a MultiLineString
...
Geometry convexHull = shape.convexHull();
if (convexHull instanceof Polygon) {                        
    shapeDTO.setShape(geometryFactory.createMultiPolygon(new Polygon[] { (Polygon) convexHull }));
} else {
    final String errMsg = "shape does not have at least 3 points, cannot create polygonal convex hull";
    log.error(errMsg);
    throw new IOException(errMsg);
}

如果形状GeometryFactory gf = new GeometryFactory(); Polygon polygon = gf.createPolygon(shape.getCoordinates()); MultiPolygon multiPolygon = gf.createMultiPolygon(new Polygon[]{ polygon }); multiPolygon.setSRID(4326); shapeDTO.setShape(multiPolygon); 是闭合的,这似乎更精确

有人处理过类似的问题吗?

0 个答案:

没有答案