458 |
# True -- warp the image to the size of the whole screen |
# True -- warp the image to the size of the whole screen |
459 |
# False -- only use the bound box of the layer (currently inaccurate) |
# False -- only use the bound box of the layer (currently inaccurate) |
460 |
if True: |
if True: |
461 |
|
#if False: |
462 |
pmin = [0,height] |
pmin = [0,height] |
463 |
pmax = [width, 0] |
pmax = [width, 0] |
464 |
else: |
else: |
466 |
bb = [[[bb[0], bb[1]], [bb[2], bb[3]],],] |
bb = [[[bb[0], bb[1]], [bb[2], bb[3]],],] |
467 |
pmin, pmax = self.projected_points(layer, bb)[0] |
pmin, pmax = self.projected_points(layer, bb)[0] |
468 |
|
|
469 |
fmin = [max(0, pmin[0]) - offx, offy - min(height, pmin[1])] |
#print bb |
470 |
fmax = [min(width, pmax[0]) - offx, offy - max(0, pmax[1])] |
#print pmin, pmax |
471 |
|
|
472 |
|
fmin = [max(0, min(pmin[0], pmax[0])) - offx, |
473 |
|
offy - min(height, max(pmin[1], pmax[1]))] |
474 |
|
|
475 |
|
fmax = [min(width, max(pmin[0], pmax[0])) - offx, |
476 |
|
offy - max(0, min(pmin[1], pmax[1]))] |
477 |
|
|
478 |
xmin = fmin[0]/self.scale |
xmin = fmin[0]/self.scale |
479 |
ymin = fmin[1]/self.scale |
ymin = fmin[1]/self.scale |
484 |
height = int(min(height, round(fmax[1] - fmin[1] + 1))) |
height = int(min(height, round(fmax[1] - fmin[1] + 1))) |
485 |
|
|
486 |
try: |
try: |
487 |
data = [width, height, |
project_params = (layer.GetImageFilename(), in_proj, out_proj, |
488 |
ProjectRasterFile(layer.GetImageFilename(), |
(xmin, ymin, xmax, ymax), "", (width, height), |
489 |
in_proj, out_proj, |
layer.UseMask()) |
490 |
(xmin, ymin, xmax, ymax), "", |
|
491 |
(width, height)) |
data = (width, height, apply(ProjectRasterFile, project_params)) |
492 |
] |
|
493 |
except (IOError, AttributeError, ValueError): |
except (IOError, AttributeError, ValueError): |
494 |
# Why does this catch AttributeError and ValueError? |
# Why does this catch AttributeError and ValueError? |
495 |
# FIXME: The exception should be communicated to the user |
# FIXME: The exception should be communicated to the user |
496 |
# better. |
# better. |
497 |
traceback.print_exc() |
traceback.print_exc() |
498 |
else: |
else: |
499 |
mask = "#030104" |
self.draw_raster_data(fmin[0]+offx, offy-fmax[1], data, "RAW") |
|
#mask = None |
|
|
self.draw_raster_data(fmin[0]+offx, offy-fmax[1], data, "RAW", mask) |
|
500 |
data = None |
data = None |
501 |
|
|
502 |
def draw_raster_data(self, x, y, data, format="BMP", mask = None): |
def draw_raster_data(self, x, y, data, format="BMP"): |
503 |
"""Draw the raster image in data onto the DC with the top |
"""Draw the raster image in data onto the DC with the top |
504 |
left corner at (x,y) |
left corner at (x,y) |
505 |
|
|
506 |
The raster image data is a list holding the image width, height, |
The raster image data is a tuple of the form |
507 |
and data in the format indicated by the format parameter. |
(width, height, (image_data, mask_data)) |
508 |
|
|
509 |
|
holding the image width, height, image data, and mask data. |
510 |
|
mask_data may be None if a mask should not be used. Both kinds |
511 |
|
of data are assumed to be in the format specified in format. |
512 |
|
|
513 |
The format parameter is a string with the name of the format. |
The format parameter is a string with the name of the format. |
514 |
The following format names should be used: |
The following format names should be used: |
519 |
|
|
520 |
The default format is 'BMP'. |
The default format is 'BMP'. |
521 |
|
|
|
The mask parameter determines how a mask (if any) is applied |
|
|
to the image. mask can have the following values: |
|
|
|
|
|
o None -- no mask is used |
|
|
o Any object accepted by wxBitmap.SetMaskColour() |
|
|
o A one-bit image the same size as the image data |
|
|
|
|
522 |
This method has to be implemented by derived classes. The |
This method has to be implemented by derived classes. The |
523 |
implementation in the derived class should try to support at |
implementation in the derived class should try to support at |
524 |
least the formats specified above and may support more. |
least the formats specified above and may support more. |