当前位置: 首页>>代码示例>>Python>>正文


Python Grid.gdal_save方法代码示例

本文整理汇总了Python中Grid.Grid.gdal_save方法的典型用法代码示例。如果您正苦于以下问题:Python Grid.gdal_save方法的具体用法?Python Grid.gdal_save怎么用?Python Grid.gdal_save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Grid.Grid的用法示例。


在下文中一共展示了Grid.gdal_save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Gridding

# 需要导入模块: from Grid import Grid [as 别名]
# 或者: from Grid.Grid import gdal_save [as 别名]
class Gridding(PointCloud):
    def __init__(self, xyzfiles, bound=None, delimiter=" ", cellsize=(1.0,1.0), nodata=0):
        self.PCL = PointCloud(xyzfiles, delimiter)
        if bound: self.bound = bound
        else:
            if not self.PCL.extent: self.PCL.stats()
            self.bound = self.PCL.extent
        self.cellsize, self.nodata = cellsize, nodata
        self.x0y0 = self.bound[0][0], self.bound[0][1]
        self.xyrange = self.bound[1][0]-self.bound[0][0], self.bound[1][1]-self.bound[0][1]
        self.shape = int(numpy.ceil(self.xyrange[0]/self.cellsize[0])), int(numpy.ceil(self.xyrange[1]/self.cellsize[1]))
        print "Grid shape will be: %d x %d" % self.shape
        self.Density, self.Intensity, self.Gridded = None, None, None

    def __converter__(self, xyz, mode="both"):
        if not(self.__within__(xyz, self.bound)): return None
        x, y = xyz[0]-self.cellsize[0]/2.0, xyz[1]-self.cellsize[1]/2.0 #Shift to grid center
        ix,iy,dx,dy = self.Density.distance(x,y)
        if(dx<self.cellsize[0] and dy<self.cellsize[1]):
            if(mode=="density"): self.Density.Z[iy,ix] = self.Density.Z[iy,ix] + 1
            if(mode=="intensity"): self.Intensity.Z[iy,ix] = self.Intensity.Z[iy,ix] + xyz[2]
            if(mode=="both"):
                self.Density.Z[iy,ix] = self.Density.Z[iy,ix] + 1
                self.Intensity.Z[iy,ix] = self.Intensity.Z[iy,ix] + xyz[2]

    def __within__(self, X, bound=None):
        if not bound: return True
        return all([bool(bound[0][axis]<>None and bound[1][axis]<>None and (bound[0][axis] <= x <= bound[1][axis])) for axis, x in enumerate(X)])

    def density(self):
        print "[Density Grid]",; self.PCL.reset()
        self.Density = Grid(self.shape, self.x0y0, self.cellsize, self.nodata)
        [[self.__converter__(xyz, mode="density") for xyz in XYZ] for XYZ in self.PCL.input.a()]
        return self.Density

    def intensity(self):
        print "[Intensity Grid]",; self.PCL.reset()
        self.Intensity = Grid(self.shape, self.x0y0, self.cellsize, self.nodata)
        [[self.__converter__(xyz, mode="intensity") for xyz in XYZ] for XYZ in self.PCL.input.a()]
        return self.Intensity

    def make_grid(self):
        if not(self.Density): self.PCL.reset(); self.Density = Grid(self.shape, self.x0y0, self.cellsize, self.nodata)
        if not(self.Intensity): self.PCL.reset(); self.Intensity = Grid(self.shape, self.x0y0, self.cellsize, self.nodata)
        [[self.__converter__(xyz, mode="both") for xyz in XYZ] for XYZ in self.PCL.input.a()]
        print "[Grid = Intensity / Density] ...";
        self.Gridded = Grid(self.shape, self.x0y0, self.cellsize, self.nodata)
        self.Gridded.Z = self.Intensity.Z / self.Density.Z
        return self.Gridded

    def save(self, fname="tmp", ascii=False, binary=True):
        if(ascii):
            self.Density.xyz_save(fname+"_density.xyz")
            self.Intensity.xyz_save(fname+"_intensity.xyz")
            self.Gridded.xyz_save(fname+".xyz")
        if(binary):
            self.Density.gdal_save(fname+"_density.tif")
            self.Intensity.gdal_save(fname+"_intensity.tif")
            self.Gridded.gdal_save(fname+".tif")

    def info(self):
        if(self.PCL.extent): print self.PCL.extent
        if(self.Density): self.Density.info()
        if(self.Intensity): self.Intensity.info()
        if(self.Gridded): self.Gridded.info()
开发者ID:geoign,项目名称:xyppy,代码行数:67,代码来源:PointCloud.py


注:本文中的Grid.Grid.gdal_save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。