changeset 307:f9e53dcc7424

Add Read/Write Support for Projections on a per Layer basis
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 06 Sep 2012 18:58:41 +0200 (2012-09-06)
parents ea3fde77ea48
children 1c949a309940
files ChangeLog src/java/de/intevation/mxd/reader/FeatureLayerReader.java src/java/de/intevation/mxd/reader/RasterLayerReader.java src/java/de/intevation/mxd/writer/MapScriptWriter.java
diffstat 4 files changed, 121 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Sep 06 18:56:20 2012 +0200
+++ b/ChangeLog	Thu Sep 06 18:58:41 2012 +0200
@@ -1,4 +1,11 @@
-2012-09-05  Andre Heinecke <aheinecke@intevation.de>
+2012-09-06  Andre Heinecke <aheinecke@intevation.de>
+
+	* src/java/de/intevation/mxd/reader/FeatureLayerReader.java,
+	src/java/de/intevation/mxd/reader/RasterLayerReader.java,
+	src/java/de/intevation/mxd/writer/MapScriptWriter.java:
+	Add Read/Write Support for Projections on a per Layer basis
+
+2012-09-06  Andre Heinecke <aheinecke@intevation.de>
 
 	* src/java/de/intevation/mxd/reader/RasterLayerReader.java:
 	Catch generic Exceptions to avoid leaking exceptions and
--- a/src/java/de/intevation/mxd/reader/FeatureLayerReader.java	Thu Sep 06 18:56:20 2012 +0200
+++ b/src/java/de/intevation/mxd/reader/FeatureLayerReader.java	Thu Sep 06 18:58:41 2012 +0200
@@ -30,6 +30,11 @@
 import com.esri.arcgis.system.IName;
 import com.esri.arcgis.system.IPropertySet;
 import com.esri.arcgis.geometry.Envelope;
+import com.esri.arcgis.geometry.ISpatialReference;
+import com.esri.arcgis.geometry.ProjectedCoordinateSystem;
+import com.esri.arcgis.geometry.GeographicCoordinateSystem;
+import com.esri.arcgis.geometry.UnknownCoordinateSystem;
+import com.esri.arcgis.geometry.Projection;
 
 import org.w3c.dom.Element;
 
@@ -230,6 +235,39 @@
                 "Could not read extent from layer "
                 + layer.getName() + ".");
         }
+        //Read the projection.
+        try {
+            ISpatialReference sr = layer.getSpatialReference();
+            int projection = 0;
+            if(sr instanceof ProjectedCoordinateSystem) {
+                ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr;
+                projection = pcs.getFactoryCode();
+            }
+            else if(sr instanceof GeographicCoordinateSystem) {
+                GeographicCoordinateSystem gcs = (GeographicCoordinateSystem)sr;
+                projection = gcs.getFactoryCode();
+            }
+            else if(sr instanceof UnknownCoordinateSystem) {
+                UnknownCoordinateSystem ucs = (UnknownCoordinateSystem)sr;
+                projection = 0;
+            }
+            else{
+                logger.debug(
+                    "Unknown SpatialReference: " +
+                    sr.getClass().toString());
+            }
+
+            if(projection == 0) {
+                logger.warn(
+                    "Unknown projection for Layer:" + layer.getName() +
+                    " Please edit projection in resulting mapfile.");
+            }
+            layerElement.setAttribute("projection", String.valueOf(projection));
+        }
+        catch(IOException ioe) {
+            logger.warn("Could not read layer projection.");
+        }
+
         try {
             String datatype = layer.getDataSourceType();
             if(layer.getWorkspace().getType() == 0) {
--- a/src/java/de/intevation/mxd/reader/RasterLayerReader.java	Thu Sep 06 18:56:20 2012 +0200
+++ b/src/java/de/intevation/mxd/reader/RasterLayerReader.java	Thu Sep 06 18:58:41 2012 +0200
@@ -30,6 +30,11 @@
 import com.esri.arcgis.system.IName;
 import com.esri.arcgis.system.IPropertySet;
 import com.esri.arcgis.geometry.Envelope;
+import com.esri.arcgis.geometry.ISpatialReference;
+import com.esri.arcgis.geometry.ProjectedCoordinateSystem;
+import com.esri.arcgis.geometry.GeographicCoordinateSystem;
+import com.esri.arcgis.geometry.UnknownCoordinateSystem;
+import com.esri.arcgis.geometry.Projection;
 
 import org.w3c.dom.Element;
 
@@ -149,6 +154,58 @@
             util.removeLayer(layerElement);
             return null;
         }
+        try {
+            Envelope rect = (Envelope)layer.getExtent();
+            layerElement.setAttribute(
+                "extent_min_x",
+                String.valueOf(rect.getXMin ()));
+            layerElement.setAttribute(
+                "extent_max_x",
+                String.valueOf(rect.getXMax()));
+            layerElement.setAttribute(
+                "extent_min_y",
+                String.valueOf(rect.getYMin()));
+            layerElement.setAttribute(
+                "extent_max_y",
+                String.valueOf(rect.getYMax()));
+        }
+        catch(Exception e) {
+            logger.warn(
+                "Could not read extent from layer "
+                + layer.getName() + ".");
+        }
+        //Read the projection.
+        try {
+            ISpatialReference sr = layer.getSpatialReference();
+            int projection = 0;
+            if(sr instanceof ProjectedCoordinateSystem) {
+                ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr;
+                projection = pcs.getFactoryCode();
+            }
+            else if(sr instanceof GeographicCoordinateSystem) {
+                GeographicCoordinateSystem gcs = (GeographicCoordinateSystem)sr;
+                projection = gcs.getFactoryCode();
+            }
+            else if(sr instanceof UnknownCoordinateSystem) {
+                UnknownCoordinateSystem ucs = (UnknownCoordinateSystem)sr;
+                projection = 0;
+            }
+            else{
+                logger.debug(
+                    "Unknown SpatialReference: " +
+                    sr.getClass().toString());
+            }
+
+            if(projection == 0) {
+                logger.warn(
+                    "Unknown projection for Layer:" + layer.getName() +
+                    " Please edit projection in resulting mapfile.");
+            }
+            layerElement.setAttribute("projection", String.valueOf(projection));
+        }
+        catch(Exception e) {
+            logger.warn("Could not read layer projection.");
+        }
 
         // Static Attributes for Raster:
         layerElement.setAttribute("type", "raster");
--- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Thu Sep 06 18:56:20 2012 +0200
+++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Thu Sep 06 18:58:41 2012 +0200
@@ -296,8 +296,26 @@
             }
             layer.setMetaData("wms_title", ulname);
 
+            //Set the projection for the Layers
+            if (layerElement.hasAttribute("projection")) {
+                int proj = Integer.parseInt(layerElement.getAttribute("projection"));
+                if(proj != 0) {
+                    try {
+                        layer.setProjection("epsg:" + layerElement.getAttribute("projection"));
+                    }
+                    catch(UnknownError e) {
+                        logger.error( "Could not set projection in layer: " + layerElement.getAttribute("projection") +
+                                ". Please ensure that it is described in your espg file.");
+                        throw e;
+                    }
+                }
+            }
             // Projection metadata.
             String mproj = mapNode.getAttribute("projection");
+            if (layerElement.hasAttribute("projection")) {
+                // Overwrite the Map Projection in the layer
+                mproj = layerElement.getAttribute("projection");
+            }
             if(mproj != null && !mproj.equals("") && !mproj.equals("0")) {
                 String wmssrs = layer.getMetaData("wms_srs");
                 String owssrs = layer.getMetaData("ows_srs");
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)