PostGIS - Working With Geospatial Data in PostgreSQL
In this article, we are going to show how to get started with Geospatial data in PostgreSQL. More specifically, we are going to learn how to store spatial information (e.g. Coordinates in a map) and how we can index and perform searches on this data (e.g. Find all coordinates inside a given area).
Installing PostGIS
PostGIS is an extension of standard PostgreSQL that allows us to work with geospatial data. This means, if the extension is not present, we won’t have these capabilities.
To check if our database has PostGIS, we can use this query:
1
SELECT PostGIS_Version();
If PostGIS is not enabled, we will get a message similar to this one:
1
ERROR: 42883: function postgis_version() does not exist
If PostGIS is enabled, we will get something like this:
1
2
3
4
postgres=# SELECT PostGIS_Version();
postgis_version
---------------------------------------
3.5 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
If PostGIS is not installed on our system, we can follow the installation instructions based on our system.