| | |
| | | /** |
| | | * 获取字段映射 |
| | | */ |
| | | private static <T> void getFieldMapper(Class clazz, Layer layer, Map<Integer, Field> map) { |
| | | private static void getFieldMapper(Class clazz, Layer layer, Map<Integer, Field> map) { |
| | | try { |
| | | FeatureDefn fd = layer.GetLayerDefn(); |
| | | for (int i = 0, count = fd.GetFieldCount(); i < count; i++) { |
| | |
| | | } |
| | | } |
| | | |
| | | if (OBJECT != clazz.getSuperclass().getName()) { |
| | | if (!OBJECT.equals(clazz.getSuperclass().getName())) { |
| | | getFieldMapper(clazz.getSuperclass(), layer, map); |
| | | } |
| | | } catch (Exception ex) { |
| | |
| | | continue; |
| | | } |
| | | Layer layer = createLayer(dataSource, baseMapper); |
| | | if(null == layer){ |
| | | if (null == layer) { |
| | | continue; |
| | | } |
| | | |
| | | String className = ClassHelper.getClassName(baseMapper); |
| | | Class clazz = ClassHelper.getEntityClass(className); |
| | | List<Field> fields = new ArrayList<>(); |
| | | getFields(clazz, fields); |
| | | |
| | | Field gField = getGeomField(clazz); |
| | | if (null == gField) { |
| | | continue; |
| | | } |
| | | |
| | | List<?> list = map.get(key); |
| | | } |
| | |
| | | SpatialReference sr = new SpatialReference(); |
| | | sr.ImportFromEPSG(null == srid ? 4326 : srid); |
| | | |
| | | Layer layer = dataSource.CreateLayer(tab, sr, getGeomType(geomType), null); |
| | | |
| | | return layer; |
| | | return dataSource.CreateLayer(tab, sr, getGeomType(geomType), null); |
| | | } |
| | | |
| | | /** |
| | | * 获取Geom类别 |
| | | */ |
| | | private static Integer getGeomType(String geomType) { |
| | | if (StringHelper.isEmpty(geomType)){ |
| | | if (StringHelper.isEmpty(geomType)) { |
| | | return ogr.wkbUnknown; |
| | | } |
| | | |
| | | switch (geomType){ |
| | | switch (geomType) { |
| | | case "ST_Point": |
| | | return ogr.wkbPoint; |
| | | case "ST_LineString": |
| | |
| | | return ogr.wkbUnknown; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取字段 |
| | | */ |
| | | private static void getFields(Class clazz, List<Field> list) { |
| | | try { |
| | | Field[] fields = clazz.getDeclaredFields(); |
| | | for (Field f : fields) { |
| | | // if ("geom".equals(f.getName())) { |
| | | // continue; |
| | | // } |
| | | |
| | | if (StaticData.READ_EXCLUDE_FIELDS.contains(f.getName())) { |
| | | continue; |
| | | } |
| | | |
| | | f.setAccessible(true); |
| | | list.add(f); |
| | | } |
| | | |
| | | if (!OBJECT.equals(clazz.getSuperclass().getName())) { |
| | | getFields(clazz.getSuperclass(), list); |
| | | } |
| | | } catch (Exception ex) { |
| | | // |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加图层字段 |
| | | */ |
| | | private static void addLayerField(Layer layer, List<Field> list) { |
| | | for (int i = 0, c = list.size(); i < c; i++) { |
| | | Field f = list.get(i); |
| | | FieldDefn fd = getLayerField(f); |
| | | |
| | | layer.CreateField(fd, i); |
| | | } |
| | | } |
| | | |
| | | private static FieldDefn getLayerField(Field f ) { |
| | | int fieldType = getFieldType(f); |
| | | FieldDefn fd = new FieldDefn(f.getName(), fieldType); |
| | | if (fieldType == ogr.OFTString) { |
| | | |
| | | } |
| | | |
| | | return fd; |
| | | } |
| | | |
| | | /** |
| | | * 获取字段类型 |
| | | */ |
| | | private static Integer getFieldType(Field f) { |
| | | switch (f.getType().getName()) { |
| | | case "java.math.BigDecimal": |
| | | case "java.lang.Double": |
| | | case "double": |
| | | return ogr.OFTReal; |
| | | case "java.lang.Long": |
| | | case "long": |
| | | return ogr.OFTInteger64; |
| | | case "java.lang.Integer": |
| | | case "int": |
| | | return ogr.OFTInteger; |
| | | case "java.sql.Timestamp": |
| | | return ogr.OFTDateTime; |
| | | default: |
| | | return ogr.OFTString; |
| | | } |
| | | } |
| | | } |