相关文章推荐
从容的蚂蚁  ·  CSS ...·  1 周前    · 
谦和的蘑菇  ·  ios extension log-掘金·  9 月前    · 
不拘小节的毛巾  ·  minifyenabled ...·  1 年前    · 
坚强的四季豆  ·  Rstudio ...·  1 年前    · 
public String getAltitude(List<String> strPoints) throws IOException, TransformException {
    String demPath = "G:/weitu/download/xian/xian.tif";
    // String demPath = "F:/Data/yanta/YanTaDOM.tif";
    File file = new File(demPath);
    Hints tiffHints = new Hints();
    tiffHints.add(new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE));
    // 默认坐标系EPSG:3857
    //tiffHints.add(new Hints(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, CRS.decode("EPSG:4326")));
    tiffHints.add(new Hints(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, DefaultGeographicCRS.WGS84));
    GeoTiffReader tifReader = new GeoTiffReader(file,tiffHints);
    GridCoverage2D coverage = tifReader.read(null);
    RenderedImage sourceImage = coverage.getRenderedImage();
    PlanarImage planarImage = (PlanarImage)sourceImage;
    //获取左上右下,包含仿射影子的左上角
    Envelope env = coverage.getEnvelope();
    //创建输出tif
    String outputPath = "D:/testTiff.tif";
    float[][] slopeData = new float[1000][1000];
    for(int i=0;i<1000;i++){
      for(int j=0;j<1000;j++)
        slopeData[i][j] = i+j;
    GridCoverageFactory factory = new GridCoverageFactory();
    GridCoverage2D outputCoverage = factory.create("test", slopeData, env);
    GeoTiffWriter writer = new GeoTiffWriter(new File(outputPath));
    writer.write(outputCoverage, null);
    writer.dispose();
    int ixtiles = sourceImage.getNumXTiles();
    Raster raster = sourceImage.getTile(0,0);
    int itilerasterwidth = raster.getWidth();
    int itilerasterheight = raster.getHeight();
    int irasternumbands = raster.getNumBands();
    //获取坐标系
    CoordinateReferenceSystem crs = coverage.getCoordinateReferenceSystem2D();
    //获取图斑名称
    String [] names = tifReader.getGridCoverageNames();
    //获取影像长宽
    int iwidth = coverage.getRenderedImage().getWidth();
    int iheight = coverage.getRenderedImage().getHeight();
    //获取仿射因子其他参数
    int a  = coverage.getGridGeometry().gridDimensionX;
    int b = coverage.getGridGeometry().gridDimensionY;
    int c = coverage.getGridGeometry().axisDimensionX;
    int d = coverage.getGridGeometry().axisDimensionY;
    //获取栅格图斑个数
    int ibandcount = coverage.getNumSampleDimensions();
    String[] sampleDimensionNames = new String[ibandcount];
    for (int i = 0; i < ibandcount; i++) {
      GridSampleDimension dim = coverage.getSampleDimension(i);
      sampleDimensionNames[i] = dim.getDescription().toString();
    //获取行列对应的像元值
    Raster sourceRaster = sourceImage.getData();
    float[] adsaf = {0};
    sourceRaster.getPixel(1500, 800,adsaf);
    float ibandvalue = sourceRaster.getSampleFloat(0,0,0);
    //获取源数据类型
    int iDataType = coverage.getRenderedImage().getSampleModel().getDataType();
    //??栅格转矢量
    // PolygonExtractionProcess process = new PolygonExtractionProcess();
    // SimpleFeatureCollection features = process.execute(tiffCoverage, 0, Boolean.TRUE, null, null, null, null);
    List list = new ArrayList();
    for(int i=0;i<strPoints.size();i++) {
      String strLonlat = strPoints.get(i);
      String[] strLonlats = strLonlat.split(" ");
      double lon = Double.parseDouble(strLonlats[0]),
          lat = Double.parseDouble(strLonlats[1]);
      //构建地理坐标
      DirectPosition position = new DirectPosition2D(crs, lon, lat);
      float[] results = (float[]) coverage.evaluate(position);
      //通过地理坐标获取行列号
      Point2D point2d = coverage.getGridGeometry().worldToGrid(position);
      //通过行列号获取地理坐标
      GridCoordinates2D coord= new GridCoordinates2D(0,0);
      DirectPosition tmpPos = coverage.getGridGeometry().gridToWorld(coord);
      float[] sss = (float[])coverage.evaluate(tmpPos);
      Map map = new HashMap();
      map.put("lon", lon);
      map.put("lat", lon);
      map.put("dem", results[0]);
      list.add(JSONObject.toJSONString(map));
                    public String getAltitude(List&lt;String&gt; strPoints) throws IOException, TransformException {    String demPath = "G:/weitu/download/xian/xian.tif";    // String demPath = "F:/Data/yanta/YanTaDO...
最近碰到了一个需求,需要通过 cesium 直接加载 geotiff 影像图。
咋一听,这个需求好像蛮奇怪,cesium 本身本来就支持加载 tile 影像图,也就是所谓的切片地图。原理其实就是,通过 geoserver 等工具,按照一定的规则和坐标系规则,切好对应的切片。
而 cesium 里面,加载瓦片地图也很简单,想要显示哪个区域的地图,就根据对应的规则,去 geoserver 里请求对应的切片。这些逻辑在 cesium 里面,也已经封装好了,直接调用就好了。
但是如果不想发布到 geos
 * @param geom 几何模型
public static GridCoverage2D SplitImageByGeometry( GeoTiffReader reader, Geometry geom,ImageMetaInfo metaInfo) {
    //元数据类型
public static GeoTiffReader getImageReader(String iamge){
 Hints tiffHints = new Hints();
 tiffHints.add(new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE));
 tiffHints.add...
				
地理信息系统和遥感影像的处理和应用过程中,栅格影像都包含有各种地理信息,而一般的 BMP、JPG、1rIFF等图像存储格式却不能对各种地理信息进行有效的存储,因此GeoTIFF作为1rIFF的一种扩 展,由于可以存储各种地理信息而得到了广泛应用。简单介绍了1rIFF图像文件结构以及对地理数据的存储方式,文最后介绍了实现GeoTIFF图像文件的读写的关键步骤
```java File file = new File("path/to/raster.tif"); AbstractGridFormat format = GridFormatFinder.findFormat(file); GridCoverage2D coverage = format.read(file, null); 2. 获取栅格数据的范围 ```java Envelope envelope = coverage.getEnvelope(); 3. 将范围转换为线要素 ```java GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); Coordinate[] coordinates = new Coordinate[5]; coordinates[0] = new Coordinate(envelope.getMinX(), envelope.getMinY()); coordinates[1] = new Coordinate(envelope.getMinX(), envelope.getMaxY()); coordinates[2] = new Coordinate(envelope.getMaxX(), envelope.getMaxY()); coordinates[3] = new Coordinate(envelope.getMaxX(), envelope.getMinY()); coordinates[4] = coordinates[0]; LineString lineString = geometryFactory.createLineString(coordinates); 这样就能够获取栅格数据的边界线要素了。