package com.onemap.analyse.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.onemap.analyse.domain.*; import com.onemap.analyse.domain.ESRI.EsriFeature; import com.onemap.analyse.domain.ESRI.EsriField; import com.onemap.analyse.domain.ESRI.EsriGeometry; import com.onemap.analyse.domain.ESRI.EsriJsonModel; import com.onemap.analyse.domain.GeoJSON.Geometry; import com.onemap.analyse.task.PythonExecute; import com.onemap.common.core.utils.StringUtils; import com.onemap.common.core.web.domain.RequestResult; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @Component public class Fxfw2SdeUtils { public static String temp; public String getTemp() { return temp; } @Value("${Hgxfx.temp}") public void setTemp(String temp) { Fxfw2SdeUtils.temp = temp; } static FxfwDictDTO fxfwDictDTO = new FxfwDictDTO(); //shp入库的方法标识码 static String shpPyFun = "shp2sde"; //esrijson入库的方法标识码 static String esrijsonPyFun = "esriJson2sde"; /** * 合规性分析范围数据入库 * * @param hgxfxEntityDTO * @param requestHgxfxDTO * @return * @throws IOException */ public static RequestResult vector2Sde(HgxfxEntityDTO hgxfxEntityDTO, HgxfxDTO requestHgxfxDTO) throws IOException { Integer fwlx = hgxfxEntityDTO.getFwlx(); String vectorFilePath = ""; String pyResult = ""; if (fxfwDictDTO.getDraw().equals(fwlx)) {//自定义绘制范围 EsriJsonModel esriModel = new EsriJsonModel(); //字段汉化 Map fieldAliases = new HashMap<>(); fieldAliases.put("RWBSM", "RWBSM"); fieldAliases.put("RWLX", "RWLX"); esriModel.setFieldAliases(fieldAliases); //geojson绘制范围转换 String xzfw = hgxfxEntityDTO.getXzfw(); if (xzfw.contains(";")) {//多个分析范围 String[] xzfws = xzfw.split(";"); //要素 List features = new ArrayList<>(); for (int i = 0; i < xzfws.length; i++) { if (StringUtils.isEmpty(xzfws[i])) { continue; } JSONObject geojson = new JSONObject(JSON.parseObject(xzfws[i])); Geometry geom = (Geometry) JSONObject.toJavaObject(geojson, Geometry.class); //字段信息 List fields = new ArrayList(); fields.add(new EsriField().init("RWBSM", "RWBSM")); fields.add(new EsriField().init("RWLX", "RWLX")); esriModel.setFields(fields); EsriFeature feature = new EsriFeature(); Map attributes = new HashMap<>(); attributes.put("RWBSM", requestHgxfxDTO.getBsm()); attributes.put("RWLX", "合规性分析"); feature.setAttributes(attributes); EsriGeometry geometry = new EsriGeometry(); geometry.setRings(geom.getCoordinates()); feature.setGeometry(geometry); features.add(feature); } esriModel.setFeatures(features); } else {//单个分析范围 JSONObject geojson = new JSONObject(JSON.parseObject(hgxfxEntityDTO.getXzfw())); Geometry geom = (Geometry) JSONObject.toJavaObject(geojson, Geometry.class); //字段信息 List fields = new ArrayList(); fields.add(new EsriField().init("RWBSM", "RWBSM")); fields.add(new EsriField().init("RWLX", "RWLX")); esriModel.setFields(fields); //要素 List features = new ArrayList<>(); EsriFeature feature = new EsriFeature(); Map attributes = new HashMap<>(); attributes.put("RWBSM", requestHgxfxDTO.getBsm()); attributes.put("RWLX", "合规性分析"); feature.setAttributes(attributes); EsriGeometry geometry = new EsriGeometry(); geometry.setRings(geom.getCoordinates()); feature.setGeometry(geometry); features.add(feature); esriModel.setFeatures(features); } vectorFilePath = temp + "\\temp\\" + System.currentTimeMillis() + ".json"; //写入文件 FileOutputStream fos = null; String fileinput = JSON.toJSONString(esriModel); Boolean writeStatus = true; try { fos = new FileOutputStream(vectorFilePath, false); //true表示在文件末尾追加 fos.write(fileinput.toString().getBytes()); fos.close(); } catch (FileNotFoundException e) { fos.close(); e.printStackTrace(); writeStatus = false; } if (!writeStatus) { return RequestResult.error("自定义范围数据转换失败", null); } Map params = new HashMap<>(); params.put("json", vectorFilePath); params.put("table", "KJGH.T_FZSS_FXRW_GIS"); pyResult = PythonExecute.RunGisHelper(esrijsonPyFun, params); } else if (fxfwDictDTO.getShp().equals(fwlx)) {//shp文件 vectorFilePath = hgxfxEntityDTO.getXzfw(); List listField = new ArrayList(); listField.add(new Field().init("RWBSM", requestHgxfxDTO.getBsm())); listField.add(new Field().init("RWLX", "合规性分析")); Map params = new HashMap<>(); params.put("shpfile", vectorFilePath); params.put("table", "KJGH.T_FZSS_FXRW_GIS"); params.put("fields", listField); pyResult = PythonExecute.RunGisHelper(shpPyFun, params); } else { return RequestResult.error("分析类型未定义", null); } if (pyResult.contains("####OK####")) { //return RequestResult.success("分析范围数据入库成功",1); } else if (pyResult.contains("####ERROR####")) { return RequestResult.error("分析范围数据入库失败", 0); } System.out.println("合规性分析范围要素插入成功!! RWBSM = " + requestHgxfxDTO.getBsm()); return null; } /** * 辅助选址分析范围数据入库 * * @param fzxzDTO * @return * @throws IOException */ public static RequestResult fzxzvector2Sde(FzxzDTO fzxzDTO, String rwlx) throws IOException { Integer fwlx = fzxzDTO.getFwlx(); rwlx = StringUtils.isEmpty(rwlx) ? "辅助选址" : rwlx; String vectorFilePath = ""; String pyResult = ""; if (fxfwDictDTO.getRegion().equals(fwlx)) { } else if (fxfwDictDTO.getDraw().equals(fwlx)) {//自定义绘制范围 EsriJsonModel esriModel = new EsriJsonModel(); //字段汉化 Map fieldAliases = new HashMap<>(); fieldAliases.put("RWBSM", "RWBSM"); fieldAliases.put("RWLX", "RWLX"); esriModel.setFieldAliases(fieldAliases); //geojson绘制范围转换 JSONObject geojson = new JSONObject(JSON.parseObject(fzxzDTO.getXzfw())); Geometry geom = (Geometry) JSONObject.toJavaObject(geojson, Geometry.class); //字段信息 List fields = new ArrayList(); fields.add(new EsriField().init("RWBSM", "RWBSM")); fields.add(new EsriField().init("RWLX", "RWLX")); esriModel.setFields(fields); //要素 List features = new ArrayList<>(); EsriFeature feature = new EsriFeature(); Map attributes = new HashMap<>(); attributes.put("RWBSM", fzxzDTO.getBsm()); attributes.put("RWLX", rwlx); feature.setAttributes(attributes); EsriGeometry geometry = new EsriGeometry(); geometry.setRings(geom.getCoordinates()); feature.setGeometry(geometry); features.add(feature); esriModel.setFeatures(features); vectorFilePath = temp + "\\temp\\" + System.currentTimeMillis() + ".json"; //写入文件 FileOutputStream fos = null; String fileinput = JSON.toJSONString(esriModel); Boolean writeStatus = true; try { fos = new FileOutputStream(vectorFilePath, false); //true表示在文件末尾追加 fos.write(fileinput.toString().getBytes()); fos.close(); } catch (FileNotFoundException e) { fos.close(); e.printStackTrace(); writeStatus = false; } if (!writeStatus) { return RequestResult.error("自定义范围数据转换失败", null); } Map params = new HashMap<>(); params.put("json", vectorFilePath); params.put("table", "KJGH.T_FZSS_FXRW_GIS"); pyResult = PythonExecute.RunGisHelper(esrijsonPyFun, params); fzxzDTO.setXzfw(""); } else if (fxfwDictDTO.getShp().equals(fwlx)) {//shp文件 vectorFilePath = fzxzDTO.getXzfw(); List listField = new ArrayList(); listField.add(new Field().init("RWBSM", fzxzDTO.getBsm())); listField.add(new Field().init("RWLX", rwlx)); Map params = new HashMap<>(); params.put("shpfile", vectorFilePath); params.put("table", "KJGH.T_FZSS_FXRW_GIS"); params.put("fields", listField); pyResult = PythonExecute.RunGisHelper(shpPyFun, params); fzxzDTO.setXzfw(""); } else { return RequestResult.error("分析类型未定义", null); } if (pyResult.contains("####OK####")) { } else if (pyResult.contains("####ERROR####")) { return RequestResult.error("分析范围数据入库失败", 0); } System.out.println("辅助选址分析范围要素插入成功!! RWBSM = " + fzxzDTO.getBsm()); return null; } }