Skip to content

Instantly share code, notes, and snippets.

@bertt
Created June 28, 2016 12:43
Show Gist options
  • Save bertt/4446f3b6d75007305f6d07024e721bf7 to your computer and use it in GitHub Desktop.
Save bertt/4446f3b6d75007305f6d07024e721bf7 to your computer and use it in GitHub Desktop.
Sample spatial queries in PostGIS using SRID and GeoJSON
// create table with srid=4326
CREATE TABLE testbert1
(
id bigserial NOT NULL,
description character varying(500),
encodingtype integer,
location public.geometry(geometry,4326)
)
// insert geometry
insert into testbert1(id,location)
values(1,ST_SetSRID(ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[-114.017347,51.048005],[-114.014433,51.047927],[-114.005899,51.045381],[-114.017347,51.048005]]]}'),4326))
// do spatial select
select id, ST_AsText(location) from testbert1
WHERE ST_Intersects(location,ST_SetSRID(ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[-114.017347,51.048005],[-114.014433,51.047927],[-114.005899,51.045381],[-114.017347,51.048005]]]}'),4326))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment