2

我使用 GeoTiffIIOMetadataAdapter 类获取 geoTiff 元数据:

    String filename = pathToMyTiffFile;
    FileImageInputStream f = new FileImageInputStream(
            new RandomAccessFile(filename, "r"));

    // Look through ImageIO readers
    Iterator iter = ImageIO.getImageReaders(f);
    IIOMetadata imdata = null;
    GeoTiffIIOMetadataAdapter geo_data;
    while (iter.hasNext() && imdata == null) {
        ImageReader reader = (ImageReader) iter.next();
        reader.setInput(f, true);
        String reader_name = reader.getFormatName().toLowerCase();
        if (reader_name.equalsIgnoreCase("tif")) {
            // Get Image metadata
            imdata = reader.getImageMetadata(0);
            geo_data = new GeoTiffIIOMetadataAdapter(imdata);
            if (geo_data != null &&
                    geo_data.getGeoKeyDirectoryVersion() == 1) {
                geo_data.getModelTiePoints(); //here i get [0.0,0.0,0.0,173084.9999999999,5845515.0,0.0]
            }
        }
    }

如何将此数组提取/转换为通常的纬度/经度坐标?173084.9999999999,5845515.0 是 tiff 文件左上角的坐标,我说得对吗?

提前致谢!

4

1 回答 1

2

答案是:是的,它是我的 tiff 文件的左上角。我的 Tiff 在http://spatialreference.org/ref/epsg/32612/中。使用我需要的地理工具将坐标转换为 wsg84(http://spatialreference.org/ref/epsg/4326/ ):

    CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326", true);
    CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:32612");
    MathTransform transformToEpsg4326 = CRS.findMathTransform(targetCRS, sourceCRS);
    double lon = geo_data.getModelTiePoints()[3];// 175784.99999999997 - X
    double lat = geo_data.getModelTiePoints()[4];// 5842215.0   - Y
    GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), 32612);
    Geometry pointUpperLeft = geometryFactory.createPoint(new Coordinate(lon, lat));
于 2012-06-26T08:16:18.477 回答