[MXD2map-commits] r252:eae3fe89e669

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Aug 15 12:09:58 CEST 2011


details:   http://hg.intevation.org/geospatial/mxd2map/rev/eae3fe89e669

changeset: 252:eae3fe89e669

user:      raimund renkert <raimund.renkert at intevation.de>

date:      Mon Aug 15 12:07:09 2011 +0200

description:
Added raster layer support.


diffstat:

 ChangeLog                                                          |   8 +
 src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java |  34 ++++++
 src/java/de/intevation/mxd/writer/MapScriptWriter.java             |  51 +++++++++-
 3 files changed, 89 insertions(+), 4 deletions(-)

diffs (147 lines):

diff -r 6b80e46b8f38 -r eae3fe89e669 ChangeLog
--- a/ChangeLog	Fri Aug 12 16:08:57 2011 +0200
+++ b/ChangeLog	Mon Aug 15 12:07:09 2011 +0200
@@ -1,3 +1,11 @@
+2011-08-15  Raimund Renkert  <raimund.renkert at intevation.de>
+
+	* src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java:
+	  Read connection information from the raster layer.
+
+	* src/java/de/intevation/mxd/writer/MapScriptWriter.java:
+	  Write raster layer to the mapfile.
+
 2011-08-12  Raimund Renkert  <raimund.renkert at intevation.de>
 
 	* build.xml: Added Apache commons-codec library for base64 encoding.
diff -r 6b80e46b8f38 -r eae3fe89e669 src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java
--- a/src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java	Fri Aug 12 16:08:57 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java	Mon Aug 15 12:07:09 2011 +0200
@@ -23,6 +23,8 @@
 
 import com.esri.arcgis.carto.ILayer;
 import com.esri.arcgis.carto.GdbRasterCatalogLayer;
+import com.esri.arcgis.system.IPropertySet;
+import com.esri.arcgis.geodatabase.IWorkspace;
 
 import org.w3c.dom.Element;
 import java.io.IOException;
@@ -142,6 +144,38 @@
             logger.warn(
                 "Could not read layer definition query.");
         }
+
+        try {
+            layerElement.setAttribute("type", "raster");
+            IWorkspace rw = layer.getWorkspace();
+            layerElement.setAttribute(
+                "dataset",
+                rw.getDatasetNames(16).next().getName());
+            IPropertySet set = rw.getConnectionProperties();
+            Object names[] = new Object[set.getCount()];
+            Object prop[] = new Object[set.getCount()];
+            set.getAllProperties(names, prop);
+            layerElement.setAttribute("connection_type", "SDE");
+            for(int i = 0; i < names.length; i++) {
+                if(names[i] != null) {
+                    String[] prop_names = (String[])names[i];
+                    for(int j = 0; j < prop_names.length; j++) {
+                        layerElement.setAttribute(
+                            prop_names[j].toLowerCase(),
+                             set.getProperty(prop_names[j]).toString());
+                    }
+                }
+            }
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+            logger.error(
+                "Could not read layer datasource." +
+                " Stopped reading layer " + layer.getName() + ".");
+            util.removeLayer(layerElement);
+            return null;
+        }
+
         return layerElement;
     }
 }
diff -r 6b80e46b8f38 -r eae3fe89e669 src/java/de/intevation/mxd/writer/MapScriptWriter.java
--- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Fri Aug 12 16:08:57 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Mon Aug 15 12:07:09 2011 +0200
@@ -301,14 +301,19 @@
             String type = layerElement.getAttribute("type");
             if(type.equals("point")) {
                 layer.setType(MS_LAYER_TYPE.MS_LAYER_POINT);
-            }
+                layer.setTileitem("");
+	    }
             else if (type.equals("line")) {
                 layer.setType(MS_LAYER_TYPE.MS_LAYER_LINE);
+                layer.setTileitem("");
             }
             else if (type.equals("polygon")) {
                 layer.setType(MS_LAYER_TYPE.MS_LAYER_POLYGON);
+                layer.setTileitem("");
             }
-            layer.setTileitem("");
+	    else if(type.equals("raster")) {
+	        layer.setType(MS_LAYER_TYPE.MS_LAYER_RASTER);
+	    }
 
             //The layer datasource.
             String con_type = layerElement.getAttribute("connection_type");
@@ -323,7 +328,7 @@
                 datasource = datasource.replaceAll("\\\\", "/");
                 layer.setData(datasource);
             }
-            else if(con_type.equals("SDE")) {
+            else if(con_type.equals("SDE") && !type.equals("raster")) {
                 // The data source is a sde database.
                 logger.info(
                     "SDE datasource found." +
@@ -391,7 +396,45 @@
                     }
                 }
             }
-            layer.setTemplate("PleaseInsertAValidTemplateForGFI");
+	    else if(con_type.equals("SDE") && type.equals("raster")) {
+                // The data source is a sde database.
+                logger.info(
+                    "SDE datasource found." +
+                    " Please edit password in mapfile.");
+		String database_auth = layerElement.getAttribute("database");
+		if (database_auth.equals("") || database_auth == null) {
+		    logger.warn("Could not set the database connection user." +
+				" Setting to \"sde\" as default.");
+		    database_auth = "sde";
+		}
+
+		String port = layerElement.getAttribute("instance");
+                StringBuffer strBuff = new StringBuffer();
+                char c;
+    
+                for (int j = 0; j < port.length() ; j++) {
+                    c = port.charAt(j);
+                    if(Character.isDigit(c)) {
+                        strBuff.append(c);
+                    }
+                }
+		
+                layer.setData(
+                    "SDE:" + layerElement.getAttribute("server") +
+                    "," + strBuff +
+		    "," + layerElement.getAttribute("database") +
+		    "," + layerElement.getAttribute("user") +
+		    ",<PASSWORD>," + layerElement.getAttribute("dataset"));
+		layer.setType(MS_LAYER_TYPE.MS_LAYER_RASTER);
+                if(layerElement.hasAttribute("definition_query") &&
+                   !layerElement.getAttribute("definition_query").equals("")) {
+                        layer.setFilter("where " +
+                        layerElement.getAttribute("definition_query"));
+                }
+	    }
+	    if(!type.equals("raster")) {
+                layer.setTemplate("PleaseInsertAValidTemplateForGFI");
+	    }
 
             // Create labelitem
             NodeList labels = layerElement.getElementsByTagName("label");


More information about the MXD2map-commits mailing list