1、测绘数据
2、数据处理
public void dealData() {
List<Map<String, Object>> shyqzdMapList = 截图数据;
Map<String, List<Map<String, Object>>> groupMap = shyqzdMapList.stream().collect(Collectors.groupingBy(item -> String.valueOf(item.get("mbsxh"))));
String geojson = "";//上传的geojson文件
if (groupMap.size() == 1) { //只有一个面
List<Map<String, Object>> polygonList = shyqzdMapList.stream().sorted(Comparator.comparing(item -> String.valueOf(item.get("xh")))).collect(Collectors.toList());
List<Coordinate> coordinateList = new ArrayList<>(polygonList.size());
for (int i = 1; i < polygonList.size(); i++) {
double x = Double.valueOf(String.valueOf(polygonList.get(i).get("x")));
double y = Double.valueOf(String.valueOf(polygonList.get(i).get("y")));
Coordinate coordinate = new Coordinate(x, y);
coordinateList.add(coordinate);
}
double xEnd = Double.valueOf(String.valueOf(polygonList.get(0).get("x")));
double yEnd = Double.valueOf(String.valueOf(polygonList.get(0).get("y")));
coordinateList.add(coordinateList.size(), new Coordinate(xEnd, yEnd));
Coordinate[] coordinates = coordinateList.toArray(new Coordinate[coordinateList.size()]);
GeometryFactory gf = new GeometryFactory();
Polygon polygon = gf.createPolygon(coordinates);
geojson = GeometryParser.geometry2Geojson(polygon);
log.info("单面;{}", geojson);
} else { //多面
List<Polygon> polygons = new ArrayList<>();
for (Map.Entry<String, List<Map<String, Object>>> entry : groupMap.entrySet()) {
List<Map<String, Object>> polygonList = entry.getValue().stream().sorted(Comparator.comparing(item -> String.valueOf(item.get("xh")))).collect(Collectors.toList());
List<Coordinate> coordinateList = new ArrayList<>(polygonList.size());
for (int i = 1; i < polygonList.size(); i++) {
double x = Double.valueOf(String.valueOf(polygonList.get(i).get("x")));
double y = Double.valueOf(String.valueOf(polygonList.get(i).get("y")));
Coordinate coordinate = new Coordinate(x, y);
coordinateList.add(coordinate);
}
double xEnd = Double.valueOf(String.valueOf(polygonList.get(0).get("x")));
double yEnd = Double.valueOf(String.valueOf(polygonList.get(0).get("y")));
coordinateList.add(coordinateList.size(), new Coordinate(xEnd, yEnd));
Coordinate[] coordinates = coordinateList.toArray(new Coordinate[coordinateList.size()]);
GeometryFactory gf = new GeometryFactory();
Polygon polygon = gf.createPolygon(coordinates);
polygons.add(polygon);
}
Polygon[] polygonArr = polygons.toArray(new Polygon[polygons.size()]);
Geometry geometry = new MultiPolygon(polygonArr, JTSFactoryFinder.getGeometryFactory());
geojson = GeometryParser.geometry2Geojson(geometry);
log.info("多面;{}", geojson);
}