| | |
| | | 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; |
| | | import com.lf.server.mapper.all.GeomBaseMapper; |
| | | import com.lf.server.service.all.BaseQueryService; |
| | | import org.apache.commons.logging.Log; |
| | |
| | | /** |
| | | * 设置值 |
| | | */ |
| | | private static <T> void setValue(T t, Feature f, Field field, Integer i) throws Exception { |
| | | public static <T> void setValue(T t, Feature f, Field field, Integer i) throws Exception { |
| | | switch (field.getType().getName()) { |
| | | case "java.math.BigDecimal": |
| | | double dd = f.GetFieldAsDouble(i); |
| | |
| | | /** |
| | | * 获取 Timestamp |
| | | */ |
| | | private static Timestamp getTimestamp(Feature f, int index) { |
| | | public static Timestamp getTimestamp(Feature f, int index) { |
| | | int[] pnYear = new int[1]; |
| | | int[] pnMonth = new int[1]; |
| | | int[] pnDay = new int[1]; |
| | |
| | | /** |
| | | * 获取 LocalDate |
| | | */ |
| | | private static LocalDate getLocalDate(Feature f, int index) { |
| | | public static LocalDate getLocalDate(Feature f, int index) { |
| | | int[] pnYear = new int[1]; |
| | | int[] pnMonth = new int[1]; |
| | | int[] pnDay = new int[1]; |
| | |
| | | for (String key : map.keySet()) { |
| | | Layer layer = null; |
| | | try { |
| | | GeomBaseMapper baseMapper = ClassHelper.getGeoBaseMapper(key); |
| | | BasicMapper baseMapper = ClassHelper.getBasicMapper(key); |
| | | if (null == baseMapper) { |
| | | continue; |
| | | } |
| | |
| | | } |
| | | |
| | | List<Field> fields = new ArrayList<>(); |
| | | // fields.add(getGeomField(clazz)) |
| | | getFields(clazz, fields); |
| | | getFields(clazz, fields, StaticData.GDB_EXCLUDE_FIELDS); |
| | | addLayerField(layer, fields); |
| | | |
| | | setLayerData(layer, fields, map.get(key)); |
| | |
| | | /** |
| | | * 创建图层 |
| | | */ |
| | | private static Layer createLayer(DataSource dataSource, GeomBaseMapper baseMapper ) { |
| | | private static Layer createLayer(DataSource dataSource, BasicMapper baseMapper ) { |
| | | String tab = BaseQueryService.getTabName(baseMapper); |
| | | if (StringHelper.isNull(tab)) { |
| | | return null; |
| | | } |
| | | |
| | | String geomType = baseMapper.selectGeometryType(tab); |
| | | if (StringHelper.isEmpty(geomType)) { |
| | | return null; |
| | | Integer srid = null; |
| | | String geomType = null; |
| | | if (baseMapper instanceof GeomBaseMapper) { |
| | | GeomBaseMapper geomMapper = (GeomBaseMapper) baseMapper; |
| | | geomType = geomMapper.selectGeometryType(tab); |
| | | |
| | | srid = geomMapper.selectSrid(tab); |
| | | } |
| | | |
| | | Integer srid = baseMapper.selectSrid(tab); |
| | | SpatialReference sr = new SpatialReference(); |
| | | sr.ImportFromEPSG(null == srid ? 4490 : srid); |
| | | |
| | |
| | | */ |
| | | private static Integer getGeomType(String geomType) { |
| | | if (StringHelper.isEmpty(geomType)) { |
| | | return ogr.wkbUnknown; |
| | | return ogr.wkbPoint; |
| | | } |
| | | |
| | | switch (geomType) { |
| | |
| | | /** |
| | | * 获取字段 |
| | | */ |
| | | private static void getFields(Class clazz, List<Field> list) { |
| | | public static void getFields(Class clazz, List<Field> list, List<String> excludeFields) { |
| | | try { |
| | | Field[] fields = clazz.getDeclaredFields(); |
| | | for (Field f : fields) { |
| | | if (StaticData.GDB_EXCLUDE_FIELDS.contains(f.getName())) { |
| | | if (excludeFields.contains(f.getName())) { |
| | | continue; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | if (!StaticData.OBJECT.equals(clazz.getSuperclass().getName())) { |
| | | getFields(clazz.getSuperclass(), list); |
| | | getFields(clazz.getSuperclass(), list, excludeFields); |
| | | } |
| | | } catch (Exception ex) { |
| | | // |
| | |
| | | for (T t : list) { |
| | | Feature f = new Feature(layer.GetLayerDefn()); |
| | | |
| | | BaseGeoEntity geoEntity = (BaseGeoEntity) t; |
| | | Geometry geom = Geometry.CreateFromWkt(geoEntity.getGeom()); |
| | | f.SetGeometry(geom); |
| | | if (t instanceof BaseGeoEntity) { |
| | | BaseGeoEntity geoEntity = (BaseGeoEntity) t; |
| | | if (!StringHelper.isEmpty(geoEntity.getGeom())) { |
| | | Geometry geom = Geometry.CreateFromWkt(geoEntity.getGeom()); |
| | | f.SetGeometry(geom); |
| | | } |
| | | } |
| | | |
| | | setFeatureData(f, fields, t); |
| | | layer.CreateFeature(f); |