[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
| Re: [udig-devel] Feature Selection using example | 
Hi Peter,
As I expect you know the function Layer#getFilter() returns the  
filter that represents the current selection for the layer.  If it is  
returning Filter.ALL that means no features are selected.  Try  
selecting something with the selection tool and then run your  
operation.  It should return some features.  As an experiment pass in  
a different filter to the line:
Query query = new DefaultQuery(layer.getSchema().getTypeName(),
layer.getFilter(),new String[]{"the_geom"});
a Filter.NONE perhaps.  This will verify that the code works.  If you  
are selecting features using a command then you must keep in mind  
that commands are run in a separate thread and in that case the  
layer's filter may not have been updated by the time this code has  
ran.  If you are using commands to set the selection then you can use  
map.#sendCommandSync().
Hope one of these tips help,
Jesse
On 25-Jan-07, at 8:02 AM, ukpete wrote:
Hello all,
Having a problem using the example (taken from this glorious list)  
returning
a collection of features
for the current layer.  Basically it always returns a collection of  
size 0.
Here is the method I'm using :
public FeatureCollection getFeaturesSelectedOnLayer ()
	{
		net.refractions.udig.project.internal.Map currentMap =
ApplicationGISInternal.getActiveMap();
		Layer layer = currentMap.getEditManagerInternal().getSelectedLayer 
();
		Query query = new DefaultQuery(layer.getSchema().getTypeName(),
layer.getFilter(),new String[]{"the_geom"});
		FeatureIterator featureIterator = null;
		FeatureCollection features = null;
		try{
	        IProgressMonitor monitor = new NullProgressMonitor();
	        FeatureSource featureSource =
layer.getResource(FeatureSource.class, monitor);
	        features = featureSource.getFeatures(query);
	        featureIterator = features.features();
	        aLogger.info("features selected are : " + features.size()  
+ "type
name is " + layer.getSchema().getTypeName() + "..is selectable? " +
layer.isSelectable());
	        while(featureIterator.hasNext() )
		    {
	        	Feature feature = featureIterator.next();
		        aLogger.info("Feature selected is : " +
feature.getAttribute("the_geom").toString());
		
		    }
		}
        catch (Exception e)
        {
        	e.printStackTrace();
        }
        finally
        {
        	if (featureIterator != null)
        	{
        		featureIterator.close();
        	}
        }
        return features;
	}
If I just call the getFeatures() method - without the query, all the
features on that layer are returned correctly.  Any idea what I am  
doing
wrong?
Thanks again for taking the time to read this.
Pete Cornwell
--
View this message in context: http://www.nabble.com/Feature- 
Selection-using-example-tf3116329.html#a8632047
Sent from the udig-devel mailing list archive at Nabble.com.
_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel