diff src/java/de/intevation/mxd/reader/FeatureLayerReader.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 191b7d18c79e
children e8021f3e411a
line wrap: on
line diff
--- 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) {
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)