Created
June 28, 2016 12:43
-
-
Save bertt/4446f3b6d75007305f6d07024e721bf7 to your computer and use it in GitHub Desktop.
Sample spatial queries in PostGIS using SRID and GeoJSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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