| | |
| | | |
| | | import com.moon.server.entity.all.StaticData; |
| | | import com.moon.server.entity.data.MetaFileEntity; |
| | | import com.moon.server.helper.GeoHelper; |
| | | import com.moon.server.helper.StringHelper; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.File; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 读取栅格服务 |
| | |
| | | */ |
| | | @Service |
| | | public class ReadRasterService { |
| | | private SpatialReference sr4326; |
| | | |
| | | private SpatialReference sr4490; |
| | | |
| | | private SpatialReference sr104903; |
| | | |
| | | private final static Log log = LogFactory.getLog(ReadRasterService.class); |
| | | |
| | | /** |
| | | * 初始化空间引用 |
| | | */ |
| | | private void initSpatialReference() { |
| | | if (null == sr4326) { |
| | | sr4326 = new SpatialReference(); |
| | | sr4326.ImportFromEPSG(StaticData.I4326); |
| | | |
| | | sr4490 = new SpatialReference(); |
| | | sr4490.ImportFromEPSG(StaticData.I4490); |
| | | |
| | | sr104903 = new SpatialReference(StaticData.MOON_2000_WKT); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 读取栅格信息 |
| | |
| | | mf.setCt(null == colorTable ? null : colorTable.toString()); |
| | | // 高程基准 |
| | | mf.sethDatum(null); |
| | | // 设置最值 |
| | | setMinAndMax(ds, mf); |
| | | |
| | | // 分辨率 |
| | | double[] tr = new double[6]; |
| | |
| | | * 获取Dataset的最大点 |
| | | */ |
| | | private Geometry getMaxPoint(Dataset ds) { |
| | | /** |
| | | /* |
| | | * transform[0] 左上角x坐标 |
| | | * transform[1] 东西方向分辨率 |
| | | * transform[2] 旋转角度, 0表示图像 "北方朝上" |
| | |
| | | * 坐标转换 |
| | | */ |
| | | private Geometry transform(Dataset ds, Geometry point) { |
| | | this.initSpatialReference(); |
| | | |
| | | point.AssignSpatialReference(ds.GetSpatialRef()); |
| | | if (ds.GetSpatialRef().IsGeographic() > 0) { |
| | | return point; |
| | |
| | | |
| | | String srsName = ds.GetSpatialRef().GetName(); |
| | | if (srsName.contains(StaticData.CGCS2000)) { |
| | | point.TransformTo(sr4490); |
| | | point.TransformTo(GeoHelper.sr4490); |
| | | } else { |
| | | point.TransformTo(sr4326); |
| | | point.TransformTo(GeoHelper.sr4326); |
| | | } |
| | | point.SwapXY(); |
| | | |
| | | return point; |
| | | } |
| | | |
| | | /** |
| | | * 设置最值 |
| | | * GDALRasterBand::GetHistogram 统计直方图 |
| | | */ |
| | | private void setMinAndMax(Dataset ds, MetaFileEntity mf) { |
| | | List<Double> minList = new ArrayList<>(); |
| | | List<Double> maxList = new ArrayList<>(); |
| | | |
| | | for (int i = 1; i <= ds.getRasterCount(); i++) { |
| | | Double[] min = new Double[1]; |
| | | Double[] max = new Double[1]; |
| | | ds.GetRasterBand(i).GetMinimum(min); |
| | | ds.GetRasterBand(i).GetMaximum(max); |
| | | |
| | | minList.add(min[0]); |
| | | maxList.add(max[0]); |
| | | } |
| | | |
| | | mf.setMin(StringHelper.join(minList, ",")); |
| | | mf.setMax(StringHelper.join(maxList, ",")); |
| | | } |
| | | } |