| | |
| | | package com.lf.server.helper; |
| | | |
| | | import com.lf.server.entity.ctrl.LayerDto; |
| | | import com.lf.server.entity.ctrl.ShpRecordEntity; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.gdal.gdal.Band; |
| | |
| | | |
| | | // 为了使属性表字段支持中文,请添加下面这句:CP936 |
| | | gdal.SetConfigOption("SHAPE_ENCODING", ""); |
| | | } |
| | | |
| | | /** |
| | | * 获取Shp第一条记录的WKT |
| | | */ |
| | | public static ShpRecordEntity readShpFirstRecord(String filePath) { |
| | | try { |
| | | org.gdal.ogr.Driver driver = ogr.GetDriverByName("ESRI shapefile"); |
| | | if (driver == null) { |
| | | return null; |
| | | } |
| | | |
| | | DataSource dataSource = driver.Open(filePath); |
| | | Layer layer = dataSource.GetLayer(0); |
| | | if (layer.GetFeatureCount() < 1) { |
| | | return null; |
| | | } |
| | | |
| | | SpatialReference spatialReference = layer.GetSpatialRef(); |
| | | String csid = spatialReference.GetAttrValue("AUTHORITY", 1); |
| | | |
| | | Feature feature = layer.GetFeature(0); |
| | | String wkt = feature.GetGeometryRef().ExportToWkt(); |
| | | |
| | | layer.delete(); |
| | | dataSource.delete(); |
| | | driver.delete(); |
| | | |
| | | return new ShpRecordEntity(wkt, csid); |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | |
| | | public static LayerDto getLayerDto(String filePath) { |
| | | public static void getLayerDto(String filePath) { |
| | | org.gdal.ogr.Driver driver = ogr.GetDriverByName("OpenFileGDB"); |
| | | if (driver == null) { |
| | | return null; |
| | | return; |
| | | } |
| | | |
| | | List<Map> list = new ArrayList<>(); |
| | | List<Map<String, String>> mapList = new ArrayList<>(); |
| | | LayerDto layerDto = new LayerDto(); |
| | | DataSource dataSource = null; |
| | | try { |
| | | dataSource = driver.Open(filePath, 0); |
| | |
| | | feature.delete(); |
| | | } while (true); |
| | | } |
| | | layerDto.setLayerName(strlayerName); |
| | | layerDto.setList(list); |
| | | layerDto.setCount(count); |
| | | layerDto.setMap(mapList); |
| | | //layerDto.setLayerName(strlayerName); |
| | | //layerDto.setList(list); |
| | | //layerDto.setCount(count); |
| | | //layerDto.setMap(mapList); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | dataSource.delete(); |
| | | } |
| | | } |
| | | return layerDto; |
| | | } |
| | | |
| | | /** |
| | |
| | | return propertyGetter.get(feature, index); |
| | | } catch (Exception ex) { |
| | | // ex.printStackTrace() |
| | | log.error(ex.getMessage() + ex.getStackTrace() + "\n"); |
| | | log.error(ex.getStackTrace()); |
| | | |
| | | return null; |
| | | } |