| @@ -258,6 +258,12 @@ | |||||
| <version>${geotools.version}</version> | <version>${geotools.version}</version> | ||||
| </dependency> | </dependency> | ||||
| <dependency> | |||||
| <groupId>org.geotools</groupId> | |||||
| <artifactId>gt-epsg-hsql</artifactId> | |||||
| <version>${geotools.version}</version> | |||||
| </dependency> | |||||
| <!-- 定时任务--> | <!-- 定时任务--> | ||||
| @@ -2,6 +2,7 @@ import cn.hutool.core.io.FileUtil; | |||||
| import cn.hutool.core.thread.ThreadUtil; | import cn.hutool.core.thread.ThreadUtil; | ||||
| import com.alibaba.fastjson2.JSON; | import com.alibaba.fastjson2.JSON; | ||||
| import com.ruoyi.RuoYiApplication; | import com.ruoyi.RuoYiApplication; | ||||
| import com.ruoyi.common.geo.GeoConverter; | |||||
| import com.ruoyi.common.geo.GeoParser; | import com.ruoyi.common.geo.GeoParser; | ||||
| import com.ruoyi.common.geo.GeoWriter; | import com.ruoyi.common.geo.GeoWriter; | ||||
| import com.ruoyi.geo.service.GeoExportHandlerService; | import com.ruoyi.geo.service.GeoExportHandlerService; | ||||
| @@ -40,11 +41,14 @@ public final class GeoTest | |||||
| public static void main(String[] args) | public static void main(String[] args) | ||||
| { | { | ||||
| String COORD = "3857"; | |||||
| COORD = "4326"; | |||||
| String DIR = "D:/m/胜利村_shp_" + COORD + "/"; | |||||
| String PATH; | String PATH; | ||||
| PATH = "D:/m/胜利村_shp_3857/cjqy.shp"; // cjqy | |||||
| PATH = "D:/m/胜利村_shp_3857/dk.shp"; // dk | |||||
| PATH = "D:/m/胜利村_shp_3857/zyhycg.shp"; // zyhycg | |||||
| PATH = "D:/m/胜利村_shp_3857/jtzy.shp"; // jtzy | |||||
| PATH = DIR + "cjqy.shp"; // cjqy | |||||
| PATH = DIR + "dk.shp"; // dk | |||||
| PATH = DIR + "zyhycg.shp"; // zyhycg | |||||
| PATH = DIR + "jtzy.shp"; // jtzy | |||||
| String OUT; | String OUT; | ||||
| OUT = "D:/m/output_胜利村_shp_3857/jtzyxx.shp"; | OUT = "D:/m/output_胜利村_shp_3857/jtzyxx.shp"; | ||||
| @@ -56,7 +60,7 @@ public final class GeoTest | |||||
| parser.Open(PATH, "UTF-8"); | parser.Open(PATH, "UTF-8"); | ||||
| System.out.println(parser.GetTypeNames()); | System.out.println(parser.GetTypeNames()); | ||||
| parser.SetSource(0); | parser.SetSource(0); | ||||
| List<Map<String, Object>> cjqies = parser.GetMapList(); | |||||
| List<Map<String, Object>> cjqies = parser.GetMapList(GeoConverter.EPSG_3857); | |||||
| //List<GeoCJQY> cjqies = parser.GetList(GeoCJQY.class); | //List<GeoCJQY> cjqies = parser.GetList(GeoCJQY.class); | ||||
| //List<GeoJTZY> cjqies = parser.GetList(GeoJTZY.class); | //List<GeoJTZY> cjqies = parser.GetList(GeoJTZY.class); | ||||
| //List<GeoZYHYCG> cjqies = parser.GetList(GeoZYHYCG.class); | //List<GeoZYHYCG> cjqies = parser.GetList(GeoZYHYCG.class); | ||||
| @@ -65,7 +69,7 @@ public final class GeoTest | |||||
| System.out.println(JSON.toJSONString(cjqies)); | System.out.println(JSON.toJSONString(cjqies)); | ||||
| System.out.println("-------------------------"); | System.out.println("-------------------------"); | ||||
| try(GeoWriter writer = new GeoWriter()) | |||||
| /*try(GeoWriter writer = new GeoWriter()) | |||||
| { | { | ||||
| writer.Open(OUT, "UTF-8"); | writer.Open(OUT, "UTF-8"); | ||||
| Map<String, Class<?>> classes = new LinkedHashMap<>(); | Map<String, Class<?>> classes = new LinkedHashMap<>(); | ||||
| @@ -77,7 +81,7 @@ public final class GeoTest | |||||
| System.out.println(writer.GetTypeNames()); | System.out.println(writer.GetTypeNames()); | ||||
| writer.SetSource(0, false); | writer.SetSource(0, false); | ||||
| writer.WriteMapList(cjqies); | writer.WriteMapList(cjqies); | ||||
| } | |||||
| }*/ | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -13,6 +13,7 @@ public final class TaskEnums | |||||
| private TaskStatus() {} | private TaskStatus() {} | ||||
| } | } | ||||
| public static final class ImportType | public static final class ImportType | ||||
| { | { | ||||
| public static final String IT_OVERRIDE = "1"; // 覆盖导入 | public static final String IT_OVERRIDE = "1"; // 覆盖导入 | ||||
| @@ -21,5 +22,14 @@ public final class TaskEnums | |||||
| private ImportType() {} | private ImportType() {} | ||||
| } | } | ||||
| public static final class CoordinateSystem | |||||
| { | |||||
| public static final String CS_3857 = "1"; // 3857 | |||||
| public static final String CS_4326 = "2"; // 4326 | |||||
| public static final String CS_DEFAULT = CS_3857; // 3857 | |||||
| private CoordinateSystem() {} | |||||
| } | |||||
| private TaskEnums() {} | private TaskEnums() {} | ||||
| } | } | ||||
| @@ -1,7 +1,7 @@ | |||||
| package com.ruoyi.geo.framework; | package com.ruoyi.geo.framework; | ||||
| import com.ruoyi.business.domain.TGisCjqy; | import com.ruoyi.business.domain.TGisCjqy; | ||||
| import com.ruoyi.common.geo.GeoCreator; | |||||
| import com.ruoyi.common.geo.GeoConverter; | |||||
| import com.ruoyi.geo.service.GeoMapperService; | import com.ruoyi.geo.service.GeoMapperService; | ||||
| import com.ruoyi.geo.structs.GeoCJQY; | import com.ruoyi.geo.structs.GeoCJQY; | ||||
| import org.locationtech.jts.geom.MultiPolygon; | import org.locationtech.jts.geom.MultiPolygon; | ||||
| @@ -55,7 +55,7 @@ public class GeoCjqyExportTask implements GeoDBExportTaskInterface | |||||
| public Map<String, Class<?>> GetTypes() | public Map<String, Class<?>> GetTypes() | ||||
| { | { | ||||
| Map<String, Class<?>> types = GeoCreator.GetClassTypes(GeoCJQY.class); | |||||
| Map<String, Class<?>> types = GeoConverter.GetClassTypes(GeoCJQY.class); | |||||
| types.put("the_geom", MultiPolygon.class); | types.put("the_geom", MultiPolygon.class); | ||||
| return types; | return types; | ||||
| } | } | ||||
| @@ -30,7 +30,7 @@ public class GeoCjqyImportTask implements GeoDBImportTaskInterface | |||||
| public int LoadDataList() | public int LoadDataList() | ||||
| { | { | ||||
| list = importTask.parser.GetList(GeoCJQY.class); | |||||
| list = importTask.parser.GetList(GeoCJQY.class, GeoImportTask.DefaultCS); | |||||
| importTask.logFile.WriteLine(TYPE_NAME + "shp读取数据条数: " + list.size()); | importTask.logFile.WriteLine(TYPE_NAME + "shp读取数据条数: " + list.size()); | ||||
| return list.size(); | return list.size(); | ||||
| @@ -4,9 +4,11 @@ import cn.hutool.core.collection.CollectionUtil; | |||||
| import cn.hutool.core.date.DateUtil; | import cn.hutool.core.date.DateUtil; | ||||
| import cn.hutool.core.io.FileUtil; | import cn.hutool.core.io.FileUtil; | ||||
| import cn.hutool.core.util.ZipUtil; | import cn.hutool.core.util.ZipUtil; | ||||
| import com.ruoyi.business.constants.TaskEnums; | |||||
| import com.ruoyi.business.domain.TTaskExport; | import com.ruoyi.business.domain.TTaskExport; | ||||
| import com.ruoyi.common.config.RuoYiConfig; | import com.ruoyi.common.config.RuoYiConfig; | ||||
| import com.ruoyi.common.core.domain.entity.SysDept; | import com.ruoyi.common.core.domain.entity.SysDept; | ||||
| import com.ruoyi.common.geo.GeoConverter; | |||||
| import com.ruoyi.common.geo.GeoWriter; | import com.ruoyi.common.geo.GeoWriter; | ||||
| import com.ruoyi.common.utils.ExceptionUtil; | import com.ruoyi.common.utils.ExceptionUtil; | ||||
| import com.ruoyi.common.utils.StringUtils; | import com.ruoyi.common.utils.StringUtils; | ||||
| @@ -144,6 +146,18 @@ public class GeoExportTask implements Runnable | |||||
| taskExport.setFileUrl("/profile" + GeoSysDir.TrimNormalized(zipFile)); | taskExport.setFileUrl("/profile" + GeoSysDir.TrimNormalized(zipFile)); | ||||
| } | } | ||||
| private String GetEPSGName() | |||||
| { | |||||
| switch(taskExport.getCoordinateSystem()) | |||||
| { | |||||
| case TaskEnums.CoordinateSystem.CS_4326: | |||||
| return GeoConverter.EPSG_4326; | |||||
| case TaskEnums.CoordinateSystem.CS_3857: | |||||
| default: | |||||
| return GeoConverter.EPSG_3857; | |||||
| } | |||||
| } | |||||
| private void CreateShp() | private void CreateShp() | ||||
| { | { | ||||
| writer = new GeoWriter(); | writer = new GeoWriter(); | ||||
| @@ -153,9 +167,12 @@ public class GeoExportTask implements Runnable | |||||
| logFile.ErrorLine("打开shp文件错误: " + shpFile); | logFile.ErrorLine("打开shp文件错误: " + shpFile); | ||||
| } | } | ||||
| String dbCrsName = GetEPSGName(); | |||||
| logFile.WriteLine("任务的坐标系: " + dbCrsName); | |||||
| logFile.WriteLine("数据库的坐标系: " + GeoConverter.EPSG_3857); | |||||
| try | try | ||||
| { | { | ||||
| writer.AddSchema(type, typeClasses); | |||||
| writer.AddSchema(type + ".shp", dbCrsName, typeClasses); | |||||
| System.out.println(writer.GetTypeNames()); | System.out.println(writer.GetTypeNames()); | ||||
| if(!writer.SetSource(type, false)) | if(!writer.SetSource(type, false)) | ||||
| @@ -4,9 +4,11 @@ import cn.hutool.core.collection.CollectionUtil; | |||||
| import cn.hutool.core.date.DateUtil; | import cn.hutool.core.date.DateUtil; | ||||
| import cn.hutool.core.io.FileUtil; | import cn.hutool.core.io.FileUtil; | ||||
| import cn.hutool.core.util.ZipUtil; | import cn.hutool.core.util.ZipUtil; | ||||
| import com.ruoyi.business.constants.TaskEnums; | |||||
| import com.ruoyi.business.domain.TTaskImport; | import com.ruoyi.business.domain.TTaskImport; | ||||
| import com.ruoyi.common.config.RuoYiConfig; | import com.ruoyi.common.config.RuoYiConfig; | ||||
| import com.ruoyi.common.core.domain.entity.SysDept; | import com.ruoyi.common.core.domain.entity.SysDept; | ||||
| import com.ruoyi.common.geo.GeoConverter; | |||||
| import com.ruoyi.common.geo.GeoParser; | import com.ruoyi.common.geo.GeoParser; | ||||
| import com.ruoyi.common.utils.ExceptionUtil; | import com.ruoyi.common.utils.ExceptionUtil; | ||||
| import com.ruoyi.common.utils.spring.SpringUtils; | import com.ruoyi.common.utils.spring.SpringUtils; | ||||
| @@ -17,7 +19,10 @@ import com.ruoyi.geo.service.GeoImportHandlerService; | |||||
| import com.ruoyi.geo.service.GeoMapperService; | import com.ruoyi.geo.service.GeoMapperService; | ||||
| import com.ruoyi.system.mapper.SysDeptMapper; | import com.ruoyi.system.mapper.SysDeptMapper; | ||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
| import org.locationtech.jts.geom.Geometry; | |||||
| import static com.ruoyi.business.constants.TaskEnums.TaskStatus; | import static com.ruoyi.business.constants.TaskEnums.TaskStatus; | ||||
| import static com.ruoyi.business.constants.TaskEnums.CoordinateSystem; | |||||
| import java.io.File; | import java.io.File; | ||||
| import java.util.Date; | import java.util.Date; | ||||
| @@ -40,6 +45,7 @@ public class GeoImportTask implements Runnable | |||||
| private String type; | private String type; | ||||
| String username; | String username; | ||||
| Date now; | Date now; | ||||
| static final String DefaultCS = GeoConverter.EPSG_3857; | |||||
| private GeoDBImportTaskInterface task; | private GeoDBImportTaskInterface task; | ||||
| @@ -136,6 +142,18 @@ public class GeoImportTask implements Runnable | |||||
| } | } | ||||
| } | } | ||||
| private String GetEPSGName() | |||||
| { | |||||
| switch(taskImport.getCoordinateSystem()) | |||||
| { | |||||
| case CoordinateSystem.CS_4326: | |||||
| return GeoConverter.EPSG_4326; | |||||
| case CoordinateSystem.CS_3857: | |||||
| default: | |||||
| return GeoConverter.EPSG_3857; | |||||
| } | |||||
| } | |||||
| private boolean LoadDataList() | private boolean LoadDataList() | ||||
| { | { | ||||
| if(!parser.SetSource(type)) | if(!parser.SetSource(type)) | ||||
| @@ -144,6 +162,13 @@ public class GeoImportTask implements Runnable | |||||
| return false; | return false; | ||||
| } | } | ||||
| String crsName = parser.GetEPSGName(); | |||||
| String dbCrsName = GetEPSGName(); | |||||
| logFile.WriteLine("任务的坐标系: " + dbCrsName); | |||||
| logFile.WriteLine("shp文件的坐标系: " + crsName); | |||||
| if(!crsName.equalsIgnoreCase(dbCrsName)) | |||||
| logFile.WriteLine("任务的坐标类型与shp文件不同: {} != {}", dbCrsName, crsName); | |||||
| int num = task.LoadDataList(); | int num = task.LoadDataList(); | ||||
| if(num == 0) | if(num == 0) | ||||
| { | { | ||||
| @@ -1,7 +1,6 @@ | |||||
| package com.ruoyi.geo.framework; | package com.ruoyi.geo.framework; | ||||
| import com.ruoyi.common.geo.GeoCreator; | |||||
| import com.ruoyi.geo.service.GeoExportHandlerService; | |||||
| import com.ruoyi.common.geo.GeoConverter; | |||||
| import com.ruoyi.geo.service.GeoMapperService; | import com.ruoyi.geo.service.GeoMapperService; | ||||
| import com.ruoyi.geo.structs.GeoJTZY; | import com.ruoyi.geo.structs.GeoJTZY; | ||||
| import com.ruoyi.resource.domain.TResourceLand; | import com.ruoyi.resource.domain.TResourceLand; | ||||
| @@ -72,7 +71,7 @@ public class GeoJtzyExportTask implements GeoDBExportTaskInterface | |||||
| public Map<String, Class<?>> GetTypes() | public Map<String, Class<?>> GetTypes() | ||||
| { | { | ||||
| Map<String, Class<?>> types = GeoCreator.GetClassTypes(GeoJTZY.class); | |||||
| Map<String, Class<?>> types = GeoConverter.GetClassTypes(GeoJTZY.class); | |||||
| types.put("the_geom", MultiPolygon.class); | types.put("the_geom", MultiPolygon.class); | ||||
| return types; | return types; | ||||
| } | } | ||||
| @@ -30,7 +30,7 @@ public class GeoJtzyImportTask implements GeoDBImportTaskInterface | |||||
| public int LoadDataList() | public int LoadDataList() | ||||
| { | { | ||||
| list = importTask.parser.GetList(GeoJTZY.class); | |||||
| list = importTask.parser.GetList(GeoJTZY.class, GeoImportTask.DefaultCS); | |||||
| importTask.logFile.WriteLine(TYPE_NAME + "shp读取数据条数: " + list.size()); | importTask.logFile.WriteLine(TYPE_NAME + "shp读取数据条数: " + list.size()); | ||||
| return list.size(); | return list.size(); | ||||
| @@ -1,12 +1,9 @@ | |||||
| package com.ruoyi.geo.framework; | package com.ruoyi.geo.framework; | ||||
| import cn.hutool.core.util.StrUtil; | |||||
| import com.ruoyi.common.geo.GeoCreator; | |||||
| import com.ruoyi.common.utils.DecimalUtils; | |||||
| import com.ruoyi.common.geo.GeoConverter; | |||||
| import com.ruoyi.geo.service.GeoMapperService; | import com.ruoyi.geo.service.GeoMapperService; | ||||
| import com.ruoyi.geo.structs.GeoZYHYCG; | import com.ruoyi.geo.structs.GeoZYHYCG; | ||||
| import com.ruoyi.resource.domain.TResourceOperation; | import com.ruoyi.resource.domain.TResourceOperation; | ||||
| import org.locationtech.jts.geom.MultiPolygon; | |||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Map; | import java.util.Map; | ||||
| @@ -69,6 +66,6 @@ public class GeoZyhycgExportTask implements GeoDBExportTaskInterface | |||||
| public Map<String, Class<?>> GetTypes() | public Map<String, Class<?>> GetTypes() | ||||
| { | { | ||||
| return GeoCreator.GetClassTypes(GeoZYHYCG.class); | |||||
| return GeoConverter.GetClassTypes(GeoZYHYCG.class); | |||||
| } | } | ||||
| } | } | ||||
| @@ -31,7 +31,7 @@ public class GeoZyhycgImportTask implements GeoDBImportTaskInterface | |||||
| public int LoadDataList() | public int LoadDataList() | ||||
| { | { | ||||
| list = importTask.parser.GetList(GeoZYHYCG.class); | |||||
| list = importTask.parser.GetList(GeoZYHYCG.class, GeoImportTask.DefaultCS); | |||||
| importTask.logFile.WriteLine(TYPE_NAME + "shp读取数据条数: " + list.size()); | importTask.logFile.WriteLine(TYPE_NAME + "shp读取数据条数: " + list.size()); | ||||
| return list.size(); | return list.size(); | ||||
| @@ -172,6 +172,11 @@ | |||||
| <artifactId>gt-geojson</artifactId> | <artifactId>gt-geojson</artifactId> | ||||
| </dependency> | </dependency> | ||||
| <dependency> | |||||
| <groupId>org.geotools</groupId> | |||||
| <artifactId>gt-epsg-hsql</artifactId> | |||||
| </dependency> | |||||
| </dependencies> | </dependencies> | ||||
| @@ -1,6 +1,8 @@ | |||||
| package com.ruoyi.common.geo; | package com.ruoyi.common.geo; | ||||
| import cn.hutool.core.util.ClassUtil; | |||||
| import org.geotools.geometry.jts.JTS; | |||||
| import org.geotools.referencing.CRS; | |||||
| import org.locationtech.jts.geom.Geometry; | |||||
| import org.locationtech.jts.geom.GeometryFactory; | import org.locationtech.jts.geom.GeometryFactory; | ||||
| import org.locationtech.jts.geom.LineString; | import org.locationtech.jts.geom.LineString; | ||||
| import org.locationtech.jts.geom.LinearRing; | import org.locationtech.jts.geom.LinearRing; | ||||
| @@ -11,18 +13,22 @@ import org.locationtech.jts.geom.Point; | |||||
| import org.locationtech.jts.geom.Polygon; | import org.locationtech.jts.geom.Polygon; | ||||
| import org.locationtech.jts.io.ParseException; | import org.locationtech.jts.io.ParseException; | ||||
| import org.locationtech.jts.io.WKTReader; | import org.locationtech.jts.io.WKTReader; | ||||
| import org.opengis.referencing.FactoryException; | |||||
| import org.opengis.referencing.crs.CoordinateReferenceSystem; | |||||
| import org.opengis.referencing.operation.MathTransform; | |||||
| import org.opengis.referencing.operation.TransformException; | |||||
| import java.lang.reflect.Field; | import java.lang.reflect.Field; | ||||
| import java.lang.reflect.Modifier; | import java.lang.reflect.Modifier; | ||||
| import java.util.HashMap; | import java.util.HashMap; | ||||
| import java.util.Map; | import java.util.Map; | ||||
| public final class GeoCreator | |||||
| public final class GeoConverter | |||||
| { | { | ||||
| private static GeoCreator geometryCreator = null; | |||||
| private static GeoConverter geometryCreator = null; | |||||
| private static GeometryFactory geometryFactory = new GeometryFactory(); | private static GeometryFactory geometryFactory = new GeometryFactory(); | ||||
| private GeoCreator() { | |||||
| private GeoConverter() { | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -157,4 +163,70 @@ public final class GeoCreator | |||||
| } | } | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| public static final String EPSG_4490 = "EPSG:4490"; | |||||
| public static final String EPSG_3857 = "EPSG:3857"; | |||||
| public static final String EPSG_4326 = "EPSG:4326"; | |||||
| public static final String EPSG_4530 = "EPSG:4530"; | |||||
| public static String EPSGName(CoordinateReferenceSystem a) | |||||
| { | |||||
| try | |||||
| { | |||||
| return CRS.lookupIdentifier(a, true); | |||||
| } | |||||
| catch(FactoryException e) | |||||
| { | |||||
| throw new RuntimeException(e); | |||||
| } | |||||
| } | |||||
| public static boolean CoordinateSystemEquals(CoordinateReferenceSystem a, CoordinateReferenceSystem b) | |||||
| { | |||||
| if(a == b) | |||||
| return true; | |||||
| if(a == null || b == null) | |||||
| return false; | |||||
| return CRS.equalsIgnoreMetadata(a, b); | |||||
| } | |||||
| public static CoordinateReferenceSystem CoordinateSystem(String format) | |||||
| { | |||||
| try | |||||
| { | |||||
| CoordinateReferenceSystem coordinateReferenceSystem = CRS.decode(format, true); | |||||
| return coordinateReferenceSystem; | |||||
| } | |||||
| catch(Exception e) | |||||
| { | |||||
| throw new RuntimeException(e); | |||||
| } | |||||
| } | |||||
| public static MathTransform Transformer(String srcFormat, String targetFormat) | |||||
| { | |||||
| try | |||||
| { | |||||
| MathTransform transform = CRS.findMathTransform(CRS.decode(srcFormat, true), CRS.decode(targetFormat, true), true); | |||||
| return transform; | |||||
| } | |||||
| catch(Exception e) | |||||
| { | |||||
| throw new RuntimeException(e); | |||||
| } | |||||
| } | |||||
| public static Geometry Convert(Geometry resource, String srcFormat, String targetFormat) | |||||
| { | |||||
| try | |||||
| { | |||||
| Geometry transform = JTS.transform(resource, CRS.findMathTransform(CRS.decode(srcFormat, true), CRS.decode(targetFormat, true), true)); | |||||
| return transform; | |||||
| } | |||||
| catch(Exception e) | |||||
| { | |||||
| throw new RuntimeException(e); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -3,13 +3,21 @@ package com.ruoyi.common.geo; | |||||
| import cn.hutool.core.bean.BeanUtil; | import cn.hutool.core.bean.BeanUtil; | ||||
| import cn.hutool.core.bean.copier.CopyOptions; | import cn.hutool.core.bean.copier.CopyOptions; | ||||
| import cn.hutool.core.lang.Assert; | import cn.hutool.core.lang.Assert; | ||||
| import cn.hutool.core.util.StrUtil; | |||||
| import com.ruoyi.common.utils.StringUtils; | |||||
| import lombok.extern.slf4j.Slf4j; | |||||
| import org.geotools.data.shapefile.ShapefileDataStore; | import org.geotools.data.shapefile.ShapefileDataStore; | ||||
| import org.geotools.data.simple.SimpleFeatureIterator; | import org.geotools.data.simple.SimpleFeatureIterator; | ||||
| import org.geotools.data.simple.SimpleFeatureSource; | import org.geotools.data.simple.SimpleFeatureSource; | ||||
| import org.geotools.geometry.jts.JTS; | |||||
| import org.geotools.referencing.CRS; | |||||
| import org.locationtech.jts.geom.Geometry; | import org.locationtech.jts.geom.Geometry; | ||||
| import org.opengis.feature.simple.SimpleFeature; | import org.opengis.feature.simple.SimpleFeature; | ||||
| import org.opengis.feature.simple.SimpleFeatureType; | import org.opengis.feature.simple.SimpleFeatureType; | ||||
| import org.opengis.feature.type.AttributeDescriptor; | import org.opengis.feature.type.AttributeDescriptor; | ||||
| import org.opengis.referencing.FactoryException; | |||||
| import org.opengis.referencing.crs.CoordinateReferenceSystem; | |||||
| import org.opengis.referencing.operation.MathTransform; | |||||
| import java.io.Closeable; | import java.io.Closeable; | ||||
| import java.io.File; | import java.io.File; | ||||
| @@ -144,9 +152,35 @@ public final class GeoParser implements Closeable | |||||
| } | } | ||||
| } | } | ||||
| public List<Map<String, Object>> GetMapList() | |||||
| public String GetEPSGName() | |||||
| { | { | ||||
| CheckSource(); | CheckSource(); | ||||
| CoordinateReferenceSystem sourceCS = source.getSchema().getCoordinateReferenceSystem(); | |||||
| return GeoConverter.EPSGName(sourceCS); | |||||
| } | |||||
| public List<Map<String, Object>> GetMapList(String targetFormat) | |||||
| { | |||||
| CheckSource(); | |||||
| CoordinateReferenceSystem sourceCS = source.getSchema().getCoordinateReferenceSystem(); | |||||
| System.out.println("[GeoParser]: 源坐标系: " + GeoConverter.EPSGName(sourceCS)); | |||||
| CoordinateReferenceSystem targetCS = null; | |||||
| if(StringUtils.isNotEmpty(targetFormat)) | |||||
| targetCS = GeoConverter.CoordinateSystem(targetFormat); | |||||
| MathTransform transformer = null; | |||||
| if(null != targetCS && !GeoConverter.CoordinateSystemEquals(sourceCS, targetCS)) | |||||
| { | |||||
| try | |||||
| { | |||||
| transformer = CRS.findMathTransform(sourceCS, targetCS, true); | |||||
| System.out.println(StrUtil.format("[GeoParser]: 需要转换坐标系: {} -> {}", CRS.toSRS(sourceCS), CRS.toSRS(targetCS))); | |||||
| } | |||||
| catch(FactoryException e) | |||||
| { | |||||
| throw new RuntimeException(e); | |||||
| } | |||||
| } | |||||
| try { | try { | ||||
| List<Map<String, Object>> ret = new ArrayList<>(); | List<Map<String, Object>> ret = new ArrayList<>(); | ||||
| @@ -158,7 +192,13 @@ public final class GeoParser implements Closeable | |||||
| for (int i = 0; i < feature.getAttributeCount(); i++) { | for (int i = 0; i < feature.getAttributeCount(); i++) { | ||||
| Object attribute = feature.getAttribute(i); | Object attribute = feature.getAttribute(i); | ||||
| if(attribute instanceof Geometry) | if(attribute instanceof Geometry) | ||||
| attribute = ((Geometry) attribute).toText(); | |||||
| { | |||||
| Geometry geometry = (Geometry) attribute; | |||||
| if(null == transformer) | |||||
| attribute = geometry.toText(); | |||||
| else | |||||
| attribute = JTS.transform(geometry, transformer).toText(); | |||||
| } | |||||
| map.put(columnMap.get(i), attribute); | map.put(columnMap.get(i), attribute); | ||||
| } | } | ||||
| ret.add(map); | ret.add(map); | ||||
| @@ -170,9 +210,9 @@ public final class GeoParser implements Closeable | |||||
| } | } | ||||
| } | } | ||||
| public <T> List<T> GetList(Class<T> clazz) | |||||
| public <T> List<T> GetList(Class<T> clazz, String targetFormat) | |||||
| { | { | ||||
| List<Map<String, Object>> maps = GetMapList(); | |||||
| List<Map<String, Object>> maps = GetMapList(targetFormat); | |||||
| return maps.stream().map((x) -> BeanUtil.mapToBean(x, clazz, false, CopyOptions.create())).collect(Collectors.toList()); | return maps.stream().map((x) -> BeanUtil.mapToBean(x, clazz, false, CopyOptions.create())).collect(Collectors.toList()); | ||||
| } | } | ||||
| } | } | ||||
| @@ -1,18 +1,15 @@ | |||||
| package com.ruoyi.common.geo; | package com.ruoyi.common.geo; | ||||
| import cn.hutool.core.bean.BeanUtil; | import cn.hutool.core.bean.BeanUtil; | ||||
| import cn.hutool.core.bean.copier.CopyOptions; | |||||
| import cn.hutool.core.io.IoUtil; | import cn.hutool.core.io.IoUtil; | ||||
| import cn.hutool.core.lang.Assert; | import cn.hutool.core.lang.Assert; | ||||
| import org.geotools.data.FeatureWriter; | import org.geotools.data.FeatureWriter; | ||||
| import org.geotools.data.Transaction; | import org.geotools.data.Transaction; | ||||
| import org.geotools.data.shapefile.ShapefileDataStore; | import org.geotools.data.shapefile.ShapefileDataStore; | ||||
| import org.geotools.data.shapefile.ShapefileDataStoreFactory; | import org.geotools.data.shapefile.ShapefileDataStoreFactory; | ||||
| import org.geotools.data.simple.SimpleFeatureIterator; | |||||
| import org.geotools.data.simple.SimpleFeatureSource; | import org.geotools.data.simple.SimpleFeatureSource; | ||||
| import org.geotools.feature.simple.SimpleFeatureTypeBuilder; | import org.geotools.feature.simple.SimpleFeatureTypeBuilder; | ||||
| import org.geotools.referencing.crs.DefaultGeographicCRS; | import org.geotools.referencing.crs.DefaultGeographicCRS; | ||||
| import org.locationtech.jts.geom.Geometry; | |||||
| import org.locationtech.jts.geom.LineString; | import org.locationtech.jts.geom.LineString; | ||||
| import org.locationtech.jts.geom.LinearRing; | import org.locationtech.jts.geom.LinearRing; | ||||
| import org.locationtech.jts.geom.MultiLineString; | import org.locationtech.jts.geom.MultiLineString; | ||||
| @@ -28,7 +25,6 @@ import java.io.Closeable; | |||||
| import java.io.File; | import java.io.File; | ||||
| import java.io.Serializable; | import java.io.Serializable; | ||||
| import java.nio.charset.Charset; | import java.nio.charset.Charset; | ||||
| import java.util.ArrayList; | |||||
| import java.util.Arrays; | import java.util.Arrays; | ||||
| import java.util.HashMap; | import java.util.HashMap; | ||||
| import java.util.LinkedHashMap; | import java.util.LinkedHashMap; | ||||
| @@ -99,15 +95,15 @@ public final class GeoWriter implements Closeable | |||||
| Assert.notNull(writer, "请先打开写入"); | Assert.notNull(writer, "请先打开写入"); | ||||
| } | } | ||||
| public void AddSchema(String name, Map<String, Class<?>> parms) | |||||
| public void AddSchema(String name, String cs, Map<String, Class<?>> parms) | |||||
| { | { | ||||
| CheckDataStore(); | CheckDataStore(); | ||||
| try { | try { | ||||
| SimpleFeatureTypeBuilder tBuilder = new SimpleFeatureTypeBuilder(); | SimpleFeatureTypeBuilder tBuilder = new SimpleFeatureTypeBuilder(); | ||||
| // 5、设置 -- WGS84:一个二维地理坐标参考系统,使用WGS84数据 | |||||
| tBuilder.setCRS(DefaultGeographicCRS.WGS84); | |||||
| tBuilder.setCRS(GeoConverter.CoordinateSystem(cs)); | |||||
| System.out.println("写入坐标系: " + cs); | |||||
| tBuilder.setName(name); | tBuilder.setName(name); | ||||
| parms.forEach(tBuilder::add); | parms.forEach(tBuilder::add); | ||||
| @@ -198,49 +194,49 @@ public final class GeoWriter implements Closeable | |||||
| if(value instanceof Point) | if(value instanceof Point) | ||||
| return value; | return value; | ||||
| else | else | ||||
| return GeoCreator.PointByWKT(value.toString()); | |||||
| return GeoConverter.PointByWKT(value.toString()); | |||||
| } | } | ||||
| else if(MultiPoint.class.isAssignableFrom(clazz)) | else if(MultiPoint.class.isAssignableFrom(clazz)) | ||||
| { | { | ||||
| if(value instanceof MultiPoint) | if(value instanceof MultiPoint) | ||||
| return value; | return value; | ||||
| else | else | ||||
| return GeoCreator.MultiPointByWKT(value.toString()); | |||||
| return GeoConverter.MultiPointByWKT(value.toString()); | |||||
| } | } | ||||
| else if(LineString.class.isAssignableFrom(clazz)) | else if(LineString.class.isAssignableFrom(clazz)) | ||||
| { | { | ||||
| if(value instanceof LineString) | if(value instanceof LineString) | ||||
| return value; | return value; | ||||
| else | else | ||||
| return GeoCreator.LineStringByWKT(value.toString()); | |||||
| return GeoConverter.LineStringByWKT(value.toString()); | |||||
| } | } | ||||
| else if(MultiLineString.class.isAssignableFrom(clazz)) | else if(MultiLineString.class.isAssignableFrom(clazz)) | ||||
| { | { | ||||
| if(value instanceof MultiLineString) | if(value instanceof MultiLineString) | ||||
| return value; | return value; | ||||
| else | else | ||||
| return GeoCreator.MultiLineByWKT(value.toString()); | |||||
| return GeoConverter.MultiLineByWKT(value.toString()); | |||||
| } | } | ||||
| else if(Polygon.class.isAssignableFrom(clazz)) | else if(Polygon.class.isAssignableFrom(clazz)) | ||||
| { | { | ||||
| if(value instanceof Polygon) | if(value instanceof Polygon) | ||||
| return value; | return value; | ||||
| else | else | ||||
| return GeoCreator.PolygonByWKT(value.toString()); | |||||
| return GeoConverter.PolygonByWKT(value.toString()); | |||||
| } | } | ||||
| else if(MultiPolygon.class.isAssignableFrom(clazz)) | else if(MultiPolygon.class.isAssignableFrom(clazz)) | ||||
| { | { | ||||
| if(value instanceof MultiPolygon) | if(value instanceof MultiPolygon) | ||||
| return value; | return value; | ||||
| else | else | ||||
| return GeoCreator.MultiPolygonByWKT(value.toString()); | |||||
| return GeoConverter.MultiPolygonByWKT(value.toString()); | |||||
| } | } | ||||
| else if(LinearRing.class.isAssignableFrom(clazz)) | else if(LinearRing.class.isAssignableFrom(clazz)) | ||||
| { | { | ||||
| if(value instanceof LinearRing) | if(value instanceof LinearRing) | ||||
| return value; | return value; | ||||
| else | else | ||||
| return GeoCreator.LinearRingByWKT(value.toString()); | |||||
| return GeoConverter.LinearRingByWKT(value.toString()); | |||||
| } | } | ||||
| else | else | ||||
| return value; | return value; | ||||