Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为gdal open构造类_Python_Image_Class_Gdal - Fatal编程技术网

Python 为gdal open构造类

Python 为gdal open构造类,python,image,class,gdal,Python,Image,Class,Gdal,我是python(2.6)的新手,有一个使用gdal打开geotif的简单函数。它返回图像数组和图像大小(x,y) 我想将其转换为类,以获得img、img.x和img.y作为输出。有人能帮我吗 谢谢, Jay这是一个班级,它的名字是IMG class-IMG: def __init__(self,path): if type(path)==str and os.path.isfile(path): self.path=path self.Raster=gd

我是python(2.6)的新手,有一个使用gdal打开geotif的简单函数。它返回图像数组和图像大小(x,y)

我想将其转换为类,以获得img、img.x和img.y作为输出。有人能帮我吗

谢谢,
Jay

这是一个班级,它的名字是IMG

class-IMG:

def __init__(self,path):
    if type(path)==str and os.path.isfile(path):
        self.path=path
        self.Raster=gdal.Open(path)
    elif type(path)==str and not os.path.isfile(path):
        raise IOError

def X(self):
    return self.Raster.RasterXSize

def Y(self):
    return self.Raster.RasterYSize

def RasterArray(self):
    return self.Raster.ReadAsArray()
以及如何使用它

filepath=“路径/光栅名称.tif”

光栅=IMG(文件路径)

xsize=graster.X()

ysize=graster.Y()


array=graster.RasterArray()

太棒了!所以我必须为x、y和图像数组创建单独的函数。谢谢!
def __init__(self,path):
    if type(path)==str and os.path.isfile(path):
        self.path=path
        self.Raster=gdal.Open(path)
    elif type(path)==str and not os.path.isfile(path):
        raise IOError

def X(self):
    return self.Raster.RasterXSize

def Y(self):
    return self.Raster.RasterYSize

def RasterArray(self):
    return self.Raster.ReadAsArray()