changeset 3918:2fdbe78a8fc2

Fixed various projection issues during map creation. flys-artifacts/trunk@5598 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 26 Sep 2012 08:00:44 +0000
parents 1ff257ab38ca
children 355c843245c1
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/mapserver/db_layer.vm flys-artifacts/doc/conf/mapserver/mapfile.vm flys-artifacts/src/main/java/de/intevation/flys/artifacts/MapArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/RiverAxisArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSBuildingsArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSCatchmentArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSFixpointsArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSFloodmapsArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSFloodplainArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSGaugeLocationArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSHwsArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSHydrBoundaryArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSHydrBoundaryPolyArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSKmArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSLineArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSQPSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/map/WMSLayerFacet.java flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java
diffstat 20 files changed, 183 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed Sep 26 08:00:44 2012 +0000
@@ -1,3 +1,44 @@
+2012-09-26  Ingo Weinzierl <ingo@intevation.de>
+
+	* doc/conf/mapserver/db_layer.vm: Set initial projection of the database
+	  to "epsg:31467".
+
+	* doc/conf/mapserver/mapfile.vm: Set initial projection of the database to
+	  "epsg:31467". Set the max extent to the extent of the river Saar.
+
+	    TODO: Set the max extent to the extent of germany!
+
+	* src/main/java/de/intevation/flys/artifacts/WMSQPSArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/WMSKmArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/WMSHydrBoundaryArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/WMSFixpointsArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/WMSFloodmapsArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/WMSHwsArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/WMSCatchmentArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/WMSHydrBoundaryPolyArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/WMSBuildingsArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/WMSGaugeLocationArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/RiverAxisArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/MapArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/WMSLineArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/WMSFloodplainArtifact.java:
+	  Added a parameter "reproject" to the getExtent() method. If reproject is
+	  set, the method should return the extent of the layer in the projection
+	  that is specified for the relevant river in the configuration.
+	  Otherwise, this method should return the extent in the projection that
+	  is used by the database.
+
+	* src/main/java/de/intevation/flys/artifacts/model/map/WMSLayerFacet.java:
+	  Added new attributes and methods for the original extent of a layer. The
+	  original extent is used in the XML document that is generated by
+	  toXML().
+
+	* src/main/java/de/intevation/flys/exports/MapGenerator.java: Use the
+	  getOriginalExtent() method of WMSLayerFacet to determine the max extent
+	  for the map (maps should be in the river projection specified in the
+	  configuration).
+
 2012-09-25	Christian Lins	<christian.lins@intevation.de>
 
 	* doc/conf/artifacts/fixanalysis.xml,
--- a/flys-artifacts/doc/conf/mapserver/db_layer.vm	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/doc/conf/mapserver/db_layer.vm	Wed Sep 26 08:00:44 2012 +0000
@@ -22,7 +22,7 @@
     #end
 
     PROJECTION
-        "init=epsg:$LAYER.getSrid()"
+        "init=epsg:31467"
     END
 
     METADATA
--- a/flys-artifacts/doc/conf/mapserver/mapfile.vm	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/doc/conf/mapserver/mapfile.vm	Wed Sep 26 08:00:44 2012 +0000
@@ -3,14 +3,14 @@
     STATUS ON
     SIZE 600 400
     MAXSIZE 4000
-    EXTENT -90 -180 90 180
+    EXTENT 3233232.55407617 5303455.37850183 3421524.44644752 5585825.50888523
     UNITS DD
     SHAPEPATH "$SHAPEFILEPATH"
     FONTSET "$CONFIGDIR/mapserver/fontset.txt"
     SYMBOLSET "$CONFIGDIR/mapserver/symbols.sym"
     IMAGECOLOR 255 255 255
     PROJECTION
-        "init=epsg:31466"
+        "init=epsg:31467"
     END
 
     DEBUG 5
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MapArtifact.java	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MapArtifact.java	Wed Sep 26 08:00:44 2012 +0000
@@ -174,7 +174,8 @@
             String name = type + "-" + artifact.identifier();
 
             facet.addLayer(name);
-            facet.setExtent(getExtent());
+            facet.setExtent(getExtent(false));
+            facet.setOriginalExtent(getExtent(true));
             facet.setSrid(getSrid());
             facet.setData(getDataString());
             facet.setFilter(getFilter());
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/RiverAxisArtifact.java	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/RiverAxisArtifact.java	Wed Sep 26 08:00:44 2012 +0000
@@ -119,11 +119,20 @@
         }
 
         @Override
