def intersection(self,filename):
""" Return coordinates of intersection between this image and another.
:param filename : path to the second image (or another GeoRaster instance)
:type filename: str, georaster.__Raster
:returns: extent of the intersection between the 2 images \
(xmin, xmax, ymin, ymax)
:rtype: tuple
"""
# Create a polygon of the envelope of the first image
xmin, xmax, ymin, ymax = self.extent
wkt = "POLYGON ((%f %f, %f %f, %f %f, %f %f, %f %f))" \
%(xmin,ymin,xmin,ymax,xmax,ymax,xmax,ymin,xmin,ymin)
poly1 = ogr.CreateGeometryFromWkt(wkt)
# Create a polygon of the envelope of the second image
img = SingleBandRaster(filename, load_data=False)
xmin, xmax, ymin, ymax = img.extent
wkt = "POLYGON ((%f %f, %f %f, %f %f, %f %f, %f %f))" \
%(xmin,ymin,xmin,ymax,xmax,ymax,xmax,ymin,xmin,ymin)
poly2 = ogr.CreateGeometryFromWkt(wkt)
# Compute intersection envelope
intersect = poly1.Intersection(poly2)
extent = intersect.GetEnvelope()
# check that intersection is not void
if intersect.GetArea()==0:
print('Warning: Intersection is void')
return 0
else:
return extent
评论列表
文章目录