384 |
the source image is in. |
the source image is in. |
385 |
|
|
386 |
visible -- True is the layer should initially be visible. |
visible -- True is the layer should initially be visible. |
387 |
|
|
388 |
|
Throws IOError if the filename is invalid or points to a file that |
389 |
|
is not in a format GDAL can use. |
390 |
""" |
""" |
391 |
|
|
392 |
BaseLayer.__init__(self, title, visible = visible) |
BaseLayer.__init__(self, title, visible = visible) |
396 |
|
|
397 |
self.bbox = -1 |
self.bbox = -1 |
398 |
|
|
399 |
self.UnsetModified() |
# |
400 |
|
# temporarily open the file so that GDAL can test if it's valid. |
401 |
|
# |
402 |
|
dataset = gdal.Open(self.filename, GA_ReadOnly) |
403 |
|
|
404 |
|
if dataset is None: |
405 |
|
raise IOError() |
406 |
|
|
407 |
|
self.UnsetModified() |
408 |
|
|
409 |
def BoundingBox(self): |
def BoundingBox(self): |
410 |
"""Return the layer's bounding box in the intrinsic coordinate system. |
"""Return the layer's bounding box in the intrinsic coordinate system. |
416 |
if dataset is None: |
if dataset is None: |
417 |
self.bbox = None |
self.bbox = None |
418 |
else: |
else: |
419 |
left, bottom = self.__CalcCorner(dataset, |
geotransform = dataset.GetGeoTransform() |
420 |
0, dataset.RasterYSize) |
if geotransform is None: |
421 |
right, top = self.__CalcCorner(dataset, |
return None |
422 |
dataset.RasterXSize, 0) |
|
423 |
|
x = 0 |
424 |
|
y = dataset.RasterYSize |
425 |
|
left = geotransform[0] + \ |
426 |
|
geotransform[1] * x + \ |
427 |
|
geotransform[2] * y |
428 |
|
|
429 |
|
bottom = geotransform[3] + \ |
430 |
|
geotransform[4] * x + \ |
431 |
|
geotransform[5] * y |
432 |
|
|
433 |
|
x = dataset.RasterXSize |
434 |
|
y = 0 |
435 |
|
right = geotransform[0] + \ |
436 |
|
geotransform[1] * x + \ |
437 |
|
geotransform[2] * y |
438 |
|
|
439 |
|
top = geotransform[3] + \ |
440 |
|
geotransform[4] * x + \ |
441 |
|
geotransform[5] * y |
442 |
|
|
443 |
self.bbox = (left, bottom, right, top) |
self.bbox = (left, bottom, right, top) |
444 |
|
|
445 |
return self.bbox |
return self.bbox |
446 |
|
|
|
def __CalcCorner(self, dataset, x, y): |
|
|
geotransform = dataset.GetGeoTransform() |
|
|
return geotransform[0] + geotransform[1] * x + geotransform[2] * y, \ |
|
|
geotransform[3] + geotransform[4] * x + geotransform[5] * y |
|
|
|
|
447 |
def LatLongBoundingBox(self): |
def LatLongBoundingBox(self): |
448 |
bbox = self.BoundingBox() |
bbox = self.BoundingBox() |
449 |
if bbox is not None: |
if bbox is None: |
|
llx, lly, urx, ury = bbox |
|
|
if self.projection is not None: |
|
|
llx, lly = self.projection.Inverse(llx, lly) |
|
|
urx, ury = self.projection.Inverse(urx, ury) |
|
|
return llx, lly, urx, ury |
|
|
else: |
|
450 |
return None |
return None |
451 |
|
|
452 |
|
llx, lly, urx, ury = bbox |
453 |
|
if self.projection is not None: |
454 |
|
llx, lly = self.projection.Inverse(llx, lly) |
455 |
|
urx, ury = self.projection.Inverse(urx, ury) |
456 |
|
|
457 |
|
return llx, lly, urx, ury |
458 |
|
|
459 |
def GetImageFilename(self): |
def GetImageFilename(self): |
460 |
return self.filename |
return self.filename |
461 |
|
|