2 @package psmap.instructions 
    4 @brief Map feature objects 
    8  - dialogs::InstructionObject 
   20  - dialogs::RasterLegend 
   21  - dialogs::VectorLegend 
   24  - dialogs::VProperties 
   26 (C) 2011-2012 by Anna Kratochvilova, and the GRASS Development Team 
   28 This program is free software under the GNU General Public License 
   29 (>=v2). Read the file COPYING that comes with GRASS for details. 
   31 @author Anna Kratochvilova <kratochanna gmail.com> (bachelor's project) 
   32 @author Martin Landa <landa.martin gmail.com> (mentor) 
   38 from time 
import strftime, localtime
 
   43 from core.gcmd          import RunCommand, GError, GMessage, GWarning
 
   44 from core.utils         import CmdToTuple, GetCmdString
 
   45 from dbmgr.vinfo        
import VectorDBInfo
 
   49     """!Class which represents instruction file""" 
   58         """!Returns text for instruction file""" 
   59         comment = 
"# timestamp: " + strftime(
"%Y-%m-%d %H:%M", 
localtime()) + 
'\n' 
   61         comment += 
"# location: %s\n" % env[
'LOCATION_NAME']
 
   62         comment += 
"# mapset: %s\n" % env[
'MAPSET']
 
   68         return comment + border + 
'\n'.join(text) + 
'\nend' 
   77         """!Test if instruction is included""" 
   84         """!Delete instruction""" 
   87                 if each.type == 
'map':
 
   92                     for item 
in vektor + vProperties + raster:
 
   94                             self.instruction.remove(item)
 
   96                 self.instruction.remove(each)
 
   98                     self.objectsToDraw.remove(id)
 
  102         """!Add instruction""" 
  104         if instruction.type == 
'map':
 
  105             self.instruction.insert(0, instruction)
 
  107             self.instruction.append(instruction)
 
  109         if instruction.type 
not in (
'page', 
'raster', 
'vector', 
'vProperties', 
'initMap'):
 
  110             if instruction.type == 
'map':
 
  111                 self.objectsToDraw.insert(0, instruction.id) 
 
  113                 self.objectsToDraw.append(instruction.id) 
 
  117         """!Find instruction(s) with the given type""" 
  120             if each.type == type:
 
  122         if len(inst) == 1 
and not list:
 
  127         """!Reads instruction file and creates instruction objects""" 
  131             file = open(filename, 
'r') 
  133             GError(message = _(
"Unable to open file\n%s") % filename)
 
  136         isRegionComment = 
False 
  137         orientation = 
'Portrait' 
  139             if '# g.region' in line:
 
  141                 isRegionComment = 
True 
  143             if '# page orientation' in line:
 
  144                 orientation = line.split(
':')[-1].strip()
 
  146         if not isRegionComment:
 
  151         region = grass.region()
 
  152         map[
'center'] = (region[
'n'] + region[
's']) / 2, (region[
'w'] + region[
'e']) / 2
 
  154         map[
'rect'] = mapRect
 
  158             toM = float(proj[
'meters'])
 
  159         units = UnitConversion(self.
parent)
 
  160         w = units.convert(value = mapRect.Get()[2], fromUnit = 
'inch', toUnit = 
'meter') / toM
 
  161         map[
'scale'] = w / abs((region[
'w'] - region[
'e']))
 
  163         SetResolution(dpi = 300, width = map[
'rect'].width, height = map[
'rect'].height)
 
  180                     if instruction == 
'scalebar':
 
  181                         kwargs[
'scale'] = map[
'scale']
 
  182                     elif instruction 
in (
'text', 
'eps', 
'point', 
'line', 
'rectangle'):
 
  183                         kwargs[
'mapInstruction'] = map
 
  184                     elif instruction 
in (
'vpoints', 
'vlines', 
'vareas'):
 
  185                         kwargs[
'id'] = wx.NewId()
 
  186                         kwargs[
'vectorMapNumber'] = vectorMapNumber
 
  188                     elif instruction == 
'paper':
 
  189                         kwargs[
'Orientation'] = orientation
 
  191                     ok = self.
SendToRead(instruction, buffer, **kwargs)
 
  192                     if not ok: 
return False 
  196             elif line.startswith(
'paper'):
 
  197                 instruction = 
'paper' 
  201             elif line.startswith(
'border'):
 
  202                 if line.split()[1].lower() 
in (
'n', 
'no', 
'none'):
 
  204                     if not ok: 
return False 
  205                 elif line.split()[1].lower() 
in (
'y', 
'yes'):
 
  206                     instruction = 
'border' 
  210             elif line.startswith(
'scale '):
 
  213                 ok = self.
SendToRead(
'scale', line, isRegionComment = isRegionComment)
 
  214                 if not ok: 
return False 
  216             elif line.startswith(
'maploc'):
 
  217                 ok = self.
SendToRead(instruction = 
'maploc', text = line)
 
  218                 if not ok: 
return False 
  220             elif line.startswith(
'raster'):
 
  221                 ok = self.
SendToRead(instruction = 
'raster', text = line)
 
  222                 if not ok: 
return False 
  224             elif line.startswith(
'mapinfo'):
 
  225                 instruction = 
'mapinfo' 
  230             elif line.startswith(
'scalebar'):
 
  231                 instruction = 
'scalebar' 
  235             elif line.startswith(
'text'):
 
  240             elif line.startswith(
'eps'):
 
  245             elif line.startswith(
'point'):
 
  246                 instruction = 
'point' 
  250             elif line.startswith(
'line'):
 
  255             elif line.startswith(
'rectangle'):
 
  256                 instruction = 
'rectangle' 
  260             elif line.startswith(
'colortable'):
 
  261                 if len(line.split()) == 2 
and line.split()[1].lower() 
in (
'n', 
'no', 
'none'):
 
  263                 instruction = 
'colortable' 
  267             elif line.startswith(
'vlegend'):
 
  268                 instruction = 
'vlegend' 
  272             elif line.startswith(
'vpoints'):
 
  273                 instruction = 
'vpoints' 
  277             elif line.startswith(
'vlines'):
 
  278                 instruction = 
'vlines' 
  282             elif line.startswith(
'vareas'):
 
  283                 instruction = 
'vareas' 
  297         map[
'drawMap'] = 
False 
  298         if map[
'scaleType'] == 0:
 
  299             mapForRegion = map[
'map']
 
  300             if map[
'mapType'] == 
'raster' and raster:
 
  301                 if mapForRegion == raster[
'raster']:
 
  302                     map[
'drawMap'] = 
True 
  303             elif map[
'mapType'] == 
'vector' and vector:
 
  304                 for vmap 
in vector[
'list']:
 
  305                     if mapForRegion == vmap[0]:
 
  306                         map[
'drawMap'] = 
True 
  310             if rasterLegend[
'rasterDefault'] 
and raster:
 
  311                 rasterLegend[
'raster'] = raster[
'raster']
 
  312                 if not rasterLegend[
'discrete']:
 
  314                     if rasterType == 
'CELL':
 
  315                         rasterLegend[
'discrete'] = 
'y' 
  317                         rasterLegend[
'discrete'] = 
'n' 
  320             height = rasterLegend.EstimateHeight(raster = rasterLegend[
'raster'], discrete = rasterLegend[
'discrete'], 
 
  321                                                  fontsize = rasterLegend[
'fontsize'],
 
  322                                                  cols = rasterLegend[
'cols'], 
 
  323                                                  height = rasterLegend[
'height'])
 
  324             width = rasterLegend.EstimateWidth(raster = rasterLegend[
'raster'], discrete = rasterLegend[
'discrete'], 
 
  325                                                fontsize = rasterLegend[
'fontsize'],
 
  326                                                cols = rasterLegend[
'cols'] , 
 
  327                                                width = rasterLegend[
'width'],
 
  329             rasterLegend[
'rect'] = Rect2D(x = float(rasterLegend[
'where'][0]), y = float(rasterLegend[
'where'][1]),
 
  330                                           width = width, height = height)
 
  335             for vmap 
in vectorMaps:
 
  336                 for i, each 
in enumerate(vector[
'list']):
 
  337                     if each[2] == vmap.id:
 
  339                         vector[
'list'][i][4] = vmap[
'label']
 
  340                         vector[
'list'][i][3] = vmap[
'lpos']
 
  342                 size = vectorLegend.EstimateSize(vectorInstr = vector, fontsize = vectorLegend[
'fontsize'],
 
  343                                                  width = vectorLegend[
'width'], cols = vectorLegend[
'cols'])                            
 
  344                 vectorLegend[
'rect'] = Rect2D(x = float(vectorLegend[
'where'][0]), y = float(vectorLegend[
'where'][1]),
 
  345                                               width = size[0], height = size[1])
 
  353             page[
'Orientation'] = orientation
 
  360         psmapInstrDict = dict(paper = [
'page'],
 
  365                               mapinfo = [
'mapinfo'],
 
  366                               scalebar = [
'scalebar'],
 
  368                               eps = [
'image', 
'northArrow'],
 
  371                               rectangle = [
'rectangle'],
 
  372                               vpoints = [
'vector', 
'vProperties'],
 
  373                               vlines = [
'vector', 
'vProperties'],
 
  374                               vareas = [
'vector', 
'vProperties'],
 
  375                               colortable = [
'rasterLegend'],
 
  376                               vlegend = [
'vectorLegend']
 
  379         myInstrDict = dict(page = PageSetup,
 
  386                            northArrow = NorthArrow,
 
  389                            rectangle = Rectangle,
 
  390                            rasterLegend = RasterLegend,
 
  391                            vectorLegend = VectorLegend,
 
  393                            vProperties = VProperties
 
  396         myInstruction = psmapInstrDict[instruction]
 
  398         for i 
in myInstruction:
 
  400             if i 
in (
'text', 
'vProperties', 
'image', 
'northArrow', 
'point', 
'line', 
'rectangle') 
or not instr:
 
  403                 if i == 
'vProperties':
 
  405                     newInstr = myInstrDict[i](id, subType = instruction[1:])
 
  406                 elif i 
in (
'image', 
'northArrow'):
 
  409                         if line.find(
"# north arrow") >= 0:
 
  411                     if i == 
'image' and commentFound 
or \
 
  412                        i == 
'northArrow' and not commentFound:
 
  414                     newInstr = myInstrDict[i](id, settings = self)
 
  416                     newInstr = myInstrDict[i](id)
 
  417                 ok = newInstr.Read(instruction, text, **kwargs)
 
  424                 ok = instr.Read(instruction, text, **kwargs)
 
  431         """!Sets region from file comment or sets current region in case of no comment""" 
  434         if regionInstruction:
 
  441                     map[
'mapType'] = 
'raster'    
  442                     map[
'map'] = cmd[1][
'rast']  
 
  443                 elif 'vect' in cmd[1]:
 
  445                     map[
'mapType'] = 
'vector'  
  446                     map[
'map'] = cmd[1][
'vect']  
 
  447                 elif 'region' in cmd[1]:
 
  449                     map[
'region'] = cmd[1][
'region']
 
  455             grass.del_temp_region()
 
  456             region = grass.region()
 
  457             grass.use_temp_region()    
 
  458             cmd = [
'g.region', region]
 
  460         GMessage(_(
"Instruction file will be loaded with following region: %s\n") % cmdString)
 
  464         except grass.ScriptError, e:
 
  465             GError(_(
"Region cannot be set\n%s") % e)
 
  470     """!Abtract class representing single instruction""" 
  482         """!Returns particular part of text instruction""" 
  486         for each 
in self.instruction.keys():
 
  495         """!Get current values""" 
  499         """!Set default values""" 
  502     def Read(self, instruction, text, **kwargs):
 
  503         """!Read instruction and save them""" 
  507         """!Converts text coordinates from percent of region to map coordinates""" 
  508         e, n = float(e.strip(
'%')), float(n.strip(
'%'))
 
  509         region = grass.region()
 
  510         N = region[
's'] + (region[
'n'] - region[
's']) / 100 * n
 
  511         E = region[
'w'] + (region[
'e'] - region[
'w']) / 100 * e
 
  515     """!Class representing virtual map""" 
  517         InstructionObject.__init__(self, id = id)
 
  527     """!Class representing map (instructions maploc, scale, border)""" 
  529         InstructionObject.__init__(self, id = id)
 
  533                                        rect = Rect2D(), scaleType = 0, scale = 
None, center = 
None,
 
  534                                        resolution = 300, border = 
'y', width = 1, color = 
'0:0:0') 
 
  543         region = grass.region()
 
  547                 comment = 
"# g.region rast=%s nsres=%s ewres=%s\n" % (map, region[
'nsres'], region[
'ewres'])
 
  549                 comment = 
"# g.region vect=%s\n" % (map)
 
  552             comment = 
"# g.region region=%s\n" % region
 
  554             comment = string.Template(
"# g.region n=$n s=$s e=$e w=$w rows=$rows cols=$cols \n").substitute(**region)
 
  562         instr += maplocInstruction
 
  567             scaleInstruction = 
"scale 1:%.0f" % (1/self.
instruction[
'scale'])
 
  568             instr += scaleInstruction
 
  571         borderInstruction = 
'' 
  573             borderInstruction = 
"border n" 
  575             borderInstruction = 
"border y\n" 
  576             borderInstruction += string.Template(
"    width $width\n    color $color\n").substitute(self.
instruction)
 
  577             borderInstruction += 
"    end" 
  578         instr += borderInstruction
 
  583     def Read(self, instruction, text, **kwargs):
 
  584         """!Read instruction and save information""" 
  585         if 'isRegionComment' in kwargs:
 
  586             isRegionComment = kwargs[
'isRegionComment']
 
  589         if instruction == 
'border':
 
  591                 if line.startswith(
'end'):
 
  594                     if line.split()[1].lower() 
in (
'n', 
'no', 
'none'):
 
  595                         instr[
'border'] = 
'n' 
  597                     elif line.split()[1].lower() 
in (
'y', 
'yes'):
 
  598                         instr[
'border'] = 
'y' 
  599                     elif line.startswith(
'width'):
 
  600                         instr[
'width'] = line.split()[1]
 
  601                     elif line.startswith(
'color'):
 
  602                         instr[
'color'] = line.split()[1]
 
  604                     GError(_(
"Failed to read instruction %s") % instruction)
 
  607         elif instruction == 
'scale':
 
  609                 scaleText = text.strip(
'scale ').
split(
':')[1]
 
  611                 if not isRegionComment:
 
  612                     instr[
'scaleType'] = 2 
 
  614                     instr[
'scaleType'] = 3
 
  616                 scale = 1/float(scaleText)
 
  617                 if abs(scale - self.
instruction[
'scale']) > (0.01 * scale):
 
  618                     GWarning(_(
"Scale has changed, old value: %(old)s\nnew value: %(new)s") % \
 
  619                                  { 
'old' : scale, 
'new' : self.
instruction[
'scale'] })
 
  620             except (ValueError, IndexError):
 
  621                 GError(_(
"Failed to read instruction %s.\nUse 1:25000 notation.") % instruction)
 
  624         elif instruction == 
'maploc':
 
  625             maploc = text.strip(
'maploc ').
split()
 
  627                 if  abs(self.
instruction[
'rect'].Get()[0] - float(maploc[0])) > 0.5 
or \
 
  628                         abs(self.
instruction[
'rect'].Get()[1] - float(maploc[1])) > 0.5:
 
  629                     GWarning(_(
"Map frame position changed, old value: %(old1)s %(old2)s\nnew value: %(new1)s %(new2)s") % \
 
  630                                  { 
'old1' : maploc[0], 
'old2' : maploc[1],
 
  635                 if  abs(self.
instruction[
'rect'].Get()[2] - float(maploc[2])) > 0.5 
or \
 
  636                         abs(self.
instruction[
'rect'].Get()[3] - float(maploc[3])) > 0.5:
 
  637                     GWarning(_(
"Map frame size changed, old value: %(old1)s %(old2)s\nnew value: %(new1)s %(new2)s") % \
 
  638                                  { 
'old1' : maploc[2], 
'old2' : maploc[3],
 
  641         self.instruction.update(instr)   
 
  645     """!Class representing page instruction""" 
  647         InstructionObject.__init__(self, id = id)
 
  651                                        Width = 8.268, Height = 11.693, Left = 0.5, Right = 0.5, Top = 1, Bottom = 1)
 
  657             instr = string.Template(
"paper\n    width $Width\n    height $Height\n").substitute(self.
instruction)
 
  659             instr = string.Template(
"paper $Format\n").substitute(self.
instruction)
 
  660         instr += string.Template(
"    left $Left\n    right $Right\n    bottom $Bottom\n    top $Top\n    end").substitute(self.
instruction)
 
  664     def Read(self, instruction, text, **kwargs):
 
  665         """!Read instruction and save information""" 
  667         self.
cats = [
'Width', 
'Height', 
'Left', 
'Right', 
'Top', 
'Bottom']
 
  668         self.
subInstr = dict(zip([
'width', 
'height', 
'left', 
'right', 
'top', 
'bottom'], self.
cats))
 
  670         if instruction == 
'paper': 
 
  672                 if line.startswith(
'paper'): 
 
  673                     if len(line.split()) > 1:
 
  674                         pformat = line.split()[1]
 
  675                         availableFormats = self.
_toDict(grass.read_command(
'ps.map', flags = 
'p',
 
  679                             instr[
'Format'] = pformat
 
  680                             for key, value 
in availableFormats[pformat].iteritems():
 
  681                                 instr[key] = float(value)
 
  684                             GError(_(
"Failed to read instruction %(file)s.\nUnknown format %(for)s") % \
 
  685                                        { 
'file' : instruction, 
'for' : format })
 
  690                         instr[
'Format'] = 
'custom' 
  692                 elif instr[
'Format'] == 
'custom' and not line.startswith(
'end'):
 
  695                         instr[self.
subInstr[text[0]]] = float(text[1])
 
  696                     except  (IndexError, KeyError):
 
  697                         GError(_(
"Failed to read instruction %s.") % instruction)
 
  700             if 'Orientation' in kwargs 
and kwargs[
'Orientation'] == 
'Landscape':
 
  701                 instr[
'Width'], instr[
'Height'] = instr[
'Height'], instr[
'Width']
 
  703             self.instruction.update(instr)
 
  706     def _toDict(self, paperStr):    
 
  709         for line 
in paperStr.strip().
split(
'\n'):
 
  710             d = dict(zip(self.
cats, line.split()[1:]))
 
  711             sizeDict[line.split()[0]] = d
 
  716     """!Class representing mapinfo instruction""" 
  718         InstructionObject.__init__(self, id = id)
 
  722                                        font = 
'Helvetica', fontsize = 10, color = 
'0:0:0', background = 
'none', 
 
  723                                        border = 
'none', rect = 
None)
 
  730         instr += string.Template(
"    font $font\n    fontsize $fontsize\n    color $color\n").substitute(self.
instruction)            
 
  731         instr += string.Template(
"    background $background\n    border $border\n").substitute(self.
instruction)  
 
  735     def Read(self, instruction, text):
 
  736         """!Read instruction and save information""" 
  740                 sub = line.split(
None,1)
 
  742                     instr[
'font'] = sub[1]
 
  743                 elif sub[0] == 
'fontsize':
 
  744                     instr[
'fontsize'] = int(sub[1])
 
  745                 elif sub[0] == 
'color':
 
  746                     instr[
'color'] = sub[1]
 
  747                 elif sub[0] == 
'background':
 
  748                     instr[
'background'] = sub[1]
 
  749                 elif sub[0] == 
'border':
 
  750                     instr[
'border'] = sub[1]
 
  751                 elif sub[0] == 
'where':
 
  752                     instr[
'where'] = float(sub[1].
split()[0]), float(sub[1].
split()[1])
 
  753         except (ValueError, IndexError):
 
  754             GError(_(
"Failed to read instruction %s") % instruction)
 
  756         self.instruction.update(instr)
 
  761         """!Estimate size to draw mapinfo""" 
  762         w = mapinfoDict[
'fontsize'] * 20 
 
  763         h = mapinfoDict[
'fontsize'] * 7
 
  764         width = self.unitConv.convert(value = w, fromUnit = 
'point', toUnit = 
'inch')
 
  765         height = self.unitConv.convert(value = h, fromUnit = 
'point', toUnit = 
'inch')
 
  766         return Rect2D(x = float(mapinfoDict[
'where'][0]), y = float(mapinfoDict[
'where'][1]),
 
  767                       width = width, height = height)
 
  770     """!Class representing text instruction""" 
  772         InstructionObject.__init__(self, id = id)
 
  775         self.
defaultInstruction = dict(text = 
"", font = 
"Helvetica", fontsize = 10, color = 
'black', background = 
'none',
 
  776                                        hcolor = 
'none', hwidth = 1, border = 
'none', width = 
'1', XY = 
True,
 
  777                                        where = (0,0), unit = 
'inch', rotate = 
None, 
 
  778                                        ref = 
"center center", xoffset = 0, yoffset = 0, east = 
None, north = 
None)
 
  783         text = self.
instruction[
'text'].replace(
'\n',
'\\n')
 
  785         instr += 
" %s\n" % text
 
  786         instr += (string.Template(
"    font $font\n    fontsize $fontsize\n    color $color\n").
 
  788         instr += string.Template(
"    hcolor $hcolor\n").substitute(self.
instruction)
 
  790             instr += string.Template(
"    hwidth $hwidth\n").substitute(self.
instruction)
 
  791         instr += string.Template(
"    border $border\n").substitute(self.
instruction)
 
  793             instr += string.Template(
"    width $width\n").substitute(self.
instruction)
 
  794         instr += string.Template(
"    background $background\n").substitute(self.
instruction)
 
  796             instr += string.Template(
"    ref $ref\n").substitute(self.
instruction)
 
  798             instr += string.Template(
"    rotate $rotate\n").substitute(self.
instruction)
 
  800             instr += (string.Template(
"    xoffset $xoffset\n    yoffset $yoffset\n").
 
  804             instr = instr.encode(
'latin1')
 
  805         except UnicodeEncodeError, err:
 
  807                 pos = str(err).
split(
'position')[1].
split(
':')[0].strip()
 
  811                 message = _(
"Characters on position %s are not supported " 
  812                             "by ISO-8859-1 (Latin 1) encoding " 
  813                             "which is required by module ps.map.") % pos
 
  815                 message = _(
"Not all characters are supported " 
  816                             "by ISO-8859-1 (Latin 1) encoding " 
  817                             "which is required by module ps.map.")
 
  818             GMessage(message = message)
 
  823     def Read(self, instruction, text, **kwargs):
 
  824         """!Read instruction and save information""" 
  825         map = kwargs[
'mapInstruction']
 
  829                 sub = line.split(
None, 1)[0]
 
  831                     e, n = line.split(
None, 3)[1:3]
 
  832                     if '%' in e 
and '%' in n:
 
  837                         instr[
'east'], instr[
'north'] = float(e), float(n)
 
  839                     instr[
'text'] = line.split(
None, 3)[3].
decode(
'latin_1')
 
  842                     instr[
'font'] = line.split(
None, 1)[1]
 
  843                 elif sub == 
'fontsize':
 
  844                     instr[
'fontsize'] = float(line.split(
None, 1)[1])
 
  846                     instr[
'color'] = line.split(
None, 1)[1]
 
  848                     instr[
'width'] = line.split(
None, 1)[1]
 
  849                 elif sub == 
'hcolor':
 
  850                     instr[
'hcolor'] = line.split(
None, 1)[1]
 
  851                 elif sub == 
'hwidth':
 
  852                     instr[
'hwidth'] = line.split(
None, 1)[1]
 
  853                 elif sub == 
'background':
 
  854                     instr[
'background'] = line.split(
None, 1)[1]
 
  855                 elif sub == 
'border':
 
  856                     instr[
'border'] = line.split(
None, 1)[1]
 
  858                     instr[
'ref'] = line.split(
None, 1)[1]
 
  859                 elif sub == 
'rotate':
 
  860                     instr[
'rotate'] = float(line.split(
None, 1)[1])
 
  861                 elif sub == 
'xoffset':
 
  862                     instr[
'xoffset'] = int(line.split(
None, 1)[1])
 
  863                 elif sub == 
'yoffset':
 
  864                     instr[
'yoffset'] = int(line.split(
None, 1)[1])
 
  865                 elif sub == 
'opaque':
 
  866                     if line.split(
None, 1)[1].lower() 
in (
'n', 
'none'):
 
  867                         instr[
'background'] = 
'none' 
  869             except(IndexError, ValueError):
 
  870                 GError(_(
"Failed to read instruction %s") % instruction)
 
  872         instr[
'where'] = 
PaperMapCoordinates(mapInstr = map, x = instr[
'east'], y = instr[
'north'], paperToMap = 
False)       
 
  873         self.instruction.update(instr)
 
  878     """!Class representing eps instruction - image""" 
  880         InstructionObject.__init__(self, id = id)
 
  885                                        east = 
None, north = 
None,
 
  886                                        rotate = 
None, scale = 1)
 
  892         epsfile = self.
instruction[
'epsfile'].replace(os.getenv(
'GISBASE'), 
"$GISBASE")
 
  895         instr += 
"    epsfile %s\n" % epsfile
 
  897             instr += string.Template(
"    rotate $rotate\n").substitute(self.
instruction)
 
  899             instr += string.Template(
"    scale $scale\n").substitute(self.
instruction)
 
  903     def Read(self, instruction, text, **kwargs):
 
  904         """!Read instruction and save information""" 
  905         mapInstr = kwargs[
'mapInstruction']
 
  909                 sub = line.split(
None, 1)[0]
 
  911                     e, n = line.split(
None, 3)[1:3]
 
  912                     if '%' in e 
and '%' in n:
 
  917                         instr[
'east'], instr[
'north'] = float(e), float(n)
 
  919                 elif sub == 
'epsfile':
 
  920                     epsfile = line.split(
None, 1)[1]
 
  921                     instr[
'epsfile'] = epsfile.replace(
"$GISBASE", os.getenv(
"GISBASE"))
 
  922                 elif sub == 
'rotate':
 
  923                     instr[
'rotate'] = float(line.split(
None, 1)[1])
 
  925                     instr[
'scale'] = float(line.split(
None, 1)[1])
 
  927             except(IndexError, ValueError):
 
  928                 GError(_(
"Failed to read instruction %s") % instruction)
 
  930         if not os.path.exists(instr[
'epsfile']):
 
  931             GError(_(
"Failed to read instruction %(inst)s: " 
  932                      "file %(file)s not found.") % { 
'inst' : instruction,
 
  933                                                      'file' : instr[
'epsfile'] })
 
  936         instr[
'epsfile'] = os.path.abspath(instr[
'epsfile'])
 
  938         if 'rotate' in instr:
 
  939             instr[
'size'] = 
BBoxAfterRotation(instr[
'size'][0], instr[
'size'][1], instr[
'rotate'])
 
  940         self.instruction.update(instr)
 
  944         w = self.unitConv.convert(value = instr[
'size'][0], fromUnit = 
'point', toUnit = 
'inch')
 
  945         h = self.unitConv.convert(value = instr[
'size'][1], fromUnit = 
'point', toUnit = 
'inch')
 
  946         instr[
'rect'] = Rect2D(x = float(instr[
'where'][0]), y = float(instr[
'where'][1]),
 
  948         self.instruction.update(instr)
 
  953         """!Change reference point (left top x center)""" 
  954         mapInstr = self.settings.FindInstructionByType(
'map')
 
  956             mapInstr = self.settings.FindInstructionByType(
'initMap')
 
  961                                            x = center[0], y = center[1], paperToMap = 
True)
 
  967             w = self.unitConv.convert(value = self.
instruction[
'size'][0], fromUnit = 
'point', toUnit = 
'inch')
 
  968             h = self.unitConv.convert(value = self.
instruction[
'size'][1], fromUnit = 
'point', toUnit = 
'inch')
 
  977         If eps, size is read from image header. 
  979         fileName = os.path.split(imagePath)[1]
 
  981         if os.path.splitext(fileName)[1].lower() == 
'.eps':
 
  982             bbInfo = 
"%%BoundingBox" 
  983             file = open(imagePath,
"r") 
  986                 line = file.readline()
 
  987                 if line.find(bbInfo) == 0:
 
  988                     w, h = line.split()[3:5]
 
  991             return float(w), float(h)
 
  993             img = wx.Image(fileName, type=wx.BITMAP_TYPE_ANY)
 
  994             return img.GetWidth(), img.GetHeight()
 
  997     """!Class representing eps instruction -- North Arrow""" 
  999         Image.__init__(self, id = id, settings = settings)
 
 1004         epsfile = self.
instruction[
'epsfile'].replace(os.getenv(
'GISBASE'), 
"$GISBASE")
 
 1007         instr += 
"# north arrow\n" 
 1008         instr += 
"    epsfile %s\n" % epsfile
 
 1010             instr += string.Template(
"    rotate $rotate\n").substitute(self.
instruction)
 
 1012             instr += string.Template(
"    scale $scale\n").substitute(self.
instruction)
 
 1017     """!Class representing point instruction""" 
 1019         InstructionObject.__init__(self, id = id)
 
 1023                                        color = 
'0:0:0', fcolor = 
'200:200:200',
 
 1024                                        rotate = 0, size = 10,
 
 1025                                        XY = 
True, where = (0,0), unit = 
'inch',
 
 1026                                        east = 
None, north = 
None)
 
 1031         instr = string.Template(
"point $east $north\n").substitute(self.
instruction)
 
 1032         instr += string.Template(
"    symbol $symbol\n").substitute(self.
instruction)
 
 1033         instr += string.Template(
"    color $color\n").substitute(self.
instruction)
 
 1034         instr += string.Template(
"    fcolor $fcolor\n").substitute(self.
instruction)
 
 1035         instr += string.Template(
"    rotate $rotate\n").substitute(self.
instruction)
 
 1036         instr += string.Template(
"    size $size\n").substitute(self.
instruction)
 
 1040     def Read(self, instruction, text, **kwargs):
 
 1041         """!Read instruction and save information""" 
 1042         mapInstr = kwargs[
'mapInstruction']
 
 1046                 sub = line.split(
None, 1)[0]
 
 1048                     e, n = line.split(
None, 3)[1:3]
 
 1049                     if '%' in e 
and '%' in n:
 
 1054                         instr[
'east'], instr[
'north'] = float(e), float(n)
 
 1056                 elif sub == 
'symbol':
 
 1057                     instr[
'symbol'] = line.split(
None, 1)[1]
 
 1058                 elif sub == 
'rotate':
 
 1059                     instr[
'rotate'] = float(line.split(
None, 1)[1])
 
 1061                     instr[
'size'] = float(line.split(
None, 1)[1])
 
 1062                 elif sub == 
'color':
 
 1063                     instr[
'color'] = line.split(
None, 1)[1]
 
 1064                 elif sub == 
'fcolor':
 
 1065                     instr[
'fcolor'] = line.split(
None, 1)[1]
 
 1068             except(IndexError, ValueError):
 
 1069                 GError(_(
"Failed to read instruction %s") % instruction)
 
 1072         self.instruction.update(instr)
 
 1074                                              y = self.
instruction[
'north'], paperToMap = 
False)
 
 1075         w = h = self.unitConv.convert(value = instr[
'size'], fromUnit = 
'point', toUnit = 
'inch')
 
 1076         instr[
'rect'] = Rect2D(x = float(instr[
'where'][0]) - w / 2, y = float(instr[
'where'][1] - h / 2),
 
 1077                                width = w, height = h)
 
 1078         self.instruction.update(instr)
 
 1083     """!Class representing line instruction""" 
 1085         InstructionObject.__init__(self, id = id)
 
 1089                                        where = [wx.Point2D(), wx.Point2D()],
 
 1090                                        east1 = 
None, north1 = 
None,
 
 1091                                        east2 = 
None, north2 = 
None)
 
 1096         instr = string.Template(
"line $east1 $north1 $east2 $north2\n").substitute(self.
instruction)
 
 1097         instr += string.Template(
"    color $color\n").substitute(self.
instruction)
 
 1098         instr += string.Template(
"    width $width\n").substitute(self.
instruction)
 
 1102     def Read(self, instruction, text, **kwargs):
 
 1103         """!Read instruction and save information""" 
 1104         mapInstr = kwargs[
'mapInstruction']
 
 1108                 sub = line.split(
None, 1)[0]
 
 1110                     e1, n1, e2, n2 = line.split(
None, 5)[1:5]
 
 1111                     if '%' in e1 
and '%' in n1 
and '%' in e2 
and '%' in n2:
 
 1112                         instr[
'east1'], instr[
'north1'] = self.
PercentToReal(e1, n1)
 
 1113                         instr[
'east2'], instr[
'north2'] = self.
PercentToReal(e2, n2)
 
 1115                         instr[
'east1'], instr[
'north1'] = float(e1), float(n1)
 
 1116                         instr[
'east2'], instr[
'north2'] = float(e2), float(n2)
 
 1118                 elif sub == 
'width':
 
 1119                     instr[
'width'] = float(line.split(
None, 1)[1])
 
 1120                 elif sub == 
'color':
 
 1121                     instr[
'color'] = line.split(
None, 1)[1]
 
 1123             except(IndexError, ValueError):
 
 1124                 GError(_(
"Failed to read instruction %s") % instruction)
 
 1127         self.instruction.update(instr)
 
 1129                                      y = self.
instruction[
'north1'], paperToMap = 
False)
 
 1131                                      y = self.
instruction[
'north2'], paperToMap = 
False)
 
 1132         instr[
'where'] = [wx.Point2D(e1, n1), wx.Point2D(e2, n2)]
 
 1133         instr[
'rect'] = Rect2DPP(instr[
'where'][0], instr[
'where'][1])
 
 1134         self.instruction.update(instr)
 
 1139     """!Class representing rectangle instruction""" 
 1141         InstructionObject.__init__(self, id = id)
 
 1145                                        east1 = 
None, north1 = 
None,
 
 1146                                        east2 = 
None, north2 = 
None)
 
 1151         instr = string.Template(
"rectangle $east1 $north1 $east2 $north2\n").substitute(self.
instruction)
 
 1152         instr += string.Template(
"    color $color\n").substitute(self.
instruction)
 
 1153         instr += string.Template(
"    fcolor $fcolor\n").substitute(self.
instruction)
 
 1154         instr += string.Template(
"    width $width\n").substitute(self.
instruction)
 
 1158     def Read(self, instruction, text, **kwargs):
 
 1159         """!Read instruction and save information""" 
 1160         mapInstr = kwargs[
'mapInstruction']
 
 1164                 sub = line.split(
None, 1)[0]
 
 1165                 if sub == 
'rectangle':
 
 1166                     e1, n1, e2, n2 = line.split(
None, 5)[1:5]
 
 1167                     if '%' in e1 
and '%' in n1 
and '%' in e2 
and '%' in n2:
 
 1168                         instr[
'east1'], instr[
'north1'] = self.
PercentToReal(e1, n1)
 
 1169                         instr[
'east2'], instr[
'north2'] = self.
PercentToReal(e2, n2)
 
 1171                         instr[
'east1'], instr[
'north1'] = float(e1), float(n1)
 
 1172                         instr[
'east2'], instr[
'north2'] = float(e2), float(n2)
 
 1174                 elif sub == 
'width':
 
 1175                     instr[
'width'] = float(line.split(
None, 1)[1])
 
 1176                 elif sub == 
'color':
 
 1177                     instr[
'color'] = line.split(
None, 1)[1]
 
 1178                 elif sub == 
'fcolor':
 
 1179                     instr[
'fcolor'] = line.split(
None, 1)[1]
 
 1182             except(IndexError, ValueError):
 
 1183                 GError(_(
"Failed to read instruction %s") % instruction)
 
 1186         self.instruction.update(instr)
 
 1188                                        y = self.
instruction[
'north1'], paperToMap = 
False)
 
 1190                                        y = self.
instruction[
'north2'], paperToMap = 
False)
 
 1191         instr[
'rect'] = Rect2DPP(wx.Point2D(e1, n1), wx.Point2D(e2, n2))
 
 1192         self.instruction.update(instr)
 
 1197     """!Class representing scalebar instruction""" 
 1199         InstructionObject.__init__(self, id = id)
 
 1203                                        unitsLength = 
