Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[udig-devel] Example of simple pick tool does not seem to work

> Hello,
> 
> I've tried the example of the simple pick tool (uDIG 1.1, RC 14). But clicking on a country in a map showing the countries shape file, there is no element in the resulting feature collection (variable featureCollection down below). Omitting the bounding box filter gets a list of all countries (as expected).
> What's going wrong?
> 
> Regards and many thanks in advance,
>     Dirk
> 
> 
> 
>   @Override
>   protected void onMouseReleased(MapMouseEvent mouseEvent) {
>     try {
>       // convert the mouse click into map coordinates. This is the CRS obtained from the
>       // ViewportModel
>       IToolContext toolContext = getContext();
>       Coordinate worldCoordinate = toolContext.pixelToWorld(mouseEvent.x, mouseEvent.y);
> 
>       // now we must transform the coordinate to the CRS of the layer
>       ILayer selectedLayer = toolContext.getSelectedLayer();
>       MathTransform mapToLayerTransform = selectedLayer.mapToLayerTransform();
> 
>       double[] from = { worldCoordinate.x, worldCoordinate.y };
>       double[] to = new double[2];
>       mapToLayerTransform.transform(from, 0, to, 0, 1);
> 
>       // Construct a envelope from the transformed coordinate
>       Coordinate coordinate = new Coordinate(to[0], to[1]);
>       Envelope env = new Envelope(coordinate);
> 
>       // Query the feature source to get the features that intersect with that coordinate
>       ProgressManager progressManager = ProgressManager.instance();
>       IProgressMonitor progressMonitor = progressManager.get();
>       FeatureSource source = selectedLayer.getResource(FeatureSource.class, progressMonitor);
>       Filter bBoxFilter = selectedLayer.createBBoxFilter(env, progressMonitor);
>       FeatureCollection featureCollection = source.getFeatures(bBoxFilter);
>       // FeatureCollection featureCollection = source.getFeatures();
> 
>       // do something with the features...
>       StrBuilder featureInfos = new StrBuilder(200);
>       FeatureIterator iterator = featureCollection.features();
>       try {
>         while (iterator.hasNext()) {
>           Feature feature = iterator.next();
>           featureInfos.append(feature.getID());
>           featureInfos.append(": ");
>           featureInfos.append(feature);
>         }
>       }
>       finally {
>         featureCollection.close(iterator);
>       }
> 
>       Display currentDisplay = Display.getCurrent();
>       Shell activeShell = currentDisplay.getActiveShell();
>       MessageDialog.openInformation(activeShell, "My Data", featureInfos.toString());
>     }
>     catch (Throwable t) {
>       // do something smart, notify user probably.
>     }
>   }
> 


Back to the top