Can you help me to connect to my postgresql database with python? I need to create graphic interface with python which will visualize shapefile data from my database (i have about 50 polygons in shapefile format in that database). Can you help me with creating such application? I am begginer in python.
For communicating with the database, use psycopg2. It's quick, easy and efficient if you are familiar with basic DB concepts.
You have several options from here. You can use shpUtils, which is supposed to be a nice package for parsing shapefiles. You can then visualize the data using numerous python graphics packages, like pil.
Every option suits a different need, depending on what you define as "create graphic interface". If you need to create a simple graphics output, build the polygons from text using one of the graphics utilities mentioned above. If you need to create a professional-looking image, try using mapnik (mentioned in some other answers), which easily reads shapefiles. If you need to create a fully functional GUI, it's probably not a beginner's task - you should start with programming basic GUI applications before diving into shapefiles and polygons.
If, however, you just need to view the polygons - skip python and just use qgis, which will very easily visualize your polygons. It also comes with a handful of other nice features, like colors, zooms and so on.
I would approach this by breaking it up into smaller problems and solving each of them
a) How do I connect to a postgresql database with python?
http://stackoverflow.com/search?q=postgresql+database+python - Looks like psycopg2 is a good option as Adam Matan suggested.
b) Drawing shapefile data in python
http://stackoverflow.com/questions/1776511/postgresql-and-python-or-pphp
Mapnik is great for drawing maps. It can handle various formats and shapefiles, too. As far as I know it also supports PostgreSQL (at least PostGIS).
And least but not last: it comes with a Python interface (see Getting started)
I cant use any software like quantum gis, and i cant use mapnik, too. It is project for my university. I didnt understand how to draw those shapefiles in python. I connected to database:
import psycopg2
conn = psycopg2.connect("dbname='***' user='***' host='***' password='***'")
print 'Succesfully connected'
cur = conn.cursor()
cur.execute("""SELECT astext(the_geom) from buildings;""")
listpoly = cur.fetchall()
conn.close()
I dont know how to continue. I would like to use matplotlib.