svn-gvsig-desktop / trunk / extensions / extPublish / src / com / iver / cit / gvsig / publish / PublishWMSControler.java @ 7125
History | View | Annotate | Download (10.8 KB)
1 | 6893 | luisw2 | package com.iver.cit.gvsig.publish; |
---|---|---|---|
2 | |||
3 | 7107 | jvhigon | /* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
4 | 7102 | jorpiell | *
|
5 | * Copyright (C) 2004 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 | 7107 | jvhigon | * Av. Blasco Ib��ez, 50
|
26 | 7102 | jorpiell | * 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 | 6893 | luisw2 | import java.awt.Color; |
44 | import java.awt.geom.Rectangle2D; |
||
45 | 7102 | jorpiell | import java.util.ArrayList; |
46 | 6893 | luisw2 | |
47 | 6954 | luisw2 | import org.gvsig.remoteservices.conf.mapserver.MapServer; |
48 | import org.gvsig.remoteservices.conf.mapserver.MapServer.CRS; |
||
49 | 6948 | luisw2 | import org.gvsig.remoteservices.conf.mapserver.MapServer.ConfigFile; |
50 | 6954 | luisw2 | import org.gvsig.remoteservices.conf.mapserver.MapServer.MapClass; |
51 | 7102 | jorpiell | import org.gvsig.remoteservices.conf.mapserver.MapServer.MapLayer; |
52 | import org.gvsig.remoteservices.conf.mapserver.MapServer.PostgisLayer; |
||
53 | 6948 | luisw2 | import org.gvsig.remoteservices.conf.mapserver.MapServer.RGB; |
54 | 7121 | jorpiell | import org.gvsig.remoteservices.conf.mapserver.MapServer.RasterLayer; |
55 | 6954 | luisw2 | import org.gvsig.remoteservices.conf.mapserver.MapServer.ShpLayer; |
56 | 6893 | luisw2 | |
57 | import com.iver.andami.PluginServices; |
||
58 | import com.iver.cit.gvsig.fmap.DriverException; |
||
59 | import com.iver.cit.gvsig.fmap.MapControl; |
||
60 | 7102 | jorpiell | import com.iver.cit.gvsig.fmap.core.FShape; |
61 | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
||
62 | 7121 | jorpiell | import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
63 | 7102 | jorpiell | import com.iver.cit.gvsig.fmap.drivers.jdbc.postgis.PostGisDriver; |
64 | import com.iver.cit.gvsig.fmap.drivers.shp.IndexedShpDriver; |
||
65 | 6893 | luisw2 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
66 | import com.iver.cit.gvsig.fmap.layers.FLayers; |
||
67 | 7121 | jorpiell | import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
68 | 6893 | luisw2 | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
69 | import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
||
70 | import com.iver.cit.gvsig.fmap.layers.VectorialFileAdapter; |
||
71 | 7102 | jorpiell | import com.iver.cit.gvsig.fmap.rendering.Legend; |
72 | import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
||
73 | import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend; |
||
74 | import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
||
75 | 6893 | luisw2 | import com.iver.cit.gvsig.gui.View; |
76 | 7121 | jorpiell | import com.iver.cit.gvsig.publish.layers.LayerException; |
77 | 7102 | jorpiell | import com.iver.cit.gvsig.publish.layers.LayerFactory; |
78 | 6893 | luisw2 | |
79 | /**
|
||
80 | 7102 | jorpiell | * This class implements the mapserver wms publication use case. Responsability:
|
81 | * This class must create the dialog, get the specific mapserver parameters and
|
||
82 | * get the view atributes in order to
|
||
83 | *
|
||
84 | 6893 | luisw2 | * @author jvhigon
|
85 | 7102 | jorpiell | *
|
86 | 6893 | luisw2 | */
|
87 | 7102 | jorpiell | public class PublishWMSControler { |
88 | private View view = null; |
||
89 | |||
90 | private MapControl mapCtrl = null; |
||
91 | |||
92 | private FLayers layers = null; |
||
93 | |||
94 | 6893 | luisw2 | /**
|
95 | * Constructor
|
||
96 | 7102 | jorpiell | *
|
97 | 6893 | luisw2 | */
|
98 | 7102 | jorpiell | public PublishWMSControler() {
|
99 | 6893 | luisw2 | view = (View) PluginServices.getMDIManager().getActiveWindow();
|
100 | mapCtrl = view.getMapControl(); |
||
101 | 7102 | jorpiell | layers = mapCtrl.getMapContext().getLayers(); |
102 | 6893 | luisw2 | } |
103 | 7102 | jorpiell | |
104 | 6893 | luisw2 | /**
|
105 | *
|
||
106 | 7102 | jorpiell | * @param url
|
107 | * @param path
|
||
108 | 6893 | luisw2 | * @param mapFile
|
109 | 7102 | jorpiell | * @param symbolsFile
|
110 | 6893 | luisw2 | * @param fontsFile
|
111 | 7102 | jorpiell | * @param ImageURL
|
112 | * @param imagePath
|
||
113 | 7121 | jorpiell | * @throws LayerException
|
114 | 6893 | luisw2 | */
|
115 | 7121 | jorpiell | public ConfigFile publish(String onlineResource, String path, String mapFile, |
116 | 7102 | jorpiell | String symbolsFile, String fontsFile, String ImageURL, |
117 | String imagePath) {
|
||
118 | 7121 | jorpiell | ArrayList layerNames = new ArrayList(); |
119 | 6893 | luisw2 | |
120 | 7102 | jorpiell | ConfigFile map = getConfigFile(path); |
121 | 7121 | jorpiell | map.www = getWebMapVect(onlineResource,imagePath,ImageURL); |
122 | 6893 | luisw2 | |
123 | 7102 | jorpiell | for (int i = 0; i < layers.getLayersCount(); i++) { |
124 | FLayer lyr = layers.getLayer(i); |
||
125 | 7121 | jorpiell | if (lyr.isVisible()){
|
126 | MapLayer mapLayer; |
||
127 | try {
|
||
128 | mapLayer = LayerFactory.getMapLayer(lyr); |
||
129 | if (lyr instanceof FLyrVect){ |
||
130 | createLayerVect((FLyrVect)lyr,mapLayer); |
||
131 | }else if(lyr instanceof FLyrRaster){ |
||
132 | createLayerRaster((FLyrRaster)lyr,mapLayer); |
||
133 | } |
||
134 | if (lyr != null){ |
||
135 | map.layers.add(mapLayer); |
||
136 | } |
||
137 | } catch (LayerException e) {
|
||
138 | // TODO Pasamos al siguiente layer. Mostrar error?
|
||
139 | e.printStackTrace(); |
||
140 | } |
||
141 | |||
142 | 6893 | luisw2 | } |
143 | 7102 | jorpiell | } |
144 | 7121 | jorpiell | map.generate(mapFile); |
145 | return map;
|
||
146 | } |
||
147 | 6893 | luisw2 | |
148 | 7121 | jorpiell | private void createLayerRaster(FLyrRaster lyrRaster,MapLayer mLayer){ |
149 | mLayer.extent = null;
|
||
150 | mLayer.classList = new ArrayList(); |
||
151 | mLayer.metadata=new MapServer.MetadataLayer();
|
||
152 | mLayer.metadata.setExtent(lyrRaster.getMinX(), |
||
153 | lyrRaster.getMinY(), |
||
154 | lyrRaster.getMaxX(), |
||
155 | lyrRaster.getMaxY()); |
||
156 | mLayer.metadata.metalayertitle="raster gv";
|
||
157 | |||
158 | 6893 | luisw2 | } |
159 | |||
160 | 7102 | jorpiell | private void createLayerVect(FLyrVect lyrVect,MapLayer mLayer){ |
161 | ReadableVectorial rv = lyrVect.getSource(); |
||
162 | if (rv instanceof VectorialFileAdapter) { |
||
163 | VectorialFileAdapter vfa = (VectorialFileAdapter) rv; |
||
164 | mLayer.data = vfa.getFile().getName(); |
||
165 | } |
||
166 | |||
167 | mLayer.type = getShpType(lyrVect); |
||
168 | 7107 | jvhigon | System.out.println(mLayer.type);
|
169 | 7102 | jorpiell | mLayer.classList = getMapClassList(lyrVect); |
170 | mLayer.metadata = new ConfigFile.MetadataLayer();
|
||
171 | mLayer.transparency = 255 - lyrVect.getLegend().getDefaultSymbol().getColor().getAlpha();
|
||
172 | |||
173 | try {
|
||
174 | mLayer.metadata.setExtent(lyrVect.getFullExtent()); |
||
175 | } catch (DriverException e) {
|
||
176 | // TODO Auto-generated catch block
|
||
177 | e.printStackTrace(); |
||
178 | } |
||
179 | 7121 | jorpiell | } |
180 | 6893 | luisw2 | |
181 | 7121 | jorpiell | |
182 | 7102 | jorpiell | private ArrayList getMapClassList(FLyrVect lyrVect){ |
183 | ArrayList mapClasses = new ArrayList(); |
||
184 | Legend legend = lyrVect.getLegend(); |
||
185 | if (legend instanceof SingleSymbolLegend){ |
||
186 | 7121 | jorpiell | MapClass mapClass = new MapClass(LayerFactory.getLayerName(lyrVect.getName()));
|
187 | 7102 | jorpiell | Color clr = legend.getDefaultSymbol().getColor();
|
188 | Color outLineclr = legend.getDefaultSymbol().getOutlineColor();
|
||
189 | mapClass.estilo = new ConfigFile.StyleMap(new RGB(outLineclr.getRed(), |
||
190 | outLineclr.getGreen(), outLineclr.getBlue()), new RGB(clr.getRed(),
|
||
191 | clr.getGreen(), clr.getBlue())); |
||
192 | mapClasses.add(mapClass); |
||
193 | }else if(legend instanceof VectorialUniqueValueLegend){ |
||
194 | VectorialUniqueValueLegend uniqueValueLegend = (VectorialUniqueValueLegend)legend; |
||
195 | FSymbol[] symbols = uniqueValueLegend.getSymbols();
|
||
196 | for (int i=0 ; i<symbols.length ; i++){ |
||
197 | MapClass mapClass = new MapClass(symbols[i].getDescription());
|
||
198 | Color clr = symbols[i].getColor();
|
||
199 | Color outLineclr = symbols[i].getOutlineColor();
|
||
200 | mapClass.estilo = new ConfigFile.StyleMap(new RGB(outLineclr.getRed(), |
||
201 | outLineclr.getGreen(), outLineclr.getBlue()), new RGB(clr.getRed(),
|
||
202 | clr.getGreen(), clr.getBlue())); |
||
203 | mapClass.expression = "('[" + uniqueValueLegend.getFieldName() + "]' = '" + |
||
204 | symbols[i].getDescription() + "')";
|
||
205 | mapClasses.add(mapClass); |
||
206 | } |
||
207 | |||
208 | }else if(legend instanceof VectorialIntervalLegend){ |
||
209 | 7121 | jorpiell | MapClass mapClass = new MapClass(LayerFactory.getLayerName(lyrVect.getName()));
|
210 | 7102 | jorpiell | Color clr = legend.getDefaultSymbol().getColor();
|
211 | Color outLineclr = legend.getDefaultSymbol().getOutlineColor();
|
||
212 | mapClass.estilo = new ConfigFile.StyleMap(new RGB(outLineclr.getRed(), |
||
213 | outLineclr.getGreen(), outLineclr.getBlue()), new RGB(clr.getRed(),
|
||
214 | clr.getGreen(), clr.getBlue())); |
||
215 | mapClasses.add(mapClass); |
||
216 | } |
||
217 | return mapClasses;
|
||
218 | } |
||
219 | 6893 | luisw2 | |
220 | 7102 | jorpiell | private ConfigFile getConfigFile(String path){ |
221 | ConfigFile map = new ConfigFile();
|
||
222 | map.mapName = "TEST_MAPSERVER";
|
||
223 | map.mapStatus = "ON";
|
||
224 | map.mapUnits = "METERS";
|
||
225 | map.mapShapePath = path; |
||
226 | map.mapcrs = new CRS(mapCtrl.getMapContext().getViewPort()
|
||
227 | .getProjection().getAbrev(), true);
|
||
228 | map.setExtent(mapCtrl.getMapContext().getViewPort().getExtent()); |
||
229 | return map;
|
||
230 | } |
||
231 | 6893 | luisw2 | |
232 | 7121 | jorpiell | private MapServer.WebMap getWebMapVect(String onlineResource, |
233 | 7102 | jorpiell | String imagePath,
|
234 | String imageURL){
|
||
235 | MapServer.WebMap webMap = new MapServer.WebMap();
|
||
236 | webMap.imagepath = imagePath; |
||
237 | webMap.imageurl = imageURL; |
||
238 | webMap.metadata = new MapServer.MetadataWeb();
|
||
239 | webMap.metadata.crs = new CRS(mapCtrl.getMapContext().getViewPort()
|
||
240 | .getProjection().getAbrev(), false);
|
||
241 | |||
242 | webMap.metadata.title = "test shape";
|
||
243 | webMap.metadata.onlineresource = onlineResource; |
||
244 | return webMap;
|
||
245 | } |
||
246 | 6893 | luisw2 | |
247 | 7102 | jorpiell | /**
|
248 | * Gets the geometry type from a shape
|
||
249 | * @param lyrVect
|
||
250 | * @return
|
||
251 | */
|
||
252 | private String getShpType(FLyrVect lyrVect){ |
||
253 | try {
|
||
254 | int lyrType = lyrVect.getShapeType();
|
||
255 | switch(lyrType){
|
||
256 | 7107 | jvhigon | case FShape.POLYGON:
|
257 | 7102 | jorpiell | return MapServer.SHP_TYPE_POLYGON;
|
258 | case FShape.LINE:
|
||
259 | return MapServer.SHP_TYPE_LINE;
|
||
260 | 7107 | jvhigon | case FShape.POINT:
|
261 | case FShape.MULTIPOINT:
|
||
262 | 7102 | jorpiell | return MapServer.SHP_TYPE_POINT;
|
263 | } |
||
264 | } catch (DriverException e) {
|
||
265 | // TODO Auto-generated catch block
|
||
266 | e.printStackTrace(); |
||
267 | } |
||
268 | return MapServer.SHP_TYPE_POLYGON;
|
||
269 | } |
||
270 | } |
||
271 | |||
272 | // print specific mapserver's atributes
|
||
273 | /*
|
||
274 | * System.out.println("Ruta mapFile:"+ mapFile); System.out.println("Ruta
|
||
275 | * symbolsFile:" + symbolsFile); System.out.println("Ruta fonstFile:" +
|
||
276 | * fontsFile); System.out.println("Ruta onlineResource:" + onlineResource );
|
||
277 | * System.out.println("Ruta onlineResource:" + shapePath);
|
||
278 | *
|
||
279 | * //print atributes for all layers for (int i= 0; i < layers.getLayersCount();
|
||
280 | * i++ ){ FLayer lyr= layers.getLayer(i); //name layer
|
||
281 | * System.out.println("Nombre de la capa: " + lyr.getName());
|
||
282 | *
|
||
283 | * //vectorial file path FLyrVect lyrvec = (FLyrVect) lyr; ReadableVectorial rv =
|
||
284 | * lyrvec.getSource(); if (rv instanceof VectorialFileAdapter){
|
||
285 | * VectorialFileAdapter vfa = (VectorialFileAdapter) rv;
|
||
286 | * System.out.println("Absolute Path: " + vfa.getFile().getAbsoluteFile());
|
||
287 | * System.out.println("File Name: " + vfa.getFile().getName()); }
|
||
288 | * // extext Rectangle2D rect = null; try { rect = lyr.getFullExtent(); } catch
|
||
289 | * (DriverException e) { // TODO Auto-generated catch block e.printStackTrace(); }
|
||
290 | * System.out.println("Extent: " + rect.getMinX() + " " + rect.getMinY() + " " +
|
||
291 | * rect.getMaxX() + " " + rect.getMaxY());
|
||
292 | *
|
||
293 | *
|
||
294 | * //maxscale System.out.println("Maxscale: " + lyr.getMaxScale());
|
||
295 | *
|
||
296 | * //minscale System.out.println("Minscale: " + lyr.getMinScale());
|
||
297 | *
|
||
298 | * //color and transparency if(lyr instanceof FLyrVect){
|
||
299 | * System.out.println("This is a vectorial datasource"); FLyrVect lyrvec2 =
|
||
300 | * (FLyrVect) lyr; Color clr =
|
||
301 | * lyrvec2.getLegend().getDefaultSymbol().getColor(); System.out.println("R: " +
|
||
302 | * clr.getRed() + " G: " + clr.getGreen() + " B: " + clr.getBlue());
|
||
303 | *
|
||
304 | * int alpha = lyrvec2.getLegend().getDefaultSymbol().getColor().getAlpha();
|
||
305 | * System.out.println("Tranparency: " + (255 - alpha));
|
||
306 | *
|
||
307 | * }else{ System.out.println("Esto no es una capa vectorial"); }
|
||
308 | *
|
||
309 | * //srs viewPort
|
||
310 | * System.out.println(mapCtrl.getMapContext().getViewPort().getProjection().getAbrev());
|
||
311 | */ |