1

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.

3 Answers 3

6

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.

Pil at work

PIL image source code here.

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. QGis example from SF.net
(source: sourceforge.net)

Sign up to request clarification or add additional context in comments.

Comments

0

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?

https://stackoverflow.com/search?q=postgresql+database+python - Looks like psycopg2 is a good option as Adam Matan suggested.

b) Drawing shapefile data in python

postgresql and python

1 Comment

Some comments gave me a deja-vu the author also says this is a project for my university and I can't use Qgis. They should just come to SO instead of going to "that" university.
0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.