Esempio n. 1
0
        def src_load(_button,*args):
            fname=GtkExtra.file_sel_box(title="Select GDAL Dataset")
            if fname is None:
                return
            ds=gdal.OpenShared(fname)
            if ds is None:
                gvutils.error('Not a valid gdal dataset!')
                return

            dict={}
            for i in range(1,ds.RasterCount+1):
                curband=fname + '.band[' + str(i) + ']'
                dict[gtk.GtkListItem(curband)] = (ds,i,curband)
                
            if srctoggle.get_active() == gtk.TRUE:
                slist=vrtutils.GetSimilarFiles(fname)
                for nname in slist:
                    ds = gdal.OpenShared(nname)
                    if ds is None:
                        continue
                    for i in range(1,ds.RasterCount+1):
                        curband=nname + '.band[' + str(i) + ']'
                        dict[gtk.GtkListItem(curband)] = (ds,i,curband)

            self.add_input_bands(dict)    
Esempio n. 2
0
        def src_load(_button, *args):
            fname = GtkExtra.file_sel_box(title="Select GDAL Dataset")
            if fname is None:
                return
            ds = gdal.OpenShared(fname)
            if ds is None:
                gvutils.error('Not a valid gdal dataset!')
                return

            dict = {}
            for i in range(1, ds.RasterCount + 1):
                curband = fname + '.band[' + str(i) + ']'
                dict[gtk.GtkListItem(curband)] = (ds, i, curband)

            if srctoggle.get_active() == gtk.TRUE:
                slist = vrtutils.GetSimilarFiles(fname)
                for nname in slist:
                    ds = gdal.OpenShared(nname)
                    if ds is None:
                        continue
                    for i in range(1, ds.RasterCount + 1):
                        curband = nname + '.band[' + str(i) + ']'
                        dict[gtk.GtkListItem(curband)] = (ds, i, curband)

            self.add_input_bands(dict)
 def getFromFile(self, *args):
     if self.sel_file2:
         try:
             os.popen("rm -f core")  # Delete any core dumps
             os.popen("rm -f core.*")  # Delete any core dumps
             os.chdir(self.extractDirectory(self.sel_file2))
         except:
             pass
     f = GtkExtra.file_sel_box(self.trans_text("Select A File..."))
     if not f: return
     self.sel_file2 = f
     if not f.endswith("/"): self.fromfileentry.set_text(str(f))
Esempio n. 4
0
    def create_cb(self, *args):
        bands = self.input_frame.get_output_bands()
        if len(bands) == 0:
            gvutils.error('No output bands specified!')
            return

        vrtbase = [gdal.CXT_Element, 'VRTDataset']
        vrtbase.append([
            gdal.CXT_Attribute, 'rasterXSize',
            [gdal.CXT_Text, str(bands[0][0].RasterXSize)]
        ])
        vrtbase.append([
            gdal.CXT_Attribute, 'rasterYSize',
            [gdal.CXT_Text, str(bands[0][0].RasterYSize)]
        ])

        # Metadata is currently taken from first output band.
        # This may be updatable later.
        mbase = vrtutils.serializeMetadata(bands[0][0])
        if mbase is not None:
            vrtbase.append(mbase)

        gbase = self.geo_frame.get_geocoding()
        for item in gbase:
            vrtbase.append(item)

        outband = 1
        for item in bands:
            dict = {}
            dict['band'] = outband
            dict['SourceBand'] = item[1]
            dict['ColorInterp'] = 'Undefined'
            bbase = vrtutils.serializeBand(item[0], opt_dict=dict)
            vrtbase.append(bbase)
            outband = outband + 1

        vrtlines = gdal.SerializeXMLTree(vrtbase)

        vrtds = gdal.OpenShared(vrtlines)

        if args[1] == 'Save':
            fname = GtkExtra.file_sel_box(title="Save File")
            if fname is None:
                return
            driver = gdal.GetDriverByName('VRT')
            driver.CreateCopy(fname, vrtds)
        elif args[1] == 'New':
            self.app.new_view()
            self.app.open_gdal_dataset(vrtds)
        else:
            self.app.open_gdal_dataset(vrtds)
