| | |
| | | package com.lf.server.service.show; |
| | | |
| | | import com.lf.server.entity.all.StaticData; |
| | | import com.lf.server.entity.data.DownloadEntity; |
| | | import com.lf.server.entity.data.MetaFileEntity; |
| | | import com.lf.server.entity.show.PipelineEntity; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.*; |
| | | import com.lf.server.mapper.all.GeomBaseMapper; |
| | | import com.lf.server.mapper.data.DownloadMapper; |
| | | import com.lf.server.mapper.show.PipelineMapper; |
| | | import net.lingala.zip4j.ZipFile; |
| | | import net.lingala.zip4j.model.FileHeader; |
| | | import net.lingala.zip4j.model.ZipParameters; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.gdal.ogr.DataSource; |
| | | import org.gdal.ogr.Driver; |
| | | import org.gdal.ogr.Layer; |
| | | import org.gdal.ogr.ogr; |
| | | import org.gdal.ogr.*; |
| | | import org.gdal.osr.SpatialReference; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | return pipelineMapper.selectPipeAnalysis(tab, gid); |
| | | } |
| | | |
| | | @Override |
| | | public List<PipelineEntity> selectAnalysisResult(String tab, Integer gid) { |
| | | return pipelineMapper.selectAnalysisResult(tab, gid); |
| | | } |
| | | |
| | | /** |
| | | * 创建Zip包 |
| | | * |
| | |
| | | * @param pwd 密码 |
| | | * @return 下载文件GUID |
| | | */ |
| | | public String createZipFile(UserEntity ue, Map<String, List<?>> map, String pwd) throws Exception { |
| | | if (map.size() == 0) { |
| | | return null; |
| | | } |
| | | |
| | | public String createZipFile(UserEntity ue, Map<String, List<PipelineEntity>> map, String pwd) throws Exception { |
| | | String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date()); |
| | | String tempPath = pathHelper.getTempPath(tempName); |
| | | String filePath = tempPath + File.separator + tempName + ".gdb"; |
| | |
| | | if (file.exists() && file.isDirectory()) { |
| | | FileHelper.deleteDir(filePath); |
| | | } |
| | | //createGdb(filePath, map); |
| | | createGdb(filePath, map); |
| | | |
| | | String zipName = tempName + ".gdb.zip"; |
| | | String zipFile = pathHelper.getDownloadFullPath() + File.separator + zipName; |
| | |
| | | /** |
| | | * 创建GDB |
| | | */ |
| | | public static void createGdb(String filePath, Map<String, List<?>> map) throws Exception { |
| | | public static void createGdb(String filePath, Map<String, List<PipelineEntity>> map) throws Exception { |
| | | Driver driver = null; |
| | | DataSource dataSource = null; |
| | | try { |
| | |
| | | for (String key : map.keySet()) { |
| | | Layer layer = null; |
| | | try { |
| | | List<PipelineEntity> list = map.get(key); |
| | | layer = createLayer(dataSource, key, list.get(0)); |
| | | |
| | | // layer = createLayer(dataSource, baseMapper); |
| | | // if (null == layer) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // String className = ClassHelper.getClassName(baseMapper); |
| | | // Class clazz = ClassHelper.getEntityClass(className); |
| | | // if (null == clazz) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // List<Field> fields = new ArrayList<>(); |
| | | // // fields.add(getGeomField(clazz)) |
| | | // getFields(clazz, fields); |
| | | // addLayerField(layer, fields); |
| | | // |
| | | // setLayerData(layer, fields, map.get(key)); |
| | | List<Field> fields = new ArrayList<>(); |
| | | getFields(PipelineEntity.class, fields); |
| | | |
| | | GdbHelper.addLayerField(layer, fields); |
| | | setLayerData(layer, fields, list); |
| | | } finally { |
| | | if (null != layer) { |
| | | layer.delete(); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 创建图层 |
| | | */ |
| | | private static Layer createLayer(DataSource dataSource, String tab, PipelineEntity pe) { |
| | | int geomType = pe.getWkt().contains("POINT") ? ogr.wkbMultiPoint : ogr.wkbMultiLineString; |
| | | |
| | | SpatialReference sr = new SpatialReference(); |
| | | sr.ImportFromEPSG(4490); |
| | | |
| | | return dataSource.CreateLayer(tab, sr, geomType, null); |
| | | } |
| | | |
| | | /** |
| | | * 获取字段 |
| | | */ |
| | | private static void getFields(Class clazz, List<Field> list) { |
| | | try { |
| | | Field[] fields = clazz.getDeclaredFields(); |
| | | for (Field f : fields) { |
| | | if (StaticData.PIPE_EXCLUDE_FIELDS.contains(f.getName())) { |
| | | continue; |
| | | } |
| | | |
| | | f.setAccessible(true); |
| | | list.add(f); |
| | | } |
| | | |
| | | if (!StaticData.OBJECT.equals(clazz.getSuperclass().getName())) { |
| | | getFields(clazz.getSuperclass(), list); |
| | | } |
| | | } catch (Exception ex) { |
| | | // |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置图层数据 |
| | | */ |
| | | private static void setLayerData(Layer layer, List<Field> fields, List<PipelineEntity> list) throws Exception { |
| | | for (PipelineEntity t : list) { |
| | | Feature f = new Feature(layer.GetLayerDefn()); |
| | | |
| | | String wkt = t.getWkt(); |
| | | if (!wkt.contains("MULTI")) { |
| | | wkt = wkt.replace("POINT", "MULTIPOINT").replace("LINESTRING", "MULTILINESTRING(") + (wkt.contains("LINESTRING") ? ")" : ""); |
| | | } |
| | | |
| | | Geometry geom = Geometry.CreateFromWkt(wkt); |
| | | f.SetGeometry(geom); |
| | | |
| | | GdbHelper.setFeatureData(f, fields, t); |
| | | layer.CreateFeature(f); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加Zip文件 |
| | | */ |
| | | private void addZipFiles(ZipFile zip, ZipParameters params, File[] files) { |