svn-gvsig-desktop / trunk / extensions / extPublish / src / com / iver / cit / gvsig / publish / PublishWMSControler.java @ 7125
History | View | Annotate | Download (10.8 KB)
1 |
package com.iver.cit.gvsig.publish; |
---|---|
2 |
|
3 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
4 |
*
|
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 |
* 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 |
import java.awt.Color; |
44 |
import java.awt.geom.Rectangle2D; |
45 |
import java.util.ArrayList; |
46 |
|
47 |
import org.gvsig.remoteservices.conf.mapserver.MapServer; |
48 |
import org.gvsig.remoteservices.conf.mapserver.MapServer.CRS; |
49 |
import org.gvsig.remoteservices.conf.mapserver.MapServer.ConfigFile; |
50 |
import org.gvsig.remoteservices.conf.mapserver.MapServer.MapClass; |
51 |
import org.gvsig.remoteservices.conf.mapserver.MapServer.MapLayer; |
52 |
import org.gvsig.remoteservices.conf.mapserver.MapServer.PostgisLayer; |
53 |
import org.gvsig.remoteservices.conf.mapserver.MapServer.RGB; |
54 |
import org.gvsig.remoteservices.conf.mapserver.MapServer.RasterLayer; |
55 |
import org.gvsig.remoteservices.conf.mapserver.MapServer.ShpLayer; |
56 |
|
57 |
import com.iver.andami.PluginServices; |
58 |
import com.iver.cit.gvsig.fmap.DriverException; |
59 |
import com.iver.cit.gvsig.fmap.MapControl; |
60 |
import com.iver.cit.gvsig.fmap.core.FShape; |
61 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
62 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
63 |
import com.iver.cit.gvsig.fmap.drivers.jdbc.postgis.PostGisDriver; |
64 |
import com.iver.cit.gvsig.fmap.drivers.shp.IndexedShpDriver; |
65 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
66 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
67 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
68 |
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 |
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 |
import com.iver.cit.gvsig.gui.View; |
76 |
import com.iver.cit.gvsig.publish.layers.LayerException; |
77 |
import com.iver.cit.gvsig.publish.layers.LayerFactory; |
78 |
|
79 |
/**
|
80 |
* 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 |
* @author jvhigon
|
85 |
*
|
86 |
*/
|
87 |
public class PublishWMSControler { |
88 |
private View view = null; |
89 |
|
90 |
private MapControl mapCtrl = null; |
91 |
|
92 |
private FLayers layers = null; |
93 |
|
94 |
/**
|
95 |
* Constructor
|
96 |
*
|
97 |
*/
|
98 |
public PublishWMSControler() {
|
99 |
view = (View) PluginServices.getMDIManager().getActiveWindow();
|
100 |
mapCtrl = view.getMapControl(); |
101 |
layers = mapCtrl.getMapContext().getLayers(); |
102 |
} |
103 |
|
104 |
/**
|
105 |
*
|
106 |
* @param url
|
107 |
* @param path
|
108 |
* @param mapFile
|
109 |
* @param symbolsFile
|
110 |
* @param fontsFile
|
111 |
* @param ImageURL
|
112 |
* @param imagePath
|
113 |
* @throws LayerException
|
114 |
*/
|
115 |
public ConfigFile publish(String onlineResource, String path, String mapFile, |
116 |
String symbolsFile, String fontsFile, String ImageURL, |
117 |
String imagePath) {
|
118 |
ArrayList layerNames = new ArrayList(); |
119 |
|
120 |
ConfigFile map = getConfigFile(path); |
121 |
map.www = getWebMapVect(onlineResource,imagePath,ImageURL); |
122 |
|
123 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
124 |
FLayer lyr = layers.getLayer(i); |
125 |
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 |
} |
143 |
} |
144 |
map.generate(mapFile); |
145 |
return map;
|
146 |
} |
147 |
|
148 |
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 |
} |
159 |
|
160 |
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 |
System.out.println(mLayer.type);
|
169 |
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 |
} |
180 |
|
181 |
|
182 |
private ArrayList getMapClassList(FLyrVect lyrVect){ |
183 |
ArrayList mapClasses = new ArrayList(); |
184 |
Legend legend = lyrVect.getLegend(); |
185 |
if (legend instanceof SingleSymbolLegend){ |
186 |
MapClass mapClass = new MapClass(LayerFactory.getLayerName(lyrVect.getName()));
|
187 |
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 |
MapClass mapClass = new MapClass(LayerFactory.getLayerName(lyrVect.getName()));
|
210 |
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 |
|
220 |
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 |
|
232 |
private MapServer.WebMap getWebMapVect(String onlineResource, |
233 |
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 |
|
247 |
/**
|
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 |
case FShape.POLYGON:
|
257 |
return MapServer.SHP_TYPE_POLYGON;
|
258 |
case FShape.LINE:
|
259 |
return MapServer.SHP_TYPE_LINE;
|
260 |
case FShape.POINT:
|
261 |
case FShape.MULTIPOINT:
|
262 |
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 |
*/
|