我使用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文件左上角的坐标吗?
提前致谢!
答案 0 :(得分: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));