Hi Johannes,
On Mon, Jun 17, 2013 at 1:24 PM, Johannes Radinger
<johannesradinger@gmail.com> wrote:
I want to create a point via python at a specific location using the
v.in.ascii command. How can I also specify the colum names or how can a
header be used in combination with the standard input. As it is only one
single point I don't want to create a txt file containing the header and the
info. I tried following in GRASS7:
I think that some of your parameters are not correct...
{{{
from grass.pygrass.modules import Module
ASCII = """cat,X,Y,Name
1,635828.3,223067.0,pub
2,643553.4,220711.5,pizzeria"""
COLS = 'cat int, x double precision, y double precision, name varchar(10)'
vina = Module('v.in.ascii', input='-', output='pnt__v_in_ascii',
format='point', separator=',', skip=1, x=2, y=3, cat=1,
columns=COLS, stdin_=ASCII, overwrite=True,
finish_=True)
}}}
Mostly with the same parameters you can run grass.write_command.
But If you are looking for a tool to "play" and experiment I highly
suggest pygrass:
{{{
from grass.pygrass.vector import VectorTopo
from grass.pygrass.geometry import Point
new = VectorTopo('mynewvect')
COLS = [(u'cat', 'INTEGER PRIMARY KEY'), (u'name', 'VAR CHAR')]
new.open('w', tab_cols=COLS)
new.write(Point(635828.3, 223067.0), ('pub', ))
new.write(Point(643553.4, 220711.5), ('restaurant', ))
new.close()
new.open('r')
new.cat(1).attrs['name'] # return: pub
new.close()
}}}
If you are interested please have a look of the ipython notebook:
https://github.com/zarch/workshop-pygrass
you have just to clone, and from a running session of grass enter in
the directory and launch:
ipython notebook
to have a briefly introduction to the library.
Have fun!
Pietro