管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-10-21 d0aa9a577e9641654a54dfc1a9fc974545d06611
src/main/java/com/lf/server/helper/GdalHelper.java
@@ -1,6 +1,6 @@
package com.lf.server.helper;
import com.lf.server.entity.ctrl.LayerDto;
import com.lf.server.entity.ctrl.ShpRecordEntity;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.gdal.gdal.Band;
@@ -42,6 +42,39 @@
        // 为了使属性表字段支持中文,请添加下面这句:CP936
        gdal.SetConfigOption("SHAPE_ENCODING", "");
    }
    /**
     * 获取Shp第一条记录的WKT
     */
    public static ShpRecordEntity readShpFirstRecord(String filePath) {
        try {
            org.gdal.ogr.Driver driver = ogr.GetDriverByName("ESRI shapefile");
            if (driver == null) {
                return null;
            }
            DataSource dataSource = driver.Open(filePath);
            Layer layer = dataSource.GetLayer(0);
            if (layer.GetFeatureCount() < 1) {
                return null;
            }
            SpatialReference spatialReference = layer.GetSpatialRef();
            String csid = spatialReference.GetAttrValue("AUTHORITY", 1);
            Feature feature = layer.GetFeature(0);
            String wkt = feature.GetGeometryRef().ExportToWkt();
            layer.delete();
            dataSource.delete();
            driver.delete();
            return new ShpRecordEntity(wkt, csid);
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }
    /**
@@ -154,14 +187,14 @@
        }
    }
    public static LayerDto getLayerDto(String filePath) {
    public static void getLayerDto(String filePath) {
        org.gdal.ogr.Driver driver = ogr.GetDriverByName("OpenFileGDB");
        if (driver == null) {
            return null;
            return;
        }
        List<Map> list = new ArrayList<>();
        List<Map<String, String>> mapList = new ArrayList<>();
        LayerDto layerDto = new LayerDto();
        DataSource dataSource = null;
        try {
            dataSource = driver.Open(filePath, 0);
@@ -208,10 +241,10 @@
                        feature.delete();
                    } while (true);
                }
                layerDto.setLayerName(strlayerName);
                layerDto.setList(list);
                layerDto.setCount(count);
                layerDto.setMap(mapList);
                //layerDto.setLayerName(strlayerName);
                //layerDto.setList(list);
                //layerDto.setCount(count);
                //layerDto.setMap(mapList);
            }
        } catch (Exception e) {
            e.printStackTrace();
@@ -220,7 +253,6 @@
                dataSource.delete();
            }
        }
        return layerDto;
    }
    /**
@@ -277,7 +309,7 @@
            return propertyGetter.get(feature, index);
        } catch (Exception ex) {
            // ex.printStackTrace()
            log.error(ex.getMessage() + ex.getStackTrace() + "\n");
            log.error(ex.getStackTrace());
            return null;
        }