comparison flys-artifacts/src/main/java/de/intevation/flys/mapserver/ArtifactMapfileGenerator.java @ 5076:cc50e1b9fc60 mapgenfix

Work on ArtifactMapfileGenerator.createUserShapefileLayer()
author Christian Lins <christian.lins@intevation.de>
date Wed, 20 Feb 2013 21:00:33 +0100
parents 1da61095040c
children cbfdd7376009
comparison
equal deleted inserted replaced
5023:1da61095040c 5076:cc50e1b9fc60
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 67 createUserShapeLayer(layerShape);
68 } 68 }
69 else if (fileName.startsWith(MS_PREFIX_WSPLGEN)) { 69 else if (fileName.startsWith(MS_PREFIX_WSPLGEN)) {
70 70
71 } 71 }
72 } 72 }
89 ) throws FileNotFoundException, IOException 89 ) throws FileNotFoundException, IOException
90 { 90 {
91 logger.debug("createUeskLayer"); 91 logger.debug("createUeskLayer");
92 92
93 LayerInfo layerinfo = new LayerInfo(); 93 LayerInfo layerinfo = new LayerInfo();
94 layerinfo.setName(MS_WSPLGEN_PREFIX + flys.identifier()); 94 layerinfo.setName(MS_PREFIX_WSPLGEN + flys.identifier());
95 layerinfo.setType("POLYGON"); 95 layerinfo.setType("POLYGON");
96 layerinfo.setDirectory(flys.identifier()); 96 layerinfo.setDirectory(flys.identifier());
97 layerinfo.setData(WSPLGEN_RESULT_SHAPE); 97 layerinfo.setData(WSPLGEN_RESULT_SHAPE);
98 layerinfo.setTitle(Resources.getMsg(Resources.getLocale(context.getMeta()), 98 layerinfo.setTitle(Resources.getMsg(Resources.getLocale(context.getMeta()),
99 "floodmap.uesk", 99 "floodmap.uesk",
147 WMSLayerFacet wms 147 WMSLayerFacet wms
148 ) 148 )
149 throws FileNotFoundException, IOException 149 throws FileNotFoundException, IOException
150 { 150 {
151 String uuid = flys.identifier(); 151 String uuid = flys.identifier();
152 String group = MS_BARRIERS_PREFIX + uuid; 152 String group = MS_PREFIX_BARRIERS + uuid;
153 String groupTitle = "I18N_BARRIERS_TITLE"; 153 String groupTitle = "I18N_BARRIERS_TITLE";
154 154
155 File dir = new File(getShapefileBaseDir(), uuid); 155 File dir = new File(getShapefileBaseDir(), uuid);
156 File test = new File(dir, WSPLGEN_LINES_SHAPE); 156 File test = new File(dir, WSPLGEN_LINES_SHAPE);
157 157
192 WMSLayerFacet wms 192 WMSLayerFacet wms
193 ) 193 )
194 throws FileNotFoundException, IOException 194 throws FileNotFoundException, IOException
195 { 195 {
196 String uuid = flys.identifier(); 196 String uuid = flys.identifier();
197 String group = uuid + MS_BARRIERS_PREFIX; 197 String group = uuid + MS_PREFIX_BARRIERS;
198 String groupTitle = "I18N_BARRIERS_TITLE"; 198 String groupTitle = "I18N_BARRIERS_TITLE";
199 199
200 File dir = new File(getShapefileBaseDir(), uuid); 200 File dir = new File(getShapefileBaseDir(), uuid);
201 File test = new File(dir, WSPLGEN_POLYGONS_SHAPE); 201 File test = new File(dir, WSPLGEN_POLYGONS_SHAPE);
202 202
230 logger.error(fnfe, fnfe); 230 logger.error(fnfe, fnfe);
231 logger.warn("Unable to write layer: " + namePolygons); 231 logger.warn("Unable to write layer: " + namePolygons);
232 } 232 }
233 } 233 }
234 234
235 protected String uuidFromPath(String path) {
236 logger.debug("uuidFromPath(" + path + ")");
237 int i1 = 0;
238 int i2 = 0;
239
240 for(;;) {
241 int i = path.indexOf('/', i2 + 1);
242 if (i == -1) {
243 return path.substring(i1 + 1, i2);
244 }
245 else {
246 i1 = i2;
247 i2 = i;
248 }
249 }
250 }
235 251
236 /** 252 /**
237 * Creates a layer file used for Mapserver's mapfile which represents the 253 * Creates a layer file used for Mapserver's mapfile which represents the
238 * shape files uploaded by the user. 254 * shape files uploaded by the user.
239 *
240 * @param flys The FLYSArtifact that owns <i>wms</i>.
241 * @param wms The WMSLayerFacet that contains information for the layer.
242 */ 255 */
243 protected void createUserShapeLayer(FLYSArtifact flys, WMSLayerFacet wms) 256 protected void createUserShapeLayer(File file)
244 throws FileNotFoundException, IOException 257 throws FileNotFoundException, IOException
245 { 258 {
246 logger.debug("createUserShapeLayer"); 259 String uuid = uuidFromPath(file.getAbsolutePath());
247 260 logger.debug("createUserShapeLayer(): uuid=" + uuid);
248 String uuid = flys.identifier(); 261
249 File dir = new File(getShapefileBaseDir(), uuid); 262 File dir = new File(getShapefileBaseDir(), uuid);
250 File test = new File(dir, WSPLGEN_USER_SHAPE); 263 File test = new File(dir, WSPLGEN_USER_SHAPE);
251 264
252 if (!test.exists() || !test.canRead()) { 265 if (!test.exists() || !test.canRead()) {
253 logger.debug("No user layer existing."); 266 logger.debug("No user layer existing.");
257 File userShape = new File(dir, WSPLGEN_USER_SHAPE); 270 File userShape = new File(dir, WSPLGEN_USER_SHAPE);
258 ShpFiles sf = new ShpFiles(userShape); 271 ShpFiles sf = new ShpFiles(userShape);
259 ShapefileReader sfr = new ShapefileReader(sf, true, false, null); 272 ShapefileReader sfr = new ShapefileReader(sf, true, false, null);
260 ShapefileHeader sfh = sfr.getHeader(); 273 ShapefileHeader sfh = sfr.getHeader();
261 274
262 String group = uuid + MS_USERSHAPE_PREFIX; 275 String group = uuid + MS_PREFIX_USER;
263 String groupTitle = "I18N_USER_SHAPE_TITLE"; 276 String groupTitle = "I18N_USER_SHAPE_TITLE";
264 277
265 LayerInfo info = new LayerInfo(); 278 LayerInfo info = new LayerInfo();
266 info.setName(MS_USERSHAPE_PREFIX + uuid); 279 info.setName(MS_PREFIX_USER + uuid);
267 if (sfh.getShapeType().isLineType()) { 280 if (sfh.getShapeType().isLineType()) {
268 info.setType("LINE"); 281 info.setType("LINE");
269 } 282 }
270 else if (sfh.getShapeType().isPolygonType()) { 283 else if (sfh.getShapeType().isPolygonType()) {
271 info.setType("POLYGON"); 284 info.setType("POLYGON");
276 info.setDirectory(uuid); 289 info.setDirectory(uuid);
277 info.setData(WSPLGEN_USER_SHAPE); 290 info.setData(WSPLGEN_USER_SHAPE);
278 info.setTitle("I18N_USER_SHAPE"); 291 info.setTitle("I18N_USER_SHAPE");
279 info.setGroup(group); 292 info.setGroup(group);
280 info.setGroupTitle(groupTitle); 293 info.setGroupTitle(groupTitle);
281 info.setSrid(wms.getSrid()); 294 //info.setSrid(wms.getSrid()); // FIXME: Required?
282 295
283 String nameUser = MS_LAYER_PREFIX + wms.getName(); 296 String nameUser = "user.layer"; //MS_LAYER_PREFIX + wms.getName();
284 297
285 Template tpl = getTemplateByName(SHP_LAYER_TEMPLATE); 298 Template tpl = getTemplateByName(SHP_LAYER_TEMPLATE);
286 if (tpl == null) { 299 if (tpl == null) {
287 logger.warn("Template '" + SHP_LAYER_TEMPLATE + "' found."); 300 logger.warn("Template '" + SHP_LAYER_TEMPLATE + "' found.");
288 return; 301 return;

http://dive4elements.wald.intevation.org