Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: UDIG 1.2.0, UDIG 1.2.1, UDIG 1.2.2
-
Fix Version/s: None
-
Component/s: catalog, metadata and search
-
Labels:None
-
Environment:Windows XP, uDig 1.2, geotools 2.6.5
Description
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 )
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)
// 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 )
} 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)
// 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)
//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)
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.
Activity
| Field | Original Value | New Value |
|---|---|---|
| Assignee | Andrea Antonello [ moovida ] |