[英]Data visualization in python - after connecting to a database
Can you help me to connect to my postgresql database with python? 您能帮我用python连接到我的postgresql数据库吗? 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).
我需要使用python创建图形界面,该界面将可视化我数据库中的shapefile数据(我在该数据库中大约有50个shapefile格式的多边形)。 Can you help me with creating such application?
您能帮我创建这样的应用程序吗? I am begginer in python.
我是python的初学者。
For communicating with the database, use psycopg2 . 要与数据库通信,请使用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.
您可以使用shpUtils ,它应该是解析shapefile的一个很好的软件包。 You can then visualize the data using numerous python graphics packages, like pil .
然后,您可以使用众多python图形包(例如pil)可视化数据。
PIL image source code here. 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.
如果您需要创建看起来专业的图像,请尝试使用mapnik(在其他一些答案中提到),它可以轻松读取shapefile。 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.
如果需要创建功能齐全的GUI,则可能不是初学者的任务-在开始学习shapefile和多边形之前,应先对基本的GUI应用程序进行编程。
If, however, you just need to view the polygons - skip python and just use qgis , which will very easily visualize your polygons. 但是,如果只需要查看多边形-跳过python并使用qgis ,这将非常容易地可视化多边形。 It also comes with a handful of other nice features, like colors, zooms and so on.
它还具有其他一些不错的功能,例如颜色,缩放等。
(source: sourceforge.net ) (来源: 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? a)如何使用python连接到Postgresql数据库?
https://stackoverflow.com/search?q=postgresql+database+python - Looks like psycopg2 is a good option as Adam Matan suggested. https://stackoverflow.com/search?q=postgresql+database+python-就像Adam Matan建议的那样,psycopg2似乎是一个不错的选择。
b) Drawing shapefile data in python b)在python中绘制shapefile数据
Mapnik is great for drawing maps. Mapnik非常适合绘制地图。 It can handle various formats and shapefiles, too.
它也可以处理各种格式和shapefile。 As far as I know it also supports PostgreSQL (at least PostGIS).
据我所知,它还支持PostgreSQL(至少是PostGIS)。
And least but not last: it comes with a Python interface (see Getting started ) 也是最重要的一点:它带有Python接口(请参阅入门 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.