| | |
| | | continue; |
| | | } |
| | | |
| | | String geom = readKml(mf.getPath()); |
| | | if (StringHelper.isEmpty(geom)) { |
| | | String wkt = readKml(mf.getPath()); |
| | | if (StringHelper.isEmpty(wkt)) { |
| | | continue; |
| | | } |
| | | |
| | | loadKmlData(mf, geom); |
| | | loadKmlData(mf, wkt); |
| | | } |
| | | } |
| | | |
| | |
| | | * 获取KWT |
| | | */ |
| | | private String getWktFromCoordinates(String coords) { |
| | | String[] strs = coords.replace("<coordinates>", "").replace("</coordinates>", "").split(" "); |
| | | String[] strs = coords.replace("\t", "").replace("<coordinates>", "").replace("</coordinates>", "").split(" "); |
| | | if (strs.length == 0) { |
| | | return null; |
| | | } |
| | |
| | | /** |
| | | * 加载Kml数据 |
| | | */ |
| | | private void loadKmlData(MetaFileEntity mf, String geom) { |
| | | private void loadKmlData(MetaFileEntity mf, String wkt) { |
| | | BasicMapper basicMapper = ClassHelper.getBasicMapper(mf.getEntity()); |
| | | if (null == basicMapper) { |
| | | return; |
| | |
| | | return; |
| | | } |
| | | |
| | | String name = FileHelper.getFileName(mf.getPath()); |
| | | List<?> list = createKmlEntity(clazz, geom, name); |
| | | String name = FileHelper.getName(mf.getPath()); |
| | | List<?> list = createKmlEntity(clazz, wkt, name); |
| | | if (null == list || list.isEmpty()) { |
| | | return; |
| | | } |
| | |
| | | /** |
| | | * 创建KML实体类 |
| | | */ |
| | | private <T> List<T> createKmlEntity(Class clazz, String geom, String name) { |
| | | private <T> List<T> createKmlEntity(Class clazz, String wkt, String name) { |
| | | try { |
| | | T t = (T) clazz.newInstance(); |
| | | |
| | | Field gField = clazz.getSuperclass().getDeclaredField("geom"); |
| | | gField.setAccessible(true); |
| | | gField.set(t, geom); |
| | | gField.set(t, null == wkt ? "null" : String.format("ST_GeomFromText('%s')", wkt)); |
| | | |
| | | Field pField = clazz.getSuperclass().getDeclaredField("pipename"); |
| | | Field pField = clazz.getDeclaredField("pipename"); |
| | | pField.setAccessible(true); |
| | | pField.set(t, name); |
| | | |