Re: [netcdf-java] Problem with findXYindexFromLatLon() on a Geogrid subset

  • To: 'Sean Arms' <sarms@xxxxxxxx>
  • Subject: Re: [netcdf-java] Problem with findXYindexFromLatLon() on a Geogrid subset
  • From: Reinquin Franck <Franck.Reinquin@xxxxxxx>
  • Date: Wed, 18 Mar 2015 06:58:09 +0000
Actually this exactly the same problem !

I was apparently unable last week to subscribe to the mailing list with my 
professional e-mail address so I posted again with a new one I created for that 
purpose.

For an unknown reason (at least for me !) the first post seems now to have 
reached the mailing list. Please disregard it !

Thanks again,
Franck

From: Sean Arms [mailto:sarms@xxxxxxxx]
Sent: Tuesday, March 17, 2015 6:26 PM
To: Reinquin Franck
Cc: netcdf-java@xxxxxxxxxxxxxxxx
Subject: Re: [netcdf-java] Problem with findXYindexFromLatLon() on a Geogrid 
subset

Greetings Franck,

This seems very similar to the issue you wrote about last week, correct? Except 
this time instead of the X coordinate being -1, now it is the Y coordinate? In 
the example output you attached to your message, the X coordinate is still 
being listed as -1.

I was able to use a snapshot of version 4.5.6, and both the x and y coordinates 
are correctly returned. Would you like a snapshot netCDF-All jar file for 4.5.6?

Cheers!

Sean


On Mon, Mar 9, 2015 at 10:37 AM, Franck Reinquin 
<franck.reinquin@xxxxxxxxxxxxxx<mailto:franck.reinquin@xxxxxxxxxxxxxx>> 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 Y coordinate.
On the original grid, everything is fine.

I use one of the sample netCDF files from the Unidata website. I'm using 
netcdfAll-4.5.jar dated March, 6. I guess it is  the 4.5.5 version.

Does anyone see what I did wrong ? Code and output below. The "start" members 
look strange.

Thanks,
Franck

------------------------------
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();
}
--
Franck Reinquin 
<franck.reinquin@xxxxxxxxxxxxxx<mailto:franck.reinquin@xxxxxxxxxxxxxx>>


_______________________________________________
netcdf-java mailing list
netcdf-java@xxxxxxxxxxxxxxxx<mailto:netcdf-java@xxxxxxxxxxxxxxxx>
For list information or to unsubscribe, visit: 
http://www.unidata.ucar.edu/mailing_lists/

  • 2015 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: