Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

UDIG-1764 ZoomSelection had wrong extend if FeatureCollection was emp…

…ty for Filter
  • Loading branch information...
commit c7dddbf3e11668c5bec9ab3fd01f1f88c92fc5ad 1 parent b4dd988
@fgdrf fgdrf authored
View
35 plugins/net.refractions.udig.tool.select/src/net/refractions/udig/tool/select/internal/ZoomSelection.java
@@ -25,7 +25,10 @@
import org.geotools.data.Query;
import org.geotools.data.simple.SimpleFeatureSource;
+import org.geotools.feature.FeatureCollection;
import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
/**
* Sets the ViewportModel bounds to equal the bounds of the selected features
@@ -49,20 +52,26 @@ public void run() {
Query query = layer.getQuery(true);
ReferencedEnvelope bounds = resource.getBounds(query);
if (bounds == null) {
- ReferencedEnvelope envelope = resource.getFeatures(query).getBounds();
- if (envelope != null) {
- bounds = new ReferencedEnvelope(envelope, layer.getCRS());
- }
+ FeatureCollection<SimpleFeatureType, SimpleFeature> featureResult = resource.getFeatures(query);
+ if (featureResult != null && !featureResult.isEmpty()) {
+ ReferencedEnvelope envelope = featureResult.getBounds();
+ if (envelope != null) {
+ bounds = new ReferencedEnvelope(envelope, layer.getCRS());
+ }
+ }
}
- // If the selection is a single point the bounds will
- // have height == 0 and width == 0. This will break
- // in ScaleUtils:306. Adding 1 to the extent fixes the problem:
- if (bounds.getHeight() <= 0 || bounds.getWidth() <= 0) {
- bounds.expandBy(1);
- }
- bounds = ScaleUtils.fitToMinAndMax(bounds, layer);
-
- getContext().sendASyncCommand(new SetViewportBBoxCommand(bounds, layer.getCRS()));
+
+ if (bounds != null) {
+ // If the selection is a single point the bounds will
+ // have height == 0 and width == 0. This will break
+ // in ScaleUtils:306. Adding 1 to the extent fixes the problem:
+ if (bounds.getHeight() <= 0 || bounds.getWidth() <= 0) {
+ bounds.expandBy(1);
+ }
+ bounds = ScaleUtils.fitToMinAndMax(bounds, layer);
+
+ getContext().sendASyncCommand(new SetViewportBBoxCommand(bounds, layer.getCRS()));
+ }
} catch (IOException e) {
SelectPlugin.log("failed to obtain resource", e); //$NON-NLS-1$
}
Please sign in to comment.
Something went wrong with that request. Please try again.