'auto', unitsHeight = 
'inch',
 
 1204                                        length = 
None, height = 0.1, rect = 
None,
 
 1205                                        fontsize = 10, background = 
'y',
 
 1206                                        scalebar = 
'f', segment = 4, numbers = 1)
 
 1211         instr = string.Template(
"scalebar $scalebar\n").substitute(self.
instruction)
 
 1213         instr += string.Template(
"    length $length\n    units $unitsLength\n").substitute(self.
instruction)
 
 1214         instr += string.Template(
"    height $height\n").substitute(self.
instruction)
 
 1215         instr += string.Template(
"    segment $segment\n    numbers $numbers\n").substitute(self.
instruction)
 
 1216         instr += string.Template(
"    fontsize $fontsize\n    background $background\n").substitute(self.
instruction)
 
 1220     def Read(self, instruction, text, **kwargs):
 
 1221         """!Read instruction and save information""" 
 1222         scale = kwargs[
'scale']
 
 1226                 if line.startswith(
'scalebar'):
 
 1227                     if 'scalebar s' in line:
 
 1228                         instr[
'scalebar'] = 
's' 
 1230                         instr[
'scalebar'] = 
'f' 
 1231                 elif line.startswith(
'where'):
 
 1232                     instr[
'where'] = map(float, line.split()[1:3])
 
 1233                 elif line.startswith(
'length'):
 
 1234                     instr[
'length'] = float(line.split()[1])
 
 1235                 elif line.startswith(
'units'):
 
 1236                     if line.split()[1] 
