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;}
}