Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…ty for Filter
  • Loading branch information...
commit c7dddbf3e11668c5bec9ab3fd01f1f88c92fc5ad 1 parent b4dd988
authored May 18, 2011
35  plugins/net.refractions.udig.tool.select/src/net/refractions/udig/tool/select/internal/ZoomSelection.java
@@ -25,7 +25,10 @@
25 25
 
26 26
 import org.geotools.data.Query;
27 27
 import org.geotools.data.simple.SimpleFeatureSource;
  28
+import org.geotools.feature.FeatureCollection;
28 29
 import org.geotools.geometry.jts.ReferencedEnvelope;
  30
+import org.opengis.feature.simple.SimpleFeature;
  31
+import org.opengis.feature.simple.SimpleFeatureType;
29 32
 
30 33
 /**
31 34
  * Sets the ViewportModel bounds to equal the bounds of the selected features
@@ -49,20 +52,26 @@ public void run() {
49 52
                 Query query = layer.getQuery(true);
50 53
                 ReferencedEnvelope bounds = resource.getBounds(query);
51 54
                 if (bounds == null) {
52  
-                    ReferencedEnvelope envelope = resource.getFeatures(query).getBounds();
53  
-                    if (envelope != null) {
54  
-                        bounds = new ReferencedEnvelope(envelope, layer.getCRS());
55  
-                    }
  55
+                	FeatureCollection<SimpleFeatureType, SimpleFeature> featureResult = resource.getFeatures(query);
  56
+                	if (featureResult != null && !featureResult.isEmpty()) {
  57
+                		ReferencedEnvelope envelope = featureResult.getBounds();
  58
+	                	if (envelope != null) {
  59
+	                		bounds = new ReferencedEnvelope(envelope, layer.getCRS());
  60
+	                	}
  61
+                	}
56 62
                 }
57  
-                // If the selection is a single point the bounds will
58  
-                // have height == 0 and width == 0. This will break
59  
-                // in ScaleUtils:306. Adding 1 to the extent fixes the problem:
60  
-                if (bounds.getHeight() <= 0 || bounds.getWidth() <= 0) {
61  
-                    bounds.expandBy(1);
62  
-                }
63  
-                bounds = ScaleUtils.fitToMinAndMax(bounds, layer);
64  
-
65  
-                getContext().sendASyncCommand(new SetViewportBBoxCommand(bounds, layer.getCRS()));
  63
+                
  64
+                if (bounds != null) {
  65
+	                // If the selection is a single point the bounds will
  66
+	                // have height == 0 and width == 0. This will break
  67
+	                // in ScaleUtils:306. Adding 1 to the extent fixes the problem:
  68
+	                if (bounds.getHeight() <= 0 || bounds.getWidth() <= 0) {
  69
+	                    bounds.expandBy(1);
  70
+	                }
  71
+	                bounds = ScaleUtils.fitToMinAndMax(bounds, layer);
  72
+	
  73
+	                getContext().sendASyncCommand(new SetViewportBBoxCommand(bounds, layer.getCRS()));
  74
+            	}
66 75
             } catch (IOException e) {
67 76
                 SelectPlugin.log("failed to obtain resource", e); //$NON-NLS-1$
68 77
             }

0 notes on commit c7dddbf

Please sign in to comment.
Something went wrong with that request. Please try again.