| | |
| | | package com.lf.server.helper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.lf.server.entity.all.BaseGeoEntity; |
| | | import com.lf.server.entity.all.StaticData; |
| | | import com.lf.server.mapper.all.BasicMapper; |
| | |
| | | /** |
| | | * 读取数据 |
| | | */ |
| | | public static <T> List<T> readData(Class clazz, String filePath, String layerName) { |
| | | public static <T> List<T> readData(Class clazz, String filePath, String layerName, boolean isTransform) { |
| | | List<T> list = new ArrayList<>(); |
| | | |
| | | Driver driver = null; |
| | |
| | | for (int i = 0, count = dataSource.GetLayerCount(); i < count; i++) { |
| | | Layer layer = dataSource.GetLayer(i); |
| | | if (layer.GetName().equals(layerName)) { |
| | | GdbHelper.readLayer(clazz, layer, list); |
| | | GdbHelper.readLayer(clazz, layer, list, isTransform); |
| | | break; |
| | | } |
| | | |
| | |
| | | /** |
| | | * 读取图层 |
| | | */ |
| | | public static <T> void readLayer(Class clazz, Layer layer, List<T> list) { |
| | | public static <T> void readLayer(Class clazz, Layer layer, List<T> list, boolean isTransform) { |
| | | try { |
| | | Field gField = getGeomField(clazz); |
| | | |
| | |
| | | field.set(t, f.GetFieldAsInteger(i)); |
| | | break; |
| | | case "java.sql.Timestamp": |
| | | field.set(t, getTimestamp(f, i)); |
| | | Timestamp ts = getTimestamp(f, i); |
| | | if (null != ts) { |
| | | field.set(t, ts); |
| | | } |
| | | break; |
| | | case "java.time.LocalDate": |
| | | field.set(t, getLocalDate(f, i)); |
| | | LocalDate ld = getLocalDate(f, i); |
| | | if (null != ld) { |
| | | field.set(t, ld); |
| | | } |
| | | break; |
| | | default: |
| | | field.set(t, f.GetFieldAsString(i)); |
| | |
| | | String geo = "null"; |
| | | if (null != f.GetGeometryRef()) { |
| | | String wkt = f.GetGeometryRef().ExportToWkt(); |
| | | // noinspection AlibabaRemoveCommentedCode |
| | | switch (f.GetGeometryRef().GetGeometryType()) { |
| | | //case 1: |
| | | // wkt = wkt.replace("POINT", "MULTIPOINT"); |
| | | // break; |
| | | case 2: |
| | | wkt = wkt.replace("LINESTRING (", "MULTILINESTRING ((") + ")"; |
| | | break; |
| | | case 3: |
| | | wkt = wkt.replace("POLYGON (", "MULTIPOLYGON ((") + ")"; |
| | | break; |
| | | default: |
| | | break; |
| | | // f.GetGeometryRef().GetGeometryType() |
| | | if (wkt.contains(StaticData.LINESTRING) && !wkt.contains(StaticData.MULTILINESTRING)) { |
| | | wkt = wkt.replace("LINESTRING (", "MULTILINESTRING ((") + ")"; |
| | | } |
| | | if (wkt.contains(StaticData.POLYGON) && !wkt.contains(StaticData.MULTIPOLYGON)) { |
| | | wkt = wkt.replace("POLYGON (", "MULTIPOLYGON ((") + ")"; |
| | | } |
| | | wkt = wkt.replace(" 0,", ",").replace(" 0)", ")"); |
| | | if (wkt.contains(StaticData.MULTICURVE)) { |
| | | wkt = wkt.replace("MULTICURVE (", "MULTILINESTRING (").replace("CIRCULARSTRING ", ""); |
| | | if (wkt.contains(StaticData.COMPOUNDCURVE)) { |
| | | wkt = wkt.replace("COMPOUNDCURVE (", "").replace(")))", "))"); |
| | | } |
| | | } |
| | | |
| | | geo = String.format("ST_GeomFromText('%s')", wkt); |
| | | } |
| | | |
| | |
| | | SpatialReference sr = new SpatialReference(); |
| | | sr.ImportFromEPSG(null == srid ? 4490 : srid); |
| | | |
| | | return dataSource.CreateLayer(tab, sr, getGeomType(geomType), null); |
| | | return dataSource.CreateLayer(tab.replace(".", "_"), sr, getGeomType(geomType), null); |
| | | } |
| | | |
| | | /** |