[postgis-users] pyshapelib + PostGIS
Daryl Herzmann
akrherz at iastate.edu
Fri May 28 13:04:16 PDT 2004
Hiya,
A bit of information here for those wanting to get PostGIS geometries into
something pyshapelib can use. This is a hack and probably the wrong way
of doing it, but it works for me :)
First I grabbed the wellknowntext.py library from Thuban.
http://www.intevation.de/cgi-bin/viewcvs-thuban.cgi/thuban/Thuban/Model/wellknowntext.py
Then in my python code, I can do this
import wellknowntext, shapelib, pg
mydb = pg.connect("postgis")
rs = mydb.query("SELECT geom from my_fancy_geometry_table").dictresult()
for i in range(len(rs)):
geom = rs[i]["geom"]
pts = wellknowntext.convert_well_known_text(geom)
# Assuming we have a polygon!
obj = shapelib.SHPObject(shapelib.SHPT_POLYGON, 1, pts)
And that seems to work. I am sure others have better ways, but googling
around, I didn't seem to find anything for my question "How to get WKT
into pyshapelib?" <-- Find this google! :)
Have a good weekend all!
later,
daryl
More information about the postgis-users
mailing list