Revision 29439
tags/tmp_build/extensions/extWCS/src/com/iver/cit/gvsig/wcs/WCSClientExtension.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.wcs; |
|
42 |
|
|
43 |
import com.iver.andami.PluginServices; |
|
44 |
import com.iver.andami.plugins.Extension; |
|
45 |
import com.iver.cit.gvsig.AddLayer; |
|
46 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
47 |
import com.iver.cit.gvsig.fmap.layers.FLyrWCS; |
|
48 |
import com.iver.cit.gvsig.gui.toc.WCSPropsTocMenuEntry; |
|
49 |
import com.iver.cit.gvsig.gui.toc.WCSZoomPixelCursorTocMenuEntry; |
|
50 |
import com.iver.cit.gvsig.gui.wcs.WCSWizard; |
|
51 |
import com.iver.cit.gvsig.project.documents.view.toc.gui.FPopupMenu; |
|
52 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
|
53 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
|
54 |
|
|
55 |
/** |
|
56 |
* @author jaume - jaume.dominguez@iver.es |
|
57 |
* |
|
58 |
*/ |
|
59 |
public class WCSClientExtension extends Extension { |
|
60 |
/** |
|
61 |
* Initializes the toc menu |
|
62 |
* |
|
63 |
*/ |
|
64 |
public void initialize() { |
|
65 |
// Adds a new tab to the "add layer" wizard for WMS layer creation |
|
66 |
AddLayer.addWizard(WCSWizard.class); |
|
67 |
|
|
68 |
|
|
69 |
// Adds an entry to the TOC's floating menu to those layers defined in this extensionFPopupMenu.addEntry(new WCSPropsTocMenuEntry()); |
|
70 |
FPopupMenu.addEntry(new WCSPropsTocMenuEntry()); |
|
71 |
|
|
72 |
// Adds an entry to the TOC's floating menu for the "zoom to pixel" tool |
|
73 |
FPopupMenu.addEntry(new WCSZoomPixelCursorTocMenuEntry()); |
|
74 |
|
|
75 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
|
76 |
extensionPoints.add("CatalogLayers","OGC:WCS",FLyrWCS.class); |
|
77 |
|
|
78 |
initializeIcons(); |
|
79 |
|
|
80 |
|
|
81 |
} |
|
82 |
|
|
83 |
public void execute(String actionCommand) { |
|
84 |
// no commands, no code. |
|
85 |
} |
|
86 |
|
|
87 |
public boolean isEnabled() { |
|
88 |
// may return whatever |
|
89 |
return true; |
|
90 |
} |
|
91 |
|
|
92 |
public boolean isVisible() { |
|
93 |
// may return whatever |
|
94 |
return false; |
|
95 |
} |
|
96 |
|
|
97 |
void initializeIcons(){ |
|
98 |
PluginServices.getIconTheme().registerDefault( |
|
99 |
"view-previsualize-area", |
|
100 |
MapControl.class.getResource("images/ZoomPixelCursor.gif") |
|
101 |
); |
|
102 |
PluginServices.getIconTheme().registerDefault( |
|
103 |
"ico-WCS-Layer", |
|
104 |
MapControl.class.getResource("images/icoLayer.png") |
|
105 |
); |
|
106 |
} |
|
107 |
} |
|
0 | 108 |
tags/tmp_build/extensions/extWCS/src/com/iver/cit/gvsig/fmap/drivers/wcs/WCSDriverException.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.drivers.wcs; |
|
2 |
|
|
3 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
4 |
|
|
5 |
public class WCSDriverException extends ReadDriverException{ |
|
6 |
|
|
7 |
public WCSDriverException(String l,Throwable exception) { |
|
8 |
super(l,exception); |
|
9 |
init(); |
|
10 |
} |
|
11 |
/** |
|
12 |
* |
|
13 |
*/ |
|
14 |
private void init() { |
|
15 |
messageKey = "error_driver_layer"; |
|
16 |
formatString = "Can?t load driver of the layer: %(layer) "; |
|
17 |
} |
|
18 |
/** |
|
19 |
* Cuts the message text to force its lines to be shorter or equal to |
|
20 |
* lineLength. |
|
21 |
* @param message, the message. |
|
22 |
* @param lineLength, the max line length in number of characters. |
|
23 |
* @return the formated message. |
|
24 |
*/ |
|
25 |
private static String format(String message, int lineLength){ |
|
26 |
if (message.length() <= lineLength) return message; |
|
27 |
String[] lines = message.split("\n"); |
|
28 |
String theMessage = ""; |
|
29 |
for (int i = 0; i < lines.length; i++) { |
|
30 |
String line = lines[i].trim(); |
|
31 |
if (line.length()<lineLength) |
|
32 |
theMessage += line+"\n"; |
|
33 |
else { |
|
34 |
String[] chunks = line.split(" "); |
|
35 |
String newLine = ""; |
|
36 |
for (int j = 0; j < chunks.length; j++) { |
|
37 |
int currentLength = newLine.length(); |
|
38 |
chunks[j] = chunks[j].trim(); |
|
39 |
if (chunks[j].length()==0) |
|
40 |
continue; |
|
41 |
if ((currentLength + chunks[j].length() + " ".length()) <= lineLength) |
|
42 |
newLine += chunks[j] + " "; |
|
43 |
else { |
|
44 |
newLine += "\n"+chunks[j]+" "; |
|
45 |
theMessage += newLine; |
|
46 |
newLine = ""; |
|
47 |
} |
|
48 |
} |
|
49 |
|
|
50 |
} |
|
51 |
} |
|
52 |
return theMessage; |
|
53 |
} |
|
54 |
} |
|
0 | 55 |
tags/tmp_build/extensions/extWCS/src/com/iver/cit/gvsig/fmap/drivers/wcs/WCSExceptionOld.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib��ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.fmap.drivers.wcs; |
|
42 |
|
|
43 |
import com.iver.andami.PluginServices; |
|
44 |
|
|
45 |
/** |
|
46 |
* Excepci�n provocada por el WCS. |
|
47 |
* |
|
48 |
* @author Vicente Caballero Navarro |
|
49 |
*/ |
|
50 |
public class WCSExceptionOld extends Exception { |
|
51 |
String message; |
|
52 |
|
|
53 |
public String getMessage() { |
|
54 |
return PluginServices.getText(this, "wcs_server_error")+"\n"+format(message, 200); |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* |
|
59 |
*/ |
|
60 |
public WCSExceptionOld() { |
|
61 |
super(); |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* Crea WCSException. |
|
66 |
* |
|
67 |
* @param message |
|
68 |
*/ |
|
69 |
public WCSExceptionOld(String message) { |
|
70 |
super(); |
|
71 |
this.message = message; |
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* Crea WCSException. |
|
76 |
* |
|
77 |
* @param message |
|
78 |
* @param cause |
|
79 |
*/ |
|
80 |
public WCSExceptionOld(String message, Throwable cause) { |
|
81 |
super(format(message, 200), cause); |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* Crea WCSException. |
|
86 |
* |
|
87 |
* @param cause |
|
88 |
*/ |
|
89 |
public WCSExceptionOld(Throwable cause) { |
|
90 |
super(cause); |
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* Cuts the message text to force its lines to be shorter or equal to |
|
95 |
* lineLength. |
|
96 |
* @param message, the message. |
|
97 |
* @param lineLength, the max line length in number of characters. |
|
98 |
* @return the formated message. |
|
99 |
*/ |
|
100 |
private static String format(String message, int lineLength){ |
|
101 |
if (message.length() <= lineLength) return message; |
|
102 |
String[] lines = message.split("\n"); |
|
103 |
String theMessage = ""; |
|
104 |
for (int i = 0; i < lines.length; i++) { |
|
105 |
String line = lines[i].trim(); |
|
106 |
if (line.length()<lineLength) |
|
107 |
theMessage += line+"\n"; |
|
108 |
else { |
|
109 |
String[] chunks = line.split(" "); |
|
110 |
String newLine = ""; |
|
111 |
for (int j = 0; j < chunks.length; j++) { |
|
112 |
int currentLength = newLine.length(); |
|
113 |
chunks[j] = chunks[j].trim(); |
|
114 |
if (chunks[j].length()==0) |
|
115 |
continue; |
|
116 |
if ((currentLength + chunks[j].length() + " ".length()) <= lineLength) |
|
117 |
newLine += chunks[j] + " "; |
|
118 |
else { |
|
119 |
newLine += "\n"+chunks[j]+" "; |
|
120 |
theMessage += newLine; |
|
121 |
newLine = ""; |
|
122 |
} |
|
123 |
} |
|
124 |
|
|
125 |
} |
|
126 |
} |
|
127 |
return theMessage; |
|
128 |
} |
|
129 |
} |
|
0 | 130 |
tags/tmp_build/extensions/extWCS/src/com/iver/cit/gvsig/fmap/drivers/wcs/FMapWCSDriver.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.fmap.drivers.wcs; |
|
42 |
|
|
43 |
import java.awt.geom.Point2D; |
|
44 |
import java.awt.geom.Rectangle2D; |
|
45 |
import java.io.File; |
|
46 |
import java.io.IOException; |
|
47 |
import java.net.ConnectException; |
|
48 |
import java.net.URL; |
|
49 |
import java.util.ArrayList; |
|
50 |
import java.util.Hashtable; |
|
51 |
import java.util.Iterator; |
|
52 |
import java.util.Set; |
|
53 |
|
|
54 |
import org.gvsig.remoteClient.exceptions.ServerErrorException; |
|
55 |
import org.gvsig.remoteClient.exceptions.WCSException; |
|
56 |
import org.gvsig.remoteClient.utils.BoundaryBox; |
|
57 |
import org.gvsig.remoteClient.wcs.WCSClient; |
|
58 |
import org.gvsig.remoteClient.wcs.WCSCoverage; |
|
59 |
import org.gvsig.remoteClient.wcs.WCSStatus; |
|
60 |
import org.gvsig.remoteClient.wcs.WCSCoverage.AxisDescription; |
|
61 |
import org.gvsig.remoteClient.wms.ICancellable; |
|
62 |
|
|
63 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
64 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
|
65 |
import com.iver.cit.gvsig.fmap.layers.FMapWCSParameter; |
|
66 |
import com.iver.cit.gvsig.fmap.layers.WCSLayer; |
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
/** |
|
71 |
* Driver between the FMap and WCSClient |
|
72 |
* |
|
73 |
* Controlador entre FMap y WCSClient |
|
74 |
* |
|
75 |
* @author jaume |
|
76 |
* |
|
77 |
*/ |
|
78 |
public class FMapWCSDriver { |
|
79 |
private WCSClient client = null; |
|
80 |
private Hashtable coverages; |
|
81 |
private WCSLayer[] layerList; |
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
/** |
|
86 |
* Obtains the host name. |
|
87 |
* |
|
88 |
* Devuelve el nombre del host. |
|
89 |
*/ |
|
90 |
public String getHost() { |
|
91 |
return client.getHost(); |
|
92 |
} |
|
93 |
|
|
94 |
private FMapWCSDriver() {} |
|
95 |
|
|
96 |
protected FMapWCSDriver(URL url) throws ConnectException, IOException { |
|
97 |
client = new WCSClient(url.toString()); |
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* Returns the string "WCSDriver", which is the driver's name. |
|
102 |
* |
|
103 |
* Devuelve "WCSDriver", el nombre del driver. |
|
104 |
* @return String |
|
105 |
*/ |
|
106 |
public String getName() { return "WCSDriver"; } |
|
107 |
|
|
108 |
/** |
|
109 |
* Sets the server that we want to connect to. |
|
110 |
* |
|
111 |
* Establece el servidor al que se quiere conectar. |
|
112 |
* |
|
113 |
* @param host |
|
114 |
* @throws IOException |
|
115 |
*/ |
|
116 |
public void setHost(String host) throws IOException{ |
|
117 |
client = new WCSClient(host); |
|
118 |
} |
|
119 |
|
|
120 |
|
|
121 |
/** |
|
122 |
* Returns a human-readable string containing the server's name. |
|
123 |
* |
|
124 |
* Devuelve el nombre legible del servidor devuelto por ?ste. |
|
125 |
* |
|
126 |
* @return String |
|
127 |
*/ |
|
128 |
public String getLabel() { |
|
129 |
return client.getServiceTitle(); |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* Returns a string containing the server's WCS version number. |
|
134 |
* |
|
135 |
* Devuelve el n?mero de versi?n WCS del servidor |
|
136 |
* |
|
137 |
* @return String |
|
138 |
*/ |
|
139 |
public String getVersion(){ |
|
140 |
return client.getVersion(); |
|
141 |
} |
|
142 |
|
|
143 |
/** |
|
144 |
* <p> |
|
145 |
* Returns name and description of the server. It is supposed to be used |
|
146 |
* as the source of the abstract field in your application's interface. |
|
147 |
* </p> |
|
148 |
* <p> |
|
149 |
* Devuelve nombre y descripci?n (abstract) del servidor. |
|
150 |
* </p> |
|
151 |
* @return String |
|
152 |
*/ |
|
153 |
public String getDescription(){ |
|
154 |
return client.getDescription(); |
|
155 |
} |
|
156 |
|
|
157 |
/** |
|
158 |
* Returns the layer descriptor for a given coverage name. |
|
159 |
* @param layerName |
|
160 |
* @return WCSLayer |
|
161 |
*/ |
|
162 |
public WCSLayer getLayer(String layerName) { |
|
163 |
getLayerList(); |
|
164 |
return (WCSLayer) coverages.get(layerName); |
|
165 |
} |
|
166 |
|
|
167 |
/** |
|
168 |
* Returns an array of WCSLayer's with the descriptors of all coverages |
|
169 |
* @return WCSLayer[] |
|
170 |
*/ |
|
171 |
public WCSLayer[] getLayerList(){ |
|
172 |
if (coverages == null || coverages.isEmpty()) { |
|
173 |
// the WCSLayer collection will be built |
|
174 |
coverages = new Hashtable(); |
|
175 |
Hashtable wcsCoverages = client.getCoverageList(); |
|
176 |
int sz = wcsCoverages.size(); |
|
177 |
|
|
178 |
// Create an array with the WCSCoverages |
|
179 |
WCSCoverage[] coverageList = new WCSCoverage[sz]; |
|
180 |
Iterator it = wcsCoverages.keySet().iterator(); |
|
181 |
int i = 0; |
|
182 |
while (it.hasNext()) { |
|
183 |
coverageList[i] = (WCSCoverage) wcsCoverages.get(it.next()); |
|
184 |
i++; |
|
185 |
} |
|
186 |
|
|
187 |
// Create a WCSLayer array from the previous WCSCoverage array |
|
188 |
layerList = new WCSLayer[sz]; |
|
189 |
for (int j = 0; j < layerList.length; j++) { |
|
190 |
WCSLayer lyr = new WCSLayer(); |
|
191 |
WCSCoverage cov = coverageList[j]; |
|
192 |
// name |
|
193 |
lyr.setName(cov.getName()); |
|
194 |
|
|
195 |
// title |
|
196 |
lyr.setTitle(cov.getTitle()); |
|
197 |
|
|
198 |
// description |
|
199 |
lyr.setDescription(cov.getAbstract()); |
|
200 |
|
|
201 |
// srs |
|
202 |
lyr.addAllSrs(cov.getAllSrs()); |
|
203 |
|
|
204 |
// native srs |
|
205 |
lyr.setNativeSRS(cov.getNativeSRS()); |
|
206 |
|
|
207 |
// extents |
|
208 |
Set k = cov.getBBoxes().keySet(); |
|
209 |
if (!k.isEmpty()) { |
|
210 |
it = k.iterator(); |
|
211 |
while (it.hasNext()) { |
|
212 |
String srs = (String) it.next(); |
|
213 |
BoundaryBox bBox = cov.getBbox(srs); |
|
214 |
Rectangle2D r = new Rectangle2D.Double( |
|
215 |
bBox.getXmin(), |
|
216 |
bBox.getYmin(), |
|
217 |
bBox.getXmax()-bBox.getXmin(), |
|
218 |
bBox.getYmax()-bBox.getYmin() |
|
219 |
); |
|
220 |
lyr.addExtent(srs, r); |
|
221 |
} |
|
222 |
} |
|
223 |
|
|
224 |
// formats |
|
225 |
lyr.setFormats(cov.getFormats()); |
|
226 |
|
|
227 |
// time positions |
|
228 |
lyr.setTimePositions(cov.getTimePositions()); |
|
229 |
|
|
230 |
// max res |
|
231 |
lyr.setMaxRes(new Point2D.Double(cov.getResX(), cov.getResY())); |
|
232 |
|
|
233 |
// interpolations |
|
234 |
lyr.setInterpolationMethods(cov.getInterpolationMethods()); |
|
235 |
|
|
236 |
// parameters |
|
237 |
k = cov.axisPool.keySet(); |
|
238 |
if (!k.isEmpty()) { |
|
239 |
it = k.iterator(); |
|
240 |
while (it.hasNext()) { |
|
241 |
AxisDescription ad = (AxisDescription) cov.axisPool.get(it.next()); |
|
242 |
FMapWCSParameter p = new FMapWCSParameter(); |
|
243 |
p.setName(ad.getName()); |
|
244 |
p.setLabel(ad.getLabel()); |
|
245 |
p.setType(ad.getInterval()==null? FMapWCSParameter.VALUE_LIST : FMapWCSParameter.INTERVAL); |
|
246 |
if (p.getType()==FMapWCSParameter.VALUE_LIST) |
|
247 |
p.setValueList(ad.getSingleValues()); |
|
248 |
else |
|
249 |
p.setInterval(ad.getInterval()); |
|
250 |
lyr.addParameter(p); |
|
251 |
} |
|
252 |
} |
|
253 |
layerList[j] = lyr; |
|
254 |
coverages.put(lyr.getName(), lyr); |
|
255 |
} |
|
256 |
} |
|
257 |
return layerList; |
|
258 |
} |
|
259 |
|
|
260 |
/** |
|
261 |
* Establishes the connection to the WCS server. Connecting to a WCS is |
|
262 |
* an abstraction.<br> |
|
263 |
* <p> |
|
264 |
* Actually, it sends a GetCapabilities and a general DescribeCoverage |
|
265 |
* request (not a coverage-specific DescribeCoverage request) to read the |
|
266 |
* necessary data for building further GetCoverage requests. |
|
267 |
* </p> |
|
268 |
* @param override |
|
269 |
* @throws IOException, DriverException. |
|
270 |
*/ |
|
271 |
public boolean connect(boolean override, ICancellable cancel) throws IOException, ReadDriverException { |
|
272 |
coverages = null; |
|
273 |
setHost(client.getHost()); |
|
274 |
return client.connect(override, cancel); |
|
275 |
} |
|
276 |
|
|
277 |
/** |
|
278 |
* No close operation is needed since WCS service it is a non-session based |
|
279 |
* protocol. So, this does nothing and you can omit it.<br> |
|
280 |
*/ |
|
281 |
public void close() { |
|
282 |
// connected = false; |
|
283 |
} |
|
284 |
|
|
285 |
/** |
|
286 |
* Returns the label of an specific coverage given by the coverage name |
|
287 |
* @param coverage name (string) |
|
288 |
* @return string |
|
289 |
*/ |
|
290 |
public String getLabel(String coverageName) { |
|
291 |
return client.getLabel(coverageName); |
|
292 |
} |
|
293 |
|
|
294 |
/** |
|
295 |
* Returns the coverage's MAX extent from the server. |
|
296 |
* @return Rectangle2D |
|
297 |
* @throws DriverException |
|
298 |
* @throws IOException |
|
299 |
*/ |
|
300 |
public Rectangle2D getFullExtent(String coverageName, String srs) throws IOException, ReadDriverException { |
|
301 |
return client.getExtent(coverageName, srs); |
|
302 |
} |
|
303 |
|
|
304 |
/** |
|
305 |
* Returns the max resolution of a specific coverage given by the coverage's name. |
|
306 |
* @param coverage name (string) |
|
307 |
* @return double |
|
308 |
*/ |
|
309 |
public Point2D getMaxResolution(String coverageName) { |
|
310 |
if (coverages.containsKey(coverageName)) { |
|
311 |
return ((WCSLayer) coverages.get(coverageName)).getMaxRes(); |
|
312 |
} |
|
313 |
return null; |
|
314 |
} |
|
315 |
|
|
316 |
|
|
317 |
/** |
|
318 |
* Returns an ArrayList containing a set of Strings with the coverage's SRSs. |
|
319 |
* @param coverage name (string) |
|
320 |
* @return ArrayList |
|
321 |
*/ |
|
322 |
public ArrayList getSRSs(String coverageName) { |
|
323 |
if (coverages.containsKey(coverageName)) { |
|
324 |
return ((WCSLayer) coverages.get(coverageName)).getSRSs(); |
|
325 |
} |
|
326 |
return null; |
|
327 |
} |
|
328 |
|
|
329 |
/** |
|
330 |
* Returns a String containing a description of an specific coverage. |
|
331 |
* @param coverage name (string) |
|
332 |
* @return string |
|
333 |
*/ |
|
334 |
public String getCoverageDescription(String coverageName) { |
|
335 |
if (coverages.containsKey(coverageName)) { |
|
336 |
return ((WCSLayer) coverages.get(coverageName)).getDescription(); |
|
337 |
} |
|
338 |
return null; |
|
339 |
} |
|
340 |
|
|
341 |
/** |
|
342 |
* Returns an ArrayList containing strings for the time positions of an |
|
343 |
* specific coverage given by the coverage's name. |
|
344 |
* @param coverage name (string) |
|
345 |
* @return ArrayList |
|
346 |
*/ |
|
347 |
public ArrayList getTimes(String coverageName) { |
|
348 |
if (coverages.containsKey(coverageName)) { |
|
349 |
return ((WCSLayer) coverages.get(coverageName)).getTimePositions(); |
|
350 |
} |
|
351 |
return null; |
|
352 |
} |
|
353 |
|
|
354 |
/** |
|
355 |
* Sends a GetCoverage request to the client. |
|
356 |
* @param status |
|
357 |
* @return |
|
358 |
* @throws WCSException |
|
359 |
*/ |
|
360 |
public File getCoverage(WCSStatus status, ICancellable cancel) throws WCSDriverException { |
|
361 |
try { |
|
362 |
return client.getCoverage(status, cancel); |
|
363 |
} catch (ServerErrorException e) { |
|
364 |
throw new WCSDriverException(getName(),e); |
|
365 |
} catch (org.gvsig.remoteClient.exceptions.WCSException e) { |
|
366 |
throw new WCSDriverException(getName(),e); |
|
367 |
} |
|
368 |
} |
|
369 |
|
|
370 |
} |
|
0 | 371 |
tags/tmp_build/extensions/extWCS/src/com/iver/cit/gvsig/fmap/drivers/wcs/FMapWCSDriverFactory.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
|
|
42 |
/* CVS MESSAGES: |
|
43 |
* |
|
44 |
* $Id$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.1 2006-06-26 16:11:05 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* |
|
50 |
*/ |
|
51 |
package com.iver.cit.gvsig.fmap.drivers.wcs; |
|
52 |
|
|
53 |
import java.io.IOException; |
|
54 |
import java.net.ConnectException; |
|
55 |
import java.net.URL; |
|
56 |
import java.util.Hashtable; |
|
57 |
|
|
58 |
public class FMapWCSDriverFactory { |
|
59 |
private static Hashtable drivers = new Hashtable(); |
|
60 |
private FMapWCSDriverFactory() { } |
|
61 |
|
|
62 |
static public final FMapWCSDriver getFMapDriverForURL(URL url) throws ConnectException, IOException { |
|
63 |
FMapWCSDriver drv = (FMapWCSDriver) drivers.get(url); |
|
64 |
if (drv == null) { |
|
65 |
drv = new FMapWCSDriver(url); |
|
66 |
drivers.put(url, drv); |
|
67 |
} |
|
68 |
return drv; |
|
69 |
} |
|
70 |
|
|
71 |
} |
|
72 |
|
|
73 |
|
|
0 | 74 |
tags/tmp_build/extensions/extWCS/src/com/iver/cit/gvsig/fmap/layers/FMapWCSParameter.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.fmap.layers; |
|
42 |
|
|
43 |
import java.util.ArrayList; |
|
44 |
|
|
45 |
/** |
|
46 |
* Class abstracting WCS's axis descriptions into FMap |
|
47 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
48 |
* @TODO add interval parameters support |
|
49 |
*/ |
|
50 |
public class FMapWCSParameter { |
|
51 |
|
|
52 |
public static final int VALUE_LIST = 0; |
|
53 |
public static final int INTERVAL = 1; |
|
54 |
private String name; |
|
55 |
private int type; |
|
56 |
private ArrayList valueList; |
|
57 |
private String interval; |
|
58 |
private String label; |
|
59 |
|
|
60 |
public void setName(String name) { |
|
61 |
this.name = name; |
|
62 |
|
|
63 |
} |
|
64 |
|
|
65 |
public void setType(int type) { |
|
66 |
this.type = type; |
|
67 |
} |
|
68 |
|
|
69 |
public int getType() { |
|
70 |
return type; |
|
71 |
} |
|
72 |
|
|
73 |
public void setValueList(ArrayList singleValues) { |
|
74 |
this.valueList = singleValues; |
|
75 |
} |
|
76 |
|
|
77 |
public void setInterval(String interval) { |
|
78 |
this.interval = interval; |
|
79 |
} |
|
80 |
|
|
81 |
public void setLabel(String label) { |
|
82 |
this.label = label; |
|
83 |
} |
|
84 |
|
|
85 |
public String toString() { |
|
86 |
return (label!=null) ? label : name; |
|
87 |
} |
|
88 |
|
|
89 |
public ArrayList getValueList() { |
|
90 |
return valueList; |
|
91 |
} |
|
92 |
|
|
93 |
public String getName() { |
|
94 |
return name; |
|
95 |
} |
|
96 |
} |
|
0 | 97 |
tags/tmp_build/extensions/extWCS/src/com/iver/cit/gvsig/fmap/layers/FLyrWCS.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package com.iver.cit.gvsig.fmap.layers; |
|
42 |
|
|
43 |
import java.awt.Dimension; |
|
44 |
import java.awt.Graphics2D; |
|
45 |
import java.awt.Point; |
|
46 |
import java.awt.Rectangle; |
|
47 |
import java.awt.geom.AffineTransform; |
|
48 |
import java.awt.geom.NoninvertibleTransformException; |
|
49 |
import java.awt.geom.Point2D; |
|
50 |
import java.awt.geom.Rectangle2D; |
|
51 |
import java.awt.image.BufferedImage; |
|
52 |
import java.awt.image.DataBuffer; |
|
53 |
import java.io.File; |
|
54 |
import java.io.IOException; |
|
55 |
import java.lang.reflect.Constructor; |
|
56 |
import java.lang.reflect.InvocationTargetException; |
|
57 |
import java.net.MalformedURLException; |
|
58 |
import java.net.URL; |
|
59 |
import java.util.ArrayList; |
|
60 |
import java.util.Hashtable; |
|
61 |
import java.util.Iterator; |
|
62 |
import java.util.Map; |
|
63 |
|
|
64 |
import javax.print.attribute.PrintRequestAttributeSet; |
|
65 |
import javax.swing.ImageIcon; |
|
66 |
|
|
67 |
import org.exolab.castor.xml.ValidationException; |
|
68 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
|
69 |
import org.gvsig.fmap.raster.layers.IRasterLayerActions; |
|
70 |
import org.gvsig.fmap.raster.layers.IStatusRaster; |
|
71 |
import org.gvsig.fmap.raster.layers.StatusLayerRaster; |
|
72 |
import org.gvsig.raster.dataset.CompositeDataset; |
|
73 |
import org.gvsig.raster.dataset.IBuffer; |
|
74 |
import org.gvsig.raster.dataset.MosaicNotValidException; |
|
75 |
import org.gvsig.raster.dataset.MultiRasterDataset; |
|
76 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
|
77 |
import org.gvsig.raster.dataset.io.RasterDriverException; |
|
78 |
import org.gvsig.raster.datastruct.ColorTable; |
|
79 |
import org.gvsig.raster.datastruct.Extent; |
|
80 |
import org.gvsig.raster.datastruct.ViewPortData; |
|
81 |
import org.gvsig.raster.grid.GridTransparency; |
|
82 |
import org.gvsig.raster.grid.filter.FilterTypeException; |
|
83 |
import org.gvsig.raster.grid.filter.RasterFilterList; |
|
84 |
import org.gvsig.raster.grid.filter.RasterFilterListManager; |
|
85 |
import org.gvsig.raster.grid.filter.enhancement.LinearEnhancementFilter; |
|
86 |
import org.gvsig.raster.grid.filter.statistics.TailTrimFilter; |
|
87 |
import org.gvsig.remoteClient.wcs.WCSStatus; |
|
88 |
import org.gvsig.remoteClient.wms.ICancellable; |
|
89 |
|
|
90 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
91 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
|
92 |
import com.iver.cit.gvsig.exceptions.layers.ConnectionErrorLayerException; |
|
93 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
|
94 |
import com.iver.cit.gvsig.exceptions.layers.UnsupportedVersionLayerException; |
|
95 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
96 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
97 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
|
98 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
99 |
import com.iver.cit.gvsig.fmap.drivers.wcs.FMapWCSDriver; |
|
100 |
import com.iver.cit.gvsig.fmap.drivers.wcs.FMapWCSDriverFactory; |
|
101 |
import com.iver.cit.gvsig.fmap.drivers.wcs.WCSDriverException; |
|
102 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem; |
|
103 |
import com.iver.utiles.StringUtilities; |
|
104 |
import com.iver.utiles.XMLEntity; |
|
105 |
import com.iver.utiles.swing.threads.Cancellable; |
|
106 |
|
|
107 |
|
|
108 |
/** |
|
109 |
* Class for the WCS layer. |
|
110 |
* |
|
111 |
* Capa para el WCS. |
|
112 |
* |
|
113 |
* Las capas WCS son tileadas para descargarlas del servidor. Esto quiere decir que |
|
114 |
* est?n formadas por multiples ficheros raster. Por esto la fuente de datos raster (IRasterDatasource) |
|
115 |
* de la capa FLyrWCS es un objeto de tipo CompositeDataset. Este objeto est? compuesto por un array |
|
116 |
* bidimensional de MultiRasterDataset. Cada uno de los MultiRasterDataset corresponde con un tile |
|
117 |
* salvado en disco. Estos MultiRasterDataset se crean cada vez que se repinta ya que en WCS a cada |
|
118 |
* zoom varian los ficheros fuente. La secuencia de creaci?n de un CompositeDataset ser?a la siguiente: |
|
119 |
* <UL> |
|
120 |
* <LI>Se hace una petici?n de dibujado por parte del usuario llamando al m?todo draw de FLyrWCS</LI> |
|
121 |
* <LI>Se tilea la petici?n</LI> |
|
122 |
* <LI>Cada tile se dibuja abriendo una FLyrRaster para ese tile</LI> |
|
123 |
* <LI>Si es el primer dibujado se guarda una referencia en la capa WMS a las propiedades de renderizado, orden de bandas, |
|
124 |
* transparencia, filtros aplicados, ...</LI> |
|
125 |
* <LI>Si no es el primer dibujado se asignan las propiedades de renderizado cuya referencia se guarda en la capa WMS</LI> |
|
126 |
* <LI>Se guarda el MultiRasterDataset de cada tile</LI> |
|
127 |
* <LI>Al acabar todos los tiles creamos un CompositeDataset con los MultiRasterDataset de todos los tiles</LI> |
|
128 |
* <LI>Asignamos a la capa la referencia de las propiedades de renderizado que tenemos almacenadas. De esta forma si hay |
|
129 |
* alguna modificaci?n desde el cuadro de propiedades ser? efectiva sobre los tiles que se dibujan.</LI> |
|
130 |
* </UL> |
|
131 |
* |
|
132 |
* @author jaume - jaume.dominguez@iver.es |
|
133 |
*/ |
|
134 |
public class FLyrWCS extends FLyrRasterSE { |
|
135 |
private FMapWCSDriver wcs = null; |
|
136 |
|
|
137 |
private URL host; |
|
138 |
private String coverageName; |
|
139 |
private Rectangle2D fullExtent; |
|
140 |
private String format; |
|
141 |
private String srs; |
|
142 |
private String time; |
|
143 |
private String parameter; |
|
144 |
private Point2D maxRes; |
|
145 |
private Hashtable onlineResources = new Hashtable(); |
|
146 |
|
|
147 |
private WCSStatus wcsStatus = new WCSStatus(); |
|
148 |
|
|
149 |
private int posX = 0, posY = 0; |
|
150 |
private double posXWC = 0, posYWC = 0; |
|
151 |
private int r = 0, g = 0, b = 0; |
|
152 |
private boolean firstLoad = false; |
|
153 |
private VisualStatus visualStatus = new VisualStatus(); |
|
154 |
|
|
155 |
private boolean mustTileDraw = false; |
|
156 |
private int maxTileDrawWidth = 1023; |
|
157 |
private int maxTileDrawHeight = 1023; |
|
158 |
//private int maxTilePrintWidth = 250; |
|
159 |
//private int maxTilePrintHeight = 250; |
|
160 |
/** |
|
161 |
* Lista de filtros aplicada en la renderizaci?n |
|
162 |
*/ |
|
163 |
private RasterFilterList filterList = null; |
|
164 |
private GridTransparency transparency = null; |
|
165 |
private int[] renderBands = null; |
|
166 |
private FLyrRasterSE layerRaster = null; |
|
167 |
private ArrayList filterArguments = null; |
|
168 |
|
|
169 |
private class MyCancellable implements ICancellable |
|
170 |
{ |
|
171 |
|
|
172 |
private Cancellable original; |
|
173 |
public MyCancellable(Cancellable cancelOriginal) |
|
174 |
{ |
|
175 |
this.original = cancelOriginal; |
|
176 |
} |
|
177 |
public boolean isCanceled() { |
|
178 |
return original.isCanceled(); |
|
179 |
} |
|
180 |
public Object getID() { |
|
181 |
return this; |
|
182 |
} |
|
183 |
|
|
184 |
} |
|
185 |
|
|
186 |
public FLyrWCS(){ |
|
187 |
super(); |
|
188 |
} |
|
189 |
|
|
190 |
public FLyrWCS(Map args) throws DriverIOException{ |
|
191 |
FMapWCSDriver drv = null; |
|
192 |
String host = (String)args.get("HOST"); |
|
193 |
String sCoverage = (String) args.get((String) "COVERAGE"); |
|
194 |
|
|
195 |
try { |
|
196 |
this.setHost(new URL(host)); |
|
197 |
} catch (MalformedURLException e) { |
|
198 |
//e.printStackTrace(); |
|
199 |
throw new DriverIOException("Malformed host URL, '" + host + "' (" + e.toString() + ")."); |
|
200 |
} |
|
201 |
try { |
|
202 |
drv = this.getDriver(); |
|
203 |
} catch (Exception e) { |
|
204 |
// e.printStackTrace(); |
|
205 |
throw new DriverIOException("Can't get driver to host '" + host + "' (" + e.toString() + ")."); |
|
206 |
} |
|
207 |
|
|
208 |
try{ |
|
209 |
if (!drv.connect(false, null)){ |
|
210 |
throw new DriverIOException("Can't connect to host '" + host + "'."); |
|
211 |
} |
|
212 |
}catch(Exception e){ |
|
213 |
throw new DriverIOException("Can't connect to host '" + host + "'."); |
|
214 |
} |
|
215 |
|
|
216 |
WCSLayer wcsNode = drv.getLayer(sCoverage); |
|
217 |
|
|
218 |
if (wcsNode == null){ |
|
219 |
throw new DriverIOException("The server '" + host + "' doesn't has the coverage '" + sCoverage + "'."); |
|
220 |
} |
|
221 |
|
|
222 |
try{ |
|
223 |
this.setFullExtent(drv.getFullExtent(sCoverage, |
|
224 |
(String) args.get((String) "CRS"))); |
|
225 |
this.setFormat((String) args.get((String) "FORMAT")); |
|
226 |
this.setParameter("BANDS=" + (String) args.get((String) "BANDS")); |
|
227 |
this.setSRS((String) args.get((String) "CRS")); |
|
228 |
this.setName(sCoverage); |
|
229 |
this.setCoverageName(sCoverage); |
|
230 |
}catch (Exception e){ |
|
231 |
throw new DriverIOException("The server '" + host + "' is not able to load the coverage '" + sCoverage + "'."); |
|
232 |
} |
|
233 |
|
|
234 |
} |
|
235 |
|
|
236 |
/** |
|
237 |
* Clase que contiene los datos de visualizaci?n de WCS. Tiene datos que representan al |
|
238 |
* raster en la vista. Este raster puede estar compuesto por tiles por lo que valores |
|
239 |
* como el ancho total o el m?nimo o m?ximo deben ser calculados a partir de todos los |
|
240 |
* tiles visualizados. |
|
241 |
* @author Nacho Brodin (brodin_ign@gva.es) |
|
242 |
*/ |
|
243 |
private class VisualStatus { |
|
244 |
/** |
|
245 |
* Ancho y alto de la imagen o del conjunto de tiles si los tiene. Coincide con |
|
246 |
* el ancho y alto del viewPort |
|
247 |
*/ |
|
248 |
private int width = 0, height = 0; |
|
249 |
private double minX = 0D, minY = 0D, maxX = 0D, maxY = 0D; |
|
250 |
private int bandCount = 0; |
|
251 |
private int dataType = DataBuffer.TYPE_UNDEFINED; |
|
252 |
|
|
253 |
/** |
|
254 |
* Ancho y alto total del raster que ser? la suma de todos los tiles. |
|
255 |
*/ |
|
256 |
private int rasterWidth = 0, rasterHeight = 0; |
|
257 |
private double rasterMinX = Double.MAX_VALUE, rasterMinY = Double.MAX_VALUE; |
|
258 |
private double rasterMaxX = 0, rasterMaxY = 0; |
|
259 |
/** |
|
260 |
* Lista de nombre de fichero que componen toda la visualizaci?n. |
|
261 |
*/ |
|
262 |
private String[] fileNames = null; |
|
263 |
} |
|
264 |
|
|
265 |
/** |
|
266 |
* @deprecated |
|
267 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#getInfo |
|
268 |
*/ |
|
269 |
public String queryByPoint(Point p) { |
|
270 |
String data = "<file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n"; |
|
271 |
ArrayList attr = this.getAttributes(); |
|
272 |
data += " <raster\n"; |
|
273 |
data += " File=\""+getName()+"\"\n"; |
|
274 |
for (int i=0; i<attr.size(); i++) { |
|
275 |
Object [] a = (Object []) attr.get(i); |
|
276 |
|
|
277 |
data += " "+a[0].toString()+"="; |
|
278 |
if (a[1].toString() instanceof String) |
|
279 |
data += "\""+a[1].toString()+"\"\n"; |
|
280 |
else |
|
281 |
data += a[1].toString()+"\n"; |
|
282 |
} |
|
283 |
data += " Point=\""+posX+" , "+posY+"\"\n"; |
|
284 |
data += " Point_WC=\""+posXWC+" , "+posYWC+"\"\n"; |
|
285 |
data += " RGB=\""+r+", "+g+", "+b+"\"\n"; |
|
286 |
data += " />\n"; |
|
287 |
|
|
288 |
data += "</file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n"; |
|
289 |
System.out.println(data); |
|
290 |
return data; |
|
291 |
} |
|
292 |
|
|
293 |
/** |
|
294 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#getInfo |
|
295 |
*/ |
|
296 |
public XMLItem[] getInfo(Point point, double tolerance, Cancellable cancel ) throws ReadDriverException { |
|
297 |
return super.getInfo(point, tolerance, cancel); |
|
298 |
} |
|
299 |
|
|
300 |
/* |
|
301 |
* (non-Javadoc) |
|
302 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent() |
|
303 |
*/ |
|
304 |
public Rectangle2D getFullExtent() { |
|
305 |
return fullExtent; |
|
306 |
} |
|
307 |
|
|
308 |
/* |
|
309 |
* (non-Javadoc) |
|
310 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.operations.Cancellable, double) |
|
311 |
*/ |
|
312 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale) throws ReadDriverException { |
|
313 |
enableStopped(); |
|
314 |
// callLegendChanged(null); |
|
315 |
|
|
316 |
if (isWithinScale(scale)) { |
|
317 |
Point2D p = viewPort.getOffset(); |
|
318 |
// p will be (0, 0) when drawing a view or other when painting onto |
|
319 |
// the Layout. |
|
320 |
visualStatus.width = viewPort.getImageWidth(); |
|
321 |
visualStatus.height = viewPort.getImageHeight(); |
|
322 |
visualStatus.minX = viewPort.getAdjustedExtent().getMinX(); |
|
323 |
visualStatus.minY = viewPort.getAdjustedExtent().getMinY(); |
|
324 |
visualStatus.maxX = viewPort.getAdjustedExtent().getMaxX(); |
|
325 |
visualStatus.maxY = viewPort.getAdjustedExtent().getMaxY(); |
|
326 |
visualStatus.rasterWidth = 0; |
|
327 |
visualStatus.rasterHeight = 0; |
|
328 |
visualStatus.rasterMinX = Double.MAX_VALUE; |
|
329 |
visualStatus.rasterMinY = Double.MAX_VALUE; |
|
330 |
visualStatus.rasterMaxX = 0; |
|
331 |
visualStatus.rasterMaxY = 0; |
|
332 |
visualStatus.fileNames = new String[1]; |
|
333 |
|
|
334 |
try { |
|
335 |
if (true) { |
|
336 |
if (viewPort.getImageWidth() <= maxTileDrawWidth && viewPort.getImageHeight() <= maxTileDrawHeight) { |
|
337 |
drawTile(g, viewPort, cancel, 0, scale); |
|
338 |
if (layerRaster == null) |
|
339 |
return; |
|
340 |
dataset = layerRaster.getDataSource(); |
|
341 |
getRender().setLastRenderBuffer(layerRaster.getRender().getLastRenderBuffer()); |
|
342 |
initializeRasterLayer(null, new IBuffer[][] { { layerRaster.getRender().getLastRenderBuffer() } }); |
|
343 |
} else { |
|
344 |
Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), viewPort.getImageWidth(), viewPort.getImageHeight()); |
|
345 |
Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r); |
|
346 |
tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone()); |
|
347 |
MultiRasterDataset[][] datasets = new MultiRasterDataset[tiles.getNumRows()][tiles.getNumCols()]; |
|
348 |
IBuffer[][] buf = new IBuffer[tiles.getNumRows()][tiles.getNumCols()]; |
|
349 |
visualStatus.fileNames = new String[tiles.getNumTiles()]; |
|
350 |
for (int tileNr = 0; tileNr < tiles.getNumTiles(); tileNr++) { |
|
351 |
// drawing part |
|
352 |
try { |
|
353 |
ViewPort vp = tiles.getTileViewPort(viewPort, tileNr); |
|
354 |
boolean painted = drawTile(g, vp, cancel, tileNr, scale); |
|
355 |
if (layerRaster != null && painted) { |
|
356 |
datasets[(int) (tileNr / tiles.getNumCols())][tileNr % tiles.getNumCols()] = (MultiRasterDataset) layerRaster.getDataSource().newDataset(); |
|
357 |
buf[(int) (tileNr / tiles.getNumCols())][tileNr % tiles.getNumCols()] = layerRaster.getRender().getLastRenderBuffer(); |
|
358 |
} |
|
359 |
} catch (NoninvertibleTransformException e) { |
|
360 |
e.printStackTrace(); |
|
361 |
} |
|
362 |
} |
|
363 |
try { |
|
364 |
if (datasets != null && datasets[0][0] != null) { |
|
365 |
dataset = new CompositeDataset(datasets); |
|
366 |
initializeRasterLayer(datasets, buf); |
|
367 |
} |
|
368 |
} catch (MosaicNotValidException e) { |
|
369 |
throw new ReadDriverException("No hay continuidad en el mosaico.", e); |
|
370 |
} catch (LoadLayerException e) { |
|
371 |
throw new ReadDriverException("Error inicializando la capa.", e); |
|
372 |
} |
|
373 |
} |
|
374 |
} else { |
|
375 |
drawTile(g, viewPort, cancel, 0, scale); |
|
376 |
if (layerRaster == null) |
|
377 |
return; |
|
378 |
dataset = layerRaster.getDataSource(); |
|
379 |
getRender().setLastRenderBuffer(layerRaster.getRender().getLastRenderBuffer()); |
|
380 |
initializeRasterLayer(null, new IBuffer[][] { { layerRaster.getRender().getLastRenderBuffer() } }); |
|
381 |
} |
|
382 |
} catch (ConnectionErrorLayerException e) { |
|
383 |
e.printStackTrace(); |
|
384 |
} catch (UnsupportedVersionLayerException e) { |
|
385 |
e.printStackTrace(); |
|
386 |
} catch (LoadLayerException e) { |
|
387 |
e.printStackTrace(); |
|
388 |
} catch (InterruptedException e) { |
|
389 |
} |
|
390 |
} |
|
391 |
disableStopped(); |
|
392 |
// callLegendChanged(null); |
|
393 |
Runtime r = Runtime.getRuntime(); |
|
394 |
long mem = r.totalMemory() - r.freeMemory(); |
|
395 |
System.err.println("Memoria total: " + (mem / 1024) +"KB"); |
|
396 |
} |
|
397 |
|
|
398 |
/** |
|
399 |
* Acciones que se realizan despu?s de asignar la fuente de datos a |
|
400 |
* la capa raster. |
|
401 |
* |
|
402 |
* @throws LoadLayerException |
|
403 |
* @throws InterruptedException |
|
404 |
*/ |
|
405 |
private void initializeRasterLayer(MultiRasterDataset[][] datasets, IBuffer[][] buf) throws LoadLayerException, InterruptedException { |
|
406 |
if(this.filterList != null) |
|
407 |
getRender().setFilterList(filterList); |
|
408 |
|
|
409 |
/* |
|
410 |
if(this.transparency != null) |
|
411 |
getRender().setLastTransparency(transparency); |
|
412 |
*/ |
|
413 |
if(this.renderBands != null) |
|
414 |
getRender().setRenderBands(renderBands); |
|
415 |
if(datasets != null) { |
|
416 |
String[][] names = new String[datasets.length][datasets[0].length]; |
|
417 |
for (int i = 0; i < datasets.length; i++) { |
|
418 |
for (int j = 0; j < datasets[i].length; j++) { |
|
419 |
if(datasets[i][j] != null) |
|
420 |
names[i][j] = datasets[i][j].getDataset(0)[0].getFName(); |
|
421 |
} |
|
422 |
} |
|
423 |
super.setLoadParams(names); |
|
424 |
} |
|
425 |
super.init(); |
|
426 |
if(buf != null) { |
|
427 |
int drawablesBandCount = layerRaster.getDataSource().getBands().getDrawableBandsCount(); |
|
428 |
IBuffer buff = null; |
|
429 |
if(dataset instanceof CompositeDataset) |
|
430 |
buff = ((CompositeDataset)dataset).generateBuffer(buf, drawablesBandCount); |
|
431 |
else |
|
432 |
buff = buf[0][0]; |
|
433 |
getRender().setLastRenderBuffer(buff); |
|
434 |
} |
|
435 |
|
|
436 |
if (transparency == null) |
|
437 |
transparency = new GridTransparency(getDataSource().getTransparencyFilesStatus()); |
|
438 |
|
|
439 |
getRender().setLastTransparency(transparency); |
|
440 |
} |
|
441 |
|
|
442 |
/** |
|
443 |
* This is the method used to draw a tile in a WCS mosaic layer. |
|
444 |
* @param tile Tile number to draw |
|
445 |
* @throws ReadDriverException |
|
446 |
* @return true when a tile has been painted |
|
447 |
*/ |
|
448 |
private boolean drawTile(Graphics2D g, ViewPort vp, Cancellable cancel, int tile, double scale) throws LoadLayerException, ReadDriverException { |
|
449 |
|
|
450 |
// Compute the query geometry |
|
451 |
// 1. Check if it is within borders |
|
452 |
Rectangle2D extent = getFullExtent(); |
|
453 |
if ((vp.getAdjustedExtent().getMinX() > extent.getMaxX()) || |
|
454 |
(vp.getAdjustedExtent().getMinY() > extent.getMaxY()) || |
|
455 |
(vp.getAdjustedExtent().getMaxX() < extent.getMinX()) || |
|
456 |
(vp.getAdjustedExtent().getMaxY() < extent.getMinY())) |
|
457 |
return false; |
|
458 |
|
|
459 |
// 2. Compute extent to be requested. |
|
460 |
Rectangle2D bBox = new Rectangle2D.Double(); |
|
461 |
Rectangle2D.intersect(vp.getAdjustedExtent(), extent, bBox); |
|
462 |
|
|
463 |
// 3. Compute size in pixels |
|
464 |
double scalex = vp.getAffineTransform().getScaleX(); |
|
465 |
double scaley = vp.getAffineTransform().getScaleY(); |
|
466 |
int wImg = (int) Math.ceil(Math.abs(bBox.getWidth() * scalex) + 1); |
|
467 |
int hImg = (int) Math.ceil(Math.abs(bBox.getHeight() * scaley) + 1); |
|
468 |
Dimension sz = new Dimension(wImg, hImg); |
|
469 |
|
|
470 |
if ((wImg <= 0) || (hImg <= 0)) |
|
471 |
return false; |
|
472 |
|
|
473 |
try { |
|
474 |
sz = new Dimension(wImg, hImg); |
|
475 |
|
|
476 |
wcsStatus.setCoveraName( coverageName ); |
|
477 |
wcsStatus.setExtent( bBox ); |
|
478 |
wcsStatus.setFormat( format ); |
|
479 |
wcsStatus.setHeight( hImg ); |
|
480 |
wcsStatus.setWidth( wImg ); |
|
481 |
wcsStatus.setSrs(srs); |
|
482 |
wcsStatus.setParameters( parameter ); |
|
483 |
wcsStatus.setTime( time ); |
|
484 |
wcsStatus.setOnlineResource((String) onlineResources.get("GetCoverage")); |
|
485 |
|
|
486 |
File f = getDriver().getCoverage(wcsStatus, new MyCancellable(cancel)); |
|
487 |
if (f == null) |
|
488 |
return false; |
|
489 |
String nameWordFile = f.getPath() + getExtensionWorldFile(); |
|
490 |
com.iver.andami.Utilities.createTemp(nameWordFile, this.getDataWorldFile(bBox, sz)); |
|
491 |
|
|
492 |
IStatusRaster status = super.getStatus(); |
|
493 |
if(status!=null && firstLoad){ |
|
494 |
try { |
|
495 |
status.applyStatus(this); |
|
496 |
} catch (NotSupportedExtensionException e) { |
|
497 |
throw new ReadDriverException("", e); |
|
498 |
} catch (RasterDriverException e) { |
|
499 |
throw new ReadDriverException("", e); |
|
500 |
} catch (FilterTypeException e) { |
|
501 |
throw new ReadDriverException("", e); |
|
502 |
} |
|
503 |
firstLoad = false; |
|
504 |
} |
|
505 |
ViewPortData vpData = new ViewPortData( |
|
506 |
vp.getProjection(), new Extent(bBox), sz ); |
|
507 |
vpData.setMat(vp.getAffineTransform()); |
|
508 |
|
|
509 |
String filePath = f.getAbsolutePath(); |
|
510 |
visualStatus.fileNames[tile] = filePath; |
|
511 |
|
|
512 |
try { |
|
513 |
rasterProcess(filePath, g, vp, scale, cancel); |
|
514 |
} catch (FilterTypeException e) { |
|
515 |
} |
|
516 |
|
|
517 |
// this.getRender().draw(g, vpData); |
|
518 |
// rasterProcess(g, vpData, f); |
|
519 |
|
|
520 |
// } catch (ValidationException e) { |
|
521 |
// UnknownResponseFormatExceptionType type = |
|
522 |
// new UnknownResponseFormatExceptionType(); |
|
523 |
// type.setLayerName(getName()); |
|
524 |
// try { |
|
525 |
// type.setDriverName(getDriver().getName()); |
|
526 |
// } catch (Exception e1) { |
|
527 |
// e1.printStackTrace(); |
|
528 |
// } |
|
529 |
// type.setFormat(format); |
|
530 |
// type.setHost(host); |
|
531 |
// type.setProtocol("WCS"); |
|
532 |
// ReadDriverException exception = new ReadDriverException("unknown_response_format",type); |
|
533 |
// throw exception; |
|
534 |
// azabala throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e); |
|
535 |
// } |
|
536 |
// catch (UnsupportedVersionLayerException e) { |
|
537 |
// UnsuportedProtocolVersionExceptionType type = |
|
538 |
// new UnsuportedProtocolVersionExceptionType(); |
|
539 |
// type.setLayerName(getName()); |
|
540 |
// try { |
|
541 |
// type.setDriverName(getDriver().getName()); |
|
542 |
// } catch (Exception ex){ |
|
543 |
// } |
|
544 |
// type.setUrl(host); |
|
545 |
// throw new ReadDriverException(PluginServices.getText(this, "version_conflict"), e, type); |
|
546 |
|
|
547 |
// azabala throw new DriverException(PluginServices.getText(this, "version_conflict"), e); |
|
548 |
} catch (IOException e) { |
|
549 |
// ConnectionErrorExceptionType type = new ConnectionErrorExceptionType(); |
|
550 |
// type.setLayerName(getName()); |
|
551 |
// try { |
|
552 |
// type.setDriverName(getDriver().getName()); |
|
553 |
// } catch (Exception e1) { |
|
554 |
// } |
|
555 |
// type.setHost(host); |
|
556 |
throw new ConnectionErrorLayerException(getName(),e); |
|
557 |
} |
|
558 |
// catch (WCSLayerException e) { |
|
559 |
////azabala: la capturamos y la convertimos en DriverException |
|
560 |
// WCSDriverExceptionType type = new WCSDriverExceptionType(); |
|
561 |
// type.setLayerName(getName()); |
|
562 |
// try { |
|
563 |
// type.setDriverName(getDriver().getName()); |
|
564 |
// } catch (Exception e1) { |
|
565 |
// } |
|
566 |
// type.setWcsStatus(wcsStatus); |
|
567 |
// this.setVisible(false); |
|
568 |
// throw new WDriverException("Error WCS", e, type); |
|
569 |
// |
|
570 |
//// JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage()); |
|
571 |
// |
|
572 |
// }// |
|
573 |
catch (WCSDriverException e) { |
|
574 |
throw new LoadLayerException(getName(),e); |
|
575 |
} catch (IllegalStateException e) { |
|
576 |
throw new LoadLayerException(getName(),e); |
|
577 |
} |
|
578 |
return true; |
|
579 |
} |
Also available in: Unified diff