之前做过关于shapefile文件的解析,这次来做将数据库返回给我们的数据解析成shapefile的一系列文件输出。这里我们需要用到外部的包geotools,其maven依赖为
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-shapefile</artifactId>
<version>17.2</version>
</dependency>
接着我们对进来的数据进行处理,以下是函数相关代码
private static final String GEOM_KEY = "the_geom";
private static final String PLOT_TYPE = "Coordinate"; //数据库里面用来表示坐标的属性
public static File searchResultToShp(List<Map<String, Object>> dataList) {
Set<String> keys = new LinkedHashSet<>(dataList.get(0).keySet());
keys.remove(PLOT_TYPE);
final long snowflakeId = Math.random(); //这个ID可以自己写个函数定义
String localDirPath = "修改为自己的路径"+ snowflakeId;
File dirFile = new File(localDirPath);
if (!dirFile.exists()) {
dirFile.mkdirs();
}
File shpFile =