in [
'auto', 
'meters', 
'kilometers', 
'feet', 
'miles', 
'nautmiles']:
 
 1237                         instr[
'unitsLength'] = line.split()[1]
 
 1238                 elif line.startswith(
'height'):
 
 1239                     instr[
'height'] = float(line.split()[1])
 
 1240                 elif line.startswith(
'fontsize'):
 
 1241                     instr[
'fontsize'] = float(line.split()[1])
 
 1242                 elif line.startswith(
'numbers'):
 
 1243                     instr[
'numbers'] = int(line.split()[1])
 
 1244                 elif line.startswith(
'segment'):
 
 1245                     instr[
'segment'] = int(line.split()[1])
 
 1246                 elif line.startswith(
'background'):
 
 1247                     if line.split()[1].strip().lower() 
in (
'y',
'yes'):
 
 1248                         instr[
'background'] = 
'y' 
 1249                     elif line.split()[1].strip().lower() 
in (
'n',
'no', 
'none'):
 
 1250                         instr[
'background'] = 
'n' 
 1251             except(IndexError, ValueError):
 
 1252                 GError(_(
"Failed to read instruction %s") % instruction)
 
 1255         self.instruction.update(instr)
 
 1263         """!Estimate size to draw scalebar""" 
 1265         if not units 
