| | |
| | | import java.time.LocalTime; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * GDB帮助类 |
| | | * @author WWW |
| | | */ |
| | | @SuppressWarnings("ALL") |
| | | public class GdbHelper { |
| | | private final static Log log = LogFactory.getLog(GdbHelper.class); |
| | | |
| | | /** |
| | | * 销毁资源 |
| | | */ |
| | | public static void delete(Layer layer) { |
| | | try { |
| | | if (null != layer) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 销毁资源 |
| | | */ |
| | | public static void delete(DataSource dataSource, Driver driver) { |
| | | try { |
| | | if (null != dataSource) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 销毁资源 |
| | | */ |
| | | public static void delete(Layer layer, DataSource dataSource, Driver driver) { |
| | | delete(layer); |
| | | delete(dataSource, driver); |
| | | } |
| | | |
| | | /** |
| | | * 获取表名 |
| | | */ |
| | | public static List<String> getTabNames(String filePath) { |
| | | List<String> list = new ArrayList<>(); |
| | | |
| | |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 读取数据 |
| | | */ |
| | | public static <T> List<T> readData(Class clazz, String filePath, String layerName, boolean isTransform) { |
| | | List<T> list = new ArrayList<>(); |
| | | |
| | |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 读取图层 |
| | | */ |
| | | public static <T> void readLayer(Class clazz, Layer layer, List<T> list, boolean isTransform) { |
| | | try { |
| | | Field gField = getGeomField(clazz); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取坐标转换器 |
| | | */ |
| | | private static CoordinateTransformation getCoordinateTransformation(Layer layer, boolean isTransform) { |
| | | if (!isTransform) { |
| | | return null; |
| | |
| | | return CoordinateTransformation.CreateCoordinateTransformation(layer.GetSpatialRef(), srTarget); |
| | | } |
| | | |
| | | /** |
| | | * 获取 geom 字段 |
| | | */ |
| | | private static Field getGeomField(Class clazz) { |
| | | try { |
| | | Field gField = clazz.getSuperclass().getDeclaredField("geom"); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取字段映射 |
| | | */ |
| | | private static void getFieldMapper(Class clazz, Layer layer, Map<Integer, Field> map) { |
| | | try { |
| | | FeatureDefn fd = layer.GetLayerDefn(); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 读取Feature |
| | | */ |
| | | private static <T> void readFeature(T t, Feature f, Map<Integer, Field> map, Field gField, CoordinateTransformation ct) { |
| | | for (Integer i : map.keySet()) { |
| | | try { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置值 |
| | | */ |
| | | public static <T> void setValue(T t, Feature f, Field field, Integer i) throws Exception { |
| | | switch (field.getType().getName()) { |
| | | case "java.math.BigDecimal": |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置 geom 字段值 |
| | | * <p> |
| | | * wkbUnknown = 0, |
| | | * wkbPoint = 1, |
| | | * wkbLineString = 2, |
| | | * wkbPolygon = 3, |
| | | * wkbMultiPoint = 4, |
| | | * wkbMultiLineString = 5, |
| | | * wkbMultiPolygon = 6, |
| | | * wkbGeometryCollection = 7, |
| | | * wkbNone = 100, |
| | | * wkbLinearRing = 101 |
| | | */ |
| | | private static <T> void setGeom(T t, Field gField, Geometry geometry, CoordinateTransformation ct) { |
| | | try { |
| | | if (null == geometry) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取 Timestamp |
| | | */ |
| | | public static Timestamp getTimestamp(Feature f, int index) { |
| | | int[] pnYear = new int[1]; |
| | | int[] pnMonth = new int[1]; |
| | |
| | | return Timestamp.valueOf(localDateTime); |
| | | } |
| | | |
| | | /** |
| | | * 获取 LocalDate |
| | | */ |
| | | public static LocalDate getLocalDate(Feature f, int index) { |
| | | int[] pnYear = new int[1]; |
| | | int[] pnMonth = new int[1]; |
| | |
| | | return LocalDate.of(pnYear[0], pnMonth[0], pnDay[0]); |
| | | } |
| | | |
| | | /** |
| | | * 创建GDB |
| | | */ |
| | | public static void createGdb(String filePath, Map<String, List<?>> map) throws Exception { |
| | | Driver driver = null; |
| | | DataSource dataSource = null; |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建图层 |
| | | */ |
| | | private static Layer createLayer(DataSource dataSource, BasicMapper baseMapper ) { |
| | | String tab = BaseQueryService.getTabName(baseMapper); |
| | | if (StringHelper.isNull(tab)) { |
| | |
| | | |
| | | // SpatialReference sr = new SpatialReference(); sr.ImportFromEPSG(null == srid || 0 == srid ? StaticData.I104903 : srid) |
| | | SpatialReference sr; |
| | | if (null == srid || 0 == srid) { |
| | | if (null == srid || StaticData.DEFAULT_EPSG.contains(srid)) { |
| | | sr = new SpatialReference(StaticData.MOON_2000_WKT); |
| | | } else { |
| | | sr = new SpatialReference(); |
| | |
| | | return dataSource.CreateLayer(tab.replace(".", "_"), sr, getGeomType(geomType), null); |
| | | } |
| | | |
| | | /** |
| | | * 获取Geom类别 |
| | | */ |
| | | private static Integer getGeomType(String geomType) { |
| | | if (StringHelper.isEmpty(geomType)) { |
| | | return ogr.wkbPoint; |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取字段 |
| | | */ |
| | | public static void getFields(Class clazz, List<Field> list, List<String> excludeFields) { |
| | | try { |
| | | Field[] fields = clazz.getDeclaredFields(); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加图层字段 |
| | | */ |
| | | public static void addLayerField(Layer layer, List<Field> list) { |
| | | for (int i = 0, c = list.size(); i < c; i++) { |
| | | Field f = list.get(i); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取字段类型 |
| | | */ |
| | | private static Integer getFieldType(Field f) { |
| | | switch (f.getType().getName()) { |
| | | case "java.math.BigDecimal": |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置图层数据 |
| | | */ |
| | | private static <T> void setLayerData(Layer layer, List<Field> fields, List<T> list) throws Exception { |
| | | for (T t : list) { |
| | | Feature f = new Feature(layer.GetLayerDefn()); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置要素的数据 |
| | | */ |
| | | public static <T> void setFeatureData(Feature f, List<Field> fields, T t) throws Exception { |
| | | for (int i = 0, c = fields.size(); i < c; i++) { |
| | | Field field = fields.get(i); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置Timestamp |
| | | */ |
| | | private static void setTimestamp(Feature f, int i, Timestamp time) { |
| | | if (null == time) { |
| | | return; |
| | |
| | | f.SetField(i, local.getYear(), local.getMonthValue(), local.getDayOfMonth(), local.getHour(), local.getMinute(), local.getSecond(), 8); |
| | | } |
| | | |
| | | /** |
| | | * 设置LocalDate |
| | | */ |
| | | private static void setLocalDate(Feature f, int i, LocalDate local) { |
| | | if (null == local) { |
| | | return; |