| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- 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<String, String> 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<EsriFeature> 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<EsriField> fields = new ArrayList<EsriField>();
- fields.add(new EsriField().init("RWBSM", "RWBSM"));
- fields.add(new EsriField().init("RWLX", "RWLX"));
- esriModel.setFields(fields);
- EsriFeature feature = new EsriFeature();
- Map<String, Object> 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<EsriField> fields = new ArrayList<EsriField>();
- fields.add(new EsriField().init("RWBSM", "RWBSM"));
- fields.add(new EsriField().init("RWLX", "RWLX"));
- esriModel.setFields(fields);
- //要素
- List<EsriFeature> features = new ArrayList<>();
- EsriFeature feature = new EsriFeature();
- Map<String, Object> 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<String, String> 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<Field> listField = new ArrayList<Field>();
- listField.add(new Field().init("RWBSM", requestHgxfxDTO.getBsm()));
- listField.add(new Field().init("RWLX", "合规性分析"));
- Map<String, Object> 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<String, String> 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<EsriField> fields = new ArrayList<EsriField>();
- fields.add(new EsriField().init("RWBSM", "RWBSM"));
- fields.add(new EsriField().init("RWLX", "RWLX"));
- esriModel.setFields(fields);
- //要素
- List<EsriFeature> features = new ArrayList<>();
- EsriFeature feature = new EsriFeature();
- Map<String, Object> 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<String, String> 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<Field> listField = new ArrayList<Field>();
- listField.add(new Field().init("RWBSM", fzxzDTO.getBsm()));
- listField.add(new Field().init("RWLX", rwlx));
- Map<String, Object> 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;
- }
- }
|