In that case you will ant the first option I outlined:
a) Do you want to add multiple points to an existing layer representing a shape
file? If so please ask the layer for a FeatureStore and call the addFeatures
method
SimpleFeatureStore store =
layer.getResource(SimpleFeatureStore.class, new
SubProgressMonitor(monitor, 1));
store.addFeatures( DataUtilities.collection( feature ) )
There is a geotools tutorial on using features and feature store here:
- http://docs.geotools.org/latest/userguide/tutorial/feature/csv2shp.html
On 06/02/2012, at 6:41 PM, Alberto Debiasi wrote:
I just want to add a single point into a layer, for example every time I click
on a specific button.
Every time I click on the button a point will be created into the layer.
2012/2/6 Jody Garnett <[email protected]<mailto:[email protected]>>
Perhaps we are talking different; it is not that I am withholding code from you
- it is that the request to add multiple resources does not make sense.
Question:
a) Do you want to add multiple points to an existing layer representing a shape
file? If so please ask the layer for a FeatureStore and call the addFeatures
method
-or-
b) do you want to change a layer showing points from a shape file; over to
showing points from a database table? If so you will need to change what
GeoResource the layer is using.
Layer.void setGeoResource( IGeoResource value ) is the method; because it is a
read/write method you will need to call it from a command.
final IGeoResource changeResource = ….
final ILayer layer = ….
layer.getMap().sendCommandAsync( new AbstractCommand(){
public String getName(){ return "Change Resource"; }
public void run(IProgressMonitor monitor){
((Layer)layer).setGeoResource( changeResource );
layer.refresh(null); // trigger redraw
}
});
--
Jody Garnett
On Monday, 6 February 2012 at 6:22 PM, Alberto Debiasi wrote:
For example:
I would like to create a resource Point into an existing layer.
Can you show me the code please?
Alberto
2012/2/6 Jody Garnett <[email protected]<mailto:[email protected]>>
Well you can set the ID on a layer (make your own command for this) or change
what data it refers to; and it should pull a new resource out of the uDig
catalog.
However a layer only does one resource at a time (in order to work with many it
will ask the catalog if it knows any other resources that are associated with
the layer it is displaying).
--
Jody Garnett
On Monday, 6 February 2012 at 6:15 PM, Alberto Debiasi wrote:
Instead of creating a new layer with some resources I would like to add some
resources to an existing layer (without create a new one).
Alberto.
2012/2/6 Jody Garnett <[email protected]<mailto:[email protected]>>
Interesting; I usually just pass the AddLayersCommand with more or more
resources (and watch it create the default styles etc…).
I don't understand your question about "add to an existing layer some
resources". The layer looks up the GeoResource to use in the catalog; using the
Style to aid in drawing etc...
--
Jody Garnett
On Saturday, 4 February 2012 at 3:11 AM, Alberto Debiasi wrote:
Hello everybody,
I use the following code in order to create a new layer with some resources:
.....
try{
IMap map = ApplicationGIS.getActiveMap();
LayerFactory layerFactory = map.getLayerFactory();
Layer layer = layerFactory.createLayer(resource);
AddLayerCommand cmd = new AddLayerCommand(layer);
map.sendCommandASync(cmd);
}catch(Exception e ){
e.printStackTrace();
}
I have a simple question:
How can I add to an existing layer some resources?
Thanks.
Alberto
_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net<http://udig.refractions.net/>
http://lists.refractions.net/mailman/listinfo/udig-devel
_______________________________________________
udig-users mailing list
[email protected]<mailto:[email protected]>
http://lists.refractions.net/mailman/listinfo/udig-users
<ATT00001.c>
_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel