mysql的geometry值如何转化成java对象Geometry
解决方法:
1.查数据的sql
加上ST_ASTEXT函数
SELECT ST_ASTEXT(e.geom) geom from tb_real_estate e
2.其中row.get("geom").toString()就是geometry字段的文本值
String wkt = row.get("geom").toString();
//WKT转Geometry
WKTReader wktReader = new WKTReader();
Geometry geometry = null;
try {
geometry = wktReader.read(wkt);
//geometry.setSRID(4326);
} catch (com.vividsolutions.jts.io.ParseException e) {
e.printStackTrace();
}
3.我的pom.xml依赖
<!--java导入矢量图shp数据-->
<dependency>
<groupId>org.geotools.jdbc</groupId>
<artifactId>gt-jdbc-mysql</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-shapefile</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-swing</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-epsg-hsql</artifactId>
<version>2.7.2</version>
</dependency>
<!--java导入矢量图shp数据-->
</dependencies>
<!--java导入矢量图shp数据-->
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net repository</name>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repository</name>
<url>http://download.osgeo.org/webdav/geotools/</url>
</repository>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>boundless</id>
<name>Boundless Maven Repository</name>
<url>http://repo.boundlessgeo.com/main</url>
</repository>
</repositories>
<!--java导入矢量图shp数据-->