Skip to content

Instantly share code, notes, and snippets.

@etaque
Last active December 31, 2015 18:49
Show Gist options
  • Save etaque/8029082 to your computer and use it in GitHub Desktop.
Save etaque/8029082 to your computer and use it in GitHub Desktop.
How to load world coasts data into PostGIS and query into
Download "Format: Shapefile, Projection: WGS84 (Large polygons are split, use for larger scales)" from:
http://openstreetmapdata.com/data/land-polygons
Import into PG database with PostGIS extension:
shp2pgsql -s 4326 land_polygons.shp | psql <database>
Add index:
CREATE INDEX idx_land_polygons_geom ON land_polygons USING gist(geom);
Query example:
select (count(*) > 0) as aground from land_polygons WHERE st_contains(geom, ST_GeomFromText('POINT(3.007813 46.759292)', 4326));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment