r/postgis • • Aug 09 '24

Use PostGIS with Felt to make maps, apps, and dashboards in seconds - and easily collaborate on & share the same. Check out our blog post on how to integrate the two here!

8 Upvotes

The blogpost:

https://felt.com/blog/felt-postgis-integration-gis-database-spatial-analysis-and-visualization

Sign up for our free upcoming webinar on “How to Build a Modern GIS Stack with Postgres and Felt”, hosted on Zoom on August 14th, here:

https://us06web.zoom.us/webinar/register/WN_YjSzHsLTT2KAkRCMzm32Vw#/registration 

Message us anytime here in the comments, via DM, or on https://felt.com/ if you have any questions or just want to chat! 💬


r/postgis • • Nov 14 '22

Using PostGIS to dramatically speed up watershed delineation

8 Upvotes

I recently wrote some Python scripts for delineating watersheds anywhere on Earth (delineator on Github). I wanted to turn this into a web app, but the scripts were far too slow. The rate-limiting steps in the script was reading shapefiles from disk and processing with GeoPandas.

I had read that you could get big performance improvements using PostGIS, and wow! I was not disappointed. Processing that took a few minutes can be done in less than a second. Figuring out how to write some of the queries took me a long time, but it was worth the effort for the huge performance gains.

Please try it out and let me know what you think!

https://mghydro.com/watersheds/


r/postgis • • Dec 06 '23

PostGIS in QGIS

5 Upvotes

Hello everybody!

I'm trying to learn about PostGIS and PostgreSQL and how to use it with QGIS and I've been watching tutorials. Now, I think I'm ready to practice with my own data from work.

Of course, a knowledge barrier was hit. So, I'm trying to upload a shapefile to the database, and it works, but it doesn't pull all the Expressions I've written for that shapefile. It doesn't pull the symbology or the labeling I've set up for that same shapefile. I've tried importing QGIS Layer Style File (.qlr), but PostGIS doesn't recognise that file type.

Please help!

Also, if you have any recommendations for further improvement and what to invest my time in for better job placement in the future!

Best regards!


r/postgis • • Dec 03 '21

Suggest a good tutorial/resource for starters

5 Upvotes

Hey everyone, I'm looking for a good resource that can give me a boost about postgis. I have been searching through internet but couldn't find a good one. GIS world seems complicated and unpopular.

PS. I know about databases, programming, sql, python etc. I'm looking for something specific for postgis.


r/postgis • • Feb 07 '25

Cloud Rasters (GeoTIFF,COG) for use in PostGIS without download

4 Upvotes

With the postgis_raster extension, it is possible to access gigabytes of raster data from the cloud, without ever downloading the data.

How? The venerable postgis_raster extension (released 13 years ago) already has the critical core support built-in!

Rasters can be stored inside the database, or outside the database, on a local file system or anywhere it can be accessed by the underlying GDAL raster support library. The storage options include S3, Azure, Google, Alibaba, and any HTTP server that supports RANGE requests.

As long as the rasters are in the cloud optimized GeoTIFF (aka "COG") format, the network access to the data will be optimized and provide access performance limited mostly by the speed of connection between your database server and the cloud storage.

More at https://www.crunchydata.com/blog/using-cloud-rasters-with-postgis


r/postgis • • Jan 28 '25

PostGIS view using "UNION" not rendering in QGIS

4 Upvotes

Hey all -

I've got a few counties worth of parcel data that I'm attempting to combine into one VIEW instead of creating a new table. I'm doing this out of the (perhaps misguided) hope that I can just maintain and update each county's data as new edits come in, then have the multi-county view "just work" without having to constantly recreate it.

Long story short, I can get a view to render in QGIS when created from either individual county, but the view based on a UNION of the two won't render, despite the data looking "correct" when I query it. I'll put the full details below and appreciate any help or guidance that can be provided.

Source Tables:
countyA_parcels

  • geom(ST_MultiPolygon, SRID: 3745)

  • name(VARCHAR(50))

  • SELECT COUNT(geom) -> 28,142

countyB_parcels

  • geom(ST_MultiPolygon, SRID: 3745)

  • name(VARCHAR(17)) --- hooray for different data sources

  • SELECT COUNT(geom) -> 146,596

Attempted View

CREATE OR REPLACE VIEW combined_parcels AS

SELECT
  CAST(a.name AS VARCHAR(50)) AS pin, 
  a.geom AS geom
FROM countyA_parcels AS a
UNION ALL
SELECT
  CAST(b.pin AS VARCHAR(50)) AS pin,
  b.geom AS geom
FROM countyB_parcels AS b;

The above SQL results in a view table that:

  • Has the expected number of results: 174,738

  • Has pins properly cast into the pin column for parcels sourced from both tables

  • Has proper geometry types returned when queried (ST_Multipolygon) for parcels sourced from both tables

But...the resulting view cannot be successfully added to QGIS. It displays an odd icon next to the name which seems to be a data source error. If I drop the union and simply create the view from either of the source tables it renders fine.

What might be happening that prevents this view from being properly handled in QGIS?

Other info:
Postgres version: 17.2 (Mac)
PostGIS version: 3.5
QGIS version: 3.34.13-Prizren

Updates:
New things I've tried:

* Forcing all geometries to 2D using ST_Force2D - turns out one of the counties has 4 coordinate dimensions in their parcels.
* Casting the geometries to ensure the proper SRID shows up in the geometry_columns view:

ST_Force2D(a.geom)::GEOMETRY(MULTIPOLYGON, 3745) as geom

Still nothing


r/postgis • • Sep 18 '24

Framework for evaluating usefulness of GeoSpatial Open Data in Social & Health Research

4 Upvotes

Hi,

We are writing to you from the Innovation & Data Analysis Unit at Hospital Universitario Virgen Macarena in Seville, Spain. To briefly introduce ourselves, we are a research team based at a university hospital, consisting primarily of engineers and data scientists. Our focus is on Digital Health research, with a particular emphasis on utilizing EHR data generated within our hospital in collaboration with multiple health centers.

Through our experience working with georeferenced open data, we have found that not all datasets and data sources are equally valuable for social and biomedical research. Some datasets are far more suitable than others and it can be difficult to navigate for some researchers without experience. In response, we are developing a framework to assess the usefulness of geospatial open data sources specifically for health, biomedical, and epidemiological research. This framework consists of 14 basic quality metrics which could be the basis for a standardized tool to help researchers evaluate the relevance, usability, reliability, and applicability of different georeferenced datasets for health research.

We have drafted an initial version of this framework and would greatly value your feedback from this community. We would be grateful if you could share your insights by completing the following survey:

https://docs.google.com/forms/d/e/1FAIpQLSeNmeMfQYd9QCapL7cN3UIWOhzpodgyDe9xk_0gmBAtjl5T9Q/viewform?usp=sf_link


r/postgis • • May 20 '22

How to make loading big geometries faster

4 Upvotes

Hi, I have a bit of a curious data set that has really big polygons. I need to show part of this geometry on a map. Currently I am querying the database with a ST_MakeEnvelope call. However since the polygons are so big, loading the data takes too long. Does postgis provide solutions for this?

- For example can I somehow return only the vertices/points within the envelope?

- IS there maybe a way to simplify polygons and return the simplified polygons? The data has hundreds of points per polygon, but not all of them are super relevant.

I have thought of manually cutting up the polygon and then storing segments individually, but that has downsides of course.

I have found two solutions on Postgis' website, but both don't seem to work. The first one suggests adding a bbox to the table. But I can't get that query to work. Alternatively they suggest turning off indexing for that query. I tried it but it has no effect.

https://postgis.net/docs/performance_tips.html#idm2842


r/postgis • • May 20 '20

Why should you care about PostGIS? — A gentle introduction to spatial databases

Thumbnail
medium.com
4 Upvotes

r/postgis • • May 23 '19

Finding the distance of the nth furthest point.

4 Upvotes

Hello, I need to find the distance of the 100th closest point from a table of points for each point in table. What is the best approach to run this query?


r/postgis • • Oct 30 '25

gdalXXX.dll missing from \bin\ folder after install postgreSQL

3 Upvotes

Hello,

I installed postgreSQL 16, 17 and 18 version thinking that the most recent version could have a problem with windows and that was the reason why the files gdal305.dll, gdal306.dll or gdal307.dll was missing but after try with precedent versions 15, 16 and 17 the files are still mising.

i read in a forum that installing pstgre directly in c:\postgreSQL worked for some people, not for me.

any idea why thoes files are not present or are hidden or they are written in a different location?

thank you


r/postgis • • Feb 24 '25

Errors during upgrade

3 Upvotes

Hi. I have spent some time making my tests pass after upgrading an old installation (postgis 2.5) to a new version.

Some of the errors was wrong use of ST_DFullyWithin, but this has been sorted out.

My remaining issue:

the query works fine as long as I dont have an index :

SELECT street,zip
FROM street
WHERE ST_DFullyWithin(
    ST_SetSRID(ST_GeomFromText('POINT(xxx yyyy)'), 32633),
    extent,
    750
) order by 1;

-- returns 9 rows
create index ON street using gist (extent );
-- query returns zero rows

I have tested on pg12,13 and 17 - for instance the docker image postgis/postgis:17-3.5

still works on pg11, postgis 2.5 :)

What am i doing wrong here?

Thank you :)

edit

steps to Reproduce:

create temp table test (street text, extent geometry(Polygon,32633));

insert into test values ('Karl Johans gate','0103000020797F0000010000000500000084377D37F9EA0F41BFDC9108495D594184377D37F9EA0F41895979F9F55D5941B3309FDC0D041041895979F9F55D5941B3309FDC0D041041BFDC9108495D594184377D37F9EA0F41BFDC9108495D5941');

set enable_seqscan=false;
SELECT street
FROM test
WHERE ST_DFullyWithin(
    ST_SetSRID(ST_GeomFromText('POINT(261471 6649815)'), 32633),
    extent,
    1700
);

-- we get our row
-- Karl Johans gate

-- create index
create index ON test using gist (extent );

-- query again

SELECT street                             
FROM test
WHERE ST_DFullyWithin(
    ST_SetSRID(ST_GeomFromText('POINT(261471 6649815)'), 32633),
    extent,
    1700
);

--  street 
-- --------
-- (0 rows)

Edit 2

This is a change in behaviour between postgis 3.4 and postgis 3.5


r/postgis • • May 01 '24

Postgis +. node + orm / query builders + typescript support

3 Upvotes

Hi all,

I am looking for a good orm or query builder to connect my node app to postgis.

After short research, it looks like I should either go with sequelize or typeorm. First (sequelize) seem to be more comprehensive but less typescript oriented. The second (typeorm) is typescript oriented and offers auto generated migrations but seem to have less features overall.

  • Would you suggest one or the other?

  • Are there any other reliable geospatial-oriented orm options?

  • What kind of headaches did you experienced with your orm and postgis?


r/postgis • • Apr 24 '24

How to speed up a ST_Within query

3 Upvotes

Hi,

I have a table with plots (Polygons), and a table with addresses (Points). I need to know how many addresses are within a 5 km radius around the plot. Plots have 8 million records, Addresses +20 million

The query itself is easy enough, its a Left join on ST_Within on the geometries. All relevant geometries have indexes, both on the geometry and the casted geography

https://github.com/garma83/public-playground/blob/master/slow_within_query/query.sql

The issue is that the query as is would take 5 days, mainly because the radius of 5km is rather large. However this is what I need.

What would be good strategies to speed up this query? Any kind of optimisation is welcome. It doesn't actually have to be super precise either. Target speed is less than an hour.


r/postgis • • Dec 13 '23

Is there a faster way to store spatial joins

3 Upvotes

Hello,

I have a few very large tables that are joined with spatial joins. Dependent on customer input these queries can get quite convoluted, with several joins on multiple tables. These queries can take very long, eg up to 3 minutes.

The data that is queried is plot data, and the plot data typically has some related geometries like buildings on the plot, or a certain zone. This data is pretty static.

Currently in essence how the query works is that it retrieves the plot, and any items that overlap with the plot (like buildings and zones) and then filters with WHERE clauses, possibly on the buildings and zones. I already have indexes on all relevant columns including the geometry columns.

I am wondering if there is a better way to store this relationship? If I can in some way tell PostgreSQL through a material view or something like that, which zones, buildings etc belong to which plot, shouldn't it be possible to do this query much faster?

Some things I thought of:

- Summarising some of the data in a column with the plot data. But that would mean I have to parse that data (because its a N:N relation)

- Creating a helper table between the plot and the other tables. Would this indeed be faster than the spatial joins?


r/postgis • • Oct 09 '23

Compression of geospatial data

3 Upvotes

Hi! Im writing a master thesis on compression of geospatial data and Im trying to figure out which filetypes/storage methods are relevant today. Does anyone know what is used in postgis?

So far I've discovered, KML and GML, also I knew about geojson from before. I think KML might be the most interesting of these so far, any thoughts?


r/postgis • • Feb 15 '22

Best Practices re loading + maintaining US Census Data

3 Upvotes

What is the best way to handle placement and naming when loading US Census Data into Postgres ?

As an example, I am working with "CSA/CBSA" and "Congressional District" polygons. I've downloaded the ZIPs from census.gov, converted the shapefiles via shp2pgsql, successfully loaded them into a Postgres instance, created some GIST indexes, etc.:

Schema |       Name       | Type  |   Owner    
--------+------------------+-------+------------
public | tl_2019_us_cbsa  | table | idtrsadmin
public | tl_2021_us_cd116 | table | idtrsadmin

All works well, but in the context of maintenance (e.g. loading next year's data), code breakage, etc. is it normal to then:

  • move these tables from "public" to another schema, e.g. "geo"

  • rename the tables, e.g. 'tl_2021_us_cd116' to 'tl_us_cd'

  • rename columns, e.g. "tl_2021_us_cd116.cd116fp' to remove the '116' reference

  • do the above via views

  • do something else (open to suggestions)


r/postgis • • Dec 15 '21

Open Layers Web Map tied to CRUD Web App via PostGIS

3 Upvotes

I have been hosting a geodatabase for 6 years on Windows 2012 R2 with Open Layers / GeoServer / PostGIS to view the geographic data and PostgreSQL PHP Generator allowed me to create a UI to perform CRUD operations for creating new records in the PostGIS enabled database. Now the time has come to update the front end. I have been researching the best way to create a Postgres web interface that users can view, create, update and delete records based on authenticated permissions. I’m more comfortable working in JavaScript than other languages, however. I’ve done a lot of research and it seems like most of not all frameworks or generators are based in PHP or Python and some require Express or Docker or some backend functionality, which is a lot more hands on in terms of getting setup. It’s not a hill to high to climb, but I just wonder:

  1. Why are these generators and admin panels almost exclusively built on PHP/Python/backend?

  2. How should I setup my project folder structure to bridge these two web interfaces?

  3. Is there a better/easier way to do this?

What am I missing????


r/postgis • • Oct 02 '21

Advice…

3 Upvotes

I’m new to PostgreS and PostGIS databases. I’ve been an ArcGIS Pro user and ArcMap user before that for about 15 years. I always had a team of geospatial experts to do the hard stuff and then just give me the end product to use. I’m now with a small startup and Ive become the “GIS Guy”. We’re using QGIS and a subscription to commercial base map and geospatial services.

My task: I have polygons. I have a connected PostGIS database (points). I have been asked to automate how much data from the db fills the respective polygons. (Polys were imported KMLs I’ve exported as shapefiles).

The database consists of gps logs from various services. The polygons are sections of cities. I need to approximate the street coverage in a given polygon.

Any advice on where to start?


r/postgis • • Jun 25 '21

Automatically Calculate Polygon Area

3 Upvotes

Hello! :)

First of all, I'm a complete noob when it comes to PostgreSQL and PostGIS, so bear that in mind.

Secondly, I'm not sure if this should be here or in r/postgresql, so I'm sorry if I'm in the wrong place.

Anyway... I have a polygon layer (in QGIS) that has an "Area" field. I can easily use Field Calculator to update all the rows with the Area value... but it would be much more interesting if the field would auto-fill when I draw the polygon.

Can it be done? How?

Is it possible to define the size and precision of the number (for example xx.xxx,xx)? How?

Thanks you very much for your help! :)


r/postgis • • Jan 28 '20

PSA: Postgresql 12 slower than 11?...

3 Upvotes

I noticed that upgrading Postgres 11 to 12 resulted in my map tile renderer being approx 50% slower for a 100km square. Logging queries over 100ms and running them by hand via psql prefixing with "explain analyze" revealed the default settings for the new JIT compilation stuff was handling some transactions and taking a long time about it: 2.5seconds vs less than 200ms. Disabled JIT, and speed restored.

I have not looked at tuning individual JIT settings.


r/postgis • • Dec 22 '19

Learn postgis

3 Upvotes

HI!

I am trying to learn to build spatial data warehouses and use them withing QGis.

The problem I am running in to is that the Qgis documentation is focused on working in an Ubuntu shell, and I am working on Windows. The second option is using Postgis in action (book) but it is published in 2015 and they are now halfway through finishing a new version of the book.

I would gladly hear if you got pointers on where I need to start gathering knowledge so I can achieve my goal above. I have finished the postgreSql documentation. Now I want to step it up a notch and start with building spatial data warehouses.

Thanks in advance.


r/postgis • • Oct 15 '19

PostGIS 3.0 not possible to install on RHEL 8 / CentOS 8?

3 Upvotes

I am attempting to install the latest PostGIS 3.0.x on CentOS 8, with no luck.

I don't think anyone is running PostGIS on RHEL 8 or CentOS 8, I can't understand why not. It does not seem possible to install.

I have successfully installed Postgres 12.0 by disabling the RHEL AppStream

Steps I took installing postgres 12 on CentOS 8

1. 
#dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

2.  
#dnf --disablerepo AppStream install postgresql12
#dnf --disablerepo AppStream install postgresql12-server

I am attempting now to install PostGIS.

dnf list --available | grep postgis30

I see that postgis30_96 is the latest offered (as listed below)

postgis30_96.x86_64                                  3.0.0alpha4-6.rhel8                                     pgdg96               
postgis30_96-client.x86_64                           3.0.0alpha4-6.rhel8                                     pgdg96               
postgis30_96-client-debuginfo.x86_64                 3.0.0alpha4-6.rhel8                                     pgdg96               
postgis30_96-debuginfo.x86_64                        3.0.0alpha4-6.rhel8                                     pgdg96               
postgis30_96-devel.x86_64                            3.0.0alpha4-6.rhel8                                     pgdg96               
postgis30_96-docs.x86_64                             3.0.0alpha4-6.rhel8                                     pgdg96               
postgis30_96-gui.x86_64                              3.0.0alpha4-6.rhel8                                     pgdg96               
postgis30_96-gui-debuginfo.x86_64                    3.0.0alpha4-6.rhel8                                     pgdg96               
postgis30_96-utils.x86_64                            3.0.0alpha4-6.rhel8                                     pgdg96  

When I try to install with the following command:

#dnf install postgis30_96

I get these errors:

Last metadata expiration check: 1:22:58 ago on Tue 15 Oct 2019 08:25:10 PM UTC.
Error: 
 Problem: cannot install the best candidate for the job
  - nothing provides hdf5 needed by postgis30_96-3.0.0alpha4-6.rhel8.x86_64
  - nothing provides xerces-c needed by postgis30_96-3.0.0alpha4-6.rhel8.x86_64
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

I look for xerces-c, and nothing is returned:

dnf list --available | grep xerces-c

I look to see if hdf5 is available to install (dependency)

dnf list --available | grep hdf5

and nothing is returned. How do I satisfy these dependencies, so that PostGIS will install?

I goto the hdf5 website, download the source and it's a BIG FAT MESS. The build/install instructions do not work - the code is out of sync with the install instructions.

I check the hdf5 website and find another set of build/install instructions, and they too are out of sync with the latest code base. I don't know which way is up with this project, if it's a zombie project out there on the web, seemingly alive, but nobody's home.

How do I get hdf5 easily onto my system and xerces-c so that nothing existing gets mucked up? I would prefer to install these through any somewhat sanctioned CentOS 8 package repo using dnf.

---

I can't log this issue on the PostGIS ticket tracking system. Logging a ticket there requires an OSGEO ID, and when I request a 'mantra' to get started, nothing is returned, no response, yet another zombie project, nobody's home. https://www.osgeo.org/community/getting-started-osgeo/osgeo_userid/

---

Please respond only if you have actually done this yourself on a CentOS 8 machine or VM, while I appreciate suggestions, pointers or imaginations from others, it pollutes r/postgis reddit with misinformation, non-working solutions, and not only wastes my time with dead ends, but also the time of others.

Someone else inevitably comes along with the same problems and is misguided with these those that are well-intentioned, but provide incorrect or incomplete information.


r/postgis • • Aug 13 '19

R course

3 Upvotes