GRASS Programmer's Manual  6.5.svn(2012)-r51648
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
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.
def split
 Platform spefic shlex.split.
def GetTempfile
 Creates GRASS temporary file using defined prefix.
def GetLayerNameFromCmd
 Get map name from GRASS command.
def GetValidLayerName
 Make layer name SQL compliant, based on G_str_to_sql()
def ListOfCatsToRange
 Convert list of category number to range(s)
def ListOfMapsets
 Get list of available/accessible mapsets.
def ListSortLower
 Sort list items (not case-sensitive)
def GetVectorNumberOfLayers
 Get list of vector layers.
def Deg2DMS
 Convert deg value to dms string.
def DMS2Deg
 Convert dms value to deg.
def GetCmdString
def CmdToTuple
 Convert command list to tuple for gcmd.RunCommand()
def PathJoin
 Check path created by os.path.join.
def ReadEpsgCodes
 Read EPSG code from the file.
def ReprojectCoordinates
 Reproject coordinates.
def GetListOfLocations
 Get list of GRASS locations in given dbase.
def GetListOfMapsets
 Get list of mapsets in given GRASS location.
def GetColorTables
 Get list of color tables.
def DecodeString
 Decode string using system encoding.
def EncodeString
 Return encoded string using system locales.
def GetFormats
 Get GDAL/OGR formats.
def GetSettingsPath
 Get full path to the settings directory.
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.
def PaperMapCoordinates
 Converts paper (inch) coordinates <-> map coordinates.
def AutoAdjust
 Computes map scale, center and map frame rectangle to fit region (scale is not fixed)
def SetResolution
 If resolution is too high, lower it.
def ComputeSetRegion
 Computes and sets region from current scale, map center coordinates and map rectangle.
def projInfo
 Return region projection and map units information, taken from render.py.
def GetMapBounds
 Run ps.map -b to get information about map bounding box.
def getRasterType
 Returns type of raster map (CELL, FCELL, DCELL)
def PilImageToWxImage
 Convert PIL image to wx.Image.
def BBoxAfterRotation
 Compute bounding box or rotated rectangle.

Variables

 formats = None
 havePILImage = True
 unitConv

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 195 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 382 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 271 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 135 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 656 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 321 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 375 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 673 of file core/utils.py.

Referenced by dialogs.ModelSearchDialog.GetCmd().

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

@param cmd GRASS command given as dictionary

@return command string

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

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

Get list of color tables.

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

References gcmd.RunCommand().

Referenced by preferences.PreferencesDialog.__init__().

Get GDAL/OGR formats.

Definition at line 739 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 75 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 591 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 614 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 330 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 348 of file psmap/utils.py.

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

Get full path to the settings directory.

Definition at line 750 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 46 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 GRASS Python SWIG...

Definition at line 164 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 280 of file core/utils.py.

References gcmd.RunCommand().

Referenced by gselect.LayerSelect.InsertLayers().

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 196 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 234 of file core/utils.py.

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

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 158 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 503 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 359 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 308 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 512 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 554 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.SetResolution (   dpi,
  width,
  height 
)

If resolution is too high, lower it.

Parameters:
dpimax DPI
widthmap frame width
heightmap frame height

Definition at line 258 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(), frame.DialogDataChanged(), prompt.GPromptSTC.EntityToComplete(), instructions.RasterLegend.EstimateHeight(), dialogs.ModelSearchDialog.GetCmd(), dialogs.PageSetupDialog.getCtrl(), frame.getFile(), globalvar.GetGRASSCommands(), GetLayerNameFromCmd(), mapwindow.GLWindow.GetLegendRect(), GetMapBounds(), manager.GCP.GetNewExtent(), dialogs.GroupDialog.GetSelectedGroup(), GetSettingsPath(), widgets.GetValue(), base.BasePlotFrame.InitRasterPairs(), colorrules.RulesPanel.LoadRules(), frame.makePSFont(), dialogs.NorthArrowDialog.OnConvergence(), manager.AttributeManager.OnDataItemDeleteAll(), prompt.TextCtrlAutoComplete.OnEnteredText(), statusbar.SbGoTo.OnGoTo(), prompt.GPromptSTC.OnItemSelected(), gselect.TreeCtrlComboPopup.OnKeyUp(), gselect.TreeCtrlComboPopup.OnLeftDown(), ghelp.MenuTreeWindow.OnRun(), prompt.GPrompt.OnRunCmd(), 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(), instructions.Instruction.SetRegion(), profile.ProfileFrame.SetupProfile(), dialogs.MapFramePanel.update(), frame.UpdateMapLabel(), tools.UpdateVectorPage(), python.vector.vector_db(), and python.vector.vector_db_select().


Variable Documentation

utils.formats = None

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

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

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