GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
utils Namespace Reference

Data Structures

class  Rect2D
 Class representing rectangle with floating point values. More...
 
class  Rect2DPP
 Rectangle specified by 2 points (with floating point values). More...
 
class  Rect2DPS
 Rectangle specified by point and size (with floating point values). More...
 
class  UnitConversion
 Class for converting units. More...
 

Functions

def normalize_whitespace
 Remove redundant whitespace from a string. More...
 
def split
 Platform spefic shlex.split. More...
 
def GetTempfile
 Creates GRASS temporary file using defined prefix. More...
 
def GetLayerNameFromCmd
 Get map name from GRASS command. More...
 
def GetValidLayerName
 Make layer name SQL compliant, based on G_str_to_sql() More...
 
def ListOfCatsToRange
 Convert list of category number to range(s) More...
 
def ListOfMapsets
 Get list of available/accessible mapsets. More...
 
def ListSortLower
 Sort list items (not case-sensitive) More...
 
def GetVectorNumberOfLayers
 Get list of vector layers. More...
 
def GetAllVectorLayers
 Returns list of all vector layers as strings. More...
 
def Deg2DMS
 Convert deg value to dms string. More...
 
def DMS2Deg
 Convert dms value to deg. More...
 
def GetCmdString
 
def CmdToTuple
 Convert command list to tuple for gcmd.RunCommand() More...
 
def PathJoin
 Check path created by os.path.join. More...
 
def ReadEpsgCodes
 Read EPSG code from the file. More...
 
def ReprojectCoordinates
 Reproject coordinates. More...
 
def GetListOfLocations
 Get list of GRASS locations in given dbase. More...
 
def GetListOfMapsets
 Get list of mapsets in given GRASS location. More...
 
def GetColorTables
 Get list of color tables. More...
 
def DecodeString
 Decode string using system encoding. More...
 
def EncodeString
 Return encoded string using system locales. More...
 
def GetFormats
 Get GDAL/OGR formats. More...
 
def GetSettingsPath
 Get full path to the settings directory. More...
 
def StoreEnvVariable
 Store environmental variable. More...
 
def SetAddOnPath
 Set default AddOn path. More...
 
def convertRGB
 Converts wx.Colour(r,g,b,a) to string 'r:g:b' or named color, or named color/r:g:b string to wx.Colour, depending on input. More...
 
def PaperMapCoordinates
 Converts paper (inch) coordinates <-> map coordinates. More...
 
def AutoAdjust
 Computes map scale, center and map frame rectangle to fit region (scale is not fixed) More...
 
def SetResolution
 If resolution is too high, lower it. More...
 
def ComputeSetRegion
 Computes and sets region from current scale, map center coordinates and map rectangle. More...
 
def projInfo
 Return region projection and map units information, taken from render.py. More...
 
def GetMapBounds
 Run ps.map -b to get information about map bounding box. More...
 
def getRasterType
 Returns type of raster map (CELL, FCELL, DCELL) More...
 
def PilImageToWxImage
 Convert PIL image to wx.Image. More...
 
def BBoxAfterRotation
 Compute bounding box or rotated rectangle. More...
 
def loadPSForWindows
 
def GhostscriptForWindows
 

Variables

 formats = None
 
 havePILImage = True
 
 unitConv
 
 im
 
 mode
 
 size
 
 tile
 

Function Documentation

def utils.AutoAdjust (   self,
  scaleType,
  rect,
  map = None,
  mapType = None,
  region = None 
)

Computes map scale, center and map frame rectangle to fit region (scale is not fixed)

Definition at line 196 of file psmap/utils.py.

Referenced by frame.PsMapBufferedWindow.OnLeftUp().

def utils.BBoxAfterRotation (   w,
  h,
  angle 
)

Compute bounding box or rotated rectangle.

Parameters
wrectangle width
hrectangle height
angleangle (0, 360) in degrees

Definition at line 383 of file psmap/utils.py.

Referenced by instructions.Image.Read(), and dialogs.ImageDialog.update().

def utils.ComputeSetRegion (   self,
  mapDict 
)

Computes and sets region from current scale, map center coordinates and map rectangle.

Definition at line 272 of file psmap/utils.py.

References projInfo(), and gcmd.RunCommand().

Referenced by frame.PsMapBufferedWindow.OnLeftUp().

def utils.convertRGB (   rgb)

Converts wx.Colour(r,g,b,a) to string 'r:g:b' or named color, or named color/r:g:b string to wx.Colour, depending on input.

Definition at line 136 of file psmap/utils.py.

References dialogs.type.

Referenced by frame.PsMapBufferedWindow.DrawGraphics(), frame.PsMapBufferedWindow.DrawRotText(), dialogs.update(), dialogs.MapinfoDialog.update(), dialogs.TextDialog.update(), dialogs.PointDialog.update(), and dialogs.updateRasterLegend().

