[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[udig-devel] WG: Example of simple pick tool does not seem to work
|
Hello again,
I found out that building an Envelope containing two slightly different coordinates gets me a Feature. I already tried other filters than the bounding box filter, but they did not get a result either.
For now I used the Jakarta commons-math library to build the second coordinate with MathUtils.nextAfter, but that seems to me a little clumsy.
Is there a better solution?
Thanks in advance.
Best Regards,
Dirk
> -----Ursprüngliche Nachricht-----
> Von: Starke, Dirk
> Gesendet: Dienstag, 15. April 2008 21:02
> An: 'udig-devel@xxxxxxxxxxxxxxxxxxxxx'
> Betreff: 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.
> }
> }
>