Esempio n. 5
0
    def create_cb(self,*args):
        bands = self.input_frame.get_output_bands()
        if len(bands) == 0:
            gvutils.error('No output bands specified!')
            return

        vrtbase = [gdal.CXT_Element,'VRTDataset']
        vrtbase.append([gdal.CXT_Attribute,'rasterXSize',
                     [gdal.CXT_Text,str(bands[0][0].RasterXSize)]])
        vrtbase.append([gdal.CXT_Attribute,'rasterYSize',
                     [gdal.CXT_Text,str(bands[0][0].RasterYSize)]])

        # Metadata is currently taken from first output band.
        # This may be updatable later.
        mbase = vrtutils.serializeMetadata(bands[0][0])
        if mbase is not None:
            vrtbase.append(mbase)
            
        gbase = self.geo_frame.get_geocoding()
        for item in gbase:
            vrtbase.append(item)

        outband = 1
        for item in bands:
            dict={}
            dict['band']=outband
            dict['SourceBand'] = item[1]
            dict['ColorInterp'] = 'Undefined'
            bbase = vrtutils.serializeBand(item[0],opt_dict=dict)
            vrtbase.append(bbase)
            outband=outband+1

        vrtlines = gdal.SerializeXMLTree(vrtbase)
    
        vrtds = gdal.OpenShared(vrtlines)
        
        if args[1] == 'Save':
            fname = GtkExtra.file_sel_box(title="Save File")
            if fname is None:
                return
            driver = gdal.GetDriverByName('VRT')
            driver.CreateCopy(fname,vrtds)
        elif args[1] == 'New':
            self.app.new_view()
            self.app.open_gdal_dataset(vrtds) 
        else:
            self.app.open_gdal_dataset(vrtds)
Esempio n. 6
0
    def copy_gcps_cb(self, *args):
        """ Copy gcps from an existing gdal dataset. """
        fname = GtkExtra.file_sel_box(title="Select GDAL Dataset")
        if fname is None:
            return

        try:
            fh = gdal.OpenShared(fname)
        except:
            gvutils.error('Unable to open ' + fname + ' as a GDAL dataset!')
            return

        gcps = fh.GetGCPs()
        prj = fh.GetGCPProjection()
        self.clear_gcps()
        for gcp in gcps:
            ngcp = CopyGDALGCP(gcp)
            self.gcplist.append(ngcp)
        self.gcpgrid.refresh()

        self.gcpprjbox.set_input_projection(prj)
Esempio n. 7
0
    def copy_gcps_cb(self,*args):
        """ Copy gcps from an existing gdal dataset. """
        fname=GtkExtra.file_sel_box(title="Select GDAL Dataset")
        if fname is None:
            return

        try:
            fh=gdal.OpenShared(fname)
        except:
            gvutils.error('Unable to open '+fname+' as a GDAL dataset!')
            return
        
        gcps=fh.GetGCPs()
        prj=fh.GetGCPProjection()
        self.clear_gcps()
        for gcp in gcps:
            ngcp=CopyGDALGCP(gcp)
            self.gcplist.append(ngcp)
        self.gcpgrid.refresh()
            
        self.gcpprjbox.set_input_projection(prj)
Esempio n. 8
0
def getprjinfo():
    fname = GtkExtra.file_sel_box(title="Select GDAL Dataset or WKT text file")
    if fname is None:
        return None
    try:
        fh = gdal.OpenShared(fname)
        prj = fh.GetProjection()
        if prj == '':
            prj = fh.GetGCPProjection()
    except:
        fh = open(fname, 'r')
        prj = string.strip(fh.readline())
        # prj files from shapes seem to have
        # an extra character at the end
        if prj[-1:] == '\x00':
            prj = prj[:-1]

    sr = osr.SpatialReference()
    val = sr.ImportFromWkt(prj)
    if val != 0:
        gvutils.error('Invalid projection information in ' + fname + '!')
        return None

    return prj
