[GRASS-user] loading points from python shell
Anna Petrášová
kratochanna at gmail.com
Mon Nov 24 09:19:06 PST 2014
On Sun, Nov 23, 2014 at 6:20 PM, Arighna <roy.arighna at gmail.com> wrote:
> Hi,
>
>
>
> I am fetching points from URL in a python script as a dictionary and
> creating json file from it. Then loading points in GRASS map from the file.
>
> Can we load points in a vector map directly from python scripts; as we
> have a python shell in GRASS.
>
You would use v.in.ascii, if you have them in a file in csv format like
x,y,attr1,attr2,... and you can choose separator:
import grass.script.core as gcore
gcore.run_command('v.in.ascii', input='path/to/file', output='mymap', x=1,
y=2, separator=',')
or if you have them as string:
gcore.write_command('v.in.ascii', input='-', stdin=points_string,
output='mymap', x=1, y=2, separator)
there are other parameters, you can also upload attributes this way by
specifying columns, more in the manual page:
http://grass.osgeo.org/grass71/manuals/v.in.ascii.html
I am not sure if you run the Python script from GRASS (that's the usual,
simple case), if not there is a way to run it outside of GRASS session but
it's more complicated, see
http://grasswiki.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly
Anna
>
> Arighna
>
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20141124/7b59eab4/attachment-0001.html>
More information about the grass-user
mailing list