or units 
not in self.unitConv.getAllUnits():
 
 1267         if scalebarDict[
'unitsLength'] != 
'auto':
 
 1268             length = self.unitConv.convert(value = scalebarDict[
'length'], fromUnit = scalebarDict[
'unitsLength'], toUnit = 
'inch')
 
 1270             length = self.unitConv.convert(value = scalebarDict[
'length'], fromUnit = units, toUnit = 
'inch')
 
 1274         height = scalebarDict[
'height'] + 2 * self.unitConv.convert(value = scalebarDict[
'fontsize'], fromUnit = 
'point', toUnit = 
'inch')     
 
 1275         return (length, height)
 
 1278     """!Class representing colortable instruction""" 
 1280         InstructionObject.__init__(self, id = id)
 
 1284                                        discrete = 
None, type = 
None,
 
 1286                                        width = 
None, height = 
None, cols = 1, font = 
"Helvetica", fontsize = 10,
 
 1288                                        color = 
'black', tickbar = 
'n', range = 
False, min = 0, max = 0,
 
 1294         instr = 
"colortable y\n" 
 1295         instr += string.Template(
"    raster $raster\n").substitute(self.
instruction)
 
 1298             instr += string.Template(
"    width $width\n").substitute(self.
instruction)
 
 1299         instr += string.Template(
"    discrete $discrete\n").substitute(self.
instruction)
 
 1302                 instr += string.Template(
"    height $height\n").substitute(self.
instruction)
 
 1303             instr += string.Template(
"    tickbar $tickbar\n").substitute(self.
instruction)
 
 1305                 instr += string.Template(
"    range $min $max\n").substitute(self.
instruction)
 
 1307             instr += string.Template(
"    cols $cols\n").substitute(self.
instruction)
 
 1308             instr += string.Template(
"    nodata $nodata\n").substitute(self.
instruction)
 
 1309         instr += string.Template(
"    font $font\n    fontsize $fontsize\n    color $color\n")\
 
 1315     def Read(self, instruction, text, **kwargs):
 
 1316         """!Read instruction and save information""" 
 1318         instr[
'rLegend'] = 
True 
 1321                 if line.startswith(
'where'):
 
 1322                     instr[
'where'] = map(float, line.split()[1:3])
 
 1323                 elif line.startswith(
'font '):
 
 1324                     instr[
'font'] = line.split()[1]
 
 1325                 elif line.startswith(
'fontsize'):
 
 1326                     instr[
'fontsize'] = float(line.split()[1])
 
 1327                 elif line.startswith(
'color '):
 
 1328                     instr[
'color'] = line.split()[1]
 
 1329                 elif line.startswith(
'raster'):
 
 1330                     instr[
'raster'] = line.split()[1]
 
 1331                 elif line.startswith(
'width'):
 
 1332                     instr[
'width'] = float(line.split()[1])
 
 1333                 elif line.startswith(
'height'):
 
 1334                     instr[
'height'] = float(line.split()[1])
 
 1335                 elif line.startswith(
'cols'):
 
 1336                     instr[
'cols'] = int(line.split()[1])                    
 
 1337                 elif line.startswith(
'range'):
 
 1338                     instr[
'range'] = 
True 
 1339                     instr[
'min'] = float(line.split()[1])
 
 1340                     instr[
'max'] = float(line.split()[2])
 
 1341                 elif line.startswith(
'nodata'):
 
 1342                     if line.split()[1].strip().lower() 
