Jed Rembold
Wednesday, November 12, 2025
ST_DWithin(|||point₁|||, |||point₂|||, |||distance|||)
returns a True or False depending on whether the two points are within
the given distance from one another
ST_Distance(|||point₁|||, |||point₂|||)
computes the distance between the two points
shp2pgsql on all operating systems
shp2pgsql utilizes several flags to control
its behavior
-I → sets up a GIST index on the geometry
column-s → specifies a specific SRID-W → specifies a particular encoding if
needed (sometimes necessary for location names)shp2pgsql -I -s |||SRID||| -W |||ENCODING||| |||SHAPEFILE.SHP||| |||TABLE_NAME|||By itself, shp2pgsql will just
generate SQL
You could save or copy that output and then run it in your database, but it can be more useful to pass that SQL directly into your database as it is created
This can be done with the | (pipe)
operator
All together then, the command would look like below (all on one line)
shp2pgsql -I -s |||SRID||| -W |||ENCODING||| |||SHAPEFILE.SHP||| |||TABLE_NAME||| | psql -d |||DATABASE||| -U postgres
Shapefiles will usually create geometry objects, which you could then cast to geography as needed
ST_AsText() function on
any geometry (or geography) object to output its WKT representation
SELECT ST_AsText(|||geom|||)
FROM |||table_name|||
LIMIT 1;
ST_AsText
to grab results for quick visualizationST_Collect to aggregate an
entire column of singular geometries into one Multi-geometry object for
each of representationST_Area(|||poly|||) will return the area
of the provided polygon. This will be in SRID specified units if
geometry or square meters if geographyST_Within(|||point|||, |||poly|||) will
return a True/False as to whether the given point lies within the
provided polygon
ST_Intersects(|||geom₁|||, |||geom₂|||)
will return a True/False if there exists an intersection between the two
geometriesST_Intersection(|||geom₁|||, |||geom₂|||)
will return a new geometry representing the intersection between the two
geometries