1

I've loaded a GeoTiff successfully in with geotools (21-SNAPSHOT), but I'm having trouble accessing the referenced UTM zone.

The code to read in the file is here:

File tiffFile = new File(filePath);
GeoTiffFormat format = new GeoTiffFormat();
Hints hint = new Hints();
hint.put(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
tiffReader = format.getReader(tiffFile, hint);
GridCoverage2D grid = tiffReader.read(null);

I'm inspecting the GridCoverage2D object in my debugger and have found the information in a few places.

The information I'm looking for here is the "UTM zone 16N". Perhaps the zone is given in numerical form somewhere else in the object?

This is inside GridCoverage2D->GridGeometry2D->CoordinateReferenceSystem2D

GridGeometry debugging

But for the life of me I cannot figure out how to access this information. There's no reference to the underlying transformation conversionFromBase in the top level object. None of the accessible methods get me anywhere closer.

Is there an encoded version somewhere in the CoordinateReferenceSystem metadata?

EDIT

The output of the .toWKT() method on my CoordinateReferenceSystem is below

PROJCS["unnamed", GEOGCS["GCS Name = unknown", DATUM["Datum = unknown", SPHEROID["Ellipsoid = unretrievable - using WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]], PROJECTION["Transverse_Mercator", AUTHORITY["EPSG","9807"]], PARAMETER["central_meridian", -87.0], PARAMETER["latitude_of_origin", 0.0], PARAMETER["scale_factor", 0.9996], PARAMETER["false_easting", 500000.0], PARAMETER["false_northing", 0.0], UNIT["m", 1.0], AXIS["Easting", EAST], AXIS["Northing", NORTH]]

1

I usually use a block like:

AbstractGridCoverage2DReader reader = format.getReader(file,hints);
GridCoverage2D coverage = reader.read(null);
crs = coverage.getCoordinateReferenceSystem();

But if you are starting with a GridGeometry then it also has a getCoordinateSystem method you can use directly.

EDIT

Querying the internals of a CoordinateReferenceSystem is possible, what you get back tends to reflect what was provided by the input file.

I use crs.getName() which gives me "EPSG:WGS 84 / UTM zone 35S" but for a fuller investigation I used:

if (crs == null) {
  crs = cov.getCoordinateReferenceSystem();

  System.err.println("Set CRS to " + crs.getName());
  Collection<GenericName> alias = crs.getAlias();
  if (alias.isEmpty()) {
    System.err.println("No Alias");
  } else {
  for (Iterator iterator = alias.iterator(); iterator.hasNext();) {
    GenericName genericName = (GenericName) iterator.next();
    System.err.println(genericName);
  }
  }
  Set<ReferenceIdentifier> ids = crs.getIdentifiers();
  if (ids.isEmpty()) {
    System.err.println("No ids");
  } else {
    for (Iterator iterator = ids.iterator(); iterator.hasNext();) {
      ReferenceIdentifier referenceIdentifier = (ReferenceIdentifier) iterator.next();

      System.err.println("id=" + referenceIdentifier);
    }
  }
  System.err.println(crs.toWKT());
}

for a full(ish) output of:

Set CRS to EPSG:WGS 84 / UTM zone 35S
No Alias
id=EPSG:32735
PROJCS["WGS 84 / UTM zone 35S", 
  GEOGCS["WGS 84", 
    DATUM["World Geodetic System 1984", 
      SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]], 
      AUTHORITY["EPSG","6326"]], 
    PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], 
    UNIT["degree", 0.017453292519943295], 
    AXIS["Geodetic longitude", EAST], 
    AXIS["Geodetic latitude", NORTH], 
    AUTHORITY["EPSG","4326"]], 
  PROJECTION["Transverse_Mercator", AUTHORITY["EPSG","9807"]], 
  PARAMETER["central_meridian", 27.0], 
  PARAMETER["latitude_of_origin", 0.0], 
  PARAMETER["scale_factor", 0.9996], 
  PARAMETER["false_easting", 500000.0], 
  PARAMETER["false_northing", 10000000.0], 
  UNIT["m", 1.0], 
  AXIS["Easting", EAST], 
  AXIS["Northing", NORTH], 
  AUTHORITY["EPSG","32735"]]

It can sometimes be worth going back to the EPSG database so

crs = CRS.decode("EPSG:32735");

or whatever your ReferenceIdentifier was used directly may help.

  • I have a similar block where I read in the file initially, I just can't find the information I need inside the CoordinateReferenceSystem object – jdavison Oct 15 '18 at 14:15
  • can you clarify your question then? – Ian Turton Oct 15 '18 at 14:27
  • I've added my code for loading the TIFF and attempted to clarify the question. – jdavison Oct 15 '18 at 14:33
  • It seems the metadata for my CRS is lacking in detail (see edit above). But the information exists lower down on the conversionFromBase transformation. – jdavison Oct 15 '18 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.