Hi Frank,
I tried applying the patch to 2.5.x, but it causes a failure in the
shapefile-renderer module. I had to add a check for the case where the
referenced envelope returned has a null crs, and when it does set it to
the source crs.
This is not my domain so i am not sure if this is an acceptable fix.
Although it does fix the test case. Andrea should be able to give us
thumbs up/down.
I attached the slightly modified patch.
-Justin
Frank Gasdorf wrote:
Hallo,
A few weeks ago I posted a patch for the DefaultMapLayer which fixed a NullPointerException if the FeatureSource.getBounds returned null. This patch were commited on trunk (Revision 32475 commited by jive) but not on the 2.5.x branch. Could somebody apply the getBounds patch (.. see attachement) on the 2.5.x brunch, because we're developing with the 2.5.x libs.
Thanks a lot,
Frank
--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.
Index: src/main/java/org/geotools/map/DefaultMapLayer.java
===================================================================
--- src/main/java/org/geotools/map/DefaultMapLayer.java (revision 33456)
+++ src/main/java/org/geotools/map/DefaultMapLayer.java (working copy)
@@ -34,11 +34,13 @@
import org.geotools.feature.SchemaException;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.map.event.MapLayerEvent;
+import org.geotools.referencing.CRS;
import org.geotools.resources.coverage.FeatureUtilities;
import org.geotools.styling.Style;
import org.opengis.coverage.grid.GridCoverage;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
+import org.opengis.geometry.Envelope;
import org.opengis.geometry.MismatchedDimensionException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.TransformException;
@@ -399,21 +401,37 @@
MapLayerEvent.FILTER_CHANGED));
}
public ReferencedEnvelope getBounds() {
-
- CoordinateReferenceSystem sourceCrs =
featureSource.getSchema().getCoordinateReferenceSystem();
- ReferencedEnvelope env;
- try {
- env = new ReferencedEnvelope(featureSource.getBounds(),
sourceCrs);
- return env;
- } catch (MismatchedDimensionException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
+ // CRS could also be null, depends on FeatureType
+ CoordinateReferenceSystem sourceCrs = featureSource.getSchema()
+ .getCoordinateReferenceSystem();
+
+ try {
+ ReferencedEnvelope bounds = featureSource.getBounds();
+ if (null != bounds) {
+ if ( bounds.getCoordinateReferenceSystem() == null ) {
+ bounds = new ReferencedEnvelope(bounds,sourceCrs);
+ }
+ // returns the bounds based on features
+ return bounds;
+ }
+
+ if (sourceCrs != null) {
+ // returns the envelope based on the
CoordinateReferenceSystem
+ Envelope envelope = CRS.getEnvelope(sourceCrs);
+ if (envelope != null) {
+ return new ReferencedEnvelope(envelope); // nice!
+ }
+ }
+
+ } catch (MismatchedDimensionException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ // return a default ReferencedEnvelope
+ return new ReferencedEnvelope(sourceCrs);
+ }
+
//
------------------------------------------------------------------------
// EVENT HANDLING CODE
//
------------------------------------------------------------------------
------------------------------------------------------------------------------
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel