[GRASS-user] access vertices coordinates of a line from Python

Martin Laloux martin.laloux at gmail.com
Sun Jun 24 08:04:49 PDT 2012


 This question was asked in
http://gis.stackexchange.com/questions/28061/how-to-access-vector-coordinates-in-grass-gis-from-python/28100#28100and
I propose a solution with
*v.out.ascii.*

But is there a better solution ?

My solution (a single line -> L 7 1)

    test = grass.read_command("v.out.ascii", input="linevector",
format="standard")
    result = test.split("\n")
    import re
    for line in result:
         if re.findall(r'^.[0-9]+\.',line):
                print line

     206643.21517601 125181.18058576
     201007.33432923 121517.8555206
     208615.77587567 118699.91687157
     199034.77765775 115036.59058769
     200725.54321492 111936.8560102
     192835.30987687 107428.14794157
     192835.30987687 107428.14794157

and

    coords = []
    for line in result:
       if re.findall(r'^.[0-9]+\.',line):
           coords.append(line.strip().split(" "))

    [['206643.21517601', '125181.18058576'], ['201007.33432923',
'121517.8555206'], ['208615.77587567', '118699.91687157'],
['199034.77765775', '115036.59058769'], ['200725.54321492',
'111936.8560102'], ['192835.30987687', '107428.14794157'],
['192835.30987687', '107428.14794157'], ['206643.21517601',
'125181.18058576'], ['201007.33432923', '121517.8555206'],
['208615.77587567', '118699.91687157'], ['199034.77765775',
'115036.59058769'], ['200725.54321492', '111936.8560102'],
['192835.30987687', '107428.14794157'], ['192835.30987687',
'107428.14794157']]

If you want, you can create a new point layer from the coordinates
(solution of Yvan Marchesini in
http://osgeo-org.1560.n6.nabble.com/How-one-can-find-the-starting-and-end-point-of-a-line-in-a-vector-file-or-how-one-can-connect-two-lie-td4542252.html
)
-------------- section suivante --------------
Une pi?ce jointe HTML a ?t? nettoy?e...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20120624/fc4e1fda/attachment.html>


More information about the grass-user mailing list