Live Book https://livebook.manning.com/book/postgis-in-action-third-edition
Windows ( part of application stackbuilder): https://postgis.net/windows_downloads/ -- (has fresh updates for PostgreSQL 11,12,13,14 with GEOS 3.10, GDAL 3.2, Proj 7.1.1, PostGIS 3.2, SFCGAL 1.4.0)(Experimental Builds section builds on each commit)
The manual - https://postgis.net/documentation
This is running in psql. If in pgAdmin just manually reconnect to your gisdb. Example is gisdb but do for any spatial databases you have.
CREATE DATABASE gisdb;
ALTER DATABASE gisdb SET search_path=public,postgis,tiger,contrib;
\c gisdb
CREATE SCHEMA IF NOT EXISTS postgis;
CREATE SCHEMA IF NOT EXISTS contrib;
-- core includes geometry / geography
CREATE EXTENSION postgis SCHEMA postgis;
-- raster type and functions
CREATE EXTENSION postgis_raster SCHEMA postgis;
-- extended support for 3D geometries
CREATE EXTENSION postgis_sfcgal SCHEMA postgis;
-- topogeometry relational view of spatial data
CREATE EXTENSION postgis_topology;
-- needed by tiger geocoder
CREATE EXTENSION fuzzystrmatch SCHEMA contrib;
-- for standardizing addresses
CREATE EXTENSION address_standardizer SCHEMA contrib;
-- geocoding and reverse geocoding using US TIGER data
CREATE EXTENSION postgis_tiger_geocoder;
SELECT postgis_extensions_upgrade();
SELECT postgis_full_version();
screen
POSTGIS="3.2.0dev 3.2.0alpha1-19-gf48c4a86a" [EXTENSION]
PGSQL="140" GEOS="3.10.0dev-CAPI-1.15.0"
SFCGAL="1.3.10" PROJ="7.1.1"
GDAL="GDAL 3.2.3, released 2021/04/27"
LIBXML="2.9.9" LIBJSON="0.12"
LIBPROTOBUF="1.2.1" WAGYU="0.5.0 (Internal)" TOPOLOGY RASTER
very very old way of creating a feature collection - https://www.postgresonline.com/journal/archives/267-Creating-GeoJSON-Feature-Collections-with-JSON-and-PostGIS-functions.html (painful)
New way
SELECT json_build_object('type', 'FeatureCollection', 'features',
json_agg(ST_AsGeoJSON(r.*)::json) )
FROM recent_building_permits AS r;