in (
'y',
'yes'):
 
 1343                         instr[
'nodata'] = 
'y' 
 1344                     elif line.split()[1].strip().lower() 
in (
'n',
'no', 
'none'):
 
 1345                         instr[
'nodata'] = 
'n' 
 1346                 elif line.startswith(
'tickbar'):
 
 1347                     if line.split()[1].strip().lower() 
in (
'y',
'yes'):
 
 1348                         instr[
'tickbar'] = 
'y' 
 1349                     elif line.split()[1].strip().lower() 
in (
'n',
'no', 
'none'):
 
 1350                         instr[
'tickbar'] = 
'n' 
 1351                 elif line.startswith(
'discrete'):
 
 1352                     if line.split()[1].strip().lower() 
in (
'y',
'yes'):
 
 1353                         instr[
'discrete'] = 
'y' 
 1354                     elif line.split()[1].strip().lower() 
in (
'n',
'no', 
'none'):
 
 1355                         instr[
'discrete'] = 
'n'             
 1357             except(IndexError, ValueError):
 
 1358                 GError(_(
"Failed to read instruction %s") % instruction)
 
 1361         if 'raster' in instr:
 
 1362             instr[
'rasterDefault'] = 
False 
 1363             if 'discrete' not in instr:
 
 1365                 instr[
'type'] = rasterType
 
 1366                 if rasterType == 
'CELL':
 
 1367                     instr[
'discrete'] = 
'y' 
 1369                     instr[
'discrete'] = 
'n' 
 1372             instr[
'rasterDefault'] = 
True 
 1373         self.instruction.update(instr)
 
 1379         """!Estimate height to draw raster legend""" 
 1384                 height = self.unitConv.convert(value = fontsize * 10,
 
 1385                                                     fromUnit = 
'point', toUnit = 
'inch')
 
 1393             rinfo = grass.raster_info(raster)
 
 1394             if rinfo[
'datatype'] 
in (
'DCELL', 
'FCELL'):
 
 1395                 minim, maxim = rinfo[
'min'], rinfo[
'max']
 
 1396                 rows = ceil(maxim / cols )
 
 1398                 cat = grass.read_command(
'r.category', map = raster,
 
 1399                                     fs = 
':').strip().
split(
'\n')
 
 1400                 rows = ceil(float(len(cat)) / cols )
 
 1403             height = self.unitConv.convert(value =  1.5 * rows * fontsize, fromUnit = 
'point', toUnit = 
'inch')
 
 1407     def EstimateWidth(self, raster, discrete, fontsize, cols = None, width = None, paperInstr = None):
 
 1408         """!Estimate size to draw raster legend""" 
 1411             rinfo = grass.raster_info(raster)
 
 1412             minim, maxim = rinfo[
'min'], rinfo[
'max']
 
 1416                 width = self.unitConv.convert(value = fontsize * 2,
 
 1417                                                     fromUnit = 
'point', toUnit = 
'inch')
 
 1418             text = len(
max(str(minim), str(maxim), key = len))
 
 1419             textPart = self.unitConv.convert(value = text * fontsize / 2,
 
 1420                                                     fromUnit = 
'point', toUnit = 
'inch')
 
 1423         elif discrete == 
'y':
 
 1432                 paperWidth = paperInstr[
'Width'] - paperInstr[
'Right'] - paperInstr[
'Left']
 
 1433                 width = (paperWidth / cols) * (cols - 1) + 1
 
 1438     """!Class representing colortable instruction""" 
 1440         InstructionObject.__init__(self, id = id)
 
 1444                                                 defaultSize = 
True, width = 0.4, cols = 1, span = 
None,
 
 1445                                                 font = 
"Helvetica", fontsize = 10,
 
 1453         instr += string.Template(
"    font $font\n    fontsize $fontsize\n").substitute(self.
instruction)
 
 1454         instr += string.Template(
"    width $width\n    cols $cols\n").substitute(self.
instruction)
 
 1456             instr += string.Template(
"    span $span\n").substitute(self.
instruction)
 
 1457         instr += string.Template(
"    border $border\n").substitute(self.
instruction)  
 
 1461     def Read(self, instruction, text, **kwargs):
 
 1462         """!Read instruction and save information""" 
 1464         instr[
'vLegend'] = 
True 
 1467                 if line.startswith(
'where'):
 
 1468                     instr[
'where'] = map(float, line.split()[1:3])
 
 1469                 elif line.startswith(
'font '):
 
 1470                     instr[
'font'] = line.split()[1]
 
 1471                 elif line.startswith(
'fontsize'):
 
 1472                     instr[
'fontsize'] = float(line.split()[1])
 
 1473                 elif line.startswith(
'width'):
 
 1474                     instr[
'width'] = float(line.split()[1])
 
 1475                 elif line.startswith(
'cols'):
 
 1476                     instr[
'cols'] = int(line.split()[1]) 
 
 1477                 elif line.startswith(
'span'):
 
 1478                     instr[
'span'] = float(line.split()[1])
 
 1479                 elif line.startswith(
'border'):
 
 1480                     instr[
'border'] = line.split()[1]
 
 1482             except(IndexError, ValueError):
 
 1483                 GError(_(
"Failed to read instruction %s") % instruction)
 
 1486         self.instruction.update(instr)
 
 1491         """!Estimate size to draw vector legend""" 
 1495             width = fontsize/24.0
 
 1502         vectors = vectorInstr[
'list']
 
 1503         labels = [vector[4] 
for vector 
in vectors 
if vector[3] != 0]
 
 1504         extent = (len(
max(labels, key = len)) * fontsize / 2, fontsize)
 
 1505         wExtent = self.unitConv.convert(value = extent[0], fromUnit = 
'point', toUnit = 
'inch')
 
 1506         hExtent = self.unitConv.convert(value = extent[1], fromUnit = 
'point', toUnit = 
'inch')
 
 1507         w = (width + wExtent) * cols
 
 1508         h = len(labels) * hExtent / cols
 
 1514     """!Class representing raster instruction""" 
 1516         InstructionObject.__init__(self, id = id)
 
 1524         instr = string.Template(
"raster $raster").substitute(self.
instruction)
 
 1528         """!Read instruction and save information""" 
 1530         instr[
'isRaster'] = 
True 
 1532             map = text.split()[1]
 
 1534             GError(_(
"Failed to read instruction %s") % instruction)
 
 1537             info = grass.find_file(map, element = 
'cell')
 
 1538         except grass.ScriptError, e:
 
 1539             GError(message = e.value)
 
 1541         instr[
'raster'] = info[
'fullname']
 
 1544         self.instruction.update(instr)
 
 1548     """!Class keeps vector layers""" 
 1550         InstructionObject.__init__(self, id = id)
 
 1559     def Read(self, instruction, text, **kwargs):
 
 1560         """!Read instruction and save information""" 
 1564             if line.startswith(
'vpoints') 
or line.startswith(
'vlines') 
or line.startswith(
'vareas'):
 
 1566                 if line.startswith(
'vpoints'):
 
 1568                 elif line.startswith(
'vlines'):
 
 1570                 elif line.startswith(
'vareas'):
 
 1573                 vmap = line.split()[1]
 
 1575                     info = grass.find_file(vmap, element = 
'vector')
 
 1576                 except grass.ScriptError, e:
 
 1577                     GError(message = e.value)
 
 1579                 vmap = info[
'fullname']
 
 1583                 lpos = kwargs[
'vectorMapNumber']
 
 1585                 label = 
