3

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;

BA354417C86A215D69E1F4168BC34B5FBA0544181788E8A54A11F41DC0D21593B9E5441C98613EA96A11F418D595C29F29D5441448591B250D11F41CC718065AB9D5441DFED1E085FDB1F417F69F221FC9C54417D958B3531E61F41A94AE99A3F9C54412EFAB9D591EC1F4190CB5C87D09B54416E6B292A8BC11F418DDC8CD9549B54410E85D990CBB91F417875F8FF4B9A5441B982AB025BB21F41130B4ECF4D995441CE08001887AA1F416B8C7078429854412423D1783A791F4191517645D896544118B5793CA18D1F41EBB1A9B2CE94544150A8A1E0759E1F4187F81BC320935441C766900D724C1F415922ACF4E89354410243253054131F41B2DC2122759454410EE13220E0FC1E416E91EF68AC945441F8AE48714BB11E41FF4AEC222B98544176FB051AF9CE1E41D4FABFC2B799544179A2ACBAB0D01E419153DAE5DB9954416A77F46BFFE61E4141CF8588B19B5441C3C388BBD7EC1E417A2BAF058CA25441F601559D91F41E417405469C07A25441F55A8D360A051F41AE160A72EDA054414FDBAC46DA221F414B6163A097A15441CFA0F1B6C9201F41019CD36FE0A2544126371B8F9C1E1F410EE74D333BA454410634B723B81D1F41BB9CE369C9A45441E6F1F05BB1251F41713DA33DEEA45441B5C6B826DE2A1F416DD74C2606A554413ABF55AC79341F419418688D32A55441CDC39EE254721F419277BA7349A454418BD9F00AA6921F41249672FACFA35441FB12B85A679C1F4140D2365AABA35441

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.