Opened 16 years ago
Closed 16 years ago
#409 closed enhancement (duplicate)
v.label.editor
Reported by: | neuba | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 6.4.0 |
Component: | Default | Version: | unspecified |
Keywords: | Cc: | ||
CPU: | Unspecified | Platform: | Unspecified |
Description
This is a python for editing and remove file item. Please is this a new for grass?
#!/usr/bin/env python ############################################################################ # # MODULE: v.label.editor # AUTHOR: Neuba Danho Fursy Rodelec (danho_f@yahoo.fr) # Ivory Coast' # # # PURPOSE: simple label file editor to modify individual label item parameters and create a new label file # ( # COPYRIGHT: (c) 2008 Neuba Danho, and the GRASS Development Team # This program is free software under the GNU General Public # License (>=v2). Read the file COPYING that comes with GRASS # for details. # ############################################################################# #%Module #% description: Edit,remove individual label item #% keywords: vector, area, dissolve #%End #%flag #%key:i #%description: get label information #%end #%flag #%key:r #%description: remove label item #%end #%option #%key: filename #%type: string #%required: yes #%description: the label filename #%end #%option #%key: parameter #%type: string #%required: yes #%description: Parameter to modify #%end #%option #%key: value #%type: string #%required: no #%description: The new value #%end #%option #%key: idlab #%type: string #%required: yes #%description: the label text #%end #%option #%key: output #%type: string #%required: no #%description: the output filename #%end import grass import sys import string as st import os __version__="1.0" def led(): ge= grass.gisenv() gdb=ge['GISDBASE'] loc=ge['LOCATION_NAME'] maps=ge['MAPSET'] paint='paint' lp='labels' filename=options['filename'] labpath=os.path.join(gdb,loc,maps,paint,lp) info=flags['i'] remove=flags['r'] idlab=options['idlab'] value=options['value'] para=options['parameter'] output=options['output'] parlist=('east','north','opaque','color','border','hwidth','yoffset','width','hcolor','fontsize','background','font','ref','xoffset','rotation') if para not in parlist: print 'paramater not in list' sys.exit() if os.path.isdir(labpath)==True: fname=os.path.join(labpath,filename) data=labelItem(fname) else: fname=os.path.join(labpath,filename) print faname+': no such file or directory' sys.exit() if info: if para: grass.message(data[idlab][para]) else: grass.message(data[idlab]) else: if output: outfile=output else: outfile=filename if remove: del data[idlab] grass.message( idlab+ ': deleted from '+filename) else: labtomodify=data[idlab] labtomodify[para]=value grass.message( para+ ': set to '+labtomodify[para]+' for label: '+idlab) data[idlab]=labtomodify createlabfile(data,labpath,outfile) def createlabfile(x,lpx,op): text='' for k in x.keys(): val=x[k] for kv in val.keys(): text=text+kv+': '+val[kv]+'\n' text=text+'text: '+k+'\n\n' fx=open(os.path.join(lpx,op),'w') fx.write(text) fx.close() def labelItem(fx): f=open(fx,'r') data={} par={} for l in f.readlines(): sl=l.split(':') if l.find(':')>-1: if sl[0]=='text': kr=st.strip(sl[1][0:len(sl[1])-1],' ') data[kr]=par par={} else: val=st.strip(sl[1][0:len(sl[1])-1],' ') par[sl[0]]=val return data f.close() if __name__=='__main__': options,flags=grass.parser() led()
Note:
See TracTickets
for help on using tickets.
continued in #410