Skip to content

Instantly share code, notes, and snippets.

@cjlaborde
Forked from rustprooflabs/srid_units.sql
Created April 27, 2020 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjlaborde/25fb71a619b513179670bb0bb1651dc3 to your computer and use it in GitHub Desktop.
Save cjlaborde/25fb71a619b513179670bb0bb1651dc3 to your computer and use it in GitHub Desktop.
Creates view in PostGIS enabled database to make it easier to find what units each SRID is in.
CREATE OR REPLACE VIEW public.srid_units AS
SELECT srid, CASE WHEN proj4text LIKE '%+units=%' THEN True
ELSE False
END AS units_set,
CASE WHEN proj4text LIKE '%+units=m%' THEN 'Meters'
WHEN proj4text LIKE '%+units=ft%' THEN 'Feet'
WHEN proj4text LIKE '%+units=us-ft%' THEN 'Feet'
WHEN proj4text LIKE '%+units=link%' THEN 'Link (Dunno)'
WHEN proj4text LIKE '%+units=%' THEN 'Set, not caught properly'
ELSE 'Decimal Degrees'
END AS units,
proj4text, srtext
FROM public.spatial_ref_sys
;
@cjlaborde
Copy link
Author

Basic usage example. Find active SRIDs in Colorado with units in Meters.

SELECT *
	FROM public.srid_units
	WHERE srtext ILIKE '%Colorado%'
		AND srtext NOT ILIKE '%deprecated%'
		AND units = 'Meters'
;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment