Hi all,
I'm starting to study uDig possibilities and achieve to do manythings now
(create new layer, add features to a layer,...) programatically. My next
step is to edit a feature after selected it on screen but I'm unable to
select one.
I've tested the PickTool code from uDig examples but got no result.
I've traced results with some println.. The coordinates are good, and I do
have the number of features count but nothing is selected.
This is the code taken from uDig examples and the println I added to see if
datas are ok.
Help would be welcome.
@Override
protected void onMouseReleased( MapMouseEvent e ) {
try{
// convert the mouse click into map coordinates. This is
the
// CRS obtained from the ViewportModel
Coordinate world = getContext().pixelToWorld(e.x, e.y);
// now we must transform the coordinate to the CRS of the
layer
ILayer layer = getContext().getSelectedLayer();
MathTransform tranform = layer.mapToLayerTransform();
double[] from=new double[]{world.x, world.y};
double[] to = new double[2];
tranform.transform(from, 0, to, 0, 1);
//I check if coordinates are ok
System.out.println(to[0]);
System.out.println(to[1]);
// Construct a envelope from the transformed coordinate
Envelope env = new Envelope(new Coordinate(to[0],to[1]));
// Query the feature source to get the features that
intersect with that coordinate
FeatureSource source =
layer.getResource(FeatureSource.class, ProgressManager.instance().get());
FeatureCollection featuresFiltre =
source.getFeatures(layer.createBBoxFilter(env,
ProgressManager.instance().get()));
FeatureCollection features = source.getFeatures();
//show the number of features on the layer and the selected features
System.out.println("Selected features on Layer : "+features.size());
System.out.println("Selected features : "+featuresFiltre.size());
// do something smart, notify user probably.
} catch (Throwable t) {
System.out.println("Nothing !!!");
}
_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel