| | |
| | | package com.lf.server.helper; |
| | | |
| | | import com.lf.server.entity.ctrl.ShpRecord; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.gdal.gdal.Band; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取Shp第一条记录的WKT |
| | | */ |
| | | public static ShpRecord 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 ShpRecord(wkt, csid); |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 读取tif文件 |
| | | * |
| | | * @param fileName |