Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

374
Views
Plotting a geometry directly from PostGIS using Python

I'm trying to plot a shapefile directly from PostGIS using Python. My shapefile is already stored in PostgreSQL. I know how to connect Python with PostgreSQL, but I just can't find anything that helps me plot my data into a map. I read somewhere that I should connect to PostgreSQL, query my shapefile table, select the geom attribute, store it into a geodataframe and then plot it.

Here's the code I'm using. Any ideas??

import psycopg2
import geopandas as gpd
import matplotlib.pyplot as plt
try:
    conn = psycopg2.connect("dbname='strokes' user='postgres' host='localhost' password='admin'")
except:
    print "I am unable to connect to the database"
    cur = conn.cursor()
    cur.execute("CREATE INDEX bassin_index ON bassin USING GIST(geom)")
    cur.execute("SELECT st_astext(geom) AS wkt, fid_limite, codebassin FROM bassin")
   rows = cur.fetchall()
   rows_list=[]
   for geom,fid_limite,codebassin in cursor:
       data={'codebassin':codeb,'fid_limite':fidlim,'geom':geo}
       rows_list.append(data)
       gdf=gpd.GeoDataFrame(rows_list).set_index('codebassin')
       gdf.head()
       gdf.plot(column='fid_limite', scheme='QUANTILES', k=5, colormap='gray')

conn.commit()
conn.close()
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!