-        protected Envelope getExtent() {
+        protected Envelope getExtent(boolean reproject) {
             River river = RiverFactory.getRiver(getRiverId());
-            return GeometryUtils.transform(
-                GeometryUtils.getRiverBoundary(river.getName()),
-                getSrid());
+            
+            if (reproject) {
+                logger.debug("Query extent for RiverAxis with Srid: " + getSrid());
+                return GeometryUtils.transform(
+                    GeometryUtils.getRiverBoundary(river.getName()),
+                    getSrid());
+            }
+            else {
+                return GeometryUtils.transform(
+                    GeometryUtils.getRiverBoundary(river.getName()),
+                    "31467");
+            }
         }
 
         @Override
@@ -133,13 +142,11 @@
 
         @Override
         protected String getDataString() {
-            String srid = getSrid();
-
             if (FLYSUtils.isUsingOracle()) {
-                return "geom FROM river_axes USING SRID " + srid;
+                return "geom FROM river_axes";
             }
             else {
-                return "geom FROM river_axes USING UNIQUE id USING SRID " + srid;
+                return "geom FROM river_axes USING UNIQUE id";
             }
         }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSBuildingsArtifact.java	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSBuildingsArtifact.java	Wed Sep 26 08:00:44 2012 +0000
@@ -101,7 +101,7 @@
         }
 
         @Override
-        protected Envelope getExtent() {
+        protected Envelope getExtent(boolean reproject) {
             List<Building> buildings =
                 Building.getBuildings(getRiverId(), getName());
 
@@ -118,7 +118,7 @@
                 max.expandToInclude(env);
             }
 
-            return max != null
+            return max != null && reproject
                 ? GeometryUtils.transform(max, getSrid())
                 : max;
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSCatchmentArtifact.java	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSCatchmentArtifact.java	Wed Sep 26 08:00:44 2012 +0000
@@ -117,7 +117,7 @@
         }
 
         @Override
-        protected Envelope getExtent() {
+        protected Envelope getExtent(boolean reproject) {
             List<Catchment> catchments =
                 Catchment.getCatchments(getRiverId(), getName());
 
@@ -134,7 +134,7 @@
                 max.expandToInclude(env);
             }
 
-            return max != null
+            return max != null && reproject
                 ? GeometryUtils.transform(max, getSrid())
                 : max;
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java	Wed Sep 26 08:00:44 2012 +0000
@@ -42,6 +42,9 @@
 
     public static final Pattern DB_URL_PATTERN =
         Pattern.compile("(.*)\\/\\/(.*):([0-9]+)\\/([a-zA-Z]+)");
+    
+    public static final Pattern DB_PSQL_URL_PATTERN =
+        Pattern.compile("(.*)\\/\\/(.*):([0-9]+)\\/([a-zA-Z0-9]+)");
 
 
     @Override
@@ -148,6 +151,7 @@
 
             facet.addLayer(name);
             facet.setExtent(getExtent());
+            facet.setOriginalExtent(getExtent(true));
             facet.setSrid(getSrid());
             facet.setData(getDataString());
             facet.setFilter(getFilter());
@@ -179,8 +183,10 @@
 
             Matcher m = DB_URL_PATTERN.matcher(url);
             if (!m.matches()) {
-                logger.warn("Could not parse Connection string.");
-                return null;
+                logger.warn("Could not parse Connection string." +
+                	"Try to parse PostgreSQL string.");
+                // maybe this is a PostgreSQL connection...
+                return getPostgreSQLConnection();
             }
 
             logger.debug("Groups for connection string: " + m.groupCount());
@@ -227,6 +233,55 @@
 
             return connection;
         }
+        
+        protected String getPostgreSQLConnection() {
+            SessionFactoryImpl sf = (SessionFactoryImpl)
+                SessionFactoryProvider.getSessionFactory();
+            
+            String user = SessionFactoryProvider.getUser(sf);
+            String pass = SessionFactoryProvider.getPass(sf);
+            String url  = SessionFactoryProvider.getURL(sf);
+            
+            Matcher m = DB_PSQL_URL_PATTERN.matcher(url);
+            if (!m.matches()) {
+                logger.warn("Could not parse PostgreSQL Connection string.");
+                return null;
+            }
+
+            int groups = m.groupCount();
+            logger.debug("Groups for PostgreSQL connection string: " + groups);
+
+            if (logger.isDebugEnabled()) {
+                for (int i = 0; i <= groups; i++) {
+                    logger.debug("Group " + i + ": " + m.group(i));
+                }
+            }
+
+            String connection = null;
+
+            if (groups < 4) {
+                logger.warn("Could only partially parse connection string.");
+                return null;
+            }
+
+            String host = m.group(2);
+            String port = m.group(3);
+            String db   = m.group(4);
+
+            StringBuilder sb = new StringBuilder();
+            sb.append("dbname=" + db);
+            sb.append(" host='" + host + "'");
+            sb.append(" port=" + port);
+            sb.append(" user=" + user);
+            sb.append(" password='" + pass + "'");
+            sb.append(" sslmode=disable");
+
+            connection = sb.toString();
+
+            logger.debug("Created connection: '" + connection + "'");
+
+            return connection;
+        }
 
         protected String getConnectionType() {
             return FLYSUtils.isUsingOracle() ? "oraclespatial" : "postgis";
@@ -309,6 +364,16 @@
                 MapfileGenerator.getInstance().update();
             }
         }
