Hello,

I am currently working with uDig, but I think I have a problem that is
specific to geotools. I am using uDig 1.2rc3 (geotools 2.6.4).

I am trying to get an elevation from a geotiff DEM at a specific point (for
testing purposes near the centre of the DEM). I am using the
GridCoverage2d.evaluate() method, which is always returning 0.0. The result
is the same if using the GEOPHYSICS or RENDERED view of the grid coverage.

Through debugging I have found that when evaluate runs (specifically the
public double[] evaluate(final Point2D coord, final double[] dest) method),
the x,y pixel coordinates used to look-up the data in the PlanarImage are
fx=0.44, fy=0.33 (these are then rounded to 0,0).

Note, the envelope for my DEM is:
GeneralEnvelope[(273760.4557496691, 5445509.296057798), (289375.7395284029,
5462637.042798709)]

and the point I am trying to evaluate is (288500.0, 5447900.0)

My CRS is NAD 83, UTM zone 10

The reason my UTM coordinates are being transformed to 0.44,0.33 pixel
coordinates appears to be because the grid's PlanarImage only has a width
and height of 1. I have no idea why this is, since the source geotiff has a
width of 986 pixels and a height of 715 pixels (note however that the
PlanarImage tileHeight is 986 and the tileWidth is 8).

Some of the code I am using is below.

Does anyone have any suggestion for why this is happening?

Thank you,
Rueben Schulz



//Get gridCoverage from uDig catalog
URL url = new URL("file:/<path to DEM>/Tofino_dem.tif");

List<IGeoResource> dataHandles = new ArrayList<IGeoResource>();
ICatalog catalog = CatalogPlugin.getDefault().getLocalCatalog();
IServiceFactory factory = CatalogPlugin.getDefault().getServiceFactory();


List<IService> services = factory.createService(url);
for (IService service : services) {
    IServiceInfo info = service.getInfo(new NullProgressMonitor());
    if (info == null) {
        continue; // could not connect
    }
    catalog.add(service);
    List<? extends IGeoResource> resources = service.resources(new
NullProgressMonitor());
    for (IGeoResource resource : resources) {
          dataHandles.add(resource);
    }
}

GridCoverage dem = dataHandles.get(0).resolve(GridCoverage.class, new
NullProgressMonitor());

// get the elevation for a specific point
double[] elev = null;

DirectPosition pt = new
DirectPosition2D(dem.getCoordinateReferenceSystem(),288500.0, 5447900.0);
elev = dem.evaluate(pt, elev);
System.out.println("Elev for first point. Length:  " + elev.length);
for (double data : elev) {
   System.out.println("    " + data);
}

GridCoverage2D dem2 = (GridCoverage2D) dem;

elev = null;
GridCoverage2D dem3 = dem2.view(ViewType.GEOPHYSICS);
elev = dem3.evaluate(pt, elev);
System.out.println("Elev for first point. GEOPHYSICS Length:  " +
elev.length);

for (double data : elev) {
    System.out.println("    " + data);
}




------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to