def utils.DecodeString (   string)

Decode string using system encoding.

Parameters
stringstring to be decoded
Returns
decoded string

Definition at line 704 of file core/utils.py.

def utils.Deg2DMS (   lon,
  lat,
  string = True,
  hemisphere = True,
  precision = 3 
)

Convert deg value to dms string.

Parameters
lonlongitude (x)
latlatitude (y)
stringTrue to return string otherwise tuple
hemisphereprint hemisphere
precisionseconds precision
Returns
DMS string or tuple of values
empty string on error

Definition at line 367 of file core/utils.py.

Referenced by statusbar.SbGoTo.GetCenterString(), statusbar.SbGoTo.OnGoTo(), statusbar.SbCoordinates.ReprojectENFromMap(), and statusbar.SbRegionExtent.ReprojectRegionFromMap().

def utils.DMS2Deg (   lon,
  lat 
)

Convert dms value to deg.

Parameters
lonlongitude (x)
latlatitude (y)
Returns
tuple of converted values
ValueError on error

Definition at line 421 of file core/utils.py.

Referenced by statusbar.SbGoTo.ReprojectENToMap().

def utils.EncodeString (   string)

Return encoded string using system locales.

Parameters
stringstring to be encoded
Returns
encoded string

Definition at line 721 of file core/utils.py.

Referenced by dialogs.ModelSearchDialog.GetCmd().

def utils.GetAllVectorLayers (   vector)

Returns list of all vector layers as strings.

Parameters
vectorname of vector map

Definition at line 332 of file core/utils.py.

References gcmd.RunCommand().

Referenced by gselect.LayerSelect.InsertLayers().

def utils.GetCmdString (   cmd)
Get GRASS command as string.

@param cmd GRASS command given as dictionary

@return command string

Definition at line 499 of file core/utils.py.

Referenced by render.Layer.GetCmd(), and instructions.Instruction.SetRegion().

def utils.GetColorTables ( )

Get list of color tables.

Definition at line 694 of file core/utils.py.

References gcmd.RunCommand().

Referenced by preferences.PreferencesDialog.__init__().

def utils.GetFormats ( )

Get GDAL/OGR formats.

Definition at line 796 of file core/utils.py.

Referenced by gselect.FormatSelect.__init__().

def utils.GetLayerNameFromCmd (   dcmd,
  fullyQualified = False,
  param = None,
  layerType = None 
)

Get map name from GRASS command.

Parameter dcmd can be modified when first parameter is not defined.

Parameters
dcmdGRASS command (given as list)
fullyQualifiedchange map name to be fully qualified
paramparams directory
layerTypecheck also layer type ('raster', 'vector', '3d-raster', ...)
Returns
tuple (name, found)

Definition at line 73 of file core/utils.py.

References tools.range, and split().

Referenced by layertree.LayerTree.AddLayer(), layertree.LayerTree.ChangeLayer(), histogram.HistogramFrame.GetOptData(), layertree.LayerTree.GetOptData(), GetTempfile(), goutput.GMConsole.OnCmdDone(), frame.MapFrame.QueryMap(), layertree.LayerTree.RecreateItem(), goutput.GMConsole.RunCmd(), and manager.GrSettingsDialog.UpdateSettings().

def utils.GetListOfLocations (   dbase)

Get list of GRASS locations in given dbase.

Parameters
dbaseGRASS database path
Returns
list of locations (sorted)

Definition at line 639 of file core/utils.py.

References ListSortLower().

Referenced by gselect.LocationSelect.UpdateItems(), and gis_set.GRASSStartup.UpdateLocations().

def utils.GetListOfMapsets (   dbase,
  location,
  selectable = False 
)

Get list of mapsets in given GRASS location.

Parameters
dbaseGRASS database path
locationGRASS location
selectableTrue to get list of selectable mapsets, otherwise all
Returns
list of mapsets - sorted (PERMANENT first)

Definition at line 662 of file core/utils.py.

References ListSortLower(), and gcmd.RunCommand().

Referenced by gselect.MapsetSelect.UpdateItems().

def utils.GetMapBounds (   filename,
  portrait = True 
)

Run ps.map -b to get information about map bounding box.

Parameters
filenamepsmap input file
portraitpage orientation

Definition at line 331 of file psmap/utils.py.

References split().

Referenced by frame.getInitMap().

def utils.getRasterType (   map)

Returns type of raster map (CELL, FCELL, DCELL)

Definition at line 349 of file psmap/utils.py.

Referenced by dialogs.OnRaster(), instructions.RasterLegend.Read(), and dialogs.updateRasterLegend().

def utils.GetSettingsPath ( )

