Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/mapserver/ArtifactMapfileGenerator.java @ 5087:cbfdd7376009 mapgenfix
ArtifactMapfileGenerator can now generate user shape mapfiles again.
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Mon, 25 Feb 2013 11:51:17 +0100 |
parents | cc50e1b9fc60 |
children | cfc5540a4eec |
comparison
equal
deleted
inserted
replaced
5076:cc50e1b9fc60 | 5087:cbfdd7376009 |
---|---|
62 String fileName = layerShape.getName(); | 62 String fileName = layerShape.getName(); |
63 if (fileName.startsWith(MS_PREFIX_BARRIERS)) { | 63 if (fileName.startsWith(MS_PREFIX_BARRIERS)) { |
64 | 64 |
65 } | 65 } |
66 else if (fileName.startsWith(MS_PREFIX_USER)) { | 66 else if (fileName.startsWith(MS_PREFIX_USER)) { |
67 createUserShapeLayer(layerShape); | 67 File userLayer = createUserShapeLayer(layerShape); |
68 if (userLayer != null) { | |
69 layerSnippets.add(userLayer.getCanonicalPath()); | |
70 } | |
68 } | 71 } |
69 else if (fileName.startsWith(MS_PREFIX_WSPLGEN)) { | 72 else if (fileName.startsWith(MS_PREFIX_WSPLGEN)) { |
70 | 73 |
71 } | 74 } |
72 } | 75 } |
251 | 254 |
252 /** | 255 /** |
253 * Creates a layer file used for Mapserver's mapfile which represents the | 256 * Creates a layer file used for Mapserver's mapfile which represents the |
254 * shape files uploaded by the user. | 257 * shape files uploaded by the user. |
255 */ | 258 */ |
256 protected void createUserShapeLayer(File file) | 259 protected File createUserShapeLayer(File file) |
257 throws FileNotFoundException, IOException | 260 throws FileNotFoundException, IOException |
258 { | 261 { |
259 String uuid = uuidFromPath(file.getAbsolutePath()); | 262 String uuid = uuidFromPath(file.getAbsolutePath()); |
260 logger.debug("createUserShapeLayer(): uuid=" + uuid); | 263 logger.debug("createUserShapeLayer(): uuid=" + uuid); |
261 | 264 |
262 File dir = new File(getShapefileBaseDir(), uuid); | 265 File dir = new File(getShapefileBaseDir(), uuid); |
263 File test = new File(dir, WSPLGEN_USER_SHAPE); | 266 File test = new File(dir, WSPLGEN_USER_SHAPE); |
264 | 267 |
265 if (!test.exists() || !test.canRead()) { | 268 if (!test.exists() || !test.canRead()) { |
266 logger.debug("No user layer existing."); | 269 logger.debug("No user layer existing."); |
267 return; | 270 return null; |
268 } | 271 } |
269 | 272 |
270 File userShape = new File(dir, WSPLGEN_USER_SHAPE); | 273 File userShape = new File(dir, WSPLGEN_USER_SHAPE); |
271 ShpFiles sf = new ShpFiles(userShape); | 274 ShpFiles sf = new ShpFiles(userShape); |
272 ShapefileReader sfr = new ShapefileReader(sf, true, false, null); | 275 ShapefileReader sfr = new ShapefileReader(sf, true, false, null); |
282 } | 285 } |
283 else if (sfh.getShapeType().isPolygonType()) { | 286 else if (sfh.getShapeType().isPolygonType()) { |
284 info.setType("POLYGON"); | 287 info.setType("POLYGON"); |
285 } | 288 } |
286 else { | 289 else { |
287 return; | 290 logger.debug("createUserShapeLayer(): unexpected geometry type"); |
291 return null; | |
288 } | 292 } |
289 info.setDirectory(uuid); | 293 info.setDirectory(uuid); |
290 info.setData(WSPLGEN_USER_SHAPE); | 294 info.setData(WSPLGEN_USER_SHAPE); |
291 info.setTitle("I18N_USER_SHAPE"); | 295 info.setTitle("I18N_USER_SHAPE"); |
292 info.setGroup(group); | 296 info.setGroup(group); |
296 String nameUser = "user.layer"; //MS_LAYER_PREFIX + wms.getName(); | 300 String nameUser = "user.layer"; //MS_LAYER_PREFIX + wms.getName(); |
297 | 301 |
298 Template tpl = getTemplateByName(SHP_LAYER_TEMPLATE); | 302 Template tpl = getTemplateByName(SHP_LAYER_TEMPLATE); |
299 if (tpl == null) { | 303 if (tpl == null) { |
300 logger.warn("Template '" + SHP_LAYER_TEMPLATE + "' found."); | 304 logger.warn("Template '" + SHP_LAYER_TEMPLATE + "' found."); |
301 return; | 305 return null; |
302 } | 306 } |
307 | |
308 File layerFile = new File(dir, nameUser); | |
303 | 309 |
304 try { | 310 try { |
305 writeLayer(info, new File(dir, nameUser), tpl); | 311 writeLayer(info, layerFile, tpl); |
306 } | 312 } |
307 catch (FileNotFoundException fnfe) { | 313 catch (FileNotFoundException fnfe) { |
308 logger.error(fnfe, fnfe); | 314 logger.error(fnfe, fnfe); |
309 logger.warn("Unable to write layer: " + nameUser); | 315 logger.warn("Unable to write layer: " + nameUser); |
310 } | 316 } |
311 | 317 return layerFile; |
312 } | 318 } |
313 | 319 |
314 | 320 |
315 /** | 321 /** |
316 * Creates a layer file used for Mapserver's mapfile which represents | 322 * Creates a layer file used for Mapserver's mapfile which represents |