'('.join(vmap.split(
'@')) + 
')' 
 1587         instr = [vmap, subType, id, lpos, label] 
 
 1595     """!Class represents instructions vareas, vlines, vpoints""" 
 1597         InstructionObject.__init__(self, id = id)
 
 1602             dd = dict(subType  = 
'points', name = 
None, type = 
'point or centroid', connection = 
False, layer = 
'1',
 
 1603                         masked = 
'n', color = 
'0:0:0', width = 1,
 
 1604                         fcolor = 
'255:0:0', rgbcolumn = 
None, symbol = os.path.join(
'basic', 
'x'), eps = 
None,
 
 1605                         size = 5, sizecolumn = 
None, scale = 
None,
 
 1606                         rotation = 
False, rotate = 0, rotatecolumn = 
None, label = 
None, lpos = 
None)
 
 1608             dd = dict(subType = 
'lines', name = 
None, type = 
'line or boundary', connection = 
False, layer = 
'1',
 
 1609                         masked = 
'n', color = 
'0:0:0', hwidth = 1,
 
 1610                         hcolor = 
'none', rgbcolumn = 
None,
 
 1611                         width = 1, cwidth = 
None,
 
 1612                         style = 
'solid', linecap = 
'butt', label = 
None, lpos = 
None)
 
 1614             dd = dict(subType = 
'areas', name = 
None, connection = 
False, layer = 
'1',    
 
 1615                         masked = 
'n', color = 
'0:0:0', width = 1,
 
 1616                         fcolor = 
'none', rgbcolumn = 
None,
 
 1617                         pat = 
None, pwidth = 1, scale = 1, label = 
None, lpos = 
None)
 
 1624         vInstruction = string.Template(
"v$subType $name\n").substitute(dic)
 
 1626         if self.
subType in (
'points', 
'lines'):
 
 1627            vInstruction += string.Template(
"    type $type\n").substitute(dic) 
 
 1628         if dic[
'connection']:
 
 1629             vInstruction += string.Template(
"    layer $layer\n").substitute(dic)
 
 1630             if dic.has_key(
'cats'):
 
 1631                 vInstruction += string.Template(
"    cats $cats\n").substitute(dic)
 
 1632             elif dic.has_key(
'where'):
 
 1633                     vInstruction += string.Template(
"    where $where\n").substitute(dic)
 
 1634         vInstruction += string.Template(
"    masked $masked\n").substitute(dic)
 
 1636         vInstruction += string.Template(
"    color $color\n").substitute(dic)
 
 1637         if self.
subType in (
'points', 
'areas'):
 
 1638             if dic[
'color'] != 
'none':
 
 1639                 vInstruction += string.Template(
"    width $width\n").substitute(dic)
 
 1640             if dic[
'rgbcolumn']:
 
 1641                 vInstruction += string.Template(
"    rgbcolumn $rgbcolumn\n").substitute(dic)
 
 1642             vInstruction += string.Template(
"    fcolor $fcolor\n").substitute(dic)
 
 1644             if dic[
'rgbcolumn']:
 
 1645                 vInstruction += string.Template(
"    rgbcolumn $rgbcolumn\n").substitute(dic)
 
 1646             elif dic[
'hcolor'] != 
'none':
 
 1647                 vInstruction += string.Template(
"    hwidth $hwidth\n").substitute(dic)
 
 1648                 vInstruction += string.Template(
"    hcolor $hcolor\n").substitute(dic)
 
 1653                 vInstruction += string.Template(
"    symbol $symbol\n").substitute(dic)
 
 1655                 vInstruction += string.Template(
"    eps $eps\n").substitute(dic)
 
 1657                 vInstruction += string.Template(
"    size $size\n").substitute(dic)            
 
 1659                 vInstruction += string.Template(
"    sizecolumn $sizecolumn\n").substitute(dic)
 
 1660                 vInstruction += string.Template(
"    scale $scale\n").substitute(dic)
 
 1662                 if dic[
'rotate'] 
is not None:
 
 1663                     vInstruction += string.Template(
"    rotate $rotate\n").substitute(dic)
 
 1665                     vInstruction += string.Template(
"    rotatecolumn $rotatecolumn\n").substitute(dic)
 
 1668             if dic[
'pat'] 
is not None:
 
 1669                 patternFile = dic[
'pat'].replace(os.getenv(
"GISBASE"), 
"$GISBASE")
 
 1670                 vInstruction += 
"    pat %s\n" % patternFile
 
 1671                 vInstruction += string.Template(
"    pwidth $pwidth\n").substitute(dic)
 
 1672                 vInstruction += string.Template(
"    scale $scale\n").substitute(dic)
 
 1675             if dic[
'width'] 
is not None:
 
 1676                 vInstruction += string.Template(
"    width $width\n").substitute(dic)
 
 1678                 vInstruction += string.Template(
"    cwidth $cwidth\n").substitute(dic)
 
 1679             vInstruction += string.Template(
"    style $style\n").substitute(dic)
 
 1680             vInstruction += string.Template(
"    linecap $linecap\n").substitute(dic)
 
 1682         vInstruction += string.Template(
"    label $label\n    lpos $lpos\n").substitute(dic)
 
 1684         vInstruction += 
"    end" 
 1686             vInstruction = vInstruction.encode(
'Latin_1')
 
 1687         except UnicodeEncodeError, err:
 
 1689                 pos = str(err).
split(
'position')[1].
split(
':')[0].strip()
 
 1693                 message = _(
"Characters on position %s are not supported " 
 1694                             "by ISO-8859-1 (Latin 1) encoding " 
 1695                             "which is required by module ps.map.") % pos
 
 1697                 message = _(
"Not all characters are supported " 
 1698                             "by ISO-8859-1 (Latin 1) encoding " 
 1699                             "which is required by module ps.map.")
 
 1700             GMessage(message = message)
 
 1704     def Read(self, instruction, text, **kwargs):
 
 1705         """!Read instruction and save information""" 
 1708             info = grass.find_file(name = text[0].
split()[1], element = 
'vector')
 
 1709         except grass.ScriptError, e:
 
 1710             GError(message = e.value)
 
 1712         instr[
'name'] = info[
'fullname']
 
 1714         instr[
'connection'] = 
True 
 1718             instr[
'connection'] = 
False 
 1721         if text[0].startswith(
'vpoints'):
 
 1722             for line 
