基本操作
当然WKT,WKB根据业务场景选择啦
1、创建点
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null );
WKTReader reader = new WKTReader( geometryFactory );
Point point = (Point) reader.read("POINT (1 1)");
2、创建线
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
WKTReader reader = new WKTReader(geometryFactory);
LineString line = (LineString) reader.read("LINESTRING(0 2, 2 0, 8 6)");
3、创建面
WKBReader wkbReader = new WKBReader(geometryFactory);
MultiPolygon polygon = (MultiPolygon) wkbReader.read(WKBReader.hexToBytes(tokens[1]));
4.Geometry是Point,Line,Polygon的父类是可以进行转换的
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
WKBReader wkbReader = new WKBReader(geometryFactory);
MultiPolygon polygon = (MultiPolygon) wkbReader.read(WKBReader.hexToBytes(tokens[1]));