Greetings Peter, I think what you might be looking for is the SimpleUnit class, which is part of netcdf-java (contained within the udunits module): http://www.unidata.ucar.edu/software/thredds/current/netcdf-java/javadoc/ You can use this class to see if units are compatible (i.e. can be converted between each other), as well as find the appropriate multiplication factor to do the conversion. So, programmatically, you can check to see if the unit supplied by the user is compatible with, say, kilometers, and then convert those values to kilometers if it is not already in that unit. For an example of checking the compatibility of units and applying the scale, check out the MultiTrajectoryObsDataset class: https://github.com/Unidata/thredds/blob/6a96808b6a67b544dc88039f639adbfb3abdb07b/cdm/src/main/java/ucar/nc2/dt/trajectory/MultiTrajectoryObsDataset.java specifically the getMetersConversionFactor method and the unit checks in the setTrajectoryInfo method. Let me know if that helps! Cheers, Sean > Hi all, > > I've been working on using the Java NetCDF CDM classes for projections > to retrieve and use grid mappings from CF-compliant netCDF files. > So far I've not been able to find in the documentation or email > archives a solution to this question - how can I detect what units > the projection system coordinates (x, y) are in? The reason I'd > like to know this is that I'd like to have sub-pixel accuracy in my > (lat,lon) <-> (row,column) calculations, and so rather than using > GridCoordSystem.findXYindexFromLatLon() and GridCoordSystem.getLatLon(), > I'd like to use this method: > > GridCoordSystem coordSystem = gridset.getGeoCoordSystem(); > Projection proj = coordSystem.getProjection(); > CoordinateAxis xAxis1D = (CoordinateAxis1D) coordSystem.getXHorizAxis(); > CoordinateAxis yAxis1D = (CoordinateAxis1D) coordSystem.getYHorizAxis(); > double column = 500.25; > double row = 500.25; > double x = xAxis1D.getStart() + column*xAxis1D.getIncrement(); > double y = yAxis1D.getStart() + row*yAxis1D.getIncrement(); > > ProjectionPoint projPoint = new ProjectionPointImpl (x, y); > LatLonPointImpl latLonPoint = new LatLonPointImpl(); > proj.projToLatLon (projPoint, latLonPoint); > > and in reverse to map (lat,lon) back to (row, column). But the issue > that I'm having is that in my case, the user may decide to write the > netCDF file with different units for the X and Y axes than is used by > the projection calculations. I've been testing with a geostationary > projection, and from what I can tell if the user decides to write the X > and Y axes using units of degrees, and the projection coordinates used by > the ucar.unidata.geoloc.projection.sat.Geostationary class are in radians, > then I need to know this so I can perform the conversion or else the > calculation isn't correct. The same goes for when the projection class > uses kilometers versus meters. I'd like to have a generic way to ask > a projection system what units it's using for projection coordinates, > but I can't find this in the API. Is there a way to do this? > > I've tried to understand what the CDM is doing from this document: > > http://www.unidata.ucar.edu/software/thredds/current/netcdf-java/reference/StandardCoordinateTransforms.html > > But I think there's a contradiction between the statement: > > "The defaullt unit is km, but any units that can be converted to > km can be used." > > and the statement: > > "in order for CF Horizontal transforms to work in the CDM, you > must [...] define x and y projection coordinate > variables, using the correct projection units, typically km on > the projection plane." > > Peter > -- > Peter Hollemans <address@hidden>, Terrenus Earth Sciences > Web: http://www.terrenus.ca Phone: +1 (778) 533-2896 > > Ticket Details =================== Ticket ID: DCA-797800 Department: Support netCDF Java Priority: Normal Status: Open
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.