Revision 9144
org.gvsig.raster/tags/org.gvsig.raster-2.2.86/org.gvsig.raster.app/org.gvsig.raster.app.common/buildNumber.properties | ||
---|---|---|
1 |
#Sun Jan 13 12:18:02 CET 2019 |
|
2 |
buildNumber=96 |
org.gvsig.raster/tags/org.gvsig.raster-2.2.86/org.gvsig.raster.app/org.gvsig.raster.app.common/src/main/resources-plugin/scripting/lib/gvsig_raster.py | ||
---|---|---|
1 |
from gvsig import * |
|
2 |
from org.gvsig.fmap.dal import DALLocator |
|
3 |
from org.gvsig.fmap.mapcontext import MapContextLocator |
|
4 |
from org.gvsig.fmap.dal.coverage import RasterLocator |
|
5 |
from org.gvsig.fmap.dal.coverage.store.parameter import NewRasterStoreParameters |
|
6 |
from org.gvsig.fmap.dal.coverage.dataset import Buffer |
|
7 |
from org.gvsig.fmap.dal.serverexplorer.filesystem import FilesystemServerExplorer |
|
8 |
from org.gvsig.raster.fmap.layers import FLyrRaster |
|
9 |
from java.lang import Byte,Short,Integer,Float,Double |
|
10 |
from java.io import File |
|
11 |
from java.awt.geom import AffineTransform |
|
12 |
import os |
|
13 |
|
|
14 |
from os.path import splitext |
|
15 |
|
|
16 |
global sourceFileName |
|
17 |
sourceFileName = [] |
|
18 |
sourceFileName.append(None) |
|
19 |
|
|
20 |
|
|
21 |
## |
|
22 |
# |
|
23 |
# Loads the raster layer given the filepath |
|
24 |
# |
|
25 |
# @params rasterfile the filename of the input layer |
|
26 |
# |
|
27 |
# @returns None loads the raster layer |
|
28 |
def loadRasterLayer (rasterfile, mode = "r" ): |
|
29 |
## Load a Raster file in a Layer |
|
30 |
sourceFileName[0]=rasterfile |
|
31 |
if not isinstance (rasterfile,File): |
|
32 |
rasterfile = File(rasterfile) |
|
33 |
|
|
34 |
name, ext = splitext(rasterfile.getName()) |
|
35 |
|
|
36 |
view = currentView() |
|
37 |
|
|
38 |
# Get the manager to use |
|
39 |
dalManager = DALLocator.getDataManager() |
|
40 |
mapContextManager = MapContextLocator.getMapContextManager() |
|
41 |
|
|
42 |
if ext.lower() == ".ecw" or ext.lower() == ".jp2" : |
|
43 |
# FIXME |
|
44 |
pass |
|
45 |
elif ext.lower() == ".mrsid": |
|
46 |
# FIXME |
|
47 |
pass |
|
48 |
else: |
|
49 |
# Create the parameters to open the raster store based in GDAL |
|
50 |
params = dalManager.createStoreParameters("Gdal Store") |
|
51 |
params.setFile(rasterfile) |
|
52 |
|
|
53 |
# Create the raster store |
|
54 |
dataStore = dalManager.createStore(params) |
|
55 |
|
|
56 |
# Create a raster layer based in this raster store |
|
57 |
layer = mapContextManager.createLayer(name, dataStore); |
|
58 |
|
|
59 |
view.addLayer(layer) |
|
60 |
return layer |
|
61 |
|
|
62 |
|
|
63 |
## @cond FALSE |
|
64 |
rasterLayerExtensions = dict () |
|
65 |
|
|
66 |
|
|
67 |
class RasterLayerExtensions(object): |
|
68 |
##This class hold aditional properties and operations need to manage the scripting raster layer |
|
69 |
def __init__(self, store=None): |
|
70 |
self.store = store |
|
71 |
self.buffer = None |
|
72 |
self.query = None |
|
73 |
self.values = None |
|
74 |
self.kernel = None |
|
75 |
self.setElem = None |
|
76 |
self.getElem = None |
|
77 |
|
|
78 |
def prepareQuery(self): |
|
79 |
## See RasterManager in javadocs for more info |
|
80 |
self.query = RasterLocator.getManager().createQuery(); |
|
81 |
## See RasterQuery in javadocs for more |
|
82 |
self.query.setAllDrawableBands() |
|
83 |
self.query.setAreaOfInterest() |
|
84 |
self.buffer = None |
|
85 |
self.values = None |
|
86 |
self.kernel = None |
|
87 |
|
|
88 |
def loadStore (self,rasterfile, mode = "r" ): |
|
89 |
if not isinstance(rasterfile,File): |
|
90 |
rasterfile = File(rasterfile) |
|
91 |
|
|
92 |
name, ext = splitext(rasterfile.getName()) |
|
93 |
|
|
94 |
dalManager = DALLocator.getDataManager() |
|
95 |
|
|
96 |
if ext.lower() == ".ecw" or ext.lower() == ".jp2" : |
|
97 |
# FIXME |
|
98 |
pass |
|
99 |
elif ext.lower() == ".mrsid": |
|
100 |
# FIXME |
|
101 |
pass |
|
102 |
else: |
|
103 |
# Create the parameters to open the raster store based in GDAL |
|
104 |
params = dalManager.createStoreParameters("Gdal Store") |
|
105 |
params.setFile(rasterfile) |
|
106 |
|
|
107 |
# Create the raster store |
|
108 |
dataStore = dalManager.createStore(params) |
|
109 |
return dataStore |
|
110 |
|
|
111 |
def createBuffer(self): |
|
112 |
if sourceFileName[0] == None: |
|
113 |
self.buffer = self.store.query(self.getQuery()) |
|
114 |
else: |
|
115 |
queryStore = self.loadStore(sourceFileName[0]) |
|
116 |
self.buffer = queryStore.query(self.getQuery()) |
|
117 |
#print self.buffer.getBandCount() |
|
118 |
|
|
119 |
def createNewBuffer(self,width, height, bandcount, datatype): |
|
120 |
if self.store != None: |
|
121 |
raise RuntimeException("Can't create a new buffer associated to a store") |
|
122 |
|
|
123 |
# FIXME: workaround to work with a jython bug passing byte, short and |
|
124 |
# double values as parameters |
|
125 |
if datatype in (Buffer.TYPE_BYTE, Buffer.TYPE_SHORT, Buffer.TYPE_INT): |
|
126 |
datatype = Buffer.TYPE_INT |
|
127 |
else: |
|
128 |
datatype = Buffer.TYPE_FLOAT |
|
129 |
# End workaround |
|
130 |
|
|
131 |
#print "---->>>>Buffer", datatype, width, height, bandcount |
|
132 |
self.buffer = RasterLocator.getManager().createBuffer( |
|
133 |
int(datatype), |
|
134 |
int(width), |
|
135 |
int(height), |
|
136 |
int(0 if bandcount is None else bandcount), |
|
137 |
True |
|
138 |
) |
|
139 |
self.prepareBuffer(self.buffer) |
|
140 |
|
|
141 |
def prepareBuffer(self, buffer): |
|
142 |
def setElemByte(buffer, line, col, band, data): |
|
143 |
buffer.setElem(line, col, band, Byte(data).byteValue()) |
|
144 |
|
|
145 |
def setElemShort (buffer, line, col, band, data): |
|
146 |
buffer.setElem(line, col, band, Short(data).shortValue()) |
|
147 |
|
|
148 |
def setElemInt(buffer, line, col, band, data): |
|
149 |
buffer.setElem(line, col, band, Integer(data).intValue()) |
|
150 |
|
|
151 |
def setElemFloat(buffer, line, col, band, data): |
|
152 |
buffer.setElem(line, col, band, Float(data).floatValue()) |
|
153 |
|
|
154 |
def setElemDouble(buffer, line, col, band, data): |
|
155 |
buffer.setElem(line, col, band, Double(data).doubleValue()) |
|
156 |
|
|
157 |
t = buffer.getDataType() |
|
158 |
if t == Buffer.TYPE_BYTE: |
|
159 |
self.getElem = buffer.getElemByte |
|
160 |
self.setElem = setElemByte |
|
161 |
elif t == Buffer.TYPE_SHORT or t == Buffer.TYPE_USHORT: |
|
162 |
self.getElem = buffer.getElemShort |
|
163 |
self.setElem = setElemShort |
|
164 |
elif t == Buffer.TYPE_INT: |
|
165 |
self.getElem = buffer.getElemInt |
|
166 |
self.setElem = setElemInt |
|
167 |
elif t == Buffer.TYPE_FLOAT: |
|
168 |
self.getElem = buffer.getElemFloat |
|
169 |
self.setElem = setElemFloat |
|
170 |
elif t == Buffer.TYPE_DOUBLE: |
|
171 |
self.getElem = buffer.getElemDouble |
|
172 |
self.setElem = setElemDouble |
|
173 |
#print buffer.getBandCount() |
|
174 |
self.values = [0 for count in range(buffer.getBandCount())] |
|
175 |
self.kernel = [[self.values for count in range(3)] for count in range(3)] |
|
176 |
|
|
177 |
def getQuery(self): |
|
178 |
if self.query == None: |
|
179 |
self.prepareQuery() |
|
180 |
return self.query |
|
181 |
|
|
182 |
def getBuffer(self, store): |
|
183 |
if self.buffer == None: |
|
184 |
self.createBuffer() |
|
185 |
self.prepareBuffer(self.buffer) |
|
186 |
return self.buffer |
|
187 |
|
|
188 |
def setValue(self, band, line, col, data): |
|
189 |
t = self.buffer.getDataType() |
|
190 |
if t == Buffer.TYPE_BYTE: |
|
191 |
self.buffer.setElem(line, col, band, Byte(data).byteValue()) |
|
192 |
elif t == Buffer.TYPE_SHORT or t == Buffer.TYPE_USHORT: |
|
193 |
self.buffer.setElem(line, col, band, Short(data).shortValue()) |
|
194 |
elif t == Buffer.TYPE_INT: |
|
195 |
self.buffer.setElem(line, col, band, Integer(data).intValue()) |
|
196 |
elif t == Buffer.TYPE_FLOAT: |
|
197 |
self.buffer.setElem(line, col, band, Float(data).floatValue()) |
|
198 |
elif t == Buffer.TYPE_DOUBLE: |
|
199 |
self.buffer.setElem(line, col, band, Double(data).doubleValue()) |
|
200 |
|
|
201 |
def getValue(self, band, row, column): |
|
202 |
if self.getElem == None: |
|
203 |
self.createBuffer() |
|
204 |
self.prepareBuffer(self.buffer) |
|
205 |
return self.getElem(row, column, band) |
|
206 |
|
|
207 |
def getBandValues(self, row, column): |
|
208 |
if self.getElem == None: |
|
209 |
self.createBuffer() |
|
210 |
self.prepareBuffer(self.buffer) |
|
211 |
for b in xrange(self.buffer.getBandCount()): |
|
212 |
self.values[b] = self.getElem(row, column, b) |
|
213 |
return self.values |
|
214 |
|
|
215 |
def setBandValues(self,row,column,values): |
|
216 |
for b in xrange(self.buffer.getBandCount()): |
|
217 |
self.setElem(self.buffer, row, column, b, values[b]) |
|
218 |
|
|
219 |
def saveBuffer(self,filename): |
|
220 |
manager = DALLocator.getDataManager () |
|
221 |
eparams = manager.createServerExplorerParameters(FilesystemServerExplorer.NAME) |
|
222 |
eparams.setDynValue("initialpath",os.path.dirname(sourceFileName[0])) |
|
223 |
serverExplorer = manager.openServerExplorer(eparams.getExplorerName(),eparams) |
|
224 |
|
|
225 |
sparams = serverExplorer.getAddParameters("Gdal Store") |
|
226 |
sparams.setDestination(os.path.dirname(sourceFileName[0]),filename) |
|
227 |
sparams.setBuffer(self.buffer) |
|
228 |
#at = AffineTransform(1, 0, 0, -1, 0, 0) |
|
229 |
#sparams.setAffineTransform(at); |
|
230 |
|
|
231 |
serverExplorer.add("Gdal Store", sparams, True) |
|
232 |
|
|
233 |
## @endcond |
|
234 |
|
|
235 |
## |
|
236 |
# |
|
237 |
# Represents a raster layer. |
|
238 |
# |
|
239 |
class RasterLayer(FLyrRaster): |
|
240 |
TYPE_BYTE = Buffer.TYPE_BYTE |
|
241 |
TYPE_SHORT = Buffer.TYPE_SHORT |
|
242 |
TYPE_INT = Buffer.TYPE_INT |
|
243 |
TYPE_FLOAT = Buffer.TYPE_FLOAT |
|
244 |
TYPE_DOUBLE = Buffer.TYPE_DOUBLE |
|
245 |
|
|
246 |
@staticmethod |
|
247 |
## @cond FALSE |
|
248 |
def getExtensions(self): |
|
249 |
## This is a internal method, don't use it. |
|
250 |
|
|
251 |
global rasterLayerExtensions |
|
252 |
extensions = rasterLayerExtensions.get(self.hashCode(), None) |
|
253 |
if extensions == None: |
|
254 |
extensions = RasterLayerExtensions(self.getDataStore()) |
|
255 |
rasterLayerExtensions[self.hashCode()] = extensions |
|
256 |
return extensions |
|
257 |
## @endcond |
|
258 |
|
|
259 |
@staticmethod |
|
260 |
## |
|
261 |
# |
|
262 |
# Return the number of bands of the raster |
|
263 |
# |
|
264 |
# @param self The raster layer object |
|
265 |
# |
|
266 |
# @return the number of bands of the raster layer |
|
267 |
# |
|
268 |
def getBandsCount(self): |
|
269 |
return self.getDataStore().getBandCount() |
|
270 |
|
|
271 |
@staticmethod |
|
272 |
## |
|
273 |
# |
|
274 |
# Return the width in points/pixels of the raster |
|
275 |
# |
|
276 |
# @param self The raster layer object |
|
277 |
# |
|
278 |
# @return the width of the raster |
|
279 |
# |
|
280 |
def getWidth(self): |
|
281 |
return self.getDataStore().getWidth() |
|
282 |
|
|
283 |
@staticmethod |
|
284 |
## |
|
285 |
# |
|
286 |
# Return the height in points/pixels of the raster |
|
287 |
# |
|
288 |
# @param self The raster layer object |
|
289 |
# |
|
290 |
# @return the height of the raster |
|
291 |
def getHeight(self): |
|
292 |
return self.getDataStore().getHeight() |
|
293 |
|
|
294 |
@staticmethod |
|
295 |
## |
|
296 |
# |
|
297 |
# Return the data type of the raster |
|
298 |
# |
|
299 |
# TYPE_BYTE = Byte datatype |
|
300 |
# |
|
301 |
# TYPE_USHORT = Unsigned Short datatype |
|
302 |
# |
|
303 |
# TYPE_SHORT = Signed Short datatype |
|
304 |
# |
|
305 |
# TYPE_INT = Integer datatype |
|
306 |
# |
|
307 |
# TYPE_FLOAT = Float Datatype |
|
308 |
# |
|
309 |
# TYPE_DOUBLE = Double Datatype |
|
310 |
# |
|
311 |
# @param self The raster layer object |
|
312 |
# |
|
313 |
# @return the datatype of the raster layer |
|
314 |
def getDataType(self): |
|
315 |
return self.getDataStore().getDataType() |
|
316 |
|
|
317 |
@staticmethod |
|
318 |
## |
|
319 |
# |
|
320 |
# Return the value of a point of a "band" from "row" and "coulmn" of |
|
321 |
# the Raster. |
|
322 |
# |
|
323 |
# This method use with care, it has a strong overhead. Use instead |
|
324 |
# the method "walk" to go over the raster. |
|
325 |
# |
|
326 |
# @param band band from which the value should be retrieved |
|
327 |
# @param row row in the raster from which the value should be retrieved |
|
328 |
# @param column column in the raster from which the value should be retrieved |
|
329 |
# |
|
330 |
# @return the value of a point/pixel of a "band" from "row" and "column" of the Raster |
|
331 |
# |
|
332 |
def getData(self, band, row, column): |
|
333 |
return self.getExtensions().getValue(band, row, column) |
|
334 |
|
|
335 |
@staticmethod |
|
336 |
## |
|
337 |
# |
|
338 |
# Go over the raster and for each point call to the function |
|
339 |
# "operation" and pass as argument a tuple with the values of |
|
340 |
# the point for each band. |
|
341 |
# |
|
342 |
# This method don't return any value |
|
343 |
# |
|
344 |
# @param self pointer to the Layer object |
|
345 |
# @param operation any operation which operates on the raster point-by-point |
|
346 |
# |
|
347 |
# @return None |
|
348 |
# |
|
349 |
def walk(self, operation): |
|
350 |
extension = self.getExtensions() |
|
351 |
store = self.getDataStore() |
|
352 |
sourceExtension = RasterLayerExtensions() |
|
353 |
sourceExtension.createNewBuffer(store.getWidth(), store.getHeight(), store.getBandCount(), store.getDataType()) |
|
354 |
|
|
355 |
for band in xrange(store.getBandCount()): |
|
356 |
for line in xrange(store.getHeight()): |
|
357 |
for column in xrange(store.getWidth()): |
|
358 |
operation(extension.getBandValues(line, column)) |
|
359 |
|
|
360 |
|
|
361 |
@staticmethod |
|
362 |
## |
|
363 |
# |
|
364 |
# Go over the raster and for each point, taking the neighbour points |
|
365 |
# as a kernel(3x3) call to the function "operation" and pass as argument a |
|
366 |
# tuple with the values of all the points in the kernel for each band. |
|
367 |
# |
|
368 |
# This method don't return any value |
|
369 |
# |
|
370 |
# @param self pointer to the Layer object |
|
371 |
# @param operation any operation which operates on the raster by a kernel(3x3). |
|
372 |
# |
|
373 |
# @return None |
|
374 |
# |
|
375 |
def walkKernel(self, operation): |
|
376 |
extension = self.getExtensions() |
|
377 |
store = self.getDataStore() |
|
378 |
sourceExtension = RasterLayerExtensions() |
|
379 |
sourceExtension.createNewBuffer(store.getWidth(), store.getHeight(), store.getBandCount(), store.getDataType()) |
|
380 |
|
|
381 |
k=0 |
|
382 |
l=0 |
|
383 |
values = [0 for count in xrange(store.getBandCount())] |
|
384 |
values = [[values for count in xrange(3)] for count in xrange(3)] |
|
385 |
outValues = list() |
|
386 |
for band in xrange(store.getBandCount()): |
|
387 |
for line in xrange(1,store.getHeight()-1): |
|
388 |
for column in xrange(1,store.getWidth()-1): |
|
389 |
|
|
390 |
i=0 |
|
391 |
for k in xrange(line-1,line+2): |
|
392 |
j=0 |
|
393 |
for l in xrange(column-1,column+2): |
|
394 |
values[i][j]=extension.getBandValues(k,l) |
|
395 |
j=j+1 |
|
396 |
i=i+1 |
|
397 |
operation(values) |
|
398 |
|
|
399 |
|
|
400 |
@staticmethod |
|
401 |
## |
|
402 |
# |
|
403 |
# Go over the raster and for each point call to the function "filter1" |
|
404 |
# and pass as argument a tuple with the values of all the points in the |
|
405 |
# kernel for each band. |
|
406 |
# |
|
407 |
# The function "filter1" must be such that it takes a tuple, modifies its value |
|
408 |
# and returns a new tuple. |
|
409 |
# |
|
410 |
# This method saves the newly created(filter applied) layer to "targetfilename" |
|
411 |
# |
|
412 |
# @param self pointer to the Layer object |
|
413 |
# @param filter1 any filter which modifies the raster layer point-by-point |
|
414 |
# @param targetfilename filename to which the output layer should be saved |
|
415 |
# @param targetdatatype datatype of which the output layer to be saved (use only TYPE_INT,TYPE_BYTE or TYPE_SHORT as of now) |
|
416 |
# @param targetbandcount number of bands in the output layer |
|
417 |
# |
|
418 |
# @return saves the created layer to "targetfilename" in the current directory |
|
419 |
# |
|
420 |
def filter(self, filter1, targetfilename, targetdatatype=None, targetbandcount=None): |
|
421 |
extension = self.getExtensions() |
|
422 |
store = self.getDataStore() |
|
423 |
targetExtension = RasterLayerExtensions() |
|
424 |
#targetExtension.createNewBuffer(store.getWidth(), store.getHeight(), store.getBandCount(), store.getDataType()) |
|
425 |
targetExtension.createNewBuffer(store.getWidth(), store.getHeight(), targetbandcount, targetdatatype) |
|
426 |
|
|
427 |
for band in xrange(store.getBandCount()): |
|
428 |
for line in xrange(store.getHeight()): |
|
429 |
for column in xrange(store.getWidth()): |
|
430 |
values = filter1(extension.getBandValues(line,column)) |
|
431 |
targetExtension.setBandValues(line, column, values) |
|
432 |
|
|
433 |
targetExtension.saveBuffer(targetfilename) |
|
434 |
|
|
435 |
@staticmethod |
|
436 |
## |
|
437 |
# |
|
438 |
# Go over the raster and for each point, taking the neighbour points |
|
439 |
# as a kernel(3x3) call to the function "filter1" and pass as argument |
|
440 |
# a tuple with the values of all the points in the kernel for each band. |
|
441 |
# |
|
442 |
# The function "filter1" must be such that it takes a tuple of multi-dimension, |
|
443 |
# modifies its value and returns a new tuple having dimensions same as input. |
|
444 |
# |
|
445 |
# This method saves the newly created(filter applied) layer to "targetfilename" |
|
446 |
# |
|
447 |
# @param self pointer to the Layer object |
|
448 |
# @param filter1 any filter which modifies the raster layer using a kernel(3x3). |
|
449 |
# @param targetfilename filename to which the output layer should be saved |
|
450 |
# @param targetdatatype datatype of which the output layer to be saved (use only TYPE_INT,TYPE_BYTE or TYPE_SHORT as of now) |
|
451 |
# @param targetbandcount number of bands in the output layer |
|
452 |
# |
|
453 |
# @return saves the created layer to "targetfilename" in the current directory |
|
454 |
# |
|
455 |
def filterKernel(self, filter1, targetfilename, targetdatatype=None, targetbandcount=None): |
|
456 |
extension = self.getExtensions() |
|
457 |
store = self.getDataStore() |
|
458 |
targetExtension = RasterLayerExtensions() |
|
459 |
#targetExtension.createNewBuffer(store.getWidth(), store.getHeight(), store.getBandCount(), store.getDataType()) |
|
460 |
targetExtension.createNewBuffer(store.getWidth(), store.getHeight(), targetbandcount, targetdatatype) |
|
461 |
|
|
462 |
k=0 |
|
463 |
l=0 |
|
464 |
values = [0 for count in xrange(store.getBandCount())] |
|
465 |
values = [[values for count in xrange(3)] for count in xrange(3)] |
|
466 |
outValues = list() |
|
467 |
for band in xrange(store.getBandCount()): |
|
468 |
for line in xrange(1,store.getHeight()-1): |
|
469 |
for column in xrange(1,store.getWidth()-1): |
|
470 |
|
|
471 |
i=0 |
|
472 |
for k in xrange(line-1,line+2): |
|
473 |
j=0 |
|
474 |
for l in xrange(column-1,column+2): |
|
475 |
values[i][j]=extension.getBandValues(k,l) |
|
476 |
j=j+1 |
|
477 |
i=i+1 |
|
478 |
outValues = filter1(values) |
|
479 |
targetExtension.setBandValues(line, column, outValues) |
|
480 |
|
|
481 |
targetExtension.saveBuffer(targetfilename) |
|
482 |
|
|
483 |
@staticmethod |
|
484 |
## |
|
485 |
# |
|
486 |
# Go over the raster layer and for each point call to the function "operation" and |
|
487 |
# pass as arguments two tuples (One corresponding to the first layer at that point, |
|
488 |
# the other corresponding to the second layer at the same point) with the values of |
|
489 |
# each point for each band. |
|
490 |
# |
|
491 |
# The function "operation" must be such that it takes two tuples as input, performs |
|
492 |
# operations involving both of them and returns a new tuple. |
|
493 |
# |
|
494 |
# This method saves the newly created(from the two rasters) layer to "targetfilename" |
|
495 |
# |
|
496 |
# @param self pointer to the Layer object |
|
497 |
# @param operation any operation which operates on both the raster layers at a respective point/pixel. |
|
498 |
# @param layer2 the layer which forms the second input to the "operation" function. |
|
499 |
# @param targetfilename filename to which the output layer should be saved |
|
500 |
# @param targetdatatype datatype of which the output layer to be saved (use only TYPE_INT,TYPE_BYTE or TYPE_SHORT as of now) |
|
501 |
# |
|
502 |
# @return saves the created layer to "targetfilename" in the current directory |
|
503 |
# |
|
504 |
def operation(self, operation, layer2, targetfilename, targetdatatype=None): |
|
505 |
layer1Extension = self.getExtensions() |
|
506 |
layer2Extension = layer2.getExtensions() |
|
507 |
|
|
508 |
layer1Store = self.getDataStore() |
|
509 |
layer2Store = layer2.getDataStore() |
|
510 |
|
|
511 |
bandCount = layer1Store.getBandCount() |
|
512 |
layerWidth = layer1Store.getWidth() |
|
513 |
layerHeight = layer1Store.getHeight() |
|
514 |
targetExtension = RasterLayerExtensions() |
|
515 |
resultValues = list() |
|
516 |
#targetExtension.createNewBuffer(layerWidth, layerHeight, bandCount, layer1Store.getDataType()) |
|
517 |
targetExtension.createNewBuffer(layerWidth, layerHeight, bandCount, targetdatatype) |
|
518 |
|
|
519 |
for band in xrange(bandCount): |
|
520 |
for line in xrange(layerHeight): |
|
521 |
for column in xrange(layerWidth): |
|
522 |
layer1Values = layer1Extension.getBandValues(line, column) |
|
523 |
layer2Values = layer2Extension.getBandValues(line, column) |
|
524 |
resultValues = operation(layer1Values, layer2Values) |
|
525 |
targetExtension.setBandValues(line, column, resultValues) |
|
526 |
|
|
527 |
targetExtension.saveBuffer(targetfilename) |
|
528 |
|
|
529 |
@staticmethod |
|
530 |
## |
|
531 |
# |
|
532 |
# Go over the raster layer and for each point, taking the neighbour points as a |
|
533 |
# kernel(3x3) call to the function "operation" and pass as arguments two tuples |
|
534 |
# (One corresponding to the first layer at that point, the other corresponding |
|
535 |
# to the second layer at the same point) with the values of all the points of the |
|
536 |
# kernel for each band. |
|
537 |
# |
|
538 |
# The function "operation" must be such that it takes two tuples of multiple |
|
539 |
# dimensions as input, performs operations involving both of them and returns a |
|
540 |
# new tuple having dimensions same as input tuples. |
|
541 |
# |
|
542 |
# This method saves the newly created(from the two rasters) layer to "targetfilename" |
|
543 |
# |
|
544 |
# @param self pointer to the Layer object |
|
545 |
# @param operation any operation which operates on both the raster layers at a respective point/pixel but involving kernel(3x3)[neighbour points]. |
|
546 |
# @param layer2 the layer which forms the second input to the "operation" function. |
|
547 |
# @param targetfilename filename to which the output layer should be saved |
|
548 |
# @param targetdatatype datatype of which the output layer to be saved (use only TYPE_INT,TYPE_BYTE or TYPE_SHORT as of now) |
|
549 |
# |
|
550 |
# @return saves the created layer to "targetfilename" in the current directory |
|
551 |
# |
|
552 |
def operationKernel(self, operation, layer2, targetfilename, targetdatatype=None): |
|
553 |
layer1Extension = self.getExtensions() |
|
554 |
layer2Extension = self.getExtensions() |
|
555 |
|
|
556 |
layer1Store = self.getDataStore() |
|
557 |
layer2Store = layer2.getDataStore() |
|
558 |
|
|
559 |
bandCount = layer1Store.getBandCount() |
|
560 |
layerWidth = layer1Store.getWidth() |
|
561 |
layerHeight = layer1Store.getHeight() |
|
562 |
targetExtension = RasterLayerExtensions() |
|
563 |
#targetExtension.createNewBuffer(layerWidth, layerHeight, bandCount, layer1Store.getDataType())targetExtension.createNewBuffer(layerWidth, layerHeight, bandCount, layer1Store.getDataType()) |
|
564 |
targetExtension.createNewBuffer(layerWidth, layerHeight, bandCount, targetdatatype) |
|
565 |
|
|
566 |
k=0 |
|
567 |
l=0 |
|
568 |
values1 = [[[None for count in range(bandCount)] for count in range(3)] for count in range(3)] |
|
569 |
values2 = [[[None for count in range(bandCount)] for count in range(3)] for count in range(3)] |
|
570 |
outValues = list() |
|
571 |
for band in xrange(bandCount): |
|
572 |
for line in xrange(1,layerHeight-1): |
|
573 |
for column in xrange(1,layerWidth-1): |
|
574 |
|
|
575 |
i=0 |
|
576 |
for k in xrange(line-1,line+2): |
|
577 |
j=0 |
|
578 |
for l in xrange(column-1,column+2): |
|
579 |
values1[i][j]=layer1Extension.getBandValues(k,l) |
|
580 |
#print i,j,values1[i][j] |
|
581 |
#print values1 |
|
582 |
values2[i][j]=layer2Extension.getBandValues(k,l) |
|
583 |
j=j+1 |
|
584 |
i=i+1 |
|
585 |
|
|
586 |
outValues = operation(values1, values2) |
|
587 |
i=0 |
|
588 |
for k in xrange(line-1,line+2): |
|
589 |
j=0 |
|
590 |
for l in xrange(column-1,column+2): |
|
591 |
targetExtension.setBandValues(k,l, outValues[i][j]) |
|
592 |
j=j+1 |
|
593 |
i=i+1 |
|
594 |
|
|
595 |
targetExtension.saveBuffer(targetfilename) |
|
596 |
|
|
597 |
|
|
598 |
# |
|
599 |
# Inject new methods in the class FLyrRaster |
|
600 |
# |
|
601 |
FLyrRaster.getExtensions = RasterLayer.getExtensions |
|
602 |
FLyrRaster.getBandsCount = RasterLayer.getBandsCount |
|
603 |
FLyrRaster.getWidth = RasterLayer.getWidth |
|
604 |
FLyrRaster.getHeight = RasterLayer.getHeight |
|
605 |
FLyrRaster.getDataType = RasterLayer.getDataType |
|
606 |
FLyrRaster.getData = RasterLayer.getData |
|
607 |
FLyrRaster.walk = RasterLayer.walk |
|
608 |
FLyrRaster.walkKernel = RasterLayer.walkKernel |
|
609 |
FLyrRaster.filter = RasterLayer.filter |
|
610 |
FLyrRaster.filterKernel = RasterLayer.filterKernel |
|
611 |
FLyrRaster.operation = RasterLayer.operation |
|
612 |
FLyrRaster.operationKernel = RasterLayer.operationKernel |
org.gvsig.raster/tags/org.gvsig.raster-2.2.86/org.gvsig.raster.app/org.gvsig.raster.app.common/src/main/resources-plugin/config.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<plugin-config> |
|
3 |
<depends plugin-name="org.gvsig.app" /> |
|
4 |
<depends plugin-name="org.gvsig.app.document.table.app.mainplugin" /> |
|
5 |
<resourceBundle name="text"/> |
|
6 |
<libraries library-dir="lib"/> |
|
7 |
<extensions> |
|
8 |
<extension class-name="org.gvsig.raster.mainplugin.RasterMainPluginExtension" |
|
9 |
description="" |
|
10 |
active="true" |
|
11 |
priority="1"> |
|
12 |
</extension> |
|
13 |
<extension class-name="org.gvsig.raster.mainplugin.GenericToolBarExtension" |
|
14 |
description="" |
|
15 |
active="true" |
|
16 |
priority="1"> |
|
17 |
</extension> |
|
18 |
</extensions> |
|
19 |
</plugin-config> |
org.gvsig.raster/tags/org.gvsig.raster-2.2.86/org.gvsig.raster.app/org.gvsig.raster.app.common/src/main/resources-plugin/org/gvsig/raster/mainplugin/i18n/text.properties | ||
---|---|---|
1 |
capa_raster=Capa Raster |
|
2 |
process_raster=Procesos Raster |
|
3 |
multispectral=Multiespectral |
|
4 |
enhanced=Realce |
|
5 |
transformaciones_geograficas=Transformaciones geograficas |
|
6 |
raster_export=Exportar Raster |
|
7 |
dataset_raster=Conjunto de datos raster |
org.gvsig.raster/tags/org.gvsig.raster-2.2.86/org.gvsig.raster.app/org.gvsig.raster.app.common/src/main/resources-plugin/org/gvsig/raster/mainplugin/i18n/text_en.properties | ||
---|---|---|
1 |
capa_raster=Raster layer |
|
2 |
process_raster=Raster process |
|
3 |
multispectral=Multispectral |
|
4 |
enhanced=Enhanced |
|
5 |
transformaciones_geograficas=Geographic transformations |
|
6 |
raster_export=Export to raster |
|
7 |
dataset_raster=Raster dataset |
org.gvsig.raster/tags/org.gvsig.raster-2.2.86/org.gvsig.raster.app/org.gvsig.raster.app.common/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
1 |
<!-- |
|
2 |
|
|
3 |
gvSIG. Desktop Geographic Information System. |
|
4 |
|
|
5 |
Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
20 |
MA 02110-1301, USA. |
|
21 |
|
|
22 |
For any additional information, do not hesitate to contact us |
|
23 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
|
24 |
|
|
25 |
--> |
|
26 |
<assembly> |
|
27 |
<id>gvsig-plugin-package</id> |
|
28 |
<formats> |
|
29 |
<format>zip</format> |
|
30 |
</formats> |
|
31 |
<baseDirectory>${project.artifactId}</baseDirectory> |
|
32 |
<includeBaseDirectory>true</includeBaseDirectory> |
|
33 |
<files> |
|
34 |
<file> |
|
35 |
<source>target/${project.artifactId}-${project.version}.jar</source> |
|
36 |
<outputDirectory>lib</outputDirectory> |
|
37 |
</file> |
|
38 |
<file> |
|
39 |
<source>target/package.info</source> |
|
40 |
</file> |
|
41 |
</files> |
|
42 |
|
|
43 |
<fileSets> |
|
44 |
<fileSet> |
|
45 |
<directory>src/main/resources-plugin</directory> |
|
46 |
<outputDirectory>.</outputDirectory> |
|
47 |
</fileSet> |
|
48 |
</fileSets> |
|
49 |
|
|
50 |
|
|
51 |
<dependencySets> |
|
52 |
<dependencySet> |
|
53 |
<useProjectArtifact>false</useProjectArtifact> |
|
54 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
55 |
<outputDirectory>lib</outputDirectory> |
|
56 |
<includes> |
|
57 |
<include>org.gvsig:org.gvsig.raster.swing.api:jar</include> |
|
58 |
<include>org.gvsig:org.gvsig.raster.swing.impl:jar</include> |
|
59 |
<include>org.gvsig:org.gvsig.raster.cache.lib.api:jar</include> |
|
60 |
<include>org.gvsig:org.gvsig.raster.cache.lib.impl:jar</include> |
|
61 |
<include>org.gvsig:org.gvsig.raster.lib.api:jar</include> |
|
62 |
<include>org.gvsig:org.gvsig.raster.lib.impl:jar</include> |
|
63 |
<include>org.gvsig:org.gvsig.raster.algorithm:jar</include> |
|
64 |
<include>org.gvsig:org.gvsig.raster.fmap:jar</include> |
|
65 |
<!-- <include>org.gvsig:org.gvsig.timesupport.lib.api:jar</include> |
|
66 |
<include>org.gvsig:org.gvsig.timesupport.lib.impl:jar</include>--> |
|
67 |
<include>org.joda:joda-time:jar</include> |
|
68 |
</includes> |
|
69 |
</dependencySet> |
|
70 |
</dependencySets> |
|
71 |
|
|
72 |
</assembly> |
|
73 |
|
|
74 |
|
org.gvsig.raster/tags/org.gvsig.raster-2.2.86/org.gvsig.raster.app/org.gvsig.raster.app.common/src/main/java/org/gvsig/raster/mainplugin/RasterMainPluginExtension.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.mainplugin; |
|
23 |
|
|
24 |
import org.gvsig.andami.IconThemeHelper; |
|
25 |
import org.gvsig.andami.plugins.Extension; |
|
26 |
import org.gvsig.i18n.Messages; |
|
27 |
import org.gvsig.raster.mainplugin.properties.RasterPropertiesTocMenuEntry; |
|
28 |
import org.gvsig.tools.ToolsLocator; |
|
29 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
|
30 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
|
31 |
|
|
32 |
|
|
33 |
/** |
|
34 |
* Main plugin for raster |
|
35 |
* |
|
36 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
37 |
*/ |
|
38 |
public class RasterMainPluginExtension extends Extension { |
|
39 |
|
|
40 |
public void initialize() { |
|
41 |
Messages.addResourceFamily("org.gvsig.raster.mainplugin.i18n.text", |
|
42 |
RasterMainPluginExtension.class.getClassLoader(), |
|
43 |
RasterMainPluginExtension.class.getClass().getName()); |
|
44 |
|
|
45 |
IconThemeHelper.registerIcon(null, "map-ok-ico", this); |
|
46 |
IconThemeHelper.registerIcon("action", "layer-properties-raster", this); |
|
47 |
|
|
48 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
|
49 |
ExtensionPoint point = null; |
|
50 |
|
|
51 |
//Registro punto de extensi?n del cuadro de propiedades |
|
52 |
if (!extensionPoints.has("RasterSEPropertiesDialog")) { |
|
53 |
point = extensionPoints.add("RasterSEPropertiesDialog"); |
|
54 |
point.setDescription("Raster Properties registrable panels (register instances of javax.swing.JPanel)"); |
|
55 |
} |
|
56 |
|
|
57 |
//Entradas del men? del toc de raster |
|
58 |
if (!extensionPoints.has("View_TocActions")) { |
|
59 |
point = extensionPoints.add("View_TocActions"); |
|
60 |
} |
|
61 |
point = extensionPoints.get("View_TocActions"); |
|
62 |
point.append("RasterSEProperties", "Raster Properties", RasterPropertiesTocMenuEntry.getSingleton()); |
|
63 |
|
|
64 |
//A?ade las propiedades de raster a la barra de herramientas. Si nadie registra paneles estar? vacio |
|
65 |
//cuando se abra |
|
66 |
|
|
67 |
point = extensionPoints.add("GenericToolBarMenu"); |
|
68 |
point.append("RasterProperties", "", RasterPropertiesTocMenuEntry.getSingleton()); |
|
69 |
} |
|
70 |
|
|
71 |
public void execute(String actionCommand) { |
|
72 |
|
|
73 |
} |
|
74 |
|
|
75 |
public boolean isEnabled() { |
|
76 |
return false; |
|
77 |
} |
|
78 |
|
|
79 |
public boolean isVisible() { |
|
80 |
return false; |
|
81 |
} |
|
82 |
|
|
83 |
} |
org.gvsig.raster/tags/org.gvsig.raster-2.2.86/org.gvsig.raster.app/org.gvsig.raster.app.common/src/main/java/org/gvsig/raster/mainplugin/toolbar/BinarySearch.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.mainplugin.toolbar; |
|
23 |
|
|
24 |
import java.util.Arrays; |
|
25 |
import java.util.List; |
|
26 |
import java.util.Vector; |
|
27 |
import org.apache.commons.lang3.StringUtils; |
|
28 |
|
|
29 |
import org.gvsig.gui.beans.comboboxconfigurablelookup.ILookUp; |
|
30 |
import org.gvsig.gui.beans.comboboxconfigurablelookup.JComboBoxConfigurableLookUp; |
|
31 |
import org.gvsig.gui.beans.comboboxconfigurablelookup.StringComparator; |
|
32 |
/** |
|
33 |
* Clase para reimplementar una nueva busqueda para el componente |
|
34 |
* {@link JComboBoxConfigurableLookUp} |
|
35 |
* |
|
36 |
* @version 13/02/2008 |
|
37 |
* @author BorSanZa - Borja S?nchez Zamorano |
|
38 |
*/ |
|
39 |
public class BinarySearch implements ILookUp { |
|
40 |
public List<Object> doLookUpConsideringCaseSensitive(String text, Vector<Object> sortOrderedItems, StringComparator comp) { |
|
41 |
Vector<Object> list = new Vector<Object>(); |
|
42 |
for (int i = 0; i < sortOrderedItems.size(); i++) { |
|
43 |
Object cur_o = sortOrderedItems.get(i); |
|
44 |
if( cur_o!=null ) { |
|
45 |
String cur_s = cur_o.toString(); |
|
46 |
if( StringUtils.isEmpty(text) ) { |
|
47 |
list.add(cur_o); |
|
48 |
} else { |
|
49 |
if (cur_s.indexOf(text) != -1) { |
|
50 |
list.add(cur_o); |
|
51 |
} |
|
52 |
} |
|
53 |
} |
|
54 |
} |
|
55 |
return Arrays.asList(list.toArray()); |
|
56 |
} |
|
57 |
|
|
58 |
public List<Object> doLookUpIgnoringCaseSensitive(String text, Vector<Object> sortOrderedItems, StringComparator comp) { |
|
59 |
Vector<Object> list = new Vector<Object>(); |
|
60 |
for (int i = 0; i < sortOrderedItems.size(); i++) { |
|
61 |
Object cur_o = sortOrderedItems.get(i); |
|
62 |
if( cur_o!=null ) { |
|
63 |
String cur_s = cur_o.toString(); |
|
64 |
if( StringUtils.isEmpty(text) ) { |
|
65 |
list.add(cur_o); |
|
66 |
} else { |
|
67 |
if (cur_s.toLowerCase().indexOf(text.toLowerCase()) != -1) { |
|
68 |
list.add(cur_o); |
|
69 |
} |
|
70 |
} |
|
71 |
} |
|
72 |
} |
|
73 |
return Arrays.asList(list.toArray()); |
|
74 |
} |
|
75 |
} |
org.gvsig.raster/tags/org.gvsig.raster-2.2.86/org.gvsig.raster.app/org.gvsig.raster.app.common/src/main/java/org/gvsig/raster/mainplugin/toolbar/IGenericToolBarMenuItem.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.mainplugin.toolbar; |
|
23 |
|
|
24 |
import javax.swing.Icon; |
|
25 |
|
|
26 |
import org.gvsig.app.project.documents.view.toc.ITocItem; |
|
27 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
28 |
|
|
29 |
/** |
|
30 |
* Interfaz que debe implementar quien quiera aparecer en la barra de |
|
31 |
* herramientas gen?rica. |
|
32 |
* |
|
33 |
* @version 06/02/2008 |
|
34 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
|
35 |
*/ |
|
36 |
public interface IGenericToolBarMenuItem { |
|
37 |
/** |
|
38 |
* Devuelve el nombre del grupo al que pertenece el item de menu |
|
39 |
* @return |
|
40 |
*/ |
|
41 |
public String getGroup(); |
|
42 |
|
|
43 |
/** |
|
44 |
* Devuelve el orden en el que aparecer? en el men? |
|
45 |
* @return |
|
46 |
*/ |
|
47 |
public int getOrder(); |
|
48 |
|
|
49 |
/** |
|
50 |
* Devuelve el orden en el que aparecer? en el men? |
|
51 |
* @return |
|
52 |
*/ |
|
53 |
public int getGroupOrder(); |
|
54 |
|
|
55 |
/** |
|
56 |
* Devuelve el texto que se ver? en el men? |
|
57 |
* @return |
|
58 |
*/ |
|
59 |
public String getText(); |
|
60 |
|
|
61 |
/** |
|
62 |
* Devuelve el icono del item del menu |
|
63 |
* @return |
|
64 |
*/ |
|
65 |
public Icon getIcon(); |
|
66 |
|
|
67 |
/** |
|
68 |
* Dice si es visible el item de menu para dicha entrada |
|
69 |
* @param item |
|
70 |
* @param selectedItems |
|
71 |
* @return |
|
72 |
*/ |
|
73 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems); |
|
74 |
|
|
75 |
/** |
|
76 |
* Dice si el item actual esta habilitado |
|
77 |
* @param item |
|
78 |
* @param selectedItems |
|
79 |
* @return |
|
80 |
*/ |
|
81 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems); |
|
82 |
|
|
83 |
/** |
|
84 |
* Metodo que sera invocado cuando el item del menu sea presionado |
|
85 |
* @param item |
|
86 |
* @param selectedItems |
|
87 |
*/ |
|
88 |
public void execute(ITocItem item, FLayer[] selectedItems); |
|
89 |
} |
org.gvsig.raster/tags/org.gvsig.raster-2.2.86/org.gvsig.raster.app/org.gvsig.raster.app.common/src/main/java/org/gvsig/raster/mainplugin/toolbar/ButtonItems.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.mainplugin.toolbar; |
|
23 |
|
|
24 |
import java.util.ArrayList; |
|
25 |
import java.util.List; |
|
26 |
|
|
27 |
import javax.swing.JButton; |
|
28 |
|
|
29 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
30 |
import org.gvsig.gui.beans.controls.combobutton.ComboButton; |
|
31 |
/** |
|
32 |
* Clase para gestionar y ordenar los items de un ComboButton |
|
33 |
* |
|
34 |
* @version 13/02/2008 |
|
35 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
|
36 |
*/ |
|
37 |
public class ButtonItems { |
|
38 |
private ComboButton comboButton = null; |
|
39 |
private FLayer[] layers = null; |
|
40 |
private List<IGenericToolBarMenuItem> arrayList = new ArrayList<IGenericToolBarMenuItem>(); |
|
41 |
private List<String> arrayKeys = new ArrayList<String>(); |
|
42 |
|
|
43 |
public ButtonItems(ComboButton comboButton, FLayer[] layers) { |
|
44 |
this.comboButton = comboButton; |
|
45 |
this.layers = layers; |
|
46 |
} |
|
47 |
|
|
48 |
/** |
|
49 |
* A?ade un item al ComboButton |
|
50 |
* @param menuItem |
|
51 |
* @param key |
|
52 |
*/ |
|
53 |
public void addButton(IGenericToolBarMenuItem menuItem, String key) { |
|
54 |
int pos = 0; |
|
55 |
boolean find = false; |
|
56 |
for (int i = 0; i < arrayList.size(); i++) { |
|
57 |
pos = i; |
|
58 |
IGenericToolBarMenuItem aux = (IGenericToolBarMenuItem) arrayList.get(i); |
|
59 |
if (aux.getGroupOrder() > menuItem.getGroupOrder()) { |
|
60 |
find = true; |
|
61 |
break; |
|
62 |
} |
|
63 |
if (aux.getGroupOrder() == menuItem.getGroupOrder()) { |
|
64 |
if (aux.getOrder() > menuItem.getOrder()) { |
|
65 |
find = true; |
|
66 |
break; |
|
67 |
} |
|
68 |
} |
|
69 |
} |
|
70 |
if (!find) |
|
71 |
pos = arrayList.size(); |
|
72 |
arrayList.add(pos, menuItem); |
|
73 |
arrayKeys.add(pos, key); |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* Refresca los items del ComboButton |
|
78 |
*/ |
|
79 |
public void refresh() { |
|
80 |
String actionCommand = comboButton.getActionCommand(); |
|
81 |
comboButton.clearButtons(); |
|
82 |
int group = -1; |
|
83 |
for (int i = 0; i < arrayList.size(); i++) { |
|
84 |
IGenericToolBarMenuItem aux = (IGenericToolBarMenuItem) arrayList.get(i); |
|
85 |
|
|
86 |
if ((group != -1) && (group != aux.getGroupOrder())) |
|
87 |
comboButton.addSeparator(); |
|
88 |
|
|
89 |
JButton button2 = new JButton(aux.getText(), aux.getIcon()); |
|
90 |
|
|
91 |
if (!aux.isVisible(null, layers)) |
|
92 |
button2.setEnabled(false); |
|
93 |
|
|
94 |
if (!aux.isEnabled(null, layers)) |
|
95 |
button2.setEnabled(false); |
|
96 |
|
|
97 |
button2.setActionCommand((String) arrayKeys.get(i)); |
|
98 |
comboButton.addButton(button2); |
|
99 |
group = aux.getGroupOrder(); |
|
100 |
} |
|
101 |
comboButton.setSelectedItem(actionCommand); |
|
102 |
} |
|
103 |
} |
org.gvsig.raster/tags/org.gvsig.raster-2.2.86/org.gvsig.raster.app/org.gvsig.raster.app.common/src/main/java/org/gvsig/raster/mainplugin/toolbar/GenericToolBarPanel.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.mainplugin.toolbar; |
|
23 |
|
|
24 |
import java.awt.Insets; |
|
25 |
import java.awt.event.ActionEvent; |
|
26 |
import java.awt.event.ActionListener; |
|
27 |
import java.awt.event.ItemEvent; |
|
28 |
import java.awt.event.ItemListener; |
|
29 |
import java.awt.event.MouseEvent; |
|
30 |
import java.awt.event.MouseListener; |
|
31 |
import java.util.ArrayList; |
|
32 |
import java.util.Iterator; |
|
33 |
import java.util.List; |
|
34 |
|
|
35 |
import javax.swing.JButton; |
|
36 |
import javax.swing.JToolBar; |
|
37 |
|
|
38 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
39 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
40 |
import org.gvsig.gui.beans.comboboxconfigurablelookup.DefaultComboBoxConfigurableLookUpModel; |
|
41 |
import org.gvsig.gui.beans.comboboxconfigurablelookup.JComboBoxConfigurableLookUp; |
|
42 |
import org.gvsig.gui.beans.controls.IControl; |
|
43 |
import org.gvsig.gui.beans.controls.combobutton.ComboButton; |
|
44 |
import org.gvsig.gui.beans.controls.combobutton.ComboButtonEvent; |
|
45 |
import org.gvsig.gui.beans.controls.combobutton.ComboButtonListener; |
|
46 |
import org.gvsig.tools.ToolsLocator; |
|
47 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
|
48 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
|
49 |
/** |
|
50 |
* Componente que contiene los objetos visuales de la barra de herramientas |
|
51 |
* generica |
|
52 |
* |
|
53 |
* @author BorSanZa - Borja S?nchez Zamorano |
|
54 |
*/ |
|
55 |
public class GenericToolBarPanel extends JToolBar implements ComboButtonListener, ActionListener, MouseListener, ItemListener, IControl { |
|
56 |
private static final long serialVersionUID = -4382962282970490523L; |
|
57 |
private JComboBoxConfigurableLookUp jCBCLU = null; |
|
58 |
private ComboButton buttonGroup = new ComboButton(); |
|
59 |
private ComboButton buttonMenu = new ComboButton(); |
|
60 |
private FLayers lastLayers = null; |
|
61 |
|
|
62 |
public GenericToolBarPanel() { |
|
63 |
super("GenericToolBarPanel"); |
|
64 |
initialize(); |
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* Especifica que las capas de la vista han cambiado. |
|
69 |
* @param layers |
|
70 |
*/ |
|
71 |
public void setLayers(FLayers layers) { |
|
72 |
lastLayers = layers; |
|
73 |
|
|
74 |
getComboBoxConfigurableLookUp().setBlockPopupHided(true); |
|
75 |
getComboBoxConfigurableLookUp().removeAllItems(); |
|
76 |
|
|
77 |
if(layers != null) { |
|
78 |
List<FLayer> lyrs = getLayerList(layers, null); |
|
79 |
for (int i = 0; i < lyrs.size(); i++) |
|
80 |
getComboBoxConfigurableLookUp().addItem(((FLayer)lyrs.get(i)).getName()); |
|
81 |
|
|
82 |
if (layers.getActives().length > 0) |
|
83 |
getComboBoxConfigurableLookUp().setSelectedItem(layers.getActives()[0].getName()); |
|
84 |
else if (layers.getLayersCount() > 0) |
|
85 |
getComboBoxConfigurableLookUp().setSelectedItem(layers.getLayer(0).getName()); |
|
86 |
} |
|
87 |
reloadSubMenu(); |
|
88 |
getComboBoxConfigurableLookUp().setBlockPopupHided(false); |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* Devuelve un combo de busqueda de items. |
|
93 |
* @return |
|
94 |
*/ |
|
95 |
private JComboBoxConfigurableLookUp getComboBoxConfigurableLookUp() { |
|
96 |
if (jCBCLU == null) { |
|
97 |
jCBCLU = new JComboBoxConfigurableLookUp(); |
|
98 |
jCBCLU.setOnlyOneColorOnText(true); |
|
99 |
jCBCLU.setPrototypeDisplayValue(" "); |
|
100 |
if (jCBCLU.getModel() instanceof DefaultComboBoxConfigurableLookUpModel) { |
|
101 |
((DefaultComboBoxConfigurableLookUpModel) jCBCLU.getModel()).setShowAllItemsInListBox(false); |
|
102 |
((DefaultComboBoxConfigurableLookUpModel) jCBCLU.getModel()).setLookUpAgent(new BinarySearch()); |
|
103 |
((DefaultComboBoxConfigurableLookUpModel) jCBCLU.getModel()).setCaseSensitive(false); |
|
104 |
jCBCLU.setToForceSelectAnItem(true); |
|
105 |
jCBCLU.setDisplayAllItemsWithArrowButton(true); |
|
106 |
} |
|
107 |
jCBCLU.addActionListener(this); |
|
108 |
} |
|
109 |
return jCBCLU; |
|
110 |
} |
|
111 |
|
|
112 |
private void initialize() { |
|
113 |
buttonGroup.addComboButtonClickedListener(this); |
|
114 |
buttonGroup.setName("Menu principal"); |
|
115 |
buttonGroup.setMargin(new Insets(0, 0, 0, 0)); |
|
116 |
buttonGroup.setAlwaysMenuOnClick(true); |
|
117 |
reloadMenuGroup(); |
|
118 |
add(buttonGroup); |
|
119 |
|
|
120 |
buttonMenu.addComboButtonClickedListener(this); |
|
121 |
buttonMenu.setName("Submenus"); |
|
122 |
buttonMenu.addMouseListener(this); |
|
123 |
buttonMenu.setMargin(new Insets(0, 0, 0, 0)); |
|
124 |
reloadMenuGroup(); |
|
125 |
add(buttonMenu); |
|
126 |
|
|
127 |
add(getComboBoxConfigurableLookUp()); |
|
128 |
this.setRollover(true); |
|
129 |
} |
|
130 |
|
|
131 |
/** |
|
132 |
* Recarga los items del menu global dejando seleccionado el item que habia |
|
133 |
* previamente, en caso de que exista |
|
134 |
*/ |
|
135 |
public void reloadMenuGroup() { |
|
136 |
FLayer[] layers = new FLayer[] { getLayerSelected() }; |
|
137 |
ButtonItems buttonItems = new ButtonItems(buttonGroup, layers); |
|
138 |
|
|
139 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
|
140 |
ExtensionPoint point = extensionPoints.get("GenericToolBarGroup"); |
|
141 |
Iterator<?> iterator = point.iterator(); |
|
142 |
while (iterator.hasNext()) { |
|
143 |
ExtensionPoint.Extension extension = (ExtensionPoint.Extension) iterator.next(); |
|
144 |
Object object; |
|
145 |
try { |
|
146 |
object = extension.create(); |
|
147 |
} catch (Exception e) { |
|
148 |
throw new RuntimeException(e); |
|
149 |
} |
|
150 |
if (object instanceof IGenericToolBarMenuItem) |
|
151 |
buttonItems.addButton((IGenericToolBarMenuItem) object, extension.getName()); |
|
152 |
} |
|
153 |
buttonItems.refresh(); |
|
154 |
reloadSubMenu(); |
|
155 |
} |
|
156 |
|
|
157 |
/** |
|
158 |
* Recarga los items del submenu dejando seleccionado el item que habia |
|
159 |
* previamente, en caso de que exista |
|
160 |
*/ |
|
161 |
public void reloadSubMenu() { |
|
162 |
FLayer[] layers = new FLayer[] { getLayerSelected() }; |
|
163 |
ButtonItems buttonItems = new ButtonItems(buttonMenu, layers); |
|
164 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
|
165 |
ExtensionPoint point = extensionPoints.add("GenericToolBarMenu"); |
|
166 |
Iterator<?> iterator = point.iterator(); |
|
167 |
while (iterator.hasNext()) { |
|
168 |
ExtensionPoint.Extension entry = (ExtensionPoint.Extension) iterator.next(); |
|
169 |
Object object; |
|
170 |
try { |
|
171 |
object = entry.create(); |
|
172 |
} catch (Exception e) { |
|
173 |
throw new RuntimeException(e); |
|
174 |
} |
|
175 |
if (object instanceof IGenericToolBarMenuItem) { |
|
176 |
IGenericToolBarMenuItem item = (IGenericToolBarMenuItem) object; |
|
177 |
if (!buttonGroup.getActionCommand().equals(item.getGroup())) |
|
178 |
continue; |
|
179 |
buttonItems.addButton(item, entry.getName()); |
|
180 |
} |
|
181 |
} |
|
182 |
buttonItems.refresh(); |
|
183 |
} |
|
184 |
|
|
185 |
/** |
|
186 |
* Devuelve el layer seleccionado en el combobox |
|
187 |
* @return |
|
188 |
*/ |
|
189 |
public FLayer getLayerSelected() { |
|
190 |
if (lastLayers == null) |
|
191 |
return null; |
|
192 |
List<FLayer> lyrs = getLayerList(lastLayers, null); |
|
193 |
for (int i = 0; i < lyrs.size(); i++) |
|
194 |
if (((FLayer)lyrs.get(i)).getName().equals(getComboBoxConfigurableLookUp().getEditor().getItem())) |
|
195 |
return (FLayer)lyrs.get(i); |
|
196 |
return null; |
|
197 |
} |
|
198 |
|
|
199 |
public static List<FLayer> getLayerList(FLayers srcLyrs, List<FLayer> destLyrs) { |
|
200 |
if(srcLyrs == null) |
|
201 |
return null; |
|
202 |
if(destLyrs == null) |
|
203 |
destLyrs = new ArrayList<FLayer>(); |
|
204 |
for (int i = 0; i < srcLyrs.getLayersCount(); i++) { |
|
205 |
if(srcLyrs.getLayer(i) instanceof FLayers) |
|
206 |
destLyrs = getLayerList((FLayers)srcLyrs.getLayer(i), destLyrs); |
|
207 |
else |
|
208 |
destLyrs.add(srcLyrs.getLayer(i)); |
|
209 |
} |
|
210 |
return destLyrs; |
|
211 |
} |
|
212 |
|
|
213 |
public void actionPerformed(ActionEvent e) { |
|
214 |
if (e.getSource() == getComboBoxConfigurableLookUp()) { |
|
215 |
// selectLayerInTOC(lastLayers, (String) getComboBoxConfigurableLookUp().getSelectedItem()); |
|
216 |
} |
|
217 |
} |
|
218 |
|
|
219 |
public void actionComboButtonClicked(ComboButtonEvent e) { |
|
220 |
if (e.getSource() == buttonGroup) { |
|
221 |
reloadSubMenu(); |
|
222 |
return; |
|
223 |
} |
|
224 |
if (e.getSource() == buttonMenu) { |
|
225 |
ExtensionPointManager extensionPoints =ToolsLocator.getExtensionPointManager(); |
|
226 |
ExtensionPoint point=extensionPoints.add("GenericToolBarMenu"); |
|
227 |
Iterator<?> iterator = point.iterator(); |
|
228 |
while (iterator.hasNext()) { |
|
229 |
ExtensionPoint.Extension entry = (ExtensionPoint.Extension) iterator |
|
230 |
.next(); |
|
231 |
if (!entry.getName().equals( |
|
232 |
((JButton) e.getSource()).getActionCommand())) |
|
233 |
continue; |
|
234 |
Object object; |
|
235 |
try { |
|
236 |
object = entry.create(); |
|
237 |
} catch (Exception e1) { |
|
238 |
// TODO Auto-generated catch block |
|
239 |
throw new RuntimeException(e1); |
|
240 |
} |
|
241 |
if (object instanceof IGenericToolBarMenuItem) { |
|
242 |
IGenericToolBarMenuItem item = (IGenericToolBarMenuItem) object; |
|
243 |
|
|
244 |
FLayer[] layers = new FLayer[] { getLayerSelected() }; |
|
245 |
if (!item.isVisible(null, layers)) |
|
246 |
continue; |
|
247 |
if (!item.isEnabled(null, layers)) |
|
248 |
continue; |
|
249 |
|
|
250 |
if (getLayerSelected() != null) { |
|
251 |
item.execute(null, new FLayer[] { getLayerSelected() }); |
Also available in: Unified diff