Skip to content

Instantly share code, notes, and snippets.

@leblancfg
Last active January 5, 2018 21:04
Show Gist options
  • Save leblancfg/865954c73842c587d07f36ab2052bcdc to your computer and use it in GitHub Desktop.
Save leblancfg/865954c73842c587d07f36ab2052bcdc to your computer and use it in GitHub Desktop.
Minimal PostGIS example
/*
Minimal example used to test that PostGIS extention is installed on Postgres.
Run with: psql -U $USERNAME -d $GEODB -p $PORT -f postgis_example.sql
Should return:
'''
id | geometry
----+--------------
2 | POINT(30 30)
(1 row)
'''
*/
CREATE TABLE test_pt
(
id SERIAL PRIMARY KEY,
geom GEOMETRY
);
CREATE TABLE test_poly
(
id SERIAL PRIMARY KEY,
geom GEOMETRY
);
INSERT INTO test_pt(geom) VALUES ('POINT (0 0)'), ('POINT (30 30)');
INSERT INTO test_poly(geom) VALUES ('POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))');
SELECT test_pt.id, ST_AsText(test_pt.geom) FROM test_pt, test_poly WHERE ST_Intersects(test_pt.geom, test_poly.geom);
DROP TABLE test_pt, test_poly;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment