Due to the current gap in continued funding from the U.S. National Science Foundation (NSF), the NSF Unidata Program Center has temporarily paused most operations. See NSF Unidata Pause in Most Operations for details.
Hi Franck: I have a fix for this checked into both 4.5.6 and 6.0. I can build a snapshot release for you if you want. John On Wed, Mar 11, 2015 at 10:40 AM, John Caron <caron@xxxxxxxx> wrote: > Hi Franck: > > yes, its a bug in GeoGrid.makeSubset(). Im working on a fix. > > thanks for the nice unit test, made it easy to find. > > John > > On Wed, Mar 11, 2015 at 6:15 AM, <franck.reinquin@xxxxxxx> wrote: > >> Hello, >> >> I have problems with the findXYindexFromLatLon() method used with a >> Geogrid subset. >> gcs.getLatLon(0,0) gives me lat/long coordinates that I try to convert >> back to XY coordinates. >> But I get -1 for the X coordinate. >> On the original grid, everything is fine. >> >> The attached example reads one of the sample netCDF files from the >> Unidata website. I'm using netcdfAll-4.5.jar dated March, 6 (v 4.5.5). >> >> Does anyone see what I did wrong ? Code and output below. The "start" >> members look strange. >> >> Thanks, >> Franck >> >> ------------------------------ >> *Output :* >> >> Grid name =area >> WHOLE GRID >> is lat/lon system ? true >> gcs bounding box : latmin=-88.927734375 latmax=88.927734375 lonmin=0.0 >> lonmax=358.59375 >> projection : LatLonProjection >> width =256, height=128 >> X is regular ? true >> X is contiguous ? true >> X start : 0.0 >> X increment : 1.40625 >> Y is regular ? false >> Y is contiguous ? true >> Y start : -88.927734375 >> Y increment : 1.4004367618110236 >> index (0,0) --> lat/lon : -88.927734375 ; 0.0 >> index (1,1) --> lat/lon : -87.53870391845703 ; 1.40625 >> looking up lat=-87.53870391845703 lon=1.40625 >> index= (1, 1) >> >> SUBGRID (latmin=-20.0 latmax=-10.0 lonmin=35.0 lonmax=45.0) >> is lat/lon system ? true >> gcs bounding box : latmin=-20.31112289428711 latmax=-10.505756378173828 >> lonmin=35.15625 lonmax=45.0 >> projection : LatLonProjection >> width =8, height=8 >> X is regular ? true >> X is contiguous ? true >> X start : 0.0 >> X increment : 1.40625 >> Y is regular ? false >> Y is contiguous ? true >> Y start : 0.0 >> Y increment : 1.4004367618110236 >> index (0,0) --> lat/lon : -20.31112289428711 ; 35.15625 >> index (1,1) --> lat/lon : -18.910356521606445 ; 36.5625 >> looking up lat=-18.910356521606445 lon=36.5625 >> index= (-1, 1) >> >> ------------------------- >> try { >> GridDataset dataset = GridDataset.open(" >> http://www.unidata.ucar.edu/software/netcdf/examples/sresa1b_ncar_ccsm3_0_run1_200001.nc >> "); >> >> GridDatatype firstGridInfo = dataset.getGrids().get(0); >> >> System.out.println("Grid name ="+firstGridInfo.getName()); >> >> GeoGrid firstGrid = (GeoGrid) dataset.getGrids().get(0); >> >> >> System.out.println("WHOLE GRID"); >> GridCoordSystem gcs = firstGrid.getCoordinateSystem(); >> System.out.println("is lat/lon system ? "+gcs.isLatLon()); >> >> LatLonRect rect = gcs.getLatLonBoundingBox(); >> System.out.println("gcs bounding box : latmin="+rect.getLatMin()+" >> latmax="+rect.getLatMax()+" lonmin="+rect.getLonMin()+" >> lonmax="+rect.getLonMax()); >> System.out.println("projection : "+gcs.getProjection()); >> System.out.println("width ="+gcs.getXHorizAxis().getSize()+", >> height="+gcs.getYHorizAxis().getSize()); >> System.out.println("X is regular ? "+((CoordinateAxis1D) >> gcs.getXHorizAxis()).isRegular()); >> System.out.println("X is contiguous ? >> "+gcs.getXHorizAxis().isContiguous()); >> System.out.println("X start : "+((CoordinateAxis1D) >> gcs.getXHorizAxis()).getStart()) ; >> System.out.println("X increment : "+((CoordinateAxis1D) >> gcs.getXHorizAxis()).getIncrement()) ; >> System.out.println("Y is regular ? "+((CoordinateAxis1D) >> gcs.getYHorizAxis()).isRegular()); >> System.out.println("Y is contiguous ? >> "+gcs.getYHorizAxis().isContiguous()); >> System.out.println("Y start : "+((CoordinateAxis1D) >> gcs.getYHorizAxis()).getStart()) ; >> System.out.println("Y increment : "+((CoordinateAxis1D) >> gcs.getYHorizAxis()).getIncrement()) ; >> >> LatLonPoint p = gcs.getLatLon(0,0); >> System.out.println("index (0,0) --> lat/lon : "+p.getLatitude()+" ; >> "+p.getLongitude()); >> p = gcs.getLatLon(1,1); >> System.out.println("index (1,1) --> lat/lon : "+p.getLatitude()+" ; >> "+p.getLongitude()); >> >> System.out.println("looking up lat="+p.getLatitude()+" >> lon="+p.getLongitude()); >> int[] xy = gcs.findXYindexFromLatLon(p.getLatitude(), p.getLongitude(), >> null); >> System.out.println("index= ("+xy[0]+", "+xy[1]+")"); >> >> >> // >> -------------------------------------------------------------------------- >> double latMin=-20.D, latMax=-10.D, lonMin=35.D, lonMax=45.D ; >> System.out.println("\nSUBGRID (latmin="+latMin+" latmax="+latMax+" >> lonmin="+lonMin+" lonmax="+lonMax+")"); >> >> LatLonRect latLonRect = new LatLonRect( >> new LatLonPointImpl(latMin, lonMin), >> new LatLonPointImpl(latMax, lonMax)) ; >> >> GeoGrid gridSubset = firstGrid.subset(null, null, latLonRect, 0, 1, 1) ; >> >> GridCoordSystem gcs2 = gridSubset.getCoordinateSystem(); >> >> rect = gcs2.getLatLonBoundingBox(); >> System.out.println("is lat/lon system ? "+gcs2.isLatLon()); >> System.out.println("gcs bounding box : latmin="+rect.getLatMin()+" >> latmax="+rect.getLatMax()+" lonmin="+rect.getLonMin()+" >> lonmax="+rect.getLonMax()); >> System.out.println("projection : "+gcs.getProjection()); >> System.out.println("width ="+gcs2.getXHorizAxis().getSize()+", >> height="+gcs2.getYHorizAxis().getSize()); >> System.out.println("X is regular ? "+((CoordinateAxis1D) >> gcs2.getXHorizAxis()).isRegular()); >> System.out.println("X is contiguous ? >> "+gcs2.getXHorizAxis().isContiguous()); >> System.out.println("X start : "+((CoordinateAxis1D) >> gcs2.getXHorizAxis()).getStart()) ; >> System.out.println("X increment : "+((CoordinateAxis1D) >> gcs2.getXHorizAxis()).getIncrement()) ; >> System.out.println("Y is regular ? "+((CoordinateAxis1D) >> gcs2.getYHorizAxis()).isRegular()); >> System.out.println("Y is contiguous ? >> "+gcs2.getYHorizAxis().isContiguous()); >> System.out.println("Y start : "+((CoordinateAxis1D) >> gcs2.getYHorizAxis()).getStart()) ; >> System.out.println("Y increment : "+((CoordinateAxis1D) >> gcs2.getYHorizAxis()).getIncrement()) ; >> >> p = gcs2.getLatLon(0,0); >> System.out.println("index (0,0) --> lat/lon : "+p.getLatitude()+" ; >> "+p.getLongitude()); >> p = gcs2.getLatLon(1,1); >> System.out.println("index (1,1) --> lat/lon : "+p.getLatitude()+" ; >> "+p.getLongitude()); >> >> System.out.println("looking up lat="+p.getLatitude()+" >> lon="+p.getLongitude()); >> xy = gcs2.findXYindexFromLatLon(p.getLatitude(), p.getLongitude(), null); >> System.out.println("index= ("+xy[0]+", "+xy[1]+")"); >> >> } catch (IOException e) { >> // TODO Auto-generated catch block >> e.printStackTrace(); >> } catch (InvalidRangeException e) { >> // TODO Auto-generated catch block >> e.printStackTrace(); >> } >> >> _______________________________________________ >> netcdf-java mailing list >> netcdf-java@xxxxxxxxxxxxxxxx >> For list information or to unsubscribe, visit: >> http://www.unidata.ucar.edu/mailing_lists/ >> > >
netcdf-java
archives: