Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[udig-devel] Polygons drawn with PolygonTool not in my FeatureStore...

One wish of my users is to get a 'geo referenced' search. (don't know if
it's the correct english word)

They want to draw a polygon on the map, click on a search button, enter
some additional restrictions for the query and finally send the query. As
result they want the elements shown in the map.

I will use a dedicated polygon layer for that. The user can draw the
polygon with the PolygonTool. To prevent queries with more than one polygon
the layer shll just store one feature/polygon. If the user draws a polygon
the old one will be removed.

What's the best way to realize this?
I tried it this way but failed:

// Featuretypebuilder, Ressource,....
// finally I have the layer :

    final Layer l = layer;
    l.addListener(new ILayerListener(){
     public void refresh(LayerEvent event) {
      // debug print
      System.out.println(event.getType().name());
      if (event.getType()== EventType.EDIT_EVENT){
       try {
        FeatureStore fs = l.getGeoResource().resolve(FeatureStore.class,
        null);
        FeatureIterator fI = fs.getFeatures().features();
        List<Feature> featureList = new ArrayList<Feature>();
        while (fI.hasNext()){
         featureList.add(fI.next());
        }
        if (featureList.size() > 1){
         // remove all features
         fs.removeFeatures(Filter.NONE);
         // add the last one
         fs.addFeatures(DataUtilities.collection(new
         Feature[]{featureList.get(featureList.size()-1)}));
         l.refresh(null);
        }
       } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
       }
      }
     }
    });


Even I draw a some polygons and see them in my application ths featureList
is empty. The event is thrown and the layerListener activated and the
FeatureStroe is not null.

What's wrong in my code? Or a bad approach? Has someone a better idea to
realize this functionality?

Thank you,
tony roth

still using 1.1RC8 :)



Back to the top