I have a table tb_regions in Postgresql having a column c_geometry which contains geometry(MultiPolygon, 3044) datatype from QGIS. I know how to retrieve data from Postgresql using pythons psycopg2 library.

As an example, one record contains the following geometry;


Given I can retrieve geometry data from Postgresql using python, how can these geometry-polygons be plotted in python? which libraries are best to use?

  • 1
    Welcome to GIS.SE. Please take the tour. Quite a few ways, one of which would be Folium, but your question is so broad and vague it can't really be answered in it's current form. – John Powell May 2 '18 at 12:53
  • 1
    A very common way to do this would be using GeoJSON and passing this to a Python mapping library like Folium, see this example. There are plenty of other ways. psychopg2 allows you to call any Postgis function, so ST_AsText, ST_AsGeoJSON, etc. Your question is still way too broad and this site is not a code writing service. I hope this gives you something to get started. – John Powell May 2 '18 at 13:16
  • using ST_AsGeoJSON, I get the following result "{"type":"MultiPolygon","coordinates":[[[[493971.65364662,5887034.922267],[494122.000695384,5887027.06872932],[494802.892954204,5887692.15336206],[496327.457351445,5889182.34625774],[496453.343624884,5889043.20755886],[496454.222129891,5889042.23663251],[49 (...)" however this is not drawable in folium. I get no multipolygon shape drawn in follium – shahzad ise May 3 '18 at 11:19
  • here is the code import os import folium import json geo_json_data = json.load(open('test.json')) m = folium.Map([52.520008, 13.404954], zoom_start=4) folium.GeoJson(geo_json_data).add_to(m) m.save('map.html') m – shahzad ise May 3 '18 at 11:21
  • could you please brief a litte on "other ways" – shahzad ise May 3 '18 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.