Mercurial > mxd2map
comparison src/java/de/intevation/mxd/reader/MapReader.java @ 31:40c0b4e5f91a
Added utility class to store map attributes.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Mon, 11 Apr 2011 16:04:03 +0200 |
parents | e5fdc37f8f94 |
children | c51376f8e24c |
comparison
equal
deleted
inserted
replaced
30:c34c450edb06 | 31:40c0b4e5f91a |
---|---|
7 import com.esri.arcgis.carto.IMap; | 7 import com.esri.arcgis.carto.IMap; |
8 import com.esri.arcgis.carto.Map; | 8 import com.esri.arcgis.carto.Map; |
9 import com.esri.arcgis.geometry.ISpatialReference; | 9 import com.esri.arcgis.geometry.ISpatialReference; |
10 import com.esri.arcgis.geometry.ProjectedCoordinateSystem; | 10 import com.esri.arcgis.geometry.ProjectedCoordinateSystem; |
11 import com.esri.arcgis.geometry.GeographicCoordinateSystem; | 11 import com.esri.arcgis.geometry.GeographicCoordinateSystem; |
12 import com.esri.arcgis.geometry.UnknownCoordinateSystem; | |
12 import com.esri.arcgis.geometry.IProjection; | 13 import com.esri.arcgis.geometry.IProjection; |
13 import com.esri.arcgis.geometry.Projection; | 14 import com.esri.arcgis.geometry.Projection; |
14 | 15 |
15 import org.w3c.dom.Document; | 16 import org.w3c.dom.Document; |
16 import org.w3c.dom.Element; | 17 import org.w3c.dom.Element; |
22 */ | 23 */ |
23 public class MapReader{ | 24 public class MapReader{ |
24 | 25 |
25 //Member | 26 //Member |
26 private IMap map; | 27 private IMap map; |
27 private Document document; | 28 private MapToXMLUtils util; |
28 | 29 |
29 private static final Logger logger = Logger.getLogger(MapReader.class); | 30 private static final Logger logger = Logger.getLogger(MapReader.class); |
30 | 31 |
31 //Constructor | 32 //Constructor |
32 public MapReader(IMap map){ | 33 public MapReader(IMap map){ |
40 /** | 41 /** |
41 * Reads the Map attributes. | 42 * Reads the Map attributes. |
42 */ | 43 */ |
43 public void read() throws IOException{ | 44 public void read() throws IOException{ |
44 logger.debug("read()"); | 45 logger.debug("read()"); |
45 if(document == null) | 46 if(util == null) |
46 throw new IOException("Can not write to document."); | 47 throw new IOException("Can not write to document."); |
47 | 48 |
48 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(document, | 49 // XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(document, |
49 "", ""); | 50 // "", ""); |
50 Element mapElement = creator.create("map"); | 51 Element mapElement; |
52 try{ | |
53 mapElement = util.createMap(); | |
54 } | |
55 catch(Exception e){ | |
56 e.printStackTrace(); | |
57 return; | |
58 } | |
51 ISpatialReference sr = map.getSpatialReference(); | 59 ISpatialReference sr = map.getSpatialReference(); |
52 logger.debug("Instance: " + sr.getClass().toString()); | 60 logger.debug("Instance: " + sr.getClass().toString()); |
53 if(sr instanceof ProjectedCoordinateSystem){ | 61 if(sr instanceof ProjectedCoordinateSystem){ |
54 ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr; | 62 ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr; |
55 Projection p = (Projection)pcs.getProjection(); | 63 Projection p = (Projection)pcs.getProjection(); |
56 creator.addAttr(mapElement, "projection", p.getName()); | 64 mapElement.setAttribute("projection", p.getName()); |
57 } | 65 } |
58 else if(sr instanceof GeographicCoordinateSystem){ | 66 else if(sr instanceof GeographicCoordinateSystem){ |
59 GeographicCoordinateSystem gcs = (GeographicCoordinateSystem)sr; | 67 GeographicCoordinateSystem gcs = (GeographicCoordinateSystem)sr; |
60 creator.addAttr(mapElement, "projection", gcs.getName()); | 68 mapElement.setAttribute("projection", gcs.getName()); |
69 } | |
70 else if(sr instanceof UnknownCoordinateSystem) { | |
71 UnknownCoordinateSystem ucs = (UnknownCoordinateSystem)sr; | |
72 mapElement.setAttribute("projection", sr.getName()); | |
61 } | 73 } |
62 else{ | 74 else{ |
63 throw new IOException("Unknown SpatialReference: " + | 75 throw new IOException("Unknown SpatialReference: " + |
64 sr.getClass().toString()); | 76 sr.getClass().toString()); |
65 } | 77 } |
66 document.appendChild(mapElement); | |
67 } | 78 } |
68 | 79 |
69 public void setDocument(Document doc){ | 80 public void setUtil(MapToXMLUtils util){ |
70 this.document = doc; | 81 this.util = util; |
71 } | 82 } |
72 } | 83 } |
73 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 84 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |