[GRASS-user] Python script in grass

Hi List,
please a little help with my python script. I don't know how to say in python:

echo "589541.859564|4473239.49338|9999" | v.in.ascii output=outlet

Thank you
Cheers

--
Eng. Margherita Di Leo
Ph.D. Candidate
Methods and Technologies for Environmental Monitoring
Department of Environmental Engineering and Physics (DIFA)

University of Basilicata Campus Macchia Romana
85100 - Potenza Italy

Office: +39-0971205363
Fax: +39-0971205160

Ciao,

What you can do, is write your point into a temporary file and then read in again this file using v.in.ascii command. For example something like this:

import grass.script as grass
import os

# For temporary files
import tempfile as pytempfile

# For deleting temp directory
import shutil

# Create temporary directory
tmpdir = pytempfile.mkdtemp()
tmp_vec = tmpdir + '/vec.ascii'

fp = open(tmp_points, 'w')
fp.write('589541.859564|4473239.49338|9999')
fp.close()

# Read in your point
grass.run_command("v.in.ascii", input=tmp_vec, output=outmap, fs='|', skip=0, x=1, y=2, cat=3, columns='x double precision, y double precision, cat int')

# Remove the temporary directory and all the files in it
shutil.rmtree(tmpdir)

Of course, some error checking would be nice...

HTH
Christian

On 6 févr. 2010, at 10:55, Margherita Di Leo wrote:

Hi List,
please a little help with my python script. I don't know how to say in python:

echo "589541.859564|4473239.49338|9999" | v.in.ascii output=outlet

Thank you
Cheers

--
Eng. Margherita Di Leo
Ph.D. Candidate
Methods and Technologies for Environmental Monitoring
Department of Environmental Engineering and Physics (DIFA)

University of Basilicata Campus Macchia Romana
85100 - Potenza Italy

Office: +39-0971205363
Fax: +39-0971205160

_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Margherita Di Leo wrote:

please a little help with my python script. I don't know how to say in
python:

echo "589541.859564|4473239.49338|9999" | v.in.ascii output=outlet

To do it using the grass.script module:

  grass.write_command('v.in.ascii', output = 'outlet',
                      stdin = "589541.859564|4473239.49338|9999")

or (more suitable when you want to feed a lot of data):

  p = grass.feed_command('v.in.ascii', output = 'outlet')
  p.stdin.write("589541.859564|4473239.49338|9999")
  p.stdin.close()
  p.wait()

--
Glynn Clements <glynn@gclements.plus.com>