-
-
Save zed/5566939 to your computer and use it in GitHub Desktop.
Revisions
-
zed revised this gist
May 13, 2013 . 1 changed file with 35 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,30 +1,44 @@ # Create a Postgis timezone DB Ubuntu's analog of [robcowie / postgis_timezone_db.markdown](https://gist.github.com/robcowie/2896200) ## Install postgis sudo apt-get install python-software-properties sudo apt-add-repository ppa:ubuntugis/ppa sudo apt-get update sudo apt-get install postgresql-9.1-postgis See [How to Get Started with PostGIS 2.0 on Ubuntu 12.04 (precise)](http://trac.osgeo.org/postgis/wiki/UsersWikiPostGIS20Ubuntu1204) ## Create a db user with the same name as the current system user XXX# sudo -u postgres createuser --superuser $(whoami) ## Create a GIS-enabled db createdb timezones psql -d timezones -c 'create extension postgis' (optional) # psql -d timezones -c 'create extension postgis_topology' ## Import timezone data from the tz_world shapefile curl -O http://efele.net/maps/tz/world/tz_world.zip unzip tz_world.zip cd world/ shp2pgsql -IiDS -s 4326 -g geom tz_world.shp timezone | psql timezones See http://efele.net/maps/tz/world/ ## Get a timezone from (longitude, latitude) psql timezones -c ' SELECT tzid FROM timezone WHERE ST_Within(ST_SetSRID(ST_Point(2.3470, 48.8742), 4326), geom); ' ## Paris psql timezones -c ' SELECT tzid FROM timezone WHERE ST_Within(ST_SetSRID(ST_Point(-81.61027, 41.50489), 4326), geom); ' ## Cleveland -
robcowie revised this gist
Sep 24, 2012 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -26,4 +26,5 @@ SRID 4326 is the grid system used in the shapefiles. It is possible to convert i * http://linfiniti.com/2010/03/batch-importing-shapefiles-into-postgis/ * http://postgis.refractions.net/documentation/manual-1.4/ch02.html#id2754935 * http://www.gisnotes.com/wordpress/2011/11/homebrew-postgresql9-0-4-postgis-1-5-3/ * http://efele.net/maps/tz/world/ * http://blog.shupp.org/2012/08/12/local-timezone-lookups-by-coordinates-with-postgis/ -
robcowie revised this gist
Aug 24, 2012 . 1 changed file with 1 addition and 13 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,18 +1,6 @@ # Create a Postgis timezone DB See https://gist.github.com/3449216 ## Create a timezone db from shapefiles -
robcowie created this gist
Jun 8, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ # Create a Postgis timezone DB ## Create postgis database template ``` $ createdb -E utf8 template_postgis $ psql -d template_postgis -f /usr/local/Cellar/postgis/1.5.3/share/postgis/postgis.sql $ psql -d template_postgis -f /usr/local/Cellar/postgis/1.5.3/share/postgis/spatial_ref_sys.sql ``` ## Create a new spatially-aware db ``` $ createdb -T template_postgis <mydb> ``` ## Create a timezone db from shapefiles ``` $ curl -O http://efele.net/maps/tz/world/tz_world.zip $ open tz_world.zip $ cd world $ createdb -T template_postgis timezones $ /usr/local/Cellar/postgis/1.5.3/bin/shp2pgsql -IiDS -s 4326 -g geom tz_world.shp timezone | psql timezones ``` ## Querying ``` SELECT tzid FROM timezone WHERE ST_Within(ST_SetSRID(ST_Point(-3.009444, 16.775833), 4326), geom); ## Timbuktu SELECT tzid FROM timezone WHERE ST_Within(ST_SetSRID(ST_Point(2.3470, 48.8742), 4326), geom); ## Paris ``` SRID 4326 is the grid system used in the shapefiles. It is possible to convert it so we don't need to convert on query. ## See * http://linfiniti.com/2010/03/batch-importing-shapefiles-into-postgis/ * http://postgis.refractions.net/documentation/manual-1.4/ch02.html#id2754935 * http://www.gisnotes.com/wordpress/2011/11/homebrew-postgresql9-0-4-postgis-1-5-3/ * http://efele.net/maps/tz/world/