I'm working with tiff files from the National Elevation Dataset and have run 
into some problems. Each file represents a tile, and I need to be able to 
evaluate points within those tiles to get the elevation at specific points.

// Point that is definitely in the tif file below
double x = -73.919996;
double y = 40.865797;
        
File path = new 
File("/Users/nicholasbs/dev/graph-data/ny/ned_tifs/ned--73.92_-73.76_40.959999999999994_40.8.tif");
GeoTiffFormat tifFormat = new GeoTiffFormat();
GeoTiffReader tifReader = (GeoTiffReader) tifFormat.getReader(path);
GridCoverage2D coverage = (GridCoverage2D) tifReader.read(null);
coverage = Interpolator2D.create(coverage, new InterpolationBilinear());

double[] result = new double[1];
DirectPosition2D pos = new DirectPosition2D(x,y);
try {
    result = coverage.evaluate((DirectPosition)pos, result);
     System.out.println(result[0]); // *should* print 7.120205980059255
} catch (PointOutsideCoverageException e) {
      System.out.println("point not found"); // what is exactly printed
}
        
This works great except for when you query for a point that falls on one of the 
pixels directly on the edge the tiff. The outermost pixels aren't considered to 
be inside the region. Pictures make this much clearer: 
http://opentripplanner.org/attachment/ticket/163/bad_points.png and 
http://opentripplanner.org/attachment/ticket/163/bad_points_zoom.png. The 
markers represent the points that threw a PointOutsideCoverageException.

Next, I tried creating an ImageMosaic as follows:

GridCoverage coverage2 = null;
ImageMosaicFormatFactory formatFactory = new ImageMosaicFormatFactory();
ImageMosaicFormat format = (ImageMosaicFormat) formatFactory.createFormat();
ImageMosaicReader reader = (ImageMosaicReader) format.getReader(
          "/Users/nicholasbs/dev/graph-data/ny/ned_test", null);
coverage2 = reader.read(new GeneralParameterValue[] {});
coverage2 = Interpolator2D.create((GridCoverage2D) coverage2, new 
InterpolationBilinear());

double[] result2 = new double[1];
coverage2.evaluate(new DirectPosition2D(x, y), result2);
        
System.out.println(result2[0]); // gt 2.5.7 prints  7.120205980059255; gt 2.6.3 
prints 0.0
                
This works with GeoTools 2.5.7, however, it is painfully slow. It takes nearly 
2.5 hours to process just my test region (for comparison, the approach above 
takes less than a minute). Each call to evaluate() takes about 400ms.

I tried upgrading to GeoTools 2.6.3. This runs about 100x faster, however, 
evaluate() returns 0.0. for *all* points, so either I'm misusing something or 
there's a bug in 2.6.3.

Any idea what's going on here and/or what I should try next?

Thanks in advance,
  -Nick
  

------------------------------------------------------------------------------
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to