def returnBoundBox(xOff, yOff, pixDim, inputRaster, targetSR='', pixelSpace=False):
# Returns Polygon for a specific square defined by a center Pixel and
# number of pixels in each dimension.
# Leave targetSR as empty string '' or specify it as a osr.SpatialReference()
# targetSR = osr.SpatialReference()
# targetSR.ImportFromEPSG(4326)
if targetSR == '':
targetSR = osr.SpatialReference()
targetSR.ImportFromEPSG(4326)
xCord = [xOff - pixDim / 2, xOff - pixDim / 2, xOff + pixDim / 2,
xOff + pixDim / 2, xOff - pixDim / 2]
yCord = [yOff - pixDim / 2, yOff + pixDim / 2, yOff + pixDim / 2,
yOff - pixDim / 2, yOff - pixDim / 2]
ring = ogr.Geometry(ogr.wkbLinearRing)
for idx in xrange(len(xCord)):
if pixelSpace == False:
geom = pixelToGeoCoord(xCord[idx], yCord[idx], inputRaster)
ring.AddPoint(geom[0], geom[1], 0)
else:
ring.AddPoint(xCord[idx], yCord[idx], 0)
poly = ogr.Geometry(ogr.wkbPolygon)
if pixelSpace == False:
poly.AssignSpatialReference(targetSR)
poly.AddGeometry(ring)
return poly
评论列表
文章目录