当前位置: 代码迷 >> 综合 >> postgres多边形存储--解决 Points of LinearRing do not form a closed linestring
  详细解决方案

postgres多边形存储--解决 Points of LinearRing do not form a closed linestring

热度:12   发布时间:2024-01-16 06:41:21.0

Points of LinearRing do not form a closed linestring错误是多边形不是闭合的区域的原因。

polygon的格式,需要开始点跟结束点一致,这样才能形成闭合区域。

String str = "POLYGON((120.5521 60.6667,121.5521 60.6667,120.6921 61.6667,122.6921 61.6667,120.5521 60.6667))";

具体存储的Java代码,wkt的生成Geometry:

public class Test {public static void main(String args[]){String str = "POLYGON((120.5521 60.6667,121.5521 60.6667,120.6921 61.6667,122.6921 61.6667,120.5521 60.6667))";Geometry t = wktToGeometry(str) ;System.out.println("result:"+t);}/*生成postgis的几何类型*/private static Geometry wktToGeometry(String wktPoint) {WKTReader fromText = new WKTReader();Geometry geom = null;try {geom = fromText.read(wktPoint);} catch (ParseException e) {throw new RuntimeException("Not a WKT string:" + wktPoint);}return geom;}
}

 

 

 

  相关解决方案