[GRASS-user] GRASS and the Python geospatial modules (Shapely, PySAL, ...)

gene martin.laloux at gmail.com
Sat Jun 30 12:06:45 PDT 2012


One thing that is not enough highlighted is the ability to use  the Python
geospatial modules like Shapely of Sean Gillies (
http://pypi.python.org/pypi/Shapely/1.2.15
http://pypi.python.org/pypi/Shapely/1.2.15 ) or PySAL (
http://pypi.python.org/pypi/pysal/1.3.0
http://pypi.python.org/pypi/pysal/1.3.0 ) in GRASS GIS. It brings very
interesting complementary treatments.

In the Python shell:

import grass.script as grass
gisbase = os.environ['GISBASE']
gisdb="/Users/me/grassdata"
location="geol"
mapset="faults"
import grass.script.setup as gsetup
gsetup.init(gisbase, gisdb, location, mapset)
vector="mypoints"
mypt = grass.read_command("v.to.db", flags="p", map=vector, type="point",
option="coor", units="meters", quiet="True")
mypt = mypt.split("\n")
xyz = []
for i in mypt:
      xyz.append(mypt[i].split("|")

and now it is possible to use Shapely

 from shapely.geometry import Point
 point = Point(float(xyz[0][1]),float(xyz[0][2]))
 point.wkt
'POINT (115421.3014247910032282 116774.7652432390023023)'
 
and all the functions of Shapely (
http://toblerity.github.com/shapely/manual.html
http://toblerity.github.com/shapely/manual.html )

The same treatments are also possible with PySAL 

By adjusting the paths, it is also possible to (yes in Linux and Mac OS X,
no in Windows ?)
   - use qgis.core in GRASS 
   - use grass.script and PyQgis modules in the Python shell without
launching GRASS GIS and Quantum GIS.

Great for Python programmers, many thanks to all GRASS developers ! 

I am working now in the conversion of results of Shapely or PySAL in GRASS
vectors (with v.out.ascii and grass.tempfile()) in pure Python. Another
solution is to create a shapefile with ogr or shapefile (
http://pypi.python.org/pypi/pyshp/1.1.4
http://pypi.python.org/pypi/pyshp/1.1.4 ) module of Joel Lawhead and import
it into GRASS (also in Python)

Some people working with Python in GRASS (treatments, not interface)
- 
http://code.google.com/p/postgis-grass-r-py/wiki/0003_01_PythonForGrassGis
http://code.google.com/p/postgis-grass-r-py/wiki/0003_01_PythonForGrassGis  
-  http://digilander.libero.it/antonioall/index.html
http://digilander.libero.it/antonioall/index.html  (in Italian)
-  http://www.portailsig.org/ http://www.portailsig.org/  (me, in French)
-  http://joseguerreroa.wordpress.com/ http://joseguerreroa.wordpress.com/ 
(in Spanish)
-  http://www.webrian.ch/2012/04/line-extraction-with-grass-gis.html
http://www.webrian.ch/2012/04/line-extraction-with-grass-gis.html 

If you know others I am interested, thanks.






--
View this message in context: http://osgeo-org.1560.n6.nabble.com/GRASS-and-the-Python-geospatial-modules-Shapely-PySAL-tp4985075.html
Sent from the Grass - Users mailing list archive at Nabble.com.


More information about the grass-user mailing list