Get full path to the settings directory.

Definition at line 807 of file core/utils.py.

References split().

Referenced by settings.Settings.SaveToFile().

def utils.GetTempfile (   pref = None)

Creates GRASS temporary file using defined prefix.

Todo:
Fix path on MS Windows/MSYS
Parameters
prefprefer the given path
Returns
Path to file name (string) or None

Definition at line 44 of file core/utils.py.

References GetLayerNameFromCmd(), and gcmd.RunCommand().

Referenced by colorrules.ColorTable.CreateColorTable(), manager.GCP.GetNewExtent(), colorrules.RasterColorTable.OnPreview(), colorrules.VectorColorTable.OnTablePreview(), manager.GCPWizard.SetSrcEnv(), and colorrules.VectorColorTable.UpdateColorColumn().

def utils.GetValidLayerName (   name)

Make layer name SQL compliant, based on G_str_to_sql()

Todo:
: Better use directly Ctypes to reuse venerable libgis C fns...

Definition at line 175 of file core/utils.py.

Referenced by gselect.GdalSelect.OnSetDsn(), and dialogs.DxfImportDialog.OnSetDsn().

def utils.GetVectorNumberOfLayers (   vector,
  parent = None 
)

Get list of vector layers.

Parameters
vectorname of vector map
parentparent window (to show dialog) or None

Definition at line 291 of file core/utils.py.

References gcmd.RunCommand().

def utils.GhostscriptForWindows (   tile,
  size,
  fp 
)
Render an image using Ghostscript (Windows only)

Definition at line 436 of file psmap/utils.py.

def utils.ListOfCatsToRange (   cats)

Convert list of category number to range(s)

Used for example for d.vect cats=[range]

Parameters
catscategory list
Returns
category range string
'' on error

Definition at line 207 of file core/utils.py.

Referenced by frame.MapFrame.AddTmpVectorMapLayer(), manager.AttributeManager.OnDataItemDeleteAll(), manager.AttributeManager.OnDeleteSelected(), manager.AttributeManager.OnExtractSelected(), and mapwindow.VDigitWindow.OnLeftUpCopyLine().

def utils.ListOfMapsets (   get = 'ordered')

Get list of available/accessible mapsets.

Parameters
getmethod ('all', 'accessible', 'ordered')
Returns
list of mapsets
None on error

Definition at line 245 of file core/utils.py.

References ListSortLower(), and gcmd.RunCommand().

def utils.ListSortLower (   list)
def utils.loadPSForWindows (   self)

Definition at line 427 of file psmap/utils.py.

def utils.normalize_whitespace (   text)

Remove redundant whitespace from a string.

Definition at line 33 of file core/utils.py.

Referenced by forms.text_beautify().

def utils.PaperMapCoordinates (   mapInstr,
  x,
  y,
  paperToMap = True 
)

Converts paper (inch) coordinates <-> map coordinates.

Parameters
mapInstrmap frame instruction
x,ypaper coords in inches or mapcoords in map units
paperToMapspecify conversion direction

Definition at line 159 of file psmap/utils.py.

References projInfo().

Referenced by instructions.Image.ChangeRefPoint(), instructions.Text.Read(), instructions.Image.Read(), instructions.Point.Read(), instructions.Line.Read(), instructions.Rectangle.Read(), frame.PsMapBufferedWindow.RecalculateEN(), dialogs.TextDialog.update(), dialogs.ImageDialog.update(), and dialogs.PointDialog.update().

def utils.PathJoin (   args)

Check path created by os.path.join.

Definition at line 551 of file core/utils.py.

def utils.PilImageToWxImage (   pilImage,
  copyAlpha = True 
)

Convert PIL image to wx.Image.

Based on http://wiki.wxpython.org/WorkingWithImages

Definition at line 360 of file psmap/utils.py.

Referenced by frame.PsMapBufferedWindow.DrawBitmap().

def utils.projInfo ( )

Return region projection and map units information, taken from render.py.

Definition at line 309 of file psmap/utils.py.

References gcmd.RunCommand().

Referenced by ComputeSetRegion(), instructions.Scalebar.EstimateSize(), frame.OnAddScalebar(), and PaperMapCoordinates().

def utils.ReadEpsgCodes (   path)

Read EPSG code from the file.

Parameters
pathfull path to the file with EPSG codes
Returns
dictionary of EPSG code
string on error

Definition at line 560 of file core/utils.py.

Referenced by wizard.EPSGPage.OnBrowseCodes(), and preferences.PreferencesDialog.OnLoadEpsgCodes().

def utils.ReprojectCoordinates (   coord,
  projOut,
  projIn = None,
  flags = '' 
)

Reproject coordinates.

Parameters
coordcoordinates given as tuple
projOutoutput projection
projIninput projection (use location projection settings)
Returns
reprojected coordinates (returned as tuple)

Definition at line 602 of file core/utils.py.

References gcmd.RunCommand(), and split().

Referenced by statusbar.SbGoTo.GetCenterString(), statusbar.SbCoordinates.ReprojectENFromMap(), statusbar.SbGoTo.ReprojectENToMap(), and statusbar.SbRegionExtent.ReprojectRegionFromMap().

def utils.SetAddOnPath (   addonPath = None)

Set default AddOn path.

path to addons (None for default)

Definition at line 893 of file core/utils.py.

References split(), and StoreEnvVariable().

Referenced by extensions.InstallExtensionWindow.OnDone(), and frame.GMFrame.OnRunScript().

def utils.SetResolution (   dpi,
  width,
  height 
)

If resolution is too high, lower it.

Parameters
dpimax DPI
widthmap frame width
heightmap frame height

Definition at line 259 of file psmap/utils.py.

References gcmd.RunCommand().

Referenced by frame.DialogDataChanged(), frame.PsMapBufferedWindow.OnLeftUp(), and frame.PsMapFrame.PSFile().

def utils.split (   s)

Platform spefic shlex.split.

Definition at line 37 of file core/utils.py.

Referenced by gcmd.GError.__init__(), ghelp.AboutWindow.__init__(), instructions.Text.__str__(), instructions.VProperties.__str__(), colorrules.VectorColorTable.AddTemporaryColumn(), layertree.LayerTree.ChangeLayer(), globalvar.CheckForWx(), globalvar.CheckWxVersion(), render.Map.Clean(), profile.ProfileFrame.CreateDatalist(), python.db.db_select(), frame.DialogDataChanged(), prompt.GPromptSTC.EntityToComplete(), instructions.RasterLegend.EstimateHeight(), dialogs.ModelSearchDialog.GetCmd(), prompt.GPrompt.GetCommandItems(), dialogs.PageSetupDialog.getCtrl(), frame.PsMapFrame.getFile(), GetLayerNameFromCmd(), mapwindow.GLWindow.GetLegendRect(), GetMapBounds(), manager.GCP.GetNewExtent(), dialogs.GroupDialog.GetSelectedGroup(), GetSettingsPath(), widgets.GetValue(), colorrules.RulesPanel.LoadRules(), python.core.locn_is_latlong(), frame.makePSFont(), dialogs.NorthArrowDialog.OnConvergence(), manager.AttributeManager.OnDataItemDeleteAll(), prompt.TextCtrlAutoComplete.OnEnteredText(), statusbar.SbGoTo.OnGoTo(), prompt.GPromptSTC.OnItemSelected(), gselect.TreeCtrlComboPopup.OnKeyUp(), gselect.TreeCtrlComboPopup.OnLeftDown(), menu.MenuTreeWindow.OnRun(), dialogs.ProfileRasterDialog.OnSelection(), ghelp.SearchModuleWindow.OnSelectModule(), gselect.GdalSelect.OnSetDsn(), dialogs.DxfImportDialog.OnSetDsn(), gselect.GdalSelect.OnSettingsDelete(), tools.OnSurfaceModeAll(), menudata.MenuData.PrintStrings(), instructions.MapFrame.Read(), instructions.Mapinfo.Read(), instructions.VProperties.Read(), frame.PsMapBufferedWindow.RecalculatePosition(), ReprojectCoordinates(), statusbar.SbGoTo.ReprojectENToMap(), manager.GCP.RMSError(), goutput.CmdThread.run(), model.Model.Run(), SetAddOnPath(), instructions.Instruction.SetRegion(), profile.ProfileFrame.SetupProfile(), StoreEnvVariable(), dialogs.MapFramePanel.update(), globalvar.UpdateGRASSAddOnCommands(), frame.UpdateMapLabel(), tools.UpdateVectorPage(), python.vector.vector_db(), and python.vector.vector_db_select().

def utils.StoreEnvVariable (   key,
  value = None,
  envFile = None 
)

Store environmental variable.

If value is not given (is None) then environmental variable is unset.

Parameters
keyenv key
valueenv value
envFilepath to the environmental file (None for default location)

Definition at line 825 of file core/utils.py.

References split().

Referenced by SetAddOnPath().

Variable Documentation

utils.formats = None

Definition at line 794 of file core/utils.py.

utils.havePILImage = True

Definition at line 25 of file psmap/utils.py.

utils.im

Definition at line 431 of file psmap/utils.py.

Referenced by chouse(), chousv(), class_discont(), and hconj().

utils.mode

Definition at line 432 of file psmap/utils.py.

utils.size

Definition at line 433 of file psmap/utils.py.

utils.unitConv

Definition at line 234 of file psmap/utils.py.