[MXD2map-commits] r307:f9e53dcc7424
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Thu Sep 6 18:59:38 CEST 2012
details: http://hg.intevation.org/geospatial/mxd2map/rev/f9e53dcc7424
changeset: 307:f9e53dcc7424
user: Andre Heinecke <aheinecke at intevation.de>
date: Thu Sep 06 18:58:41 2012 +0200
description:
Add Read/Write Support for Projections on a per Layer basis
diffstat:
ChangeLog | 9 ++-
src/java/de/intevation/mxd/reader/FeatureLayerReader.java | 38 ++++++++++
src/java/de/intevation/mxd/reader/RasterLayerReader.java | 57 +++++++++++++++
src/java/de/intevation/mxd/writer/MapScriptWriter.java | 18 ++++
4 files changed, 121 insertions(+), 1 deletions(-)
diffs (175 lines):
diff -r ea3fde77ea48 -r f9e53dcc7424 ChangeLog
--- 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 at intevation.de>
+2012-09-06 Andre Heinecke <aheinecke at 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 at intevation.de>
* src/java/de/intevation/mxd/reader/RasterLayerReader.java:
Catch generic Exceptions to avoid leaking exceptions and
diff -r ea3fde77ea48 -r f9e53dcc7424 src/java/de/intevation/mxd/reader/FeatureLayerReader.java
--- 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) {
diff -r ea3fde77ea48 -r f9e53dcc7424 src/java/de/intevation/mxd/reader/RasterLayerReader.java
--- 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");
diff -r ea3fde77ea48 -r f9e53dcc7424 src/java/de/intevation/mxd/writer/MapScriptWriter.java
--- 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");
More information about the MXD2map-commits
mailing list