[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [udig-devel] More question about "Adding images"
|
Hi Magna,
What "should" work is make a
1. IGeoResource from you image
2, Add service to the catalog
3. call ApplicationGIS.addLayerToMap( .... )
That should work.
What is the error you are getting?
Jesse
On 9-Feb-07, at 11:07 AM, Schmitt, Magna (CIP) wrote:
Hello:
I had read the answer of the mail "Adding images" where there were
a few steps to add images (could be used to show the .png file from
a "gridfile")
The point is that i was trying to implement it but without success.
The steps and examples in the mail were the following:
- Create an IGeoResource from your image
- Create a Layer from your IGeoResource
- Add the Layer to the Map
As for the last steps:
Create a layer from the IGeoResource:
IGeoResource pngGeoResource;
ILayer layer = pngGeoResource.resolve(ILayer.class, null);
Obtain the map:
ApplicationGIS.getProjects().get(0).getElements(IMap.class).get(0)
To add the layer to the map:
map.sendCommandASync(new AddLayerCommand(layer) );
I have this method that was working well with former versions of
uDig (addToMap) and i changed some lines (in addToMap_1) to get my
image but i do not know how can I create my IGeoResource from a
FileStringPath and show it in the map editor:
This is the former method:
public static void addToMap(String strOutputFilePath){
File file = new File(strOutputFilePath);
List<IService> imagePng;
try {
imagePng = new ServiceFactoryImpl().aquire(file.toURL());
for( IService service : imagePng ) {
if (service != null) {
if (service.members(null) != null) {
try {
MapFactory.instance().process(null,
service.members(null),false);
break;
} catch (Exception e1) {
System.err.println(e1.getMessage());
}
}
}
}
} catch (MalformedURLException e2) {
e2.printStackTrace();
} catch (IOException e3) {
e3.printStackTrace();
}
}
This is my failed shot:
public static void addToMap_1(String strOutputFilePath){
File file = new File(strOutputFilePah);
List<IService> imagePng = null;
try {
imagePng = new ServiceFactoryImpl().aquire(file.toURL());
IGeoResource pngGeoResource = null;
ILayer layer = pngGeoResource.resolve(ILayer.class, null);
ApplicationGIS.getActiveMap().sendCommandASync(new
AddLayerCommand((Layer) layer));
} catch (MalformedURLException e2) {
e2.printStackTrace();
} catch (IOException e3) {
e3.printStackTrace();
}
}
Why I should do?
Thank you,
Magna
_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel