def __init__(self, reg=region.Region(), default=False, prec=4, meta=None): self.c_region = ctypes.pointer(libgis.Cell_head()) self.corners = self.llcorner(reg) self.prec = prec self.meta = meta if default: self.get_default() else: self.get_current()
def run_benchmark(resolution_list, runs, testdict, profile): regions = [] for resolution in resolution_list: core.use_temp_region() core.run_command("g.region", e=50, w=-50, n=50, s=-50, res=resolution, flags="p") # Adjust the computational region for this process region = libgis.Cell_head() libraster.Rast_get_window(ctypes.byref(region)) region.e = 50 region.w = -50 region.n = 50 region.s = -50 region.ew_res = resolution region.ns_res = resolution libgis.G_adjust_Cell_head(ctypes.byref(region), 0, 0) libraster.Rast_set_window(ctypes.byref(region)) libgis.G_set_window(ctypes.byref(region)) # Create two raster maps with random numbers core.mapcalc("test_a = rand(0, 100)", quite=True, overwrite=True) core.mapcalc("test_b = rand(0.0, 1.0)", quite=True, overwrite=True) result = collections.OrderedDict() result["res"] = resolution result["cols"] = region.cols result["rows"] = region.rows result["cells"] = region.rows * region.cols result["results"] = copy.deepcopy(testdict) for execmode, operation in result["results"].items(): print(execmode) for oper, operdict in operation.items(): operdict["time"], operdict["times"] = mytimer( operdict["func"], runs) if profile: filename = "{0}_{1}_{2}".format(execmode, oper, profile) cProfile.runctx( operdict["func"].__name__ + "()", globals(), locals(), filename=filename, ) print((" {0}: {1: 40.6f}s".format(oper, operdict["time"]))) del operdict["func"] regions.append(result) core.del_temp_region() return regions
def __init__(self, name, mapset=''): """Read the information for a raster map. :: >>> info = Info(test_raster_name) >>> info.read() >>> info # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE abstract_test_map@ rows: 4 cols: 4 north: 40.0 south: 0.0 nsres:10.0 east: 40.0 west: 0.0 ewres:10.0 range: 11, 44 ... <BLANKLINE> """ self.name = name self.mapset = mapset self.c_region = ctypes.pointer(libgis.Cell_head()) self.c_range = None
def adjust_window_to_box(self, src, rows, cols): dst = grasslib.Cell_head() dst = src ns = src.ns_res ns = (src.ns_res * src.rows) / rows ew = (src.ew_res * src.cols) / cols if ns > ew: ew = ns else: ns = ew dst.ns_res = ns dst.ew_res = ew r = int(abs(round(((dst.north - dst.south) / dst.ns_res), 0))) c = int(abs(round(((dst.east - dst.west) / dst.ew_res), 0))) dst.rows = r dst.cols = c return dst
def __init__(self, name, mapset=''): """Read the information for a raster map. :: >>> info = Info('elevation') >>> info.read() >>> info elevation@ rows: 1350 cols: 1500 north: 228500.0 south: 215000.0 nsres:10.0 east: 645000.0 west: 630000.0 ewres:10.0 range: 56, 156 proj: 99 <BLANKLINE> """ self.name = name self.mapset = mapset self.c_region = ctypes.pointer(libgis.Cell_head()) self.c_range = None
def __init__(self, default=False): """:: >>> default = Region(default=True) >>> current = Region() >>> default == current True >>> current.cols 1500 >>> current.ewres 10.0 >>> current.cols = 3000 >>> current.ewres 5.0 >>> current.ewres = 20.0 >>> current.cols 750 >>> current.set_current() >>> default == current False >>> current.set_default() >>> default = Region(default=True) >>> default == current True >>> default Region(n=228500, s=215000, e=645000, w=630000, nsres=10, ewres=20) >>> current Region(n=228500, s=215000, e=645000, w=630000, nsres=10, ewres=20) >>> default.ewres = 10. >>> default.set_default() """ self.c_region = ctypes.pointer(libgis.Cell_head()) if default: self.get_default() else: self.get_current()
def __init__(self): self._region = libgis.Cell_head() libgis.G_get_set_window(c.byref(self._region))
def __init__(self, default=False): self.c_region = libgis.Cell_head() if default: self.read_default() else: self.read()
def __init__(self, parent=None, id=wx.ID_ANY, title=_("Imagery - wx.class"), pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, toolbars=["map"], tree=None, notebook=None, gismgr=None, page=None, Map=None, auimgr=None): self._layerManager = gismgr self.Map = Map self.gismanager = gismgr # GIS Manager object self.Map = Map # instance of render.Map self.tree = tree # GIS Manager layer tree object self.page = page # Notebook page holding the layer tree self.layerbook = notebook # GIS Manager layer tree notebook self.parent = parent # # available cursors # self.counter = 0 # available cursors # self.cursors = { # default: cross # "default" : wx.StockCursor(wx.CURSOR_DEFAULT), "default": wx.StockCursor(wx.CURSOR_ARROW), "cross": wx.StockCursor(wx.CURSOR_CROSS), "hand": wx.StockCursor(wx.CURSOR_HAND), "pencil": wx.StockCursor(wx.CURSOR_PENCIL), "sizenwse": wx.StockCursor(wx.CURSOR_SIZENWSE) } wx.Frame.__init__(self, parent, id, title, pos, size, style) self.SetName("MapWindow") # # set the size & system icon # self.SetClientSize(size) self.iconsize = (16, 16) self.SetIcon( wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass_map.ico'), wx.BITMAP_TYPE_ICO)) # # Fancy gui # # self._mgr = auimgr self._mgr = wx.aui.AuiManager(self) # # Add toolbars # self.toolbars = { 'map': None, 'vdigit': None, 'georect': None, 'nviz': None } # for toolb in toolbars: # self.AddToolbar(toolb) # # Add statusbar # self.statusbar = self.CreateStatusBar(number=4, style=0) self.statusbar.SetStatusWidths([-5, -2, -1, -1]) self.statusbarWin = dict() self.statusbarWin['toggle'] = wx.Choice( self.statusbar, wx.ID_ANY, choices=globalvar.MAP_DISPLAY_STATUSBAR_MODE) self.statusbarWin['toggle'].SetSelection( UserSettings.Get(group='display', key='statusbarMode', subkey='selection')) self.statusbar.Bind(wx.EVT_CHOICE, self.OnToggleStatus, self.statusbarWin['toggle']) # auto-rendering checkbox self.statusbarWin['render'] = wx.CheckBox(parent=self.statusbar, id=wx.ID_ANY, label=_("Render")) self.statusbar.Bind(wx.EVT_CHECKBOX, self.OnToggleRender, self.statusbarWin['render']) self.statusbarWin['render'].SetValue( UserSettings.Get(group='display', key='autoRendering', subkey='enabled')) self.statusbarWin['render'].SetToolTip( wx.ToolTip(_("Enable/disable auto-rendering"))) # show region self.statusbarWin['region'] = wx.CheckBox( parent=self.statusbar, id=wx.ID_ANY, label=_("Show computational extent")) self.statusbar.Bind(wx.EVT_CHECKBOX, self.OnToggleShowRegion, self.statusbarWin['region']) self.statusbarWin['region'].SetValue(False) self.statusbarWin['region'].Hide() self.statusbarWin['region'].SetToolTip( wx.ToolTip( _("Show/hide computational " "region extent (set with g.region). " "Display region drawn as a blue box inside the " "computational region, " "computational region inside a display region " "as a red box)."))) # set resolution self.statusbarWin['resolution'] = wx.CheckBox( parent=self.statusbar, id=wx.ID_ANY, label=_("Constrain display resolution to computational settings")) self.statusbar.Bind(wx.EVT_CHECKBOX, self.OnToggleResolution, self.statusbarWin['resolution']) self.statusbarWin['resolution'].SetValue( UserSettings.Get(group='display', key='compResolution', subkey='enabled')) self.statusbarWin['resolution'].Hide() self.statusbarWin['resolution'].SetToolTip( wx.ToolTip( _("Constrain display resolution " "to computational region settings. " "Default value for new map displays can " "be set up in 'User GUI settings' dialog."))) # map scale self.statusbarWin['mapscale'] = wx.ComboBox(parent=self.statusbar, id=wx.ID_ANY, style=wx.TE_PROCESS_ENTER, size=(150, -1)) self.statusbarWin['mapscale'].SetItems([ '1:1000', '1:5000', '1:10000', '1:25000', '1:50000', '1:100000', '1:1000000' ]) self.statusbarWin['mapscale'].Hide() self.statusbar.Bind(wx.EVT_TEXT_ENTER, self.OnChangeMapScale, self.statusbarWin['mapscale']) self.statusbar.Bind(wx.EVT_COMBOBOX, self.OnChangeMapScale, self.statusbarWin['mapscale']) # go to self.statusbarWin['goto'] = wx.TextCtrl(parent=self.statusbar, id=wx.ID_ANY, value="", style=wx.TE_PROCESS_ENTER, size=(300, -1)) self.statusbarWin['goto'].Hide() #self.statusbar.Bind(wx.EVT_TEXT_ENTER, MapFrame.OnGoTo, self.statusbarWin['goto']) # projection self.statusbarWin['projection'] = wx.CheckBox( parent=self.statusbar, id=wx.ID_ANY, label=_("Use defined projection")) self.statusbarWin['projection'].SetValue(False) size = self.statusbarWin['projection'].GetSize() self.statusbarWin['projection'].SetMinSize((size[0] + 150, size[1])) self.statusbarWin['projection'].SetToolTip( wx.ToolTip( _("Reproject coordinates displayed " "in the statusbar. Projection can be " "defined in GUI preferences dialog " "(tab 'Display')"))) self.statusbarWin['projection'].Hide() # mask self.statusbarWin['mask'] = wx.StaticText(parent=self.statusbar, id=wx.ID_ANY, label='') self.statusbarWin['mask'].SetForegroundColour(wx.Colour(255, 0, 0)) # on-render gauge self.statusbarWin['progress'] = wx.Gauge(parent=self.statusbar, id=wx.ID_ANY, range=0, style=wx.GA_HORIZONTAL) self.statusbarWin['progress'].Hide() self.StatusbarReposition() # reposition statusbar # # Init map display (buffered DC & set default cursor) # self.MapWindow2D = BufferedWindow2(self, id=wx.ID_ANY, Map=self.Map, tree=self.tree, lmgr=self.gismanager) # default is 2D display mode self.MapWindow = self.MapWindow2D #self.MapWindow.Bind(wx.EVT_MOTION, BufferedWindow2.OnMotion) self.MapWindow.SetCursor(self.cursors["default"]) # used by Nviz (3D display mode) self.MapWindow3D = None self.MapWindow.Bind(wx.EVT_LEFT_DCLICK, self.OnButtonDClick) self.MapWindow.Bind(wx.EVT_RIGHT_DCLICK, self.RDClick) # # initialize region values # self.width, self.height = self.GetClientSize() self.Map.ChangeMapSize(self.GetClientSize()) self.Map.region = self.Map.GetRegion() # # Bind various events # #self.Bind(wx.EVT_ACTIVATE, self.OnFocus) self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) #self.Bind(render.EVT_UPDATE_PRGBAR, self.OnUpdateProgress) # # Update fancy gui style # self._mgr.AddPane( self.MapWindow, wx.aui.AuiPaneInfo().CentrePane().Dockable(False).BestSize( (-1, -1)).CloseButton(False).DestroyOnClose(True).Layer(0)) self._mgr.Update() # # Init print module and classes # #self.printopt = disp_print.PrintOptions(self, self.MapWindow) # # Initialization of digitization tool # self.digit = None # # Init zoom history # # # Re-use dialogs # self.dialogs = {} self.dialogs['attributes'] = None self.dialogs['category'] = None self.dialogs['barscale'] = None self.dialogs['legend'] = None self.decorationDialog = None # decoration/overlays # # Re-use dialogs # self.coords = [] self.coor = [] self.mapname = 'lsat7_2000_10@' + grass1.gisenv()['MAPSET'] self.cmd = ['d.rast', str("map=" + self.mapname)] self.Map.AddLayer(type='raster', name=self.mapname, command=self.cmd) self.MapWindow.UpdateMap(render=True) self.dialogs = {} self.dialogs['attributes'] = None self.dialogs['category'] = None self.dialogs['barscale'] = None self.dialogs['legend'] = None self.decorationDialog = None # decoration/overlays #self.Maximize() self.X = [] self.Y = [] self.tempX = [] self.tempY = [] self.npoints = 0 self.VX = [] self.VY = [] self.perimeter_npoints = 0 self.perimeterX = [] self.perimeterY = [] self.Region_perimeter = [] # initialize self.data_type = [] self.inrast = [] self.infd = [] self.Band_sum = [] self.Bandbuf = [] self.Band_histo = [] self.Band_Product = [] self.Band_min = [] self.Band_max = [] self.np = 0 # find map in search path self.name = [ 'lsat7_2000_10', 'lsat7_2000_20', 'lsat7_2000_30', 'lsat7_2000_40', 'lsat7_2000_50', 'lsat7_2000_70' ] # determine the inputmap type (CELL/FCELL/DCELL) */ # for n in range(0,6): # self.data_type = grass.G_raster_map_type(name[n], mapset) # self.infd.append( grass.G_open_cell_old(name[n], mapset)) # determine the inputmap type (CELL/FCELL/DCELL) */ self.mapset = 'landsat' self.mapset = c_char_p(self.mapset).value self.open_band_files() self.vnrows = 0 self.vncols = 0 self.hnrows = 0 self.hncols = 0 self.htop = self.hbottom = self.hleft = self.hright = 0 self.view() self.viewhistogram() self.cellhd = grasslib.Cell_head() if (raster.Rast_get_cellhd('lsat7_2000_10', self.mapset, byref(self.cellhd))) == 0: print "error1" #9400694566 self.Band_cellhd = self.cellhd self.dst = self.adjust_window_to_box(self.cellhd, self.vnrows, self.vncols) self.vcleft = self.vleft + (self.vncols - self.dst.cols) / 2 self.vcright = self.vcleft + self.dst.cols - 1 self.vctop = self.vtop + (self.vnrows - self.dst.rows) / 2 self.vcbottom = self.vctop + self.dst.rows - 1 self.vc_ns_res = self.cellhd.ns_res self.vc_ew_res = self.cellhd.ew_res for b in xrange(6): self.Band_sum.append(0.0) self.Band_histo.append([]) for b2 in xrange(256): self.Band_Product.append([]) self.Band_histo[b].append(0.0) for b2 in xrange(255): self.Band_Product[b].append(0)
def _read_raster_info(name, mapset): """Read the raster map info from the file system and store the content into a dictionary This method uses the ctypes interface to the gis and raster libraries to read the map metadata information :param name: The name of the map :param mapset: The mapset of the map :returns: The key value pairs of the map specific metadata, or None in case of an error """ kvp = {} if not libgis.G_find_raster(name, mapset): return None # Read the region information region = libgis.Cell_head() libraster.Rast_get_cellhd(name, mapset, byref(region)) kvp["north"] = region.north kvp["south"] = region.south kvp["east"] = region.east kvp["west"] = region.west kvp["nsres"] = region.ns_res kvp["ewres"] = region.ew_res kvp["rows"] = region.cols kvp["cols"] = region.rows maptype = libraster.Rast_map_type(name, mapset) if maptype == libraster.DCELL_TYPE: kvp["datatype"] = "DCELL" elif maptype == libraster.FCELL_TYPE: kvp["datatype"] = "FCELL" elif maptype == libraster.CELL_TYPE: kvp["datatype"] = "CELL" # Read range if libraster.Rast_map_is_fp(name, mapset): range = libraster.FPRange() libraster.Rast_init_fp_range(byref(range)) ret = libraster.Rast_read_fp_range(name, mapset, byref(range)) if ret < 0: logging.error(_("Unable to read range file")) return None if ret == 2: kvp["min"] = None kvp["max"] = None else: min = libgis.DCELL() max = libgis.DCELL() libraster.Rast_get_fp_range_min_max(byref(range), byref(min), byref(max)) kvp["min"] = min.value kvp["max"] = max.value else: range = libraster.Range() libraster.Rast_init_range(byref(range)) ret = libraster.Rast_read_range(name, mapset, byref(range)) if ret < 0: logging.error(_("Unable to read range file")) return None if ret == 2: kvp["min"] = None kvp["max"] = None else: min = libgis.CELL() max = libgis.CELL() libraster.Rast_get_range_min_max(byref(range), byref(min), byref(max)) kvp["min"] = min.value kvp["max"] = max.value return kvp
def __init__(self, default=False): self.c_region = ctypes.pointer(libgis.Cell_head()) if default: self.get_default() else: self.get_current()