基于geotools24.0版本读取tif文件范围和坐标系统srs的功能
File file=null;
GeoTiffReader reader=null;
GridCoverage2D coverage=null;
try {
file = new File(filePath);
reader = new GeoTiffReader(file, new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE));
coverage = reader.read(null);
Envelope2D env = coverage.getEnvelope2D();
extent.add(BigDecimal.valueOf(env.getBounds().getMinX()));
extent.add(BigDecimal.valueOf(env.getBounds().getMinY()));
extent.add(BigDecimal.valueOf(env.getBounds().getMaxX()));
extent.add(BigDecimal.valueOf(env.getBounds().getMaxY()));
//
res.setExtent(extent);
CoordinateSystem cs=reader.getCoordinateReferenceSystem().getCoordinateSystem();
if(cs!=null) {
if(cs.getIdentifiers().size()>0) {
Iterator<ReferenceIdentifier> item=cs.getIdentifiers().iterator();
while(item.hasNext()){
NamedIdentifier ref=(NamedIdentifier)item.next();
if(ref!=null) {
res.setSrs(ref.toString());
}
}
}
}
}
catch (Exception ee)
{
}
finally {
if(coverage!=null)
{
coverage.dispose(true);
coverage=null;
}
if(reader!=null)
{
reader.dispose();
reader=null;
}
if(file!=null)
{
file=null;
}
}