comparison src/java/de/intevation/mxd/reader/MapReader.java @ 121:9f74f4d36822

Set default values and improved logging and exception handling for map reader.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 16 Jun 2011 18:36:48 +0200
parents 8da6555f1c12
children b9ee44070056
comparison
equal deleted inserted replaced
120:11d63bf00326 121:9f74f4d36822
60 Element mapElement; 60 Element mapElement;
61 try{ 61 try{
62 mapElement = util.createMap(); 62 mapElement = util.createMap();
63 } 63 }
64 catch(Exception e){ 64 catch(Exception e){
65 e.printStackTrace(); 65 logger.error("Could not create DOM element. Aborting.");
66 return; 66 throw new IOException("Error creating DOM element.");
67 } 67 }
68 68
69 //Read map name. 69 //Read map name.
70 mapElement.setAttribute("name", map.getName()); 70 try {
71 mapElement.setAttribute("name", map.getName());
72 }
73 catch(IOException ioe) {
74 logger.warn(
75 "Could not read map name." +
76 " Setting map name to \"default-map\"");
77 mapElement.setAttribute("name", "default-map");
78 }
71 79
72 //Read map extent. 80 //Read map extent.
73 IEnvelope ext = map.getExtent(); 81 try {
74 mapElement.setAttribute( 82 IEnvelope ext = map.getExtent();
75 "extent_max_x", 83 mapElement.setAttribute(
76 String.valueOf(ext.getXMax())); 84 "extent_max_x",
77 mapElement.setAttribute( 85 String.valueOf(ext.getXMax()));
78 "extent_max_y", 86 mapElement.setAttribute(
79 String.valueOf(ext.getYMax())); 87 "extent_max_y",
80 mapElement.setAttribute( 88 String.valueOf(ext.getYMax()));
81 "extent_min_x", 89 mapElement.setAttribute(
82 String.valueOf(ext.getXMin())); 90 "extent_min_x",
83 mapElement.setAttribute( 91 String.valueOf(ext.getXMin()));
84 "extent_min_y", 92 mapElement.setAttribute(
85 String.valueOf(ext.getYMin())); 93 "extent_min_y",
94 String.valueOf(ext.getYMin()));
95 }
96 catch(IOException ioe) {
97 logger.warn("Could not read map extend. Setting to 0, 0, 0, 0.");
98 mapElement.setAttribute("extend_max_x", "0");
99 mapElement.setAttribute("extend_min_x", "0");
100 mapElement.setAttribute("extend_max_y", "0");
101 mapElement.setAttribute("extend_min_y", "0");
102 }
86 103
87 //Read map units. 104 //Read map units.
88 int units = map.getMapUnits(); 105 int units = 0;
106 try {
107 units = map.getMapUnits();
108 }
109 catch(IOException ioe) {
110 logger.warn(
111 "Could not read map units." +
112 " Setting map units to unknown.");
113 units = 0;
114 }
115
89 String s_units; 116 String s_units;
90 switch(units) { 117 switch(units) {
118 case 1: s_units = "inches"; break;
119 case 2: s_units = "points"; break;
91 case 3: s_units = "feet"; break; 120 case 3: s_units = "feet"; break;
92 case 1: s_units = "inches"; break; 121 case 4: s_units = "yards"; break;
93 case 10: s_units = "kilometers"; break;
94 case 9: s_units = "meters"; break;
95 case 5: s_units = "miles"; break; 122 case 5: s_units = "miles"; break;
96 case 6: s_units = "nauticalmiles"; break; 123 case 6: s_units = "nauticalmiles"; break;
97 case 2: s_units = "points"; break; 124 case 7: s_units = "millimeters"; break;
98 default : s_units = "meters"; break; 125 case 8: s_units = "centimeters"; break;
126 case 9: s_units = "meters"; break;
127 case 10: s_units = "kilometers"; break;
128 case 11: s_units = "degree"; break;
129 case 12: s_units = "decimeters"; break;
130 case 13: s_units = "units_last"; break;
131 default : s_units = "unknown"; break;
99 } 132 }
100 mapElement.setAttribute("units", s_units); 133 mapElement.setAttribute("units", s_units);
101 134
135 if(units == 0) {
136 logger.warn(
137 "Unknown units." +
138 " Please edit units in resulting mapfile.");
139 }
140
102 //TODO: Find out whats the correct scale value. 141 //TODO: Find out whats the correct scale value.
103 mapElement.setAttribute( 142 try {
104 "scale", 143 mapElement.setAttribute(
105 String.valueOf(map.getMaxScale())); 144 "scale",
145 String.valueOf(map.getMaxScale()));
146 }
147 catch(IOException ioe) {
148 logger.warn("Could not read map scale. Setting map scale to 1000");
149 mapElement.setAttribute("scale", "1000");
150 }
106 151
107 //Read the projection. 152 //Read the projection.
108 ISpatialReference sr = map.getSpatialReference(); 153 try {
109 if(sr instanceof ProjectedCoordinateSystem) { 154 ISpatialReference sr = map.getSpatialReference();
110 ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr; 155 String projection = "";
111 Projection p = (Projection)pcs.getProjection(); 156 if(sr instanceof ProjectedCoordinateSystem) {
112 mapElement.setAttribute("projection", p.getName()); 157 ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr;
158 Projection p = (Projection)pcs.getProjection();
159 projection = p.getName();
160 }
161 else if(sr instanceof GeographicCoordinateSystem) {
162 GeographicCoordinateSystem gcs = (GeographicCoordinateSystem)sr;
163 projection = gcs.getName();
164 }
165 else if(sr instanceof UnknownCoordinateSystem) {
166 UnknownCoordinateSystem ucs = (UnknownCoordinateSystem)sr;
167 projection = ucs.getName();
168 }
169 else{
170 logger.debug(
171 "Unknown SpatialReference: " +
172 sr.getClass().toString());
173 }
174
175 if(projection.equals("Unknown")) {
176 logger.warn(
177 "Unknown projection." +
178 " Please edit projection in resulting mapfile.");
179 }
180 mapElement.setAttribute("projection", projection);
113 } 181 }
114 else if(sr instanceof GeographicCoordinateSystem) { 182 catch(IOException ioe) {
115 GeographicCoordinateSystem gcs = (GeographicCoordinateSystem)sr; 183 logger.warn(
116 mapElement.setAttribute("projection", gcs.getName()); 184 "Could not read map projection." +
117 } 185 " Setting map projection to unknown.");
118 else if(sr instanceof UnknownCoordinateSystem) { 186 mapElement.setAttribute("projection", "Unknown");
119 UnknownCoordinateSystem ucs = (UnknownCoordinateSystem)sr;
120 if (sr.getName().equals("Unknown")) {
121 mapElement.setAttribute ("projection", "EPSG:31467");
122 }
123 else {
124 mapElement.setAttribute("projection", sr.getName());
125 }
126 }
127 else{
128 throw new IOException("Unknown SpatialReference: " +
129 sr.getClass().toString());
130 } 187 }
131 } 188 }
132 189
133 /** 190 /**
134 * Set the utilities. 191 * Set the utilities.
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)