+        
+        /**
+         * This method returns the extent of a DB layer in the projection of the
+         * database.
+         * 
+         * @return the extent of the DB layer in the projection of the database.
+         */
+        protected Envelope getExtent() {
+            return getExtent(false);
+        }
 
 
         protected abstract String getFacetType();
@@ -317,7 +382,19 @@
 
         protected abstract String getSrid();
 
-        protected abstract Envelope getExtent();
+        /**
+         * This method returns the extent of the DB layer. The projection of the
+         * extent depends on the <i>reproject</i> parameter. If reproject is set,
+         * the extent is reprojected into the original projection which is
+         * specified in the configuration. Otherwise, the projection of the
+         * database is used.
+         * 
+         * @param reproject True, to reproject the extent into the projection
+         * specified in the configuration.
+         * 
+         * @return the extent of the database layer.
+         */
+        protected abstract Envelope getExtent(boolean reproject);
 
         protected abstract String getFilter();
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSFixpointsArtifact.java	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSFixpointsArtifact.java	Wed Sep 26 08:00:44 2012 +0000
@@ -101,7 +101,7 @@
         }
 
         @Override
-        protected Envelope getExtent() {
+        protected Envelope getExtent(boolean reproject) {
             List<Fixpoint> fixpoints = Fixpoint.getFixpoints(getRiverId());
 
             Envelope max = null;
@@ -117,7 +117,7 @@
                 max.expandToInclude(env);
             }
 
-            return max != null
+            return max != null && reproject
                 ? GeometryUtils.transform(max, getSrid())
                 : max;
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSFloodmapsArtifact.java	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSFloodmapsArtifact.java	Wed Sep 26 08:00:44 2012 +0000
@@ -101,7 +101,7 @@
         }
 
         @Override
-        protected Envelope getExtent() {
+        protected Envelope getExtent(boolean reproject) {
             List<Floodmaps> floodmaps =
                 Floodmaps.getFloodmaps(getRiverId(), getName());
 
@@ -118,7 +118,7 @@
                 max.expandToInclude(env);
             }
 
-            return max != null
+            return max != null && reproject
                 ? GeometryUtils.transform(max, getSrid())
                 : max;
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSFloodplainArtifact.java	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSFloodplainArtifact.java	Wed Sep 26 08:00:44 2012 +0000
@@ -120,13 +120,15 @@
         }
 
         @Override
-        protected Envelope getExtent() {
+        protected Envelope getExtent(boolean reproject) {
             River      river = getRiver();
             Floodplain plain = Floodplain.getFloodplain(river.getName());
 
-            return GeometryUtils.transform(
-                plain.getGeom().getEnvelopeInternal(),
-                getSrid());
+            Envelope e = plain.getGeom().getEnvelopeInternal();
+            
+            return e != null && reproject
+                ? GeometryUtils.transform(e, getSrid())
+                : e;
         }
 
         @Override
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSGaugeLocationArtifact.java	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSGaugeLocationArtifact.java	Wed Sep 26 08:00:44 2012 +0000
@@ -103,7 +103,7 @@
         }
 
         @Override
-        protected Envelope getExtent() {
+        protected Envelope getExtent(boolean reproject) {
             List<GaugeLocation> gauges =
                 GaugeLocation.getGaugeLocations(getRiverId(), getName());
 
@@ -120,7 +120,7 @@
                 max.expandToInclude(env);
             }
 
-            return max != null
+            return max != null && reproject
                 ? GeometryUtils.transform(max, getSrid())
                 : max;
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSHwsArtifact.java	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSHwsArtifact.java	Wed Sep 26 08:00:44 2012 +0000
@@ -117,7 +117,7 @@
         }
 
         @Override
-        protected Envelope getExtent() {
+        protected Envelope getExtent(boolean reproject) {
             List<Hws> hws = Hws.getHws(getRiverId(), getName());
 
             Envelope max = null;
@@ -133,7 +133,7 @@
                 max.expandToInclude(env);
             }
 
-            return max != null
+            return max != null && reproject
                 ? GeometryUtils.transform(max, getSrid())
                 : max;
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSHydrBoundaryArtifact.java	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSHydrBoundaryArtifact.java	Wed Sep 26 08:00:44 2012 +0000
@@ -101,7 +101,7 @@
         }
 
         @Override
