Hi, a problem to do multiple Filter to featureSource : 

void selectFeatures(MapMouseEvent ev) throws CQLException {

        System.out.println("Mouse click at: " + ev.getMapPosition());

    
        Point screenPos = ev.getPoint();
        Rectangle screenRect = new Rectangle(screenPos.x-25, screenPos.y-25, 
50, 50);
      
        AffineTransform screenToWorld = 
mapFrame.getMapPane().getScreenToWorldTransform();
        Rectangle2D worldRect = 
screenToWorld.createTransformedShape(screenRect).getBounds2D();
        ReferencedEnvelope bbox = new ReferencedEnvelope(
                worldRect,
                mapFrame.getMapContent().getCoordinateReferenceSystem());

        Filter filter = ff.bbox(ff.property(geometryAttributeName), bbox);
 
        Filter filter2 = CQL.toFilter("OSTRAHLER='5'");
    
     
        try {

            SimpleFeatureCollection selectedFeatures = 
featureSource.getFeatures(filter+filter2); //HERE ,
            SimpleFeatureIterator iter = selectedFeatures.features();
            Set<FeatureId> IDs = new HashSet<FeatureId>();
            try {
                while (iter.hasNext()) {
                
                    SimpleFeature feature = iter.next();
                    IDs.add(feature.getIdentifier());

                    System.out.println("   " + feature.getIdentifier());
                }

            } finally {
                iter.close();
            }

            if (IDs.isEmpty()) {
                System.out.println("   no feature selected");
            }

            displaySelectedFeatures(IDs);

        } catch (Exception ex) {
            ex.printStackTrace();
            return;
        }
    }

Best Regards,

ptitdje

Date: Thu, 3 May 2012 22:12:54 +1000
From: [email protected]
To: [email protected]
CC: [email protected]
Subject: Re: [Geotools-gt2-users] Geologie France


                
                    I am afraid we have to keep things on the list. If you 
really would like to contact me privately my employer LISAsoft would be happy 
to arrange a support contact with you :-)
                
It seems you are having trouble using a geometry intersects with a literal 
bounding box?
Here are some things to try.
* There is a BBOX function which is a fast version of what you are trying to 
do.* The geometry functions tend to work with geometry; so try converting your 
bounding box to a polygon if you would like to use Intersects.* Finally be very 
very sure that your two geometry are in the same coordinate reference system! 
This is probably the most common mistake when doing this sort of thing. Your 
code example did screen -> world (i.e. map crs). But I am not sure if I saw you 
do world -> data (i.e. data crs).
-- Jody Garnett


                 
                On Wednesday, 2 May 2012 at 7:13 PM, jérémy lacombe wrote:
                
                    



Hi, i got a litle problem but i really don't know why so i prefer don't spam 
the user list and ask before to you :
The problem is i can do a fliter with proprety but the other filter didn't work 
=/



void selectFeatures(MapMouseEvent ev) {

        System.out.println("Mouse click at: " + ev.getMapPosition());

        /*
         * Construct a 5x5 pixel rectangle centred on the mouse click position
         */
        Point screenPos = ev.getPoint();
        Rectangle screenRect = new Rectangle(screenPos.x-2, screenPos.y-2, 
5000, 5000);
        
        /*
         * Transform the screen rectangle into bounding box in the coordinate
         * reference system of our map context. Note: we are using a naive 
method
         * here but GeoTools also offers other, more accurate methods.
         */

        AffineTransform screenToWorld = 
fenMap.getMapPane().getScreenToWorldTransform();
        Rectangle2D worldRect = 
screenToWorld.createTransformedShape(screenRect).getBounds2D();
        ReferencedEnvelope bbox = new ReferencedEnvelope(
                worldRect,
                fenMap.getMapContext().getCoordinateReferenceSystem());







// THE FILTER with CQL WORK PERFECTLY 
        /*
         * Create a Filter to select features that intersect with
         * the bounding box
         */
        Filter filter = null;
        try {
            filter = (Filter) CQL.toFilter("OSTRAHLER='5'");
        } catch (CQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        





 THIS ONE DOESN'T WORK AT ALL
    //Filter filter = (Filter) 
ff.intersects(ff.property(geometryAttributeName), ff.literal(bbox));

        /*
         * Use the filter to identify the selected features
         */




        try {
         SimpleFeatureCollection selectedFeatures =
                    (SimpleFeatureCollection) 
ImportVecteur2.getFeatureSource().getFeatures(filter);

            SimpleFeatureIterator iter = selectedFeatures.features();
            Set<FeatureId> IDs = new HashSet<FeatureId>();
            try {
                while (iter.hasNext()) {
                    SimpleFeature feature = iter.next();
                    IDs.add(feature.getIdentifier());

                    System.out.println("   " + feature.getIdentifier());
                }

            } finally {
                iter.close();
            }

            if (IDs.isEmpty()) {
                System.out.println("   no feature selected");
            }

         //   displaySelectedFeatures(IDs);

        } catch (Exception ex) {
            ex.printStackTrace();
            return;
        }
    }

Date: Mon, 30 Apr 2012 21:49:23 +1000
From: [email protected]
To: [email protected]
CC: [email protected]
Subject: Re: [Geotools-gt2-users] Geologie France


                
                    Opps - please keep discussion on the email list. That way 
more people are able to take part and possibly help you?
                
I think what you may want to do is:
1) Get the geometry for your selected feature
Geometry geom = feature.getDefaultGeometry();
2) Take the centre
Coordiante centre = geom.getCentriod();
3) turn that back into a geometry
Point point = geometryFactory.createPoint( centre );
4) And then …. buffer the point to obtain a Polygon (it will be a circle)
point.buffer( amount )
The tricky part is determining what the amount should be.
Jody
                  
                On Saturday, 28 April 2012 at 11:56 PM, jérémy lacombe wrote:
                    




Good afternoon,


In reality, i just want to select a feature and draw a circle around this 
feature. But, i don't know how to do that. and i just want to have the property 
of the feature selected ^^

Regards ,

ptitdje


Date: Sat, 28 Apr 2012 22:27:12 +1000
From: [email protected]
To: [email protected]
CC: [email protected]
Subject: Re: [Geotools-gt2-users] Geologie France


                
                    The tutorials are written for GeoTools 8.
                - 
http://docs.geotools.org/latest/userguide/tutorial/map/style.html
What is the link to "opensourcejavaphp.net you found? The web is a strange 
place …
You can find the older (i.e. stable) copy of the tutorials here:- 
http://docs.geotools.org/stable/tutorials/
Please keep in mind that "selection" is a concept for your application. 
GeoTools is just providing the ability to work with features; and draw 
features. That selection tutorial focuses on "draw" some features that have 
been considered selected in that example. You may wish to handle the idea of 
selection in the same manner for your application?
Jody
Moving to the small problem I encountered:
-----> I followed the tutorial for display and loading the shapefile. PERFECT = 
D
------> I took a second tutorial (
http://www.opensourcejavaphp.net/java/geotools/org/geotools/demo/SelectionLab.java.html)
 to select one feature at a click on the JMapPane. NOT PERFECT = / Let me 
explain I have a compilation error in this online tutorial:
mapFrame = new JMapFrame (map);


                                                          

                  
                  
                  
                  
                
                    

                                                          

                 
                 
                 
                 
                
                 
                
                    

                                                          
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to