Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[udig-devel] [jira] Created: (UDIG-1730) GridCoverage2D evaluate method does not work with grid coverage from uDig catalog

GridCoverage2D evaluate method does not work with grid coverage from uDig catalog
---------------------------------------------------------------------------------

                 Key: UDIG-1730
                 URL: http://jira.codehaus.org/browse/UDIG-1730
             Project: uDIG
          Issue Type: Bug
          Components: catalog, metadata and search
    Affects Versions: UDIG 1.2.0, UDIG 1.2.1, UDIG 1.2.x
         Environment: Windows XP, uDig 1.2, geotools 2.6.5
            Reporter: Rueben Schulz


The GridCoverage2D.evaluate() method does not perform as expected when used to get a value from a DEM, if the grid coverage was obtained from the uDig catalog.

The following code works as expected:

URL url = new URL("file:/pathToFile/Tofino_dem.tif");
			
GeoTiffReader geoTiffReader = new GeoTiffReader(url);
GridCoverage2D coverage = geoTiffReader.read(null);
GridCoverage2D readCoverage = coverage.view(ViewType.GEOPHYSICS);

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


However, this fails (does not perform as expected) if the DEM is obtained from the uDig catalog as in the following code:

URL url = new URL("file:/pathToFile/Tofino_dem.tif");
			
//Open up the DEM

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

//see if it is already in the catalog
List<IService> handles = catalog.find(IService.class, url, new NullProgressMonitor());
IService handle = null;
if (handles != null) {
    for( IService iService : handles ) {
          IServiceInfo info = iService.getInfo(new NullProgressMonitor());
          if (info != null) {
              handle = iService;
              break;
          }
          // could not connect try next
    }
}
  
if (handle != null) {
    System.out.println("DEM in catalog");
    // connected okay add all resources
    List<? extends IGeoResource> resources = handle.resources(new NullProgressMonitor());
    for( IGeoResource resource : resources ) {
        dataHandles.add(resource);
    }
    
} else {
    System.out.println("service for DEM being created");
   
    List<IService> services = factory.createService(url);

    //System.out.println("services size: " + services.size());
    for (IService service : services) {
      //System.out.println("  Service created");
      IServiceInfo info = service.getInfo(new NullProgressMonitor());
      if (info == null) {
        continue; // could not connect
      }
      // connected okay add all resources
      catalog.add(service);
      List<? extends IGeoResource> resources = service.resources(new NullProgressMonitor());

      for (IGeoResource resource : resources) {
        dataHandles.add(resource);
      }
    }
}
	        
//Get the first grid coverage (both geoTiff and worldImage created)
//

GridCoverage dem = null;
for (IGeoResource gr : dataHandles) {
    //IGeoResource gr = dataHandles.get(0);

    System.out.println("DEM geoResource: " + gr.toString());
    System.out.println("Title: " + gr.getTitle());
    dem =  gr.resolve(GridCoverage.class, new NullProgressMonitor());
    System.out.println("Envelope: " + dem.getEnvelope().toString());
    System.out.println("CRS: " + dem.getCoordinateReferenceSystem().toString());
    System.out.println("");
}

//Just get the first one for now (usually geoTiff)
dem = dataHandles.get(0).resolve(GridCoverage.class, new NullProgressMonitor());

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;
Set<ViewType> views = dem2.getViewTypes();
for (ViewType v : views) {
    System.out.println("Available View: " + v.toString());
}

//try the geophysics grid.

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);
}


Note, the DEM being used in this test has already been sent to Andrea.


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


Back to the top