svn-gvsig-desktop / trunk / extensions / extPublish / src / org / gvsig / remoteservices / conf / mapserver / MapServer.java @ 7103
History | View | Annotate | Download (12.7 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 7103 2006-09-07 12:59:44Z jorpiell $
|
46 |
* $Log$
|
47 |
* Revision 1.7 2006-09-07 12:59:44 jorpiell
|
48 |
* Enganchada la interfaz gr?fica con el generador de ficheros
|
49 |
*
|
50 |
* Revision 1.6 2006/09/07 12:51:54 jorpiell
|
51 |
* Enganchada la interfaz gr?fica con el generador de ficheros
|
52 |
*
|
53 |
* Revision 1.5 2006/09/07 12:47:39 jorpiell
|
54 |
* A?adida la expression en el classMap
|
55 |
*
|
56 |
* Revision 1.4 2006/09/07 11:19:40 jvhigon
|
57 |
* A?adido soporte para multiples class en una layer, y para layer sdentro de layer
|
58 |
*
|
59 |
* Revision 1.3 2006/09/01 06:59:00 luisw2
|
60 |
* Headers mofification
|
61 |
*
|
62 |
*/
|
63 |
import java.awt.Dimension; |
64 |
import java.awt.Rectangle; |
65 |
import java.awt.geom.Rectangle2D; |
66 |
import java.io.File; |
67 |
import java.io.FileNotFoundException; |
68 |
import java.io.FileOutputStream; |
69 |
import java.io.PrintStream; |
70 |
import java.util.ArrayList; |
71 |
import java.util.Iterator; |
72 |
|
73 |
|
74 |
/**
|
75 |
* Genera un .MAP
|
76 |
* ... como este:
|
77 |
MAP
|
78 |
NAME test_postgis
|
79 |
STATUS ON
|
80 |
SIZE 400 300
|
81 |
#SYMBOLSET ../etc/symbols.sym
|
82 |
EXTENT 638610.4375 4222780 789330 4484662.5
|
83 |
UNITS METERS
|
84 |
SHAPEPATH "/home/shapes/"
|
85 |
IMAGECOLOR 255 255 255
|
86 |
#FONTSET ../etc/fonts.txt
|
87 |
|
88 |
WEB
|
89 |
# IMAGEPATH "/ms4w/tmp/ms_tmp/"
|
90 |
# IMAGEURL "/ms_tmp/"
|
91 |
METADATA
|
92 |
"wms_title" "test postgis" ##required
|
93 |
"wms_onlineresource" "http://localhost/mapserver/mapserv" ##required
|
94 |
"wms_srs" "EPSG:42304 EPSG:42101 EPSG:4269 EPSG:4326 EPSG:23030" ##recommended
|
95 |
END
|
96 |
END
|
97 |
|
98 |
PROJECTION
|
99 |
"init=epsg:23030" ##required
|
100 |
END
|
101 |
|
102 |
#
|
103 |
# Start of layer definitions
|
104 |
#
|
105 |
|
106 |
LAYER
|
107 |
NAME "autopistas"
|
108 |
DATA "the_geom from autopistas"
|
109 |
CONNECTIONTYPE POSTGIS
|
110 |
CONNECTION "user=david password=chkdsk dbname=betel host=localhost port=5434"
|
111 |
STATUS ON
|
112 |
TYPE LINE
|
113 |
METADATA
|
114 |
"wms_title" "Autopistas GV" ##required
|
115 |
"wms_extent" "638610.4375 4222780 789330 4484662.5"
|
116 |
END
|
117 |
PROJECTION
|
118 |
"init=epsg:23030" ##recommended
|
119 |
END
|
120 |
CLASS
|
121 |
NAME "Autopistas"
|
122 |
STYLE
|
123 |
COLOR 200 255 0
|
124 |
OUTLINECOLOR 120 120 120
|
125 |
END
|
126 |
END
|
127 |
END
|
128 |
|
129 |
END # Map File
|
130 |
|
131 |
* @author david
|
132 |
*/
|
133 |
|
134 |
public abstract class MapServer { |
135 |
public static final String SHP_TYPE_LINE = "LINE"; |
136 |
public static final String SHP_TYPE_POLYLINE = "POLYLINE"; |
137 |
public static final String SHP_TYPE_POINT = "POINT"; |
138 |
public static final String SHP_TYPE_POLYGON = "POLYGON"; |
139 |
|
140 |
public static class RGB { |
141 |
int r,g,b;
|
142 |
public RGB(int red,int green,int blue){ |
143 |
r=red; |
144 |
g=green; |
145 |
b=blue; |
146 |
} |
147 |
public String toString(){ |
148 |
return ""+r+" "+g+" "+b; |
149 |
} |
150 |
} |
151 |
|
152 |
public static class CRS extends MapServer { |
153 |
boolean init = false; |
154 |
String crs = ""; |
155 |
public CRS(String crs, boolean init) { |
156 |
this.crs = crs;
|
157 |
this.init =init;
|
158 |
} |
159 |
|
160 |
public String toString() { |
161 |
String str = ""; |
162 |
if (init)
|
163 |
str += "init=";
|
164 |
return str+crs.toLowerCase();
|
165 |
} |
166 |
|
167 |
public void toMap() { |
168 |
toMapln("PROJECTION");
|
169 |
tabIn(); |
170 |
toMapln("\""+this+"\""); |
171 |
tabOut(); |
172 |
toMapln("END");
|
173 |
} |
174 |
} |
175 |
|
176 |
static PrintStream salida = null; |
177 |
static String tabstop = ""; |
178 |
public Rectangle2D extent = null; |
179 |
public CRS crs = null; |
180 |
|
181 |
public void setExtent(double minx, double miny, double maxx, double maxy) { |
182 |
this.extent = new Rectangle2D.Double(minx, miny, maxx, maxy); |
183 |
} |
184 |
|
185 |
public void setExtent(Rectangle2D extent) { |
186 |
this.extent = extent;
|
187 |
} |
188 |
|
189 |
|
190 |
String extentToMapString(Rectangle2D ext) { |
191 |
if (ext != null) |
192 |
return ext.getMinX()+" "+ext.getMinY()+" "+ext.getMaxX()+" "+ext.getMaxY(); |
193 |
return ""; |
194 |
} |
195 |
|
196 |
void projectionToMap(CRS prj, boolean init) { |
197 |
if (prj == null) |
198 |
return;
|
199 |
toMapln("PROJECTION");
|
200 |
if (init == true) |
201 |
prj.toString(); |
202 |
tabIn(); |
203 |
toMapln("\""+prj+"\""); |
204 |
tabOut(); |
205 |
toMapln("END");
|
206 |
} |
207 |
|
208 |
public String replicate(String str, int n) { |
209 |
int i;
|
210 |
String ret = ""; |
211 |
for(i=0;i<n;i++){ |
212 |
ret += str; |
213 |
} |
214 |
return ret;
|
215 |
} |
216 |
|
217 |
public void tabIn() { |
218 |
tabstop += " ";
|
219 |
} |
220 |
|
221 |
public void tabOut() { |
222 |
tabstop = tabstop.substring(0,tabstop.length()-3); |
223 |
} |
224 |
|
225 |
void toMapln(String str){ |
226 |
if (salida == null) |
227 |
System.out.println(tabstop+str);
|
228 |
else
|
229 |
salida.println(tabstop+str); |
230 |
} |
231 |
|
232 |
public static class Metadata extends MapServer { |
233 |
public String prefix = "wms"; |
234 |
public String title = null; |
235 |
|
236 |
public void setServiceAsWFS() { |
237 |
prefix = "wfs";
|
238 |
} |
239 |
|
240 |
public void setServiceAsWMS() { |
241 |
prefix = "wms";
|
242 |
} |
243 |
public void setServiceAsWCS() { |
244 |
prefix = "wcs";
|
245 |
} |
246 |
//
|
247 |
void startMetadataToMap(){
|
248 |
toMapln("METADATA");
|
249 |
tabIn(); |
250 |
if (title != null) |
251 |
toMapln("\""+prefix+"_title\" " +"\""+title+"\""); |
252 |
} |
253 |
|
254 |
void endMetadataToMap() {
|
255 |
tabOut(); |
256 |
toMapln("END");
|
257 |
} |
258 |
} |
259 |
|
260 |
public static class MetadataWeb extends Metadata { |
261 |
//Atributos wms_xxxx WEB
|
262 |
public String onlineresource = null; |
263 |
public String ows_schemas_location = null; |
264 |
void metadataToMap(){
|
265 |
startMetadataToMap(); |
266 |
toMapln("\""+prefix+"_onlineresource\" \""+onlineresource+"\""); |
267 |
toMapln("\""+prefix+"_srs\" \""+crs+"\""); |
268 |
if (ows_schemas_location != null) |
269 |
toMapln("\"ows_schemas_location\" \""+ows_schemas_location+"\""); |
270 |
endMetadataToMap(); |
271 |
} |
272 |
} |
273 |
|
274 |
public static class MetadataLayer extends Metadata { |
275 |
//Atributos wms_xxxx LAYER
|
276 |
public String metalayertitle = null; |
277 |
public String gml_include_items = null; |
278 |
void metadataToMap(){
|
279 |
startMetadataToMap(); |
280 |
if (extent != null) |
281 |
toMapln("\""+prefix+"_extent\" \""+extentToMapString(extent)+"\""); |
282 |
if (gml_include_items != null) |
283 |
toMapln("\"gml_include_items\" \""+gml_include_items+"\""); |
284 |
endMetadataToMap(); |
285 |
} |
286 |
} |
287 |
|
288 |
public static class StyleMap extends MapServer { |
289 |
public RGB styleColor = null; |
290 |
public RGB styleColorOutline = null; |
291 |
public StyleMap(RGB line, RGB fill) {
|
292 |
styleColor = fill; |
293 |
styleColorOutline = line; |
294 |
} |
295 |
void styleToMap(){
|
296 |
toMapln("STYLE ");
|
297 |
tabIn(); |
298 |
toMapln("COLOR "+styleColor);
|
299 |
toMapln("OUTLINECOLOR "+styleColorOutline);
|
300 |
tabOut(); |
301 |
toMapln("END");
|
302 |
} |
303 |
} |
304 |
|
305 |
public static class WebMap extends MapServer{ |
306 |
public MetadataWeb metadata = null; |
307 |
public String imagepath = null; |
308 |
public String imageurl = null; |
309 |
void webToMap(){
|
310 |
toMapln("WEB");
|
311 |
tabIn(); |
312 |
toMapln("IMAGEPATH \""+imagepath+"\""); |
313 |
toMapln("IMAGEURL \""+imageurl+"\""); |
314 |
metadata.metadataToMap(); |
315 |
tabOut(); |
316 |
toMapln("END");
|
317 |
} |
318 |
} |
319 |
|
320 |
public static class MapClass extends MapServer { |
321 |
public String name; |
322 |
public StyleMap estilo = null; |
323 |
public String template = null; |
324 |
public String expression = null; |
325 |
public MapClass(String n) { |
326 |
name = n; |
327 |
} |
328 |
public void classToMap(){ |
329 |
toMapln("CLASS");
|
330 |
tabIn(); |
331 |
if (expression != null){ |
332 |
toMapln("EXPRESSION " + expression);
|
333 |
} |
334 |
toMapln("NAME \""+name+"\""); |
335 |
if (estilo != null) |
336 |
estilo.styleToMap(); |
337 |
if (template != null) |
338 |
toMapln("TEMPLATE "+template);
|
339 |
tabOut(); |
340 |
toMapln("END");
|
341 |
} |
342 |
} |
343 |
|
344 |
public abstract static class MapLayer extends MapServer { |
345 |
public String name; |
346 |
public String title; |
347 |
public String status = "ON"; |
348 |
public String type = null; |
349 |
public int transparency = 0; |
350 |
public ArrayList classList = null; |
351 |
public ArrayList layerList = null; |
352 |
public String data; |
353 |
public MetadataLayer metadata = null; |
354 |
public boolean dump = false; |
355 |
public CRS layercrs=null; |
356 |
|
357 |
public void setDump(boolean d) { |
358 |
dump = d; |
359 |
} |
360 |
|
361 |
void startToMap() {
|
362 |
toMapln("LAYER");
|
363 |
tabIn(); |
364 |
toMapln("NAME \""+name+"\""); |
365 |
toMapln("STATUS "+status);
|
366 |
toMapln("TRANSPARENCY " + transparency);
|
367 |
if (type != null) |
368 |
toMapln("TYPE "+type);
|
369 |
if (dump)
|
370 |
toMapln("DUMP TRUE # required");
|
371 |
} |
372 |
|
373 |
void endToMap() {
|
374 |
tabOut(); |
375 |
toMapln("END # Layer");
|
376 |
} |
377 |
|
378 |
public void addClass(MapClass c) { |
379 |
if (classList == null) |
380 |
classList = new ArrayList(); |
381 |
classList.add(c); |
382 |
} |
383 |
|
384 |
public void classListToMap() { |
385 |
if (classList != null) { |
386 |
Iterator iter = classList.iterator();
|
387 |
while (iter.hasNext()) {
|
388 |
MapClass c = (MapClass) iter.next(); |
389 |
c.classToMap(); |
390 |
} |
391 |
} |
392 |
|
393 |
} |
394 |
|
395 |
public void addLayer(MapLayer c) { |
396 |
if (layerList == null) |
397 |
layerList = new ArrayList(); |
398 |
layerList.add(c); |
399 |
} |
400 |
|
401 |
public void layerListToMap() { |
402 |
if (layerList != null) { |
403 |
Iterator iter = layerList.iterator();
|
404 |
tabIn(); |
405 |
while (iter.hasNext()) {
|
406 |
MapLayer l = (MapLayer) iter.next(); |
407 |
l.layerToMap(); |
408 |
} |
409 |
tabOut(); |
410 |
} |
411 |
|
412 |
} |
413 |
|
414 |
public abstract void layerToMap(); |
415 |
} |
416 |
|
417 |
public static class ShpLayer extends MapLayer { |
418 |
public void layerToMap() { |
419 |
startToMap(); |
420 |
toMapln("DATA \""+data+"\""); |
421 |
metadata.metadataToMap(); |
422 |
if (layercrs != null) layercrs.toMap(); |
423 |
classListToMap(); |
424 |
endToMap(); |
425 |
} |
426 |
} |
427 |
|
428 |
public static class PostgisLayer extends MapLayer { |
429 |
public String user; |
430 |
public String pass; |
431 |
public String host; |
432 |
public String dbname; |
433 |
public String port; |
434 |
|
435 |
public String tabla; |
436 |
public String data; |
437 |
|
438 |
public void setConnParams(String user, String pass, String host, |
439 |
String dbname, String port) { |
440 |
this.user = user;
|
441 |
this.pass = pass;
|
442 |
this.host = host;
|
443 |
this.dbname = dbname;
|
444 |
this.port = port;
|
445 |
} |
446 |
|
447 |
public void layerToMap() { |
448 |
startToMap(); |
449 |
toMapln("DATA \""+data+"\""); |
450 |
toMapln("CONNECTIONTYPE POSTGIS");
|
451 |
toMapln("CONNECTION \"user="+user+" password="+pass+" dbname="+dbname+" host="+host+" port="+port+"\""); |
452 |
metadata.metadataToMap(); |
453 |
if (layercrs != null) layercrs.toMap(); |
454 |
classListToMap(); |
455 |
endToMap(); |
456 |
} |
457 |
} |
458 |
|
459 |
public static class RasterLayer extends MapLayer { |
460 |
public void layerToMap() { |
461 |
startToMap(); |
462 |
toMapln("DATA \""+data+"\""); |
463 |
metadata.metadataToMap(); |
464 |
if (layercrs != null) layercrs.toMap(); |
465 |
classListToMap(); |
466 |
endToMap(); |
467 |
} |
468 |
} |
469 |
|
470 |
public static class ConfigFile extends MapServer { |
471 |
/**
|
472 |
* Atributos wms_xxxx comunes a WEB y LAYER.
|
473 |
* @author david
|
474 |
*/
|
475 |
|
476 |
public String mapFileName = null; |
477 |
public String fName = null; |
478 |
public String mapName = null; |
479 |
public String mapStatus = null; |
480 |
public String mapUnits= null; |
481 |
public String mapShapePath; |
482 |
public Dimension mapSize = null; |
483 |
public CRS mapcrs= null; |
484 |
public WebMap www = null; |
485 |
public String symbolset = null; |
486 |
public String fontset = null; |
487 |
public RGB imageColor = null; |
488 |
|
489 |
public ArrayList layers = new ArrayList(); |
490 |
|
491 |
public ConfigFile() {
|
492 |
} |
493 |
|
494 |
public void generate() { |
495 |
generate(null);
|
496 |
} |
497 |
|
498 |
public void generate(String donde) { |
499 |
openMapFile(donde); |
500 |
toMapln("MAP");
|
501 |
tabIn(); |
502 |
toMapln("NAME "+mapName);
|
503 |
if (mapSize != null) |
504 |
toMapln("SIZE "+mapSize.width+" "+mapSize.height); |
505 |
toMapln("EXTENT "+extentToMapString(extent));
|
506 |
toMapln("STATUS "+mapStatus);
|
507 |
toMapln("UNITS "+mapUnits);
|
508 |
toMapln("SHAPEPATH \""+mapShapePath+"\""); |
509 |
if (symbolset != null) |
510 |
toMapln("SYMBOLSET "+symbolset);
|
511 |
if (symbolset != null) |
512 |
toMapln("FONTSET "+symbolset);
|
513 |
if (imageColor != null) |
514 |
toMapln("IMAGECOLOR \""+imageColor);
|
515 |
www.webToMap(); |
516 |
if (mapcrs != null) |
517 |
projectionToMap(mapcrs,true);
|
518 |
Iterator iter = layers.iterator();
|
519 |
while(iter.hasNext()) {
|
520 |
MapLayer l = (MapLayer) iter.next(); |
521 |
l.layerToMap(); |
522 |
} |
523 |
tabOut(); |
524 |
toMapln("END # Map File");
|
525 |
closeMapFile(); |
526 |
} |
527 |
|
528 |
void openMapFile(String donde) { |
529 |
setMapFileName(donde); |
530 |
if (mapFileName == null) |
531 |
return;
|
532 |
File wmsmap = new File( mapFileName ); |
533 |
try{
|
534 |
//salida = new PrintStream(new BufferedOutputStream(new FileOutputStream(wmsmap)));
|
535 |
salida = new PrintStream(new FileOutputStream(wmsmap)); |
536 |
} catch(FileNotFoundException e){ |
537 |
System.out.println("Fichero no encontrado."); |
538 |
} |
539 |
System.out.println(mapFileName+" abierto."); |
540 |
|
541 |
} |
542 |
|
543 |
void closeMapFile() {
|
544 |
if (salida != null) |
545 |
salida.close(); |
546 |
} |
547 |
|
548 |
public String getMapFileName() { |
549 |
return mapFileName;
|
550 |
} |
551 |
|
552 |
public void setMapFileName(String mapFileName) { |
553 |
this.mapFileName = mapFileName;
|
554 |
} |
555 |
} |
556 |
} |