in text[1:]:
 
 1723                 if line.startswith(
'type'):
 
 1725                     if line.find(
'point') != -1:
 
 1727                     if line.find(
'centroid') != -1:
 
 1728                         tp.append(
'centroid')
 
 1729                     instr[
'type'] = 
' or '.join(tp)
 
 1730                 elif line.startswith(
'fcolor'):
 
 1731                     instr[
'fcolor'] = line.split()[1]
 
 1732                 elif line.startswith(
'rgbcolumn'):
 
 1733                     instr[
'rgbcolumn'] = line.split()[1]
 
 1734                 elif line.startswith(
'symbol'):
 
 1735                     instr[
'symbol'] = line.split()[1]
 
 1736                 elif line.startswith(
'eps'):
 
 1737                     instr[
'eps'] = line.split()[1]
 
 1738                 elif line.startswith(
'size '):
 
 1739                     instr[
'size'] = line.split()[1]
 
 1740                 elif line.startswith(
'sizecolumn'):
 
 1741                     instr[
'size'] = 
None 
 1742                     instr[
'sizecolumn'] = line.split()[1]
 
 1743                 elif line.startswith(
'scale '):
 
 1744                     instr[
'scale'] = float(line.split()[1])
 
 1745                 elif line.startswith(
'rotate '):
 
 1746                     instr[
'rotation'] = 
True 
 1747                     instr[
'rotate'] = line.split()[1]
 
 1748                 elif line.startswith(
'rotatecolumn'):
 
 1749                     instr[
'rotatecolumn'] = line.split()[1]
 
 1750                     instr[
'rotation'] = 
True 
 1751                     instr[
'rotate'] = 
None 
 1754         elif text[0].startswith(
'vlines'):
 
 1755             for line 
in text[1:]:
 
 1756                 if line.startswith(
'type'):
 
 1758                     if line.find(
'line') != -1:
 
 1760                     if line.find(
'boundary') != -1:
 
 1761                         tp.append(
'boundary')
 
 1762                     instr[
'type'] = 
' or '.join(tp)
 
 1763                 elif line.startswith(
'hwidth'):
 
 1764                     instr[
'hwidth'] = float(line.split()[1])
 
 1765                 elif line.startswith(
'hcolor'):
 
 1766                     instr[
'hcolor'] = line.split()[1]
 
 1767                 elif line.startswith(
'rgbcolumn'):
 
 1768                     instr[
'rgbcolumn'] = line.split()[1]                    
 
 1769                 elif line.startswith(
'cwidth'):
 
 1770                     instr[
'cwidth'] = float(line.split()[1])
 
 1771                     instr[
'width'] = 
None 
 1772                 elif line.startswith(
'style'):
 
 1773                     instr[
'style'] = line.split()[1]       
 
 1774                 elif line.startswith(
'linecap'):
 
 1775                     instr[
'linecap'] = line.split()[1]
 
 1777         elif text[0].startswith(
'vareas'):
 
 1778             for line 
in text[1:]:
 
 1779                 if line.startswith(
'fcolor'):
 
 1780                     instr[
'fcolor'] = line.split()[1]    
 
 1781                 elif line.startswith(
'pat'):
 
 1782                     patternFile = line.split()[1]
 
 1783                     instr[
'pat'] = patternFile.replace(
"$GISBASE", os.getenv(
"GISBASE"))
 
 1784                 elif line.startswith(
'pwidth'):
 
 1785                     instr[
'pwidth'] = float(line.split()[1])
 
 1786                 elif line.startswith(
'scale'):
 
 1787                     instr[
'scale'] = float(line.split()[1])
 
 1791         for line 
in text[1:]:
 
 1792             if line.startswith(
'lpos'):
 
 1793                 instr[
'lpos'] = int(line.split()[1])
 
 1794             elif line.startswith(
'label'):
 
 1795                 instr[
'label'] = line.split(
None, 1)[1].
decode(
'latin_1')
 
 1796             elif line.startswith(
'layer'):
 
 1797                 instr[
'layer'] = line.split()[1]
 
 1798             elif line.startswith(
'masked'):
 
 1799                 if line.split()[1].lower() 
in (
'y', 
'yes'):
 
 1800                     instr[
'masked'] = 
'y' 
 1802                     instr[
'masked'] = 
'n' 
 1803             elif line.startswith(
'color'):
 
 1804                 instr[
'color'] = line.split()[1]
 
 1805             elif line.startswith(
'rgbcolumn'):
 
 1806                 instr[
'rgbcolumn'] = line.split()[1] 
 
 1807             elif line.startswith(
'width'):
 
 1808                 instr[
'width'] = float(line.split()[1])
 
 1810         if 'label' not in instr:
 
 1811             instr[
'label'] = 
'('.join(instr[
'name'].
split(
'@')) + 
')' 
 1812         if 'lpos' not in instr:
 
 1813             instr[
'lpos'] = kwargs[
'vectorMapNumber']
 
 1814         self.instruction.update(instr)
 
def CmdToTuple
Convert command list to tuple for gcmd.RunCommand() 
 
def Read
Read instruction and save information. 
 
def Read
Read instruction and save information. 
 
def Read
Read instruction and save information. 
 
def projInfo
Return region projection and map units information, taken from render.py. 
 
def getRasterType
Returns type of raster map (CELL, FCELL, DCELL) 
 
def PaperMapCoordinates
Converts paper (inch) coordinates <-> map coordinates. 
 
def GetInstruction
Get current values. 
 
def EstimateHeight
Estimate height to draw raster legend. 
 
Class representing colortable instruction. 
 
def Read
Read instruction and save them. 
 
def __str__
Returns particular part of text instruction. 
 
def __contains__
Test if instruction is included. 
 
def Read
Read instruction and save information. 
 
Class representing scalebar instruction. 
 
def ChangeRefPoint
Change reference point (left top x center) 
 
def Read
Read instruction and save information. 
 
Class representing text instruction. 
 
def SetRegion
Sets region from file comment or sets current region in case of no comment. 
 
def Read
Read instruction and save information. 
 
def SetResolution
If resolution is too high, lower it. 
 
def Read
Read instruction and save information. 
 
Class representing rectangle instruction. 
 
def EstimateRect
Estimate size to draw mapinfo. 
 
def Read
Read instruction and save information. 
 
def Read
Read instruction and save information. 
 
def Read
Read instruction and save information. 
 
def GetImageOrigSize
Get image size. 
 
def split
Platform spefic shlex.split. 
 
def EstimateSize
Estimate size to draw scalebar. 
 
def FindInstructionByType
Find instruction(s) with the given type. 
 
Class representing map (instructions maploc, scale, border) 
 
def BBoxAfterRotation
Compute bounding box or rotated rectangle. 
 
def __str__
Returns text for instruction file. 
 
Class representing virtual map. 
 
Class keeps vector layers. 
 
utilities for wxpsmap (classes, functions) 
 
Class representing mapinfo instruction. 
 
Class representing line instruction. 
 
def SetInstruction
Set default values. 
 
def Read
Read instruction and save information. 
 
def AddInstruction
Add instruction. 
 
def Read
Read instruction and save information. 
 
def __delitem__
Delete instruction. 
 
Class representing eps instruction - image. 
 
Misc utilities for wxGUI. 
 
Abtract class representing single instruction. 
 
def Read
Read instruction and save information. 
 
Class representing point instruction. 
 
def GetMapBounds
Run ps.map -b to get information about map bounding box. 
 
def EstimateWidth
Estimate size to draw raster legend. 
 
Class representing eps instruction – North Arrow. 
 
Class representing page instruction. 
 
Class representing raster instruction. 
 
Class represents instructions vareas, vlines, vpoints. 
 
def Read
Read instruction and save information. 
 
def Read
Reads instruction file and creates instruction objects. 
 
Class representing colortable instruction. 
 
def PercentToReal
Converts text coordinates from percent of region to map coordinates. 
 
Class which represents instruction file. 
 
def EstimateSize
Estimate size to draw vector legend. 
 
def RunCommand
Run GRASS command.