简体   繁体   中英

Data visualization in python - after connecting to a database

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 .

在工作中

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. SF.net的QGis示例
(source: sourceforge.net )

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

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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM