svn-gvsig-desktop / trunk / extensions / extPublish / src / org / gvsig / remoteservices / conf / mapserver / MapServer.java @ 7339
History | View | Annotate | Download (24.2 KB)
1 |
package org.gvsig.remoteservices.conf.mapserver; |
---|---|
2 |
|
3 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
4 |
*
|
5 |
* Copyright (C) 2004-2006 IVER T.I. and Generalitat Valenciana.
|
6 |
*
|
7 |
* This program is free software; you can redistribute it and/or
|
8 |
* modify it under the terms of the GNU General Public License
|
9 |
* as published by the Free Software Foundation; either version 2
|
10 |
* of the License, or (at your option) any later version.
|
11 |
*
|
12 |
* This program is distributed in the hope that it will be useful,
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
* GNU General Public License for more details.
|
16 |
*
|
17 |
* You should have received a copy of the GNU General Public License
|
18 |
* along with this program; if not, write to the Free Software
|
19 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
*
|
21 |
* For more information, contact:
|
22 |
*
|
23 |
* Generalitat Valenciana
|
24 |
* Conselleria d'Infraestructures i Transport
|
25 |
* Av. Blasco Ib??ez, 50
|
26 |
* 46010 VALENCIA
|
27 |
* SPAIN
|
28 |
*
|
29 |
* +34 963862235
|
30 |
* gvsig@gva.es
|
31 |
* www.gvsig.gva.es
|
32 |
*
|
33 |
* or
|
34 |
*
|
35 |
* IVER T.I. S.A
|
36 |
* Salamanca 50
|
37 |
* 46005 Valencia
|
38 |
* Spain
|
39 |
*
|
40 |
* +34 963163400
|
41 |
* dac@iver.es
|
42 |
*/
|
43 |
/* CVS MESSAGES:
|
44 |
*
|
45 |
* $Id: MapServer.java 7339 2006-09-19 07:34:00Z dagilgon $
|
46 |
* $Log$
|
47 |
* Revision 1.25 2006-09-19 07:34:00 dagilgon
|
48 |
* Corregida salida duplicada del campo crs en matadataweb
|
49 |
*
|
50 |
* Revision 1.24 2006/09/19 00:30:31 luisw2
|
51 |
* Soporte para WCS en mapserver. Pendiente de verificar que va
|
52 |
*
|
53 |
* Revision 1.23 2006/09/18 08:41:22 dagilgon
|
54 |
* A?adida clase leyend y label
|
55 |
*
|
56 |
* Revision 1.22 2006/09/14 12:06:16 jorpiell
|
57 |
* A?adido el constructor con dos colores para el stylemap
|
58 |
*
|
59 |
* Revision 1.21 2006/09/13 12:08:31 luisw2
|
60 |
* Adding WCS to mapserver ...
|
61 |
*
|
62 |
* Revision 1.19 2006/09/08 18:03:18 jorpiell
|
63 |
* El EPSG se escribe en min?sculas y los times se escriben en orden
|
64 |
*
|
65 |
* Revision 1.18 2006/09/08 17:58:01 jorpiell
|
66 |
* El EPSG se escribe en min?sculas y los times se escriben en orden
|
67 |
*
|
68 |
* Revision 1.17 2006/09/08 12:50:20 jorpiell
|
69 |
* Se tiene en cuanta el par?metro TIME
|
70 |
*
|
71 |
* Revision 1.16 2006/09/08 10:50:05 jorpiell
|
72 |
* A?adida la opci?n de generar una capa POSTGIS
|
73 |
*
|
74 |
* Revision 1.15 2006/09/08 10:14:04 luisw2
|
75 |
* IRSLayer Added
|
76 |
*
|
77 |
* Revision 1.14 2006/09/08 07:12:03 luisw2
|
78 |
* Minor corrections for raster; abstract added
|
79 |
*
|
80 |
* Revision 1.13 2006/09/07 19:25:01 luisw2
|
81 |
* Correcciones en metadata
|
82 |
*
|
83 |
* Revision 1.12 2006/09/07 19:20:51 jorpiell
|
84 |
* Classpath modificado
|
85 |
*
|
86 |
* Revision 1.11 2006/09/07 19:16:30 jorpiell
|
87 |
* *** empty log message ***
|
88 |
*
|
89 |
* Revision 1.10 2006/09/07 18:11:06 luisw2
|
90 |
* Adding Time to mapserver ...
|
91 |
*
|
92 |
* Revision 1.9 2006/09/07 16:34:28 luisw2
|
93 |
* A?adido size
|
94 |
*
|
95 |
* Revision 1.8 2006/09/07 16:10:45 luisw2
|
96 |
* a?adido flush() en el close;
|
97 |
*
|
98 |
* Revision 1.7 2006/09/07 12:59:44 jorpiell
|
99 |
* Enganchada la interfaz gr?fica con el generador de ficheros
|
100 |
*
|
101 |
* Revision 1.6 2006/09/07 12:51:54 jorpiell
|
102 |
* Enganchada la interfaz gr?fica con el generador de ficheros
|
103 |
*
|
104 |
* Revision 1.5 2006/09/07 12:47:39 jorpiell
|
105 |
* A?adida la expression en el classMap
|
106 |
*
|
107 |
* Revision 1.4 2006/09/07 11:19:40 jvhigon
|
108 |
* A?adido soporte para multiples class en una layer, y para layer sdentro de layer
|
109 |
*
|
110 |
* Revision 1.3 2006/09/01 06:59:00 luisw2
|
111 |
* Headers mofification
|
112 |
*
|
113 |
*/
|
114 |
import java.awt.Color; |
115 |
import java.awt.Dimension; |
116 |
import java.awt.geom.Rectangle2D; |
117 |
import java.io.File; |
118 |
import java.io.FileNotFoundException; |
119 |
import java.io.FileOutputStream; |
120 |
import java.io.PrintStream; |
121 |
import java.util.ArrayList; |
122 |
import java.util.Iterator; |
123 |
import java.awt.Point; |
124 |
|
125 |
import org.gvsig.remoteservices.conf.IRSLayer; |
126 |
|
127 |
/**
|
128 |
* Allows to write a .map Mapserver configuration file.
|
129 |
*
|
130 |
* @author David Gilsanz
|
131 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
132 |
*/
|
133 |
|
134 |
/* MAP
|
135 |
NAME test_postgis
|
136 |
STATUS ON
|
137 |
SIZE 400 300
|
138 |
#SYMBOLSET ../etc/symbols.sym
|
139 |
EXTENT 638610.4375 4222780 789330 4484662.5
|
140 |
UNITS METERS
|
141 |
SHAPEPATH "/home/shapes/"
|
142 |
IMAGECOLOR 255 255 255
|
143 |
#FONTSET ../etc/fonts.txt
|
144 |
|
145 |
WEB
|
146 |
# IMAGEPATH "/ms4w/tmp/ms_tmp/"
|
147 |
# IMAGEURL "/ms_tmp/"
|
148 |
METADATA
|
149 |
"wms_title" "test postgis" ##required
|
150 |
"wms_onlineresource" "http://localhost/mapserver/mapserv" ##required
|
151 |
"wms_srs" "EPSG:42304 EPSG:42101 EPSG:4269 EPSG:4326 EPSG:23030" ##recommended
|
152 |
END
|
153 |
END
|
154 |
|
155 |
PROJECTION
|
156 |
"init=epsg:23030" ##required
|
157 |
END
|
158 |
|
159 |
#
|
160 |
# Start of layer definitions
|
161 |
#
|
162 |
|
163 |
LAYER
|
164 |
NAME "autopistas"
|
165 |
DATA "the_geom from autopistas"
|
166 |
CONNECTIONTYPE POSTGIS
|
167 |
CONNECTION "user=david password=pwd dbname=betel host=localhost port=5434"
|
168 |
STATUS ON
|
169 |
TYPE LINE
|
170 |
METADATA
|
171 |
"wms_title" "Autopistas GV" ##required
|
172 |
"wms_extent" "638610.4375 4222780 789330 4484662.5"
|
173 |
END
|
174 |
PROJECTION
|
175 |
"init=epsg:23030" ##recommended
|
176 |
END
|
177 |
CLASS
|
178 |
NAME "Autopistas"
|
179 |
STYLE
|
180 |
COLOR 200 255 0
|
181 |
OUTLINECOLOR 120 120 120
|
182 |
END
|
183 |
END
|
184 |
END
|
185 |
|
186 |
END # Map File
|
187 |
*/
|
188 |
public abstract class MapServer { |
189 |
public static final String SHP_TYPE_LINE = "LINE"; |
190 |
public static final String SHP_TYPE_POLYLINE = "POLYLINE"; |
191 |
public static final String SHP_TYPE_POINT = "POINT"; |
192 |
public static final String SHP_TYPE_POLYGON = "POLYGON"; |
193 |
|
194 |
public static class RGB { |
195 |
int r,g,b;
|
196 |
public RGB(int red,int green,int blue){ |
197 |
r=red; |
198 |
g=green; |
199 |
b=blue; |
200 |
} |
201 |
public String toString(){ |
202 |
return ""+r+" "+g+" "+b; |
203 |
} |
204 |
} |
205 |
|
206 |
public static class CRS extends MapServer { |
207 |
boolean init = false; |
208 |
String crs = ""; |
209 |
public CRS(String crs, boolean init) { |
210 |
this.crs = crs;
|
211 |
this.init =init;
|
212 |
} |
213 |
|
214 |
public String toString() { |
215 |
String str = ""; |
216 |
if (init){
|
217 |
str += "init=";
|
218 |
return str+crs.toLowerCase();
|
219 |
} |
220 |
return crs; //LWS .toLowerCase(); |
221 |
} |
222 |
|
223 |
public void toMap() { |
224 |
toMapln("PROJECTION");
|
225 |
tabIn(); |
226 |
toMapln("\""+this+"\""); |
227 |
tabOut(); |
228 |
toMapln("END");
|
229 |
} |
230 |
|
231 |
/**
|
232 |
* @return Returns the crs.
|
233 |
*/
|
234 |
public String getCrs() { |
235 |
return crs;
|
236 |
} |
237 |
} |
238 |
|
239 |
public static class OutputFormat extends MapServer { |
240 |
/*
|
241 |
OUTPUTFORMAT
|
242 |
NAME GEOTIFF_INT16
|
243 |
DRIVER "GDAL/GTiff"
|
244 |
IMAGEMODE INT16
|
245 |
EXTENSION "tif"
|
246 |
END
|
247 |
*/
|
248 |
public String name = null; |
249 |
public String driver = null; |
250 |
public String imageMode = null; |
251 |
public String extension = null; |
252 |
|
253 |
/**
|
254 |
* Creates a new OutputFormat.
|
255 |
* @param name
|
256 |
* @param driver
|
257 |
* @param imageMode
|
258 |
* @param extension
|
259 |
*/
|
260 |
public OutputFormat(String name, String driver, String imageMode, String extension) { |
261 |
this.name = name;
|
262 |
this.driver = driver;
|
263 |
this.imageMode = imageMode;
|
264 |
this.extension = extension;
|
265 |
} |
266 |
|
267 |
public void toMap() { |
268 |
toMapln("OUTPUTFORMAT");
|
269 |
tabIn(); |
270 |
toMapln("NAME "+name+""); |
271 |
toMapln("DRIVER \""+driver+"\""); |
272 |
toMapln("IMAGEMODE "+imageMode+""); |
273 |
toMapln("EXTENSION \""+extension+"\""); |
274 |
tabOut(); |
275 |
toMapln("END");
|
276 |
} |
277 |
} |
278 |
public static class Label extends MapServer{ |
279 |
|
280 |
public String angle = null; |
281 |
public String antialias = null; |
282 |
public RGB backgroundcolor = null; |
283 |
public RGB backgroundshadowcolor = null; |
284 |
public Point backgroundshadowsize = null; |
285 |
public String buffer = null; |
286 |
public RGB color = null; |
287 |
public String encoding = null; |
288 |
public String force = null; |
289 |
public String maxsize = null; |
290 |
public String mindistance = null; |
291 |
public String minfeaturesize = null; |
292 |
public String minsize = null; |
293 |
public Point offset = null; |
294 |
public RGB outlinecolor = null; |
295 |
public String partials = null; |
296 |
public String position = null; |
297 |
public RGB shadowcolor = null; |
298 |
public Point shadowsize = null; |
299 |
public String size = null; |
300 |
public String type = null; |
301 |
public String wrap = null; |
302 |
|
303 |
public void tomap(){ |
304 |
toMapln("LABEL");
|
305 |
tabIn(); |
306 |
if(angle != null) |
307 |
toMapln("ANGLE "+angle.toUpperCase()+""); |
308 |
if(antialias != null) |
309 |
toMapln("ANTIALIAS \""+antialias+"\""); |
310 |
if(backgroundcolor != null) |
311 |
toMapln("BACKGROUNDCOLOR "+backgroundcolor.toString()+""); |
312 |
if(backgroundshadowcolor != null) |
313 |
toMapln("BACKGROUNDSHADOWCOLOR "+backgroundshadowcolor.toString()+""); |
314 |
if(backgroundshadowsize != null) |
315 |
toMapln("BACKGROUNDSHADOWSIZE "+backgroundshadowsize.toString()+""); |
316 |
if(buffer != null) |
317 |
toMapln("BUFFER \""+buffer+"\""); |
318 |
if(color != null) |
319 |
toMapln("COLOR "+color.toString()+""); |
320 |
if(encoding != null) |
321 |
toMapln("ENCODING \""+encoding+"\""); |
322 |
if(force != null) |
323 |
toMapln("FORCE \""+force+"\""); |
324 |
if(maxsize != null) |
325 |
toMapln("MAXSIZE "+maxsize+""); |
326 |
if(mindistance != null) |
327 |
toMapln("MINDISTANCE "+mindistance+""); |
328 |
if(minfeaturesize != null) |
329 |
toMapln("MINFEATURESIZE "+minfeaturesize+"" +""); |
330 |
if(minsize != null) |
331 |
toMapln("MINSIZE "+minsize+""); |
332 |
if(offset != null) |
333 |
toMapln("OFFSET "+offset.toString()+""); |
334 |
if(outlinecolor != null) |
335 |
toMapln("OUTLINECOLOR "+outlinecolor.toString()+""); |
336 |
if(partials != null) |
337 |
toMapln("PARTIALS \""+partials+"\""); |
338 |
if(position != null) |
339 |
toMapln("POSITION \""+position+"\""); |
340 |
if(shadowcolor!= null) |
341 |
toMapln("SHADOWCOLOR "+shadowcolor.toString()+""); |
342 |
if(shadowsize != null) |
343 |
toMapln("SHADOWSIZE "+shadowsize.toString()+""); |
344 |
if(size != null) |
345 |
toMapln("SIZE \""+size.toUpperCase()+"\""); |
346 |
if(type != null) |
347 |
toMapln("TYPE \""+type+"\""); |
348 |
if(wrap != null) |
349 |
toMapln("WRAP \""+wrap+"\""); |
350 |
tabOut(); |
351 |
toMapln("END");
|
352 |
} |
353 |
} |
354 |
|
355 |
public static class Legend extends MapServer{ |
356 |
public RGB imagecolor = null; |
357 |
public RGB outlinecolor = null; |
358 |
public String interlace = null; |
359 |
public Label legendlabel = null; |
360 |
public String position = null; |
361 |
public Point keysize = null; |
362 |
public Point keyspacing = null; |
363 |
public String postlabelcache = null; |
364 |
public String status = null; |
365 |
public String template = null; |
366 |
public String transparent = null; |
367 |
|
368 |
public void toMap(){ |
369 |
toMapln("LEGEND");
|
370 |
tabIn(); |
371 |
if(imagecolor != null) |
372 |
toMapln("IMAGECOLOR "+imagecolor.toString());
|
373 |
if(outlinecolor != null) |
374 |
toMapln("OUTLINECOLOR "+outlinecolor.toString());
|
375 |
if(interlace != null){ |
376 |
toMapln("INTERLACE \""+interlace.toUpperCase()+"\""); |
377 |
} |
378 |
if(legendlabel != null){ |
379 |
legendlabel.tomap(); |
380 |
} |
381 |
if(position != null) |
382 |
toMapln("POSITION \""+position+"\""); |
383 |
if(keysize != null) |
384 |
toMapln("KEYSIZE "+keysize.toString());
|
385 |
if(keyspacing != null) |
386 |
toMapln("KEYSPACING "+keyspacing.toString());
|
387 |
if(postlabelcache != null) |
388 |
toMapln("POSTLABELCACHE \""+postlabelcache+"\""); |
389 |
if(status != null) |
390 |
toMapln("STATUS \""+status.toUpperCase()+"\""); |
391 |
if(template!=null){ |
392 |
toMapln("TEMPLATE \""+template+"\""); |
393 |
} |
394 |
if(transparent != null){ |
395 |
toMapln("TRANSPARENT \""+transparent.toUpperCase()+"\""); |
396 |
} |
397 |
tabOut(); |
398 |
toMapln("END");
|
399 |
} |
400 |
} |
401 |
|
402 |
public static class Metadata extends MapServer { |
403 |
public String prefix = "wms"; |
404 |
public String title = null; |
405 |
public String abstrac = null; |
406 |
public String label = null; |
407 |
public String name = null; |
408 |
|
409 |
public void setServiceAsWFS() { |
410 |
prefix = "wfs";
|
411 |
} |
412 |
|
413 |
public void setServiceAsWMS() { |
414 |
prefix = "wms";
|
415 |
} |
416 |
public void setServiceAsWCS() { |
417 |
prefix = "wcs";
|
418 |
} |
419 |
//
|
420 |
void startMetadataToMap(){
|
421 |
toMapln("METADATA");
|
422 |
tabIn(); |
423 |
if (name != null) |
424 |
toMapln("\""+prefix+"_name\" \""+name+"\""); |
425 |
if (label != null) |
426 |
toMapln("\""+prefix+"_label\" \""+label+"\""); |
427 |
if (title != null) |
428 |
toMapln("\""+prefix+"_title\" " +"\""+title+"\""); |
429 |
if (abstrac != null) |
430 |
toMapln("\""+prefix+"_astract\" " +"\""+abstrac+"\""); |
431 |
if (crs != null) |
432 |
toMapln("\""+prefix+"_srs\" \""+crs+"\""); |
433 |
if (extent != null) |
434 |
toMapln("\""+prefix+"_extent\" \""+extentToMapString()+"\""); |
435 |
} |
436 |
|
437 |
void endMetadataToMap() {
|
438 |
tabOut(); |
439 |
toMapln("END");
|
440 |
} |
441 |
} |
442 |
|
443 |
public static class MetadataWeb extends Metadata { |
444 |
//Atributos wms_xxxx WEB
|
445 |
public String onlineresource = null; |
446 |
public String ows_schemas_location = null; |
447 |
public String timeFormat = null; |
448 |
public String keywordlist = null; |
449 |
|
450 |
void metadataToMap(){
|
451 |
startMetadataToMap(); |
452 |
if (keywordlist != null) |
453 |
toMapln("\""+prefix+"_keywordlist\" \""+keywordlist+"\""); |
454 |
toMapln("\""+prefix+"_onlineresource\" \""+onlineresource+"\""); |
455 |
//if (crs != null)
|
456 |
// toMapln("\""+prefix+"_srs\" \""+crs+"\"");
|
457 |
if (ows_schemas_location != null) |
458 |
toMapln("\"ows_schemas_location\" \""+ows_schemas_location+"\""); |
459 |
if (timeFormat != null) |
460 |
toMapln("\""+prefix+"_timeformat\" \""+timeFormat+"\""); |
461 |
endMetadataToMap(); |
462 |
} |
463 |
} |
464 |
|
465 |
public static class MetadataLayer extends Metadata { |
466 |
//Atributos wms_xxxx LAYER
|
467 |
public String gml_include_items = null; |
468 |
public String timeExtent = null; |
469 |
public String timeDefault = null; |
470 |
public String timeItem = null; |
471 |
// WCS
|
472 |
public String description = null; |
473 |
public String resolution = null; |
474 |
public String formats = null; |
475 |
public String bandCount = null; |
476 |
public String nativeFormat = null; |
477 |
public String rangesetAxes = null; |
478 |
public String rangesetLabels = null; |
479 |
public String rangesetName = null; |
480 |
|
481 |
public void setRangeset(String str) { |
482 |
rangesetAxes = rangesetLabels = rangesetName = str; |
483 |
} |
484 |
|
485 |
void metadataToMap(){
|
486 |
startMetadataToMap(); |
487 |
if (gml_include_items != null) |
488 |
toMapln("\"gml_include_items\" \""+gml_include_items+"\""); |
489 |
// WMS with TIME
|
490 |
if (timeExtent != null) |
491 |
toMapln("\""+prefix+"_timeextent\" \""+timeExtent+"\""); |
492 |
if (timeDefault != null) |
493 |
toMapln("\""+prefix+"_timedefault\" \""+timeDefault+"\""); |
494 |
if (timeItem != null) |
495 |
toMapln("\""+prefix+"_timeitem\" \""+timeItem+"\""); |
496 |
// WCS
|
497 |
if (description != null) |
498 |
toMapln("\""+prefix+"_description\" \""+description+"\""); |
499 |
if (resolution != null) |
500 |
toMapln("\""+prefix+"_resolution\" \""+resolution+"\""); |
501 |
if (formats != null) |
502 |
toMapln("\""+prefix+"_formats\" \""+formats+"\""); |
503 |
if (bandCount != null) |
504 |
toMapln("\""+prefix+"_bandcount\" \""+bandCount+"\""); |
505 |
if (nativeFormat != null) |
506 |
toMapln("\""+prefix+"_nativeformat\" \""+nativeFormat+"\""); |
507 |
if (rangesetAxes != null) |
508 |
toMapln("\""+prefix+"_rangeset_axes\" \""+rangesetAxes+"\""); |
509 |
if (rangesetLabels != null) |
510 |
toMapln("\""+prefix+"_rangeset_labels\" \""+rangesetLabels+"\""); |
511 |
if (rangesetName != null) |
512 |
toMapln("\""+prefix+"_rangeset_name\" \""+rangesetName+"\""); |
513 |
|
514 |
endMetadataToMap(); |
515 |
} |
516 |
} |
517 |
|
518 |
public static class StyleMap extends MapServer { |
519 |
public RGB styleColor = null; |
520 |
public RGB styleColorOutline = null; |
521 |
public int size = -1; |
522 |
public StyleMap(RGB line, RGB fill) {
|
523 |
styleColor = fill; |
524 |
styleColorOutline = line; |
525 |
} |
526 |
public StyleMap(Color color, Color outLineColor) { |
527 |
RGB rgbStyleColor = null;
|
528 |
RGB rgbStyleColorOutline = null;
|
529 |
try{
|
530 |
rgbStyleColor = (new RGB(color.getRed(),
|
531 |
color.getGreen(), |
532 |
color.getBlue())); |
533 |
}catch(NullPointerException e){ |
534 |
//Line color is empty
|
535 |
} |
536 |
try{
|
537 |
rgbStyleColorOutline = (new RGB(outLineColor.getRed(),
|
538 |
outLineColor.getGreen(), |
539 |
outLineColor.getBlue())); |
540 |
}catch(NullPointerException e){ |
541 |
//Fill color is empty
|
542 |
} |
543 |
styleColor = rgbStyleColor; |
544 |
styleColorOutline = rgbStyleColorOutline; |
545 |
} |
546 |
void styleToMap(){
|
547 |
toMapln("STYLE ");
|
548 |
tabIn(); |
549 |
if (styleColor != null){ |
550 |
toMapln("COLOR "+styleColor);
|
551 |
} |
552 |
if (styleColorOutline != null){ |
553 |
toMapln("OUTLINECOLOR "+styleColorOutline);
|
554 |
} |
555 |
if (size > -1) |
556 |
toMapln("SIZE "+size);
|
557 |
tabOut(); |
558 |
toMapln("END");
|
559 |
} |
560 |
} |
561 |
|
562 |
public static class WebMap extends MapServer{ |
563 |
public MetadataWeb metadata = null; |
564 |
public String imagepath = null; |
565 |
public String imageurl = null; |
566 |
public String log = null; |
567 |
|
568 |
void webToMap(){
|
569 |
toMapln("WEB");
|
570 |
tabIn(); |
571 |
if (log != null) |
572 |
toMapln("LOG \""+log+"\""); |
573 |
toMapln("IMAGEPATH \""+imagepath+"\""); |
574 |
toMapln("IMAGEURL \""+imageurl+"\""); |
575 |
metadata.metadataToMap(); |
576 |
tabOut(); |
577 |
toMapln("END");
|
578 |
} |
579 |
} |
580 |
|
581 |
public static class MapClass extends MapServer { |
582 |
public String name; |
583 |
public StyleMap estilo = null; |
584 |
public String template = null; |
585 |
public String expression = null; |
586 |
public Label etiqueta = null; |
587 |
public int size = -1; |
588 |
public MapClass(String n) { |
589 |
name = n; |
590 |
} |
591 |
public void classToMap(){ |
592 |
toMapln("CLASS");
|
593 |
tabIn(); |
594 |
if (expression != null){ |
595 |
toMapln("EXPRESSION " + expression);
|
596 |
} |
597 |
toMapln("NAME \""+name+"\""); |
598 |
if (estilo != null) |
599 |
estilo.styleToMap(); |
600 |
if (size > -1) |
601 |
toMapln("SIZE "+size);
|
602 |
if (template != null) |
603 |
toMapln("TEMPLATE "+template);
|
604 |
if (etiqueta != null) |
605 |
etiqueta.tomap(); |
606 |
tabOut(); |
607 |
toMapln("END");
|
608 |
} |
609 |
} |
610 |
|
611 |
public abstract static class MapLayer extends MapServer |
612 |
implements IRSLayer {
|
613 |
public String name; |
614 |
public String title=null; |
615 |
public String status = "ON"; |
616 |
public String type = null; |
617 |
public int transparency = -1; |
618 |
public ArrayList classList = null; |
619 |
public ArrayList layerList = null; |
620 |
public String data; |
621 |
public MetadataLayer metadata = null; |
622 |
public boolean dump = false; |
623 |
public CRS layercrs=null; |
624 |
public String tileIndex = null; |
625 |
public String tileItem = null; |
626 |
|
627 |
|
628 |
public MapLayer() {
|
629 |
super();
|
630 |
metadata=new MetadataLayer();
|
631 |
} |
632 |
|
633 |
public void setDump(boolean d) { |
634 |
dump = d; |
635 |
} |
636 |
|
637 |
void startToMap() {
|
638 |
toMapln("LAYER");
|
639 |
tabIn(); |
640 |
toMapln("NAME \""+name+"\""); |
641 |
// if (title != null)
|
642 |
// toMapln("TITLE \""+title+"\"");
|
643 |
toMapln("STATUS "+status);
|
644 |
if (transparency > -1) |
645 |
toMapln("TRANSPARENCY " + transparency);
|
646 |
if (tileIndex != null) |
647 |
toMapln("TILEINDEX \""+tileIndex+"\""); |
648 |
if (tileItem != null) |
649 |
toMapln("TILEITEM \""+tileItem+"\""); |
650 |
if (type != null) |
651 |
toMapln("TYPE "+type);
|
652 |
if (dump)
|
653 |
toMapln("DUMP TRUE # required");
|
654 |
if (data != null) |
655 |
toMapln("DATA \""+data+"\""); |
656 |
} |
657 |
|
658 |
void endToMap() {
|
659 |
tabOut(); |
660 |
toMapln("END # Layer");
|
661 |
} |
662 |
|
663 |
public void addClass(MapClass c) { |
664 |
if (classList == null) |
665 |
classList = new ArrayList(); |
666 |
classList.add(c); |
667 |
} |
668 |
|
669 |
public void classListToMap() { |
670 |
if (classList != null) { |
671 |
Iterator iter = classList.iterator();
|
672 |
while (iter.hasNext()) {
|
673 |
MapClass c = (MapClass) iter.next(); |
674 |
c.classToMap(); |
675 |
} |
676 |
} |
677 |
|
678 |
} |
679 |
|
680 |
public void addLayer(MapLayer c) { |
681 |
if (layerList == null) |
682 |
layerList = new ArrayList(); |
683 |
layerList.add(c); |
684 |
} |
685 |
|
686 |
public void layerListToMap() { |
687 |
if (layerList != null) { |
688 |
Iterator iter = layerList.iterator();
|
689 |
tabIn(); |
690 |
while (iter.hasNext()) {
|
691 |
MapLayer l = (MapLayer) iter.next(); |
692 |
l.layerToMap(); |
693 |
} |
694 |
tabOut(); |
695 |
} |
696 |
} |
697 |
|
698 |
public abstract void layerToMap(); |
699 |
|
700 |
public String getName() { |
701 |
return name;
|
702 |
} |
703 |
|
704 |
public void setName(String name) { |
705 |
this.name = name;
|
706 |
metadata.name = name; |
707 |
setTitle(name); |
708 |
} |
709 |
|
710 |
public String getTitle() { |
711 |
return title;
|
712 |
} |
713 |
|
714 |
public void setTitle(String title) { |
715 |
this.title = title;
|
716 |
metadata.title = title; |
717 |
} |
718 |
|
719 |
public void setExtent(double minx, double miny, double maxx, double maxy) { |
720 |
super.setExtent(minx, miny, maxx, maxy);
|
721 |
metadata.setExtent(extent); |
722 |
} |
723 |
|
724 |
public void setExtent(Rectangle2D extent) { |
725 |
super.setExtent(extent);
|
726 |
metadata.setExtent(extent); |
727 |
} |
728 |
|
729 |
} |
730 |
|
731 |
public static class ShpLayer extends MapLayer { |
732 |
public void layerToMap() { |
733 |
startToMap(); |
734 |
metadata.metadataToMap(); |
735 |
if (layercrs != null) layercrs.toMap(); |
736 |
classListToMap(); |
737 |
endToMap(); |
738 |
} |
739 |
} |
740 |
|
741 |
public static class PostgisLayer extends MapLayer { |
742 |
public String user; |
743 |
public String pass; |
744 |
public String host; |
745 |
public String dbname; |
746 |
public String port; |
747 |
|
748 |
public String tabla; |
749 |
public String data; |
750 |
|
751 |
public void setConnParams(String user, String pass, String host, |
752 |
String dbname, String port) { |
753 |
this.user = user;
|
754 |
this.pass = pass;
|
755 |
this.host = host;
|
756 |
this.dbname = dbname;
|
757 |
this.port = port;
|
758 |
} |
759 |
|
760 |
public void layerToMap() { |
761 |
startToMap(); |
762 |
toMapln("DATA \""+data+"\""); |
763 |
toMapln("CONNECTIONTYPE POSTGIS");
|
764 |
StringBuffer connection = new StringBuffer(); |
765 |
connection.append("CONNECTION \"user="+user);
|
766 |
if (pass != null){ |
767 |
connection.append(" password="+pass);
|
768 |
} |
769 |
connection.append(" dbname="+dbname+" host="+host+" port="+port+"\""); |
770 |
toMapln(connection.toString()); |
771 |
metadata.metadataToMap(); |
772 |
if (layercrs != null) layercrs.toMap(); |
773 |
classListToMap(); |
774 |
endToMap(); |
775 |
} |
776 |
} |
777 |
|
778 |
public static class RasterLayer extends MapLayer { |
779 |
public void layerToMap() { |
780 |
startToMap(); |
781 |
metadata.metadataToMap(); |
782 |
if (layercrs != null) layercrs.toMap(); |
783 |
classListToMap(); |
784 |
endToMap(); |
785 |
} |
786 |
} |
787 |
|
788 |
public static class ConfigFile extends MapServer { |
789 |
/**
|
790 |
* Atributos wms_xxxx comunes a WEB y LAYER.
|
791 |
* @author david
|
792 |
*/
|
793 |
|
794 |
public String mapFileName = null; |
795 |
public String fName = null; |
796 |
public String mapName = null; |
797 |
public String mapStatus = null; |
798 |
public String mapUnits= null; |
799 |
public String mapShapePath; |
800 |
public Dimension mapSize = null; |
801 |
public CRS mapcrs= null; |
802 |
public WebMap www = null; |
803 |
public String symbolset = null; |
804 |
public String fontset = null; |
805 |
public RGB imageColor = null; |
806 |
public Legend leyenda = null; |
807 |
|
808 |
private ArrayList outputFormats = new ArrayList(); |
809 |
private ArrayList layers = new ArrayList(); |
810 |
|
811 |
public ConfigFile() {
|
812 |
www = new MapServer.WebMap();
|
813 |
www.metadata=new MapServer.MetadataWeb();
|
814 |
} |
815 |
|
816 |
public void generate() { |
817 |
generate(null);
|
818 |
} |
819 |
|
820 |
public void generate(String donde) { |
821 |
openMapFile(donde); |
822 |
toMapln("MAP");
|
823 |
tabIn(); |
824 |
toMapln("NAME "+mapName);
|
825 |
if (mapSize != null) |
826 |
toMapln("SIZE "+mapSize.width+" "+mapSize.height); |
827 |
if (extent != null) |
828 |
toMapln("EXTENT "+extentToMapString());
|
829 |
toMapln("STATUS "+mapStatus);
|
830 |
toMapln("UNITS "+mapUnits);
|
831 |
// OUTPUTFORMATS
|
832 |
{ |
833 |
Iterator iter = outputFormats.iterator();
|
834 |
while(iter.hasNext()) {
|
835 |
OutputFormat o = (OutputFormat) iter.next(); |
836 |
o.toMap(); |
837 |
} |
838 |
} |
839 |
|
840 |
toMapln("SHAPEPATH \""+mapShapePath+"\""); |
841 |
if (symbolset != null) |
842 |
toMapln("SYMBOLSET "+symbolset);
|
843 |
if (symbolset != null) |
844 |
toMapln("FONTSET "+symbolset);
|
845 |
if (imageColor != null) |
846 |
toMapln("IMAGECOLOR \""+imageColor+"\""); |
847 |
if(leyenda!=null){ |
848 |
leyenda.toMap(); |
849 |
} |
850 |
www.webToMap(); |
851 |
if (mapcrs != null) |
852 |
projectionToMap(mapcrs,true);
|
853 |
// LAYERS
|
854 |
{ |
855 |
Iterator iter = layers.iterator();
|
856 |
while(iter.hasNext()) {
|
857 |
MapLayer l = (MapLayer) iter.next(); |
858 |
l.layerToMap(); |
859 |
} |
860 |
} |
861 |
tabOut(); |
862 |
toMapln("END # Map File");
|
863 |
closeMapFile(); |
864 |
} |
865 |
|
866 |
void openMapFile(String donde) { |
867 |
setMapFileName(donde); |
868 |
if (mapFileName == null) |
869 |
return;
|
870 |
File wmsmap = new File( mapFileName ); |
871 |
if (wmsmap.exists());
|
872 |
wmsmap.delete(); |
873 |
try{
|
874 |
//salida = new PrintStream(new BufferedOutputStream(new FileOutputStream(wmsmap)));
|
875 |
salida = new PrintStream(new FileOutputStream(wmsmap)); |
876 |
} catch(FileNotFoundException e){ |
877 |
System.out.println("Fichero no encontrado."); |
878 |
} |
879 |
System.out.println(mapFileName+" abierto."); |
880 |
|
881 |
} |
882 |
|
883 |
void closeMapFile() {
|
884 |
if (salida != null) { |
885 |
salida.flush(); |
886 |
salida.close(); |
887 |
} |
888 |
} |
889 |
|
890 |
public String getMapFileName() { |
891 |
return mapFileName;
|
892 |
} |
893 |
|
894 |
public void setMapFileName(String mapFileName) { |
895 |
this.mapFileName = mapFileName;
|
896 |
} |
897 |
|
898 |
public void add(MapLayer l) { |
899 |
layers.add(l); |
900 |
} |
901 |
public int layersCnt() { |
902 |
return layers.size();
|
903 |
} |
904 |
public MapLayer getLayer(int i) { |
905 |
return (MapLayer) layers.get(i);
|
906 |
} |
907 |
public void add(OutputFormat of) { |
908 |
outputFormats.add(of); |
909 |
} |
910 |
} |
911 |
|
912 |
static PrintStream salida = null; |
913 |
static String tabstop = ""; |
914 |
public Rectangle2D extent = null; |
915 |
public CRS crs = null; |
916 |
|
917 |
/**
|
918 |
*
|
919 |
* @param minx
|
920 |
* @param miny
|
921 |
* @param maxx
|
922 |
* @param maxy
|
923 |
*/
|
924 |
public void setExtent(double minx, double miny, double maxx, double maxy) { |
925 |
extent = new Rectangle2D.Double(); |
926 |
extent.setFrameFromDiagonal(minx, miny, maxx, maxy); |
927 |
} |
928 |
|
929 |
public void setExtent(Rectangle2D extent) { |
930 |
this.extent = extent;
|
931 |
} |
932 |
|
933 |
|
934 |
String extentToMapString(Rectangle2D ext) { |
935 |
if (ext != null) |
936 |
return ext.getMinX()+" "+ext.getMinY()+" "+ext.getMaxX()+" "+ext.getMaxY(); |
937 |
return ""; |
938 |
} |
939 |
String extentToMapString() {
|
940 |
if (extent != null) |
941 |
return extentToMapString(extent);
|
942 |
return ""; |
943 |
} |
944 |
|
945 |
void projectionToMap(CRS prj, boolean init) { |
946 |
if (prj == null) |
947 |
return;
|
948 |
toMapln("PROJECTION");
|
949 |
if (init == true) |
950 |
prj.toString(); |
951 |
tabIn(); |
952 |
toMapln("\""+prj+"\""); |
953 |
tabOut(); |
954 |
toMapln("END");
|
955 |
} |
956 |
|
957 |
public String replicate(String str, int n) { |
958 |
int i;
|
959 |
String ret = ""; |
960 |
for(i=0;i<n;i++){ |
961 |
ret += str; |
962 |
} |
963 |
return ret;
|
964 |
} |
965 |
|
966 |
public void tabIn() { |
967 |
tabstop += " ";
|
968 |
} |
969 |
|
970 |
public void tabOut() { |
971 |
tabstop = tabstop.substring(0,tabstop.length()-3); |
972 |
} |
973 |
|
974 |
void toMapln(String str){ |
975 |
if (salida == null) |
976 |
System.out.println(tabstop+str);
|
977 |
else
|
978 |
salida.println(tabstop+str); |
979 |
} |
980 |
} |