Esempio n. 9
0
def getprjinfo():
    fname=GtkExtra.file_sel_box(title="Select GDAL Dataset or WKT text file")
    if fname is None:
        return None
    try:
        fh=gdal.OpenShared(fname)
        prj=fh.GetProjection()
        if prj == '':
            prj=fh.GetGCPProjection()
    except:
        fh=open(fname,'r')
        prj=string.strip(fh.readline())
        # prj files from shapes seem to have
        # an extra character at the end
        if prj[-1:] == '\x00':
            prj=prj[:-1]

    sr=osr.SpatialReference()
    val=sr.ImportFromWkt(prj)
    if val != 0:
        gvutils.error('Invalid projection information in '+fname+'!')
        return None

    return prj
Esempio n. 10
0
 def python_run(self, mi=None):
     fname = GtkExtra.file_sel_box("Run")
     if fname:
         self.run_script(fname)
    def save_cb(self, *args):
        if self.copy_but.active:
            outfile=GtkExtra.file_sel_box(title=_("Output File"))
            if outfile is None:
                return

        ds = self.viewarea1.active_layer().get_parent().get_dataset()
        bright_val = math.floor(self.bright_adjustment.value*255/100)
        contrast_val = (100+self.contrast_adjustment.value)/100
        gamma_val = self.gamma_adjustment.value

        outarray = Numeric.zeros((ds.RasterCount,ds.RasterYSize,ds.RasterXSize),typecode=Numeric.UnsignedInt8)

        try:
            size = ds.RasterYSize
            import EasyDialogs
            progress = EasyDialogs.ProgressBar(title='Working...',maxval=size)
        except:
            pass

        lut = []
        for i in range(256):
            value = i + math.floor(bright_val)
            if value < 0 :
                value = 0
            elif value >= 255:
                value = 255
            if contrast_val != 1.0:
                value = value * contrast_val
            if value < 0 :
                value = 0
            elif value >= 255:
                value = 255
            if gamma_val != 1:
                value = 255*math.pow(float(abs(value))/255,1.0/gamma_val)
            if value < 0 :
                value = 0
            elif value >= 255:
                value = 255
            value = int(value)
            lut.append(value)

        lutarray = Numeric.array((lut),typecode=Numeric.UnsignedInt8)

        for m in range(ds.RasterCount):
            inband = ds.GetRasterBand(m+1)
            for i in range(ds.RasterYSize):
                #inarray = inband.ReadAsArray()
                inarray = inband.ReadAsArray(0, i, inband.XSize, 1, inband.XSize, 1)[0].astype(Numeric.UnsignedInt8)
                #outarray = Numeric.zeros(inarray.shape)

                try:
                    progress.label('Processing Band: ' + str(m+1) + ', Line: '+str(i))
                    progress.set(i)
                except:
                    pass

                outarray[m][i].flat[:] = Numeric.take(lutarray,inarray.flat)

        res_ds = gdalnumeric.OpenArray(outarray,ds)
        res_ds = gview.manager.add_dataset(res_ds)

        view = gview.app.sel_manager.get_active_view_window()
        if self.copy_but.active:
            driver = ds.GetDriver()
            driver.CreateCopy(outfile,res_ds)
            view.file_open_by_name(outfile)
            self.destroy()
        elif self.owrite_but.active:
            for layer in gview.app.sel_manager.get_active_view().list_layers():
                if gvutils.is_of_class( layer.__class__, 'GvRasterLayer' ) == 1:
                    if layer.get_parent().get_dataset().GetDescription() == ds.GetDescription():
                        gview.app.sel_manager.get_active_view().remove_layer(layer)

            fname = ds.GetDescription()
            driver = ds.GetDriver()
            driver.CreateCopy(fname,res_ds)
            view.file_open_by_name(fname)
            view.refresh_cb()
            self.destroy()
                
        del ds
        del res_ds
        del outarray
