diff src/java/de/intevation/mxd/reader/RasterLayerReader.java @ 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
parents ea3fde77ea48
children 5e3a40a84539
line wrap: on
line diff
--- 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");
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)