Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[udig-devel] How to add GeoTiff from code

Hi,

I have a geotiff file that I can drag and drop into uDig with no problems.  I'm trying to add this same file from code, and can't quite figure out how to do it.

I've tried two ways, neither with success:

First (try/catch ommitted for readability)

GeoTiffFormat format = new GeoTiffFormat();
GeoTiffReader geoReader = new GeoTiffReader(rasterFile);
GridCoverage2D gc = (GridCoverage2D) geoReader.read(null);
Style style = getStyle();  // method to return a style
new DefaultMapContext().addLayer( gc , style );

This doesn't seem to do anything in the ui - I think b/c it's not working on the MapContext for my active map - but I can't figure out how to get access to that MapContext.

Second approach:

GeoTiffServiceImpl gtsi = new GeoTiffServiceImpl(uri.toURL(), new GeoTiffFormatFactorySpi());
GeoTiffGeoResourceImpl gtiffgeo = new GeoTiffGeoResourceImpl(gtsi, "Data"); // igeoresource
List <IGeoResource> geoResourceList = new LinkedList<IGeoResource>();
geoResourceList.add(gtiffgeo);
ApplicationGIS.addLayersToMap(ApplicationGIS.getActiveMap(), geoResourceList, -1);

In this case, a layer is added, but it says that no CRS is found.  I don't see where to set it, and going into the properties dialog from the layer in the layers view and setting it doesn't make it display anyway.

===============

Can anyone point me to an example or spot what I've done wrong?  Seems like it should be doable since I can use drag and drop to insert it, I'm just at a dead end as for how to do it.

Oh,this is all in the 1.2 release and associated SDK.

Thanks for any help,

- Ned





Back to the top