Thanks your code helped me a lot !
Didn't you mixed up X and Y in the ReferencedEnveloppe ?
I changed a little bit your code and here is mine :
(Points also change their color when they are selected, thanks to a new
maplayer...)
*public* *void* mouseClicked(MouseEvent ev) {
*if*(carto.mappane.getState() == JMapPane.*Select*) {
FeatureCollection features;
*try* {
features = carto.maplayer1.getFeatureSource().getFeatures();
FeatureIterator featuresIte = features.features();
FeatureCollection featureSel = FeatureCollections.*newCollection*();
//
JMapPane map = carto.mappane;
map.setSelectionLayer(carto.maplayer1);
Rectangle bounds = map.getBounds();
*double* x = (*double*) (ev.getX());
*double* y = (*double*) (ev.getY());
Envelope mapArea = map.getMapArea();
*double* width = mapArea.getWidth();
*double* height = mapArea.getHeight();
*double* mapX_min = (((x - 1) * width) / (*double*) bounds.width)
+ mapArea.getMinX();
*double* mapY_min = (((bounds.getHeight() - (y + 1)) * height) / (*double*)
bounds.height)
+ mapArea.getMinY();
*double* mapX_max = (((x + 1) * width) / (*double*) bounds.width)
+ mapArea.getMinX();
*double* mapY_max = (((bounds.getHeight() - (y - 1)) * height) / (*double*)
bounds.height)
+ mapArea.getMinY();
CoordinateReferenceSystem selectedCRS = CRS.*decode*("EPSG:27572");
ReferencedEnvelope selected = *new* ReferencedEnvelope(
mapX_min, mapX_max, mapY_min, mapY_max, selectedCRS);
System.*out*.println(selected);
selected.expandBy(20);
*FilterFactory* ff = *FilterFactoryFinder.createFilterFactory()*;
*Expression* bbox = *ff.createBBoxExpression( selected )*;
*GeometryFilter* bboxFilter = *ff.createGeometryFilter(GeometryFilter.
GEOMETRY_BBOX)*;
*bboxFilter.addRightGeometry( bbox )*;
*while* (featuresIte.hasNext()) {
Feature oneFeature = featuresIte.next();
*if* (*bboxFilter.contains(oneFeature)*) {
carto.mapcontext.removeLayer(carto.maplayer3);
StyleBuilder sb = *new* StyleBuilder();
Mark redCross = sb.createMark(StyleBuilder.*MARK_CROSS*, Color.*YELLOW*,
Color.*BLACK*, 0.8);
Graphic graph = sb.createGraphic(*null*, redCross, *null*);
PointSymbolizer pt2 = sb.createPointSymbolizer(graph);
Style ptStyle = sb.createStyle();
ptStyle.addFeatureTypeStyle(sb.createFeatureTypeStyle(pt2));
Style solstyle = sb.createStyle();
solstyle.addFeatureTypeStyle(sb.createFeatureTypeStyle(pt2));
featureSel.add(oneFeature);
carto.maplayer3 = *new* DefaultMapLayer(featureSel, solstyle);
carto.mapcontext.addLayer(carto.maplayer3);
}
}
featuresIte.close();
} *catch* (IOException e) {
// *TODO* Auto-generated catch block
e.printStackTrace();
} *catch* (MismatchedDimensionException e1) {
// *TODO* Auto-generated catch block
e1.printStackTrace();
} *catch* (NoSuchAuthorityCodeException e) {
// *TODO* Auto-generated catch block
e.printStackTrace();
} *catch* (FactoryException e) {
// *TODO* Auto-generated catch block
e.printStackTrace();
}
}
*if*(carto.mappane.getState() == JMapPane.*ZoomIn*) {
carto.getEnveloppe();
}
}
2008/8/7, VASkO-4 <[EMAIL PROTECTED]>:
>
>
> >Jody wrote:
> >There are some examples of making a Filter for a BBOX query; usually you
> >make abounding box the size of the pixel and perform a query that way.
> >-
> >
> http://docs.codehaus.org/display/GEOTDOC/Filter+Examples#FilterExamples-WhatdidIclickon
> I'd like to mention, those examples need a little bit of checking and
> refreshing. I did a bbox filter with a help from the examples:
>
> JMapPane map = view.getMap();
>
> map.setSelectionLayer(context.getLayer(3));
> Rectangle bounds = map.getBounds();
> double x = (double) (aE.getX());
> double y = (double) (aE.getY());
> Envelope mapArea = map.getMapArea();
> double width = mapArea.getWidth();
> double height = mapArea.getHeight();
> double mapX_min = (((x - 1) * width)
> / (double) bounds.width)
> + mapArea.getMinX();
> double mapY_min =
> (((bounds.getHeight() - (y + 1)) * height) / (double)
> bounds.height)
> + mapArea.getMinY();
> double mapX_max = (((x + 1) * width)
> / (double) bounds.width)
> + mapArea.getMinX();
> double mapY_max =
> (((bounds.getHeight() - (y - 1)) * height) / (double)
> bounds.height)
> + mapArea.getMinY();
>
> CoordinateReferenceSystem
> selectedCRS = null;
>
> try {
> selectedCRS =
> CRS.parseWKT(wkt1);
> } catch (FactoryException fe) {
> System.err.println("Napaka
> pri izdelavi projekcije");
> fe.printStackTrace();
> }
> ReferencedEnvelope selected = new
> ReferencedEnvelope(
> mapX_min, mapY_min,
> mapX_max, mapY_max, selectedCRS);
> FilterFactory2 ff =
> CommonFactoryFinder
>
> .getFilterFactory2(GeoTools.getDefaultHints());
> Filter filter =
> ff.bbox(ff.property("the_geom"), selected);
>
> Iterator<SimpleFeature> iterator =
> fCvozniRed.iterator();
> try {
> while (iterator.hasNext()) {
> SimpleFeature
> vozniRed = iterator.next();
> if
> (filter.evaluate(vozniRed)) {
>
> System.out.println(vozniRed.getID()
>
> + " was selected");
> }
> }
> } finally {
> fCvozniRed.close(iterator);
> }
>
>
> >Okay; usually we make one postgis table for all the schedules; and then
> >do one of those queries to see what is clicked on. In uDig when we have
> >many layers and the user clicks we have two ways to handle the situation:
> >- perform the BBOX query against the "selected" layer ... this does not
> >match you use case
> >- perofrm the BBOX query against all the layers and give the user of all
> >the results to choose from (this is what we do for our info tool).
> >
> >I am not too sure about the layer interface; when you make a layer using
> >a collection to actually wraps the thing up in a MemoryDataStore using a
> >DataUtilities method if I remember. You can ask the layer for the
> >FeatureSource in order to make queries against this MemoryDataStore.
> I changed the code as suggested. All schedules into one FeatureCollection
> and iterate through them. Now I'll try to set a different color style to
> the
> selected feature by adding it to a different layer. Or is there any way to
> set styles directly to a feature?
>
> >But if you keep your feature collection around you can always go through
> >the content yourself and use filter.evaulate( feature ) one at a time to
> Thanks! It would take much time to dig through the API docs and find that
> usefull method.
>
> >Note you can create a Style that does this; have a Rule for each
> >feature; not very fun but you can do it...
> >Jody
> I forgot to mention, I allready had that part coded and working.
>
>
> --
> View this message in context:
> http://www.nabble.com/ways-to-get-Features-with-click-tp18799656p18866778.html
> Sent from the geotools-gt2-users mailing list archive at Nabble.com.
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
--
Marie LAMBOIS
Ecole Nationale des Sciences Géographiques
Spécialité : Informatique appliquée aux Systèmes de l'Information
Géographique
[EMAIL PROTECTED]
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users