[GRASSLIST:145] s.label -- MIA?

Matej Cepl cepl at surfbest.net
Fri May 23 00:47:47 EDT 2003


Hi,

I am fairly new to GRASS (and GIS as such -- being lawyer and 
sociologist, I didn't need maps so far :-), so this may be silly 
question. I need to create EPS map from vector file (something similar 
to this map of Boston[1]). Manpage of ps.map tells me, that I need 
labels to display names of towns, but the ``user'' interface of p.label 
seems to me too dreadfull to even think about using it. I found 
a manpage for program s.label, which seems to be able to help me. In 
order to import vector area categories and their labels to sites, I have 
even created a Python script (see below; would you be so kind and 
comment on it, please? I am really newbie in GRASS and not the best 
programmer in the first place). However, when looking for the program 
itself, I found that it is not present neither in the binary tarball of 
grass 5.0.2 (April 2003) I have got yesterday from grass.ibiblio.org, 
nor in the Debian package of 5.0.0pre4 I used before.

Could anybody help me and locate a copy of it (probably the best would 
be a binary version for the above mentioned binary package, because I do 
not have sources and enough space on harddisk to compile whole GRASS, 
but if only sources are available, then I will do it)? Thanks.

   Have a nice day,

      Matej Cepl


[1] http://www.ceplovi.cz/tmp/BostonNghbrds.eps
-- 
Matej Cepl,
GPG Finger: 89EF 4BC6 288A BF43 1BAB  25C3 E09F EF25 D964 84AC
138 Highland Ave. #10, Somerville, Ma 02143, (617) 623-1488


#!/usr/bin/env python
"""
v.to.site.area -- export area label points and category labels 
into site.

Copyright (c) 2003 Matej Cepl <matej at ceplovi.cz>
   
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

$Id: v.to.site.area,v 1.2 2003/05/23 03:26:31 matej Exp $
"""

from sys import exit,argv,stderr
from os import environ,popen,sep
from os.path import abspath
from string import split

def errorexit(msg,exitflag):
	stderr.write(msg)
	stderr.write("\nUse --help to see valid options and arguments\n")
	exit(exitflag)

if len(environ["GISBASE"])==0:
	print "You must be in GRASS GIS to run this program."
	exit(1)

inmap=argv[1]
#lazy to do proper parsin :-)
try:
	p=popen('g.gisenv get=GISDBASE','r')
	location=p.read()[0:-1]
	p=popen('g.gisenv get=LOCATION_NAME','r')
	location=location+sep+p.read()[0:-1]
	p=popen('g.gisenv get=MAPSET','r')
	location=location+sep+p.read()[0:-1]
	p.close()
except:
	errorexit("Cannot get value of the current LOCATION.",10)

inlabfilename=abspath(location+'/dig_cats/'+inmap)
incatfilename=abspath(location+'/dig_att/'+inmap)

# Read category label file
try:
	inlabfile=open(inlabfilename,'r')
	inlab=inlabfile.readlines()
	inlabfile.close()
except:
	errorexit("Cannot read category label file.",5)

# Read category attribute file
try:
	incatfile=open(incatfilename,'r')
	incat=incatfile.readlines()
	incatfile.close()
except:
	errorexit("Cannot read category attribute file.",5)

# Open site file
outfilename=abspath(location+'/site_lists/'+inmap)
try:
	outfile=open(outfilename,'w')
except:
	errorexit("Cannot open output site file.",5)

cats={}
# east,north
for catno in range(len(incat)):
	line=split(incat[catno])
	if line[0]=="A":
		cats[str(line[3])]=line[1],line[2]

# Prepare reading category label file
line=split(inlab[0])
labnomax=line[1]
if labnomax==1:
	raise EOFError, "No labels available."
title=inlab[1][0:-1]
if len(title)!=0:
	title="-"+title

#Print the header of file
outfile.write("#generated by "+argv[0]+"\n")
outfile.write("name|"+inmap+title+"\n")
outfile.write("desc|sites of "+inmap+"\n")
outfile.write("labels|Easting|Northing|%No Label\n")

for labno in range(4,len(inlab)):
	line=split(inlab[labno],':')
	id=str(line[0])
	meow=cats[id]
	label=str(line[1])
	outfile.write(meow[0]+"|"+meow[1]+"|#"+id+" @"+label)

try:
	outfile.close()
except:
	errorexit("Cannot close output site file.",5)

# vim:fo=trocq:noet:ts=4:sw=4:cin:




More information about the grass-user mailing list