changeset 252:eae3fe89e669

Added raster layer support.
author raimund renkert <raimund.renkert@intevation.de>
date Mon, 15 Aug 2011 12:07:09 +0200
parents 6b80e46b8f38
children cedb23deb057
files ChangeLog src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java src/java/de/intevation/mxd/writer/MapScriptWriter.java
diffstat 3 files changed, 89 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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@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@intevation.de>
 
 	* build.xml: Added Apache commons-codec library for base64 encoding.
--- 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;
     }
 }
--- 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");
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)