Esempio n. 12
0
	def python_debug(self, mi=None):
		fname = GtkExtra.file_sel_box("Debug")
		if fname:
			self.debug_script(fname)
Esempio n. 13
0
    def save_cb(self, *args):
        if self.copy_but.active:
            outfile = GtkExtra.file_sel_box(title=_("Output File"))
            if outfile is None:
                return

        ds = self.viewarea1.active_layer().get_parent().get_dataset()
        bright_val = math.floor(self.bright_adjustment.value * 255 / 100)
        contrast_val = (100 + self.contrast_adjustment.value) / 100
        gamma_val = self.gamma_adjustment.value

        outarray = Numeric.zeros(
            (ds.RasterCount, ds.RasterYSize, ds.RasterXSize),
            typecode=Numeric.UnsignedInt8)

        try:
            size = ds.RasterYSize
            import EasyDialogs
            progress = EasyDialogs.ProgressBar(title='Working...', maxval=size)
        except:
            pass

        lut = []
        for i in range(256):
            value = i + math.floor(bright_val)
            if value < 0:
                value = 0
            elif value >= 255:
                value = 255
            if contrast_val != 1.0:
                value = value * contrast_val
            if value < 0:
                value = 0
            elif value >= 255:
                value = 255
            if gamma_val != 1:
                value = 255 * math.pow(
                    float(abs(value)) / 255, 1.0 / gamma_val)
            if value < 0:
                value = 0
            elif value >= 255:
                value = 255
            value = int(value)
            lut.append(value)

        lutarray = Numeric.array((lut), typecode=Numeric.UnsignedInt8)

        for m in range(ds.RasterCount):
            inband = ds.GetRasterBand(m + 1)
            for i in range(ds.RasterYSize):
                #inarray = inband.ReadAsArray()
                inarray = inband.ReadAsArray(0, i, inband.XSize, 1,
                                             inband.XSize,
                                             1)[0].astype(Numeric.UnsignedInt8)
                #outarray = Numeric.zeros(inarray.shape)

                try:
                    progress.label('Processing Band: ' + str(m + 1) +
                                   ', Line: ' + str(i))
                    progress.set(i)
                except:
                    pass

                outarray[m][i].flat[:] = Numeric.take(lutarray, inarray.flat)

        res_ds = gdalnumeric.OpenArray(outarray, ds)
        res_ds = gview.manager.add_dataset(res_ds)

        view = gview.app.sel_manager.get_active_view_window()
        if self.copy_but.active:
            driver = ds.GetDriver()
            driver.CreateCopy(outfile, res_ds)
            view.file_open_by_name(outfile)
            self.destroy()
        elif self.owrite_but.active:
            for layer in gview.app.sel_manager.get_active_view().list_layers():
                if gvutils.is_of_class(layer.__class__, 'GvRasterLayer') == 1:
                    if layer.get_parent().get_dataset().GetDescription(
                    ) == ds.GetDescription():
                        gview.app.sel_manager.get_active_view().remove_layer(
                            layer)

            fname = ds.GetDescription()
            driver = ds.GetDriver()
            driver.CreateCopy(fname, res_ds)
            view.file_open_by_name(fname)
            view.refresh_cb()
            self.destroy()

        del ds
        del res_ds
        del outarray
Esempio n. 14
0
	def python_prof(self, mi=None):
		fname = GtkExtra.file_sel_box("Profile")
		if fname:
			self.profile_script(fname)
Esempio n. 15
0
 def python_debug(self, mi=None):
     fname = GtkExtra.file_sel_box("Debug")
     if fname:
         self.debug_script(fname)
Esempio n. 16
0
 def python_prof(self, mi=None):
     fname = GtkExtra.file_sel_box("Profile")
     if fname:
         self.profile_script(fname)
Esempio n. 17
0
	def python_run(self, mi=None):
		fname = GtkExtra.file_sel_box("Run")
		if fname:
			self.run_script(fname)