def bbox2geom(bbox, t_srs=None):
#Check bbox
#bbox = numpy.array([-180, 180, 60, 90])
x = [bbox[0], bbox[0], bbox[1], bbox[1], bbox[0]]
y = [bbox[2], bbox[3], bbox[3], bbox[2], bbox[2]]
geom_wkt = 'POLYGON(({0}))'.format(', '.join(['{0} {1}'.format(*a) for a in zip(x,y)]))
geom = ogr.CreateGeometryFromWkt(geom_wkt)
if t_srs is not None and not wgs_srs.IsSame(t_srs):
ct = osr.CoordinateTransformation(t_srs, wgs_srs)
geom.Transform(ct)
geom.AssignSpatialReference(t_srs)
return geom
评论列表
文章目录