Mercurial > mxd2map
changeset 41:60ed2164035a
Introduced MapScript writer.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Thu, 14 Apr 2011 11:31:29 +0200 (2011-04-14) |
parents | a1bc7220efe7 |
children | 395307e8b7ee |
files | ChangeLog src/java/de/intevation/mxd/Converter.java src/java/de/intevation/mxd/writer/IWriter.java src/java/de/intevation/mxd/writer/MapScriptWriter.java |
diffstat | 4 files changed, 155 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Apr 14 11:25:57 2011 +0200 +++ b/ChangeLog Thu Apr 14 11:31:29 2011 +0200 @@ -1,3 +1,13 @@ +2011-04-14 Raimund Renkert <raimund.renkert@intevation.de> + + Introduced MapScript writer. + + * M src/java/de/intevation/mxd/Converter.java: Added mapscript writer. + + * src/java/de/intevation/mxd/writer/IWriter.java, + src/java/de/intevation/mxd/writer/MapScriptWriter.java: + New. The MapScript writer uses the Java MapScript API to create a mapfile. + 2011-04-14 Raimund Renkert <raimund.renkert@intevation.de> * src/java/de/intevation/mxd/reader/FeatureLayerReader.java:
--- a/src/java/de/intevation/mxd/Converter.java Thu Apr 14 11:25:57 2011 +0200 +++ b/src/java/de/intevation/mxd/Converter.java Thu Apr 14 11:31:29 2011 +0200 @@ -10,7 +10,8 @@ import de.intevation.mxd.reader.IReader; import de.intevation.mxd.reader.MXDReader; - +import de.intevation.mxd.writer.IWriter; +import de.intevation.mxd.writer.MapScriptWriter; /** * The entry point of the MXD converter tool. * @@ -68,6 +69,7 @@ try{ IReader reader = new MXDReader(); + IWriter writer = new MapScriptWriter(); reader.init(); String path = System.getProperty("mxd.file"); @@ -79,6 +81,7 @@ reader.setFilename(path); reader.read(); + writer.write(reader.getMapDocument()); reader.shutdown(); } catch(IOException e){
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java/de/intevation/mxd/writer/IWriter.java Thu Apr 14 11:31:29 2011 +0200 @@ -0,0 +1,18 @@ +package de.intevation.mxd.writer; + +import java.io.IOException; + +import org.w3c.dom.Document; + +/** + * The interface to the MXD-Reader. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public interface IWriter { + /** + * write the content. + */ + boolean write(Document doc) throws IOException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java Thu Apr 14 11:31:29 2011 +0200 @@ -0,0 +1,123 @@ +package de.intevation.mxd.writer; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import javax.xml.xpath.XPathConstants; + +import edu.umn.gis.mapscript.mapObj; +import edu.umn.gis.mapscript.layerObj; +import edu.umn.gis.mapscript.MS_UNITS; + +import de.intevation.mxd.utils.XMLUtils; + +/** + * The MXD file reader. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class MapScriptWriter +implements IWriter +{ + private Document root; + private mapObj map; + + private static final Logger logger = Logger.getLogger(MapScriptWriter.class); + + public MapScriptWriter() { + map = new mapObj(""); + } + + public MapScriptWriter(String path) { + map = new mapObj(path); + } + + public boolean write(Document doc) { + logger.debug("write()"); + this.root = doc; + + //Get the filename. + Element fileNode = (Element)XMLUtils.xpath( + root, + "/mxd/file", + XPathConstants.NODE); + String filename = fileNode.getAttribute("name"); + if(filename.endsWith(".mxd")) { + filename = filename.replace(".mxd", ".map"); + } + //Write the map attributes. + writeMap(); + + //Save the map. + map.save(filename); + return true; + } + + private void writeMap() { + logger.debug("writeMap()"); + //Get the map. + Element mapNode = (Element)XMLUtils.xpath( + root, + "/mxd/map", + XPathConstants.NODE); + + //Set the name. + map.setName(mapNode.getAttribute("name")); + + //Set the extent. + map.setExtent( + Double.parseDouble(mapNode.getAttribute("extent_min_x")), + Double.parseDouble(mapNode.getAttribute("extent_min_y")), + Double.parseDouble(mapNode.getAttribute("extent_max_x")), + Double.parseDouble(mapNode.getAttribute("extent_max_y"))); + + //Set the units. + String units = mapNode.getAttribute("units"); + MS_UNITS msu; + if(units.equals("feet")) { + msu = MS_UNITS.MS_FEET; + } + else if(units.equals("inches")) { + msu = MS_UNITS.MS_INCHES; + } + else if(units.equals("kilometers")) { + msu = MS_UNITS.MS_KILOMETERS; + } + else if(units.equals("meters")) { + msu = MS_UNITS.MS_METERS; + } + else if(units.equals("miles")) { + msu = MS_UNITS.MS_MILES; + } + else if(units.equals("nauticalmiles")) { + msu = MS_UNITS.MS_NAUTICALMILES; + } + else if(units.equals("points")) { + msu = MS_UNITS.MS_PIXELS; + } + else { + msu = MS_UNITS.MS_DD; + } + map.setUnits(msu); + + //TODO: Find out whats the correct scale value. + //map.setScaledenom(Double.parseDouble(mapNode.getAttribute("scale"))); + } + + private void writeLayer() { + + } + + private void writeClass() { + + } + + private void writeSymbol() { + + } + +} +