| | |
| | | package com.lf.server.helper; |
| | | |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | return propertyGetter.get(feature, index); |
| | | } catch (Exception ex) { |
| | | // ex.printStackTrace() |
| | | log.error(ex.getMessage() + ex.getStackTrace() + "\n"); |
| | | log.error(ex.getStackTrace()); |
| | | |
| | | return null; |
| | | } |