-        protected Envelope getExtent() {
+        protected Envelope getExtent(boolean reproject) {
             List<HydrBoundary> boundaries = HydrBoundary.getHydrBoundaries(
                 getRiverId(), getName());
 
@@ -118,7 +118,7 @@
                 max.expandToInclude(env);
             }
 
-            return max != null
+            return max != null && reproject
                 ? GeometryUtils.transform(max, getSrid())
                 : max;
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSHydrBoundaryPolyArtifact.java	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSHydrBoundaryPolyArtifact.java	Wed Sep 26 08:00:44 2012 +0000
@@ -101,7 +101,7 @@
         }
 
         @Override
-        protected Envelope getExtent() {
+        protected Envelope getExtent(boolean reproject) {
             List<HydrBoundaryPoly> boundaries = HydrBoundaryPoly.getHydrBoundaries(
                 getRiverId(), getName());
 
@@ -118,7 +118,7 @@
                 max.expandToInclude(env);
             }
 
-            return max != null
+            return max != null && reproject
                 ? GeometryUtils.transform(max, getSrid())
                 : max;
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSKmArtifact.java	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSKmArtifact.java	Wed Sep 26 08:00:44 2012 +0000
@@ -118,7 +118,7 @@
         }
 
         @Override
-        protected Envelope getExtent() {
+        protected Envelope getExtent(boolean reproject) {
             List<RiverAxisKm> kms = RiverAxisKm.getRiverAxisKms(getRiverId());
 
             Envelope max = null;
@@ -134,7 +134,7 @@
                 max.expandToInclude(env);
             }
 
-            return max != null
+            return max != null && reproject
                 ? GeometryUtils.transform(max, getSrid())
                 : max;
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSLineArtifact.java	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSLineArtifact.java	Wed Sep 26 08:00:44 2012 +0000
@@ -117,7 +117,7 @@
         }
 
         @Override
-        protected Envelope getExtent() {
+        protected Envelope getExtent(boolean reproject) {
             List<Line> lines = Line.getLines(getRiverId(), getName());
 
             Envelope max = null;
@@ -133,7 +133,7 @@
                 max.expandToInclude(env);
             }
 
-            return max != null
+            return max != null && reproject
                 ? GeometryUtils.transform(max, getSrid())
                 : max;
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSQPSArtifact.java	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSQPSArtifact.java	Wed Sep 26 08:00:44 2012 +0000
@@ -116,7 +116,7 @@
         }
 
         @Override
-        protected Envelope getExtent() {
+        protected Envelope getExtent(boolean reproject) {
             River river = RiverFactory.getRiver(getRiverId());
 
             List<CrossSectionTrack> qps =
@@ -135,7 +135,7 @@
                 max.expandToInclude(env);
             }
 
-            return max != null
+            return max != null && reproject
                 ? GeometryUtils.transform(max, getSrid())
                 : max;
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/map/WMSLayerFacet.java	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/map/WMSLayerFacet.java	Wed Sep 26 08:00:44 2012 +0000
@@ -29,6 +29,7 @@
     protected String       hash;
     protected String       url;
     protected Envelope     extent;
+    protected Envelope     originalExtent;
     protected String       srid;
 
 
@@ -106,6 +107,16 @@
     public Envelope getExtent() {
         return extent;
     }
+    
+    
+    public void setOriginalExtent(Envelope originalExtent) {
+        this.originalExtent = originalExtent;
+    }
+    
+    
+    public Envelope getOriginalExtent() {
+        return originalExtent;
+    }
 
 
     public void setSrid(String srid) {
@@ -140,8 +151,8 @@
         ec.addAttr(facet, "url", url, true);
         ec.addAttr(facet, "layers", layers.get(0), true);
         ec.addAttr(facet, "srid", srid != null ? srid : "", true);
-        ec.addAttr(facet, "extent", extent != null
-            ? GeometryUtils.jtsBoundsToOLBounds(extent)
+        ec.addAttr(facet, "extent", originalExtent != null
+            ? GeometryUtils.jtsBoundsToOLBounds(originalExtent)
             : "", true);
         ec.addAttr(facet, "queryable", String.valueOf(isQueryable()), true);
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java	Wed Sep 26 08:00:44 2012 +0000
@@ -99,7 +99,7 @@
 
         if (nativeFacet instanceof WMSLayerFacet) {
             WMSLayerFacet wms = (WMSLayerFacet) nativeFacet;
-            Envelope   extent = wms.getExtent();
+            Envelope   extent = wms.getOriginalExtent();
 
             layers.add(wms);
 

http://dive4elements.wald.intevation.org