Tuesday, July 30, 2013
Tuesday, July 16, 2013
Tuesday, July 9, 2013
How to import OpenStreetMap data into PostgreSQL
How to import OpenStreetMap data into PostgreSQL
13 Replies
1. Download data and software
The instructions are fairly generic, so should work for both Windows, Linux and Mac OS X. I wrote them for Windows, but I’ve since then switched to Mac OS X.
PostgreSQL+PostGIS
I assume that you do not already have Postgres/PostGIS installed on your system.
Download PostgreSQL+PostGIS for all platforms here: http://www.postgresql.org/download/
Follow the instructions provided to install the database software.
OSM data
Download OpenStreetMap data (.osm file):
downloads.cloudmade.com
downloads.cloudmade.com
I chose europe -> denmark.
osm2pgsql
Download the version for your platform (Windows, Linux, Mac OS X etc):
wiki.openstreetmap.org/wiki/Osm2pgsql
wiki.openstreetmap.org/wiki/Osm2pgsql
2. Create and prepare database
If you add the PostgreSQL bin folder to your path, you’ll have access to commands likecreateuser and createdb in your shell.
Create a user (after running command, answer ‘y’ to superuser):
createuser -U postgres <enter your username, I entered kostas>
Create the database (should be called ‘gis’):
createdb -U postgres -E UTF8 -O kostas gis
Install language plpgsql (on my system this was already installed):
createlang -U postgres plpgsql gis
Add PostGIS functionality to database (you should get pages of output as functions etc are created):
psql -U postgres -d gis -f PATH_TO_POSTGRES/share/contrib/postgis-1.5/postgis.sql
Download the file 900913.sql. The following will add spherical mercator projection to the database:
psql -U postgres -d gis -f PATH_TO_FILE/900913.sql
3. Add OSM data to database
Change directory to where you unzipped osm2pgsql:
cd PATH_TO_OSM2PGSQL
Import OSM data:
osm2pgsql -U postgres -s -S ./default.style PATH_TO_OSM_FILE/denmark.osm
Options for osm2pgsql:
- -U postgres
Run program with the PostgreSQL admin user - -s
Run in “slim” mode, which means running the program not in RAM, which is necessary on my system - -S ./default.style
On windows (maybe also Linux and other OS) you must specify path to style file. Use default which comes with osm2pgsql.
That’s it! You now have a database full of street data.
4. Testing the database
This is where I live:
select name, astext(way) from planet_osm_line where name='Anders Henriksens Gade'
Which gives the name of the road plus a WKT representation of the geometry:
Anders Henriksens Gade LINESTRING(1402528.63 7491973.55,1402602.4 7491829.85)
Conclusion
It works, but tables are created in the ‘public’ schema of the ‘gis’ database. This is not so nice. I’d prefer that tables were created e.g. in ‘osm’ schema. When I’ve looked into how this is done, I’ll update this post.
I’d like to write a howto that uses Osmosis to continuously update the local OSM data with diffs from OSM.
Error: connection to database failed: fe_sendauth: no password supplied.
f the problem is specific to this client, you may need to change one or more of:
- pg_hba.conf
host sa all 192.168.0.nnn/32 trust
f you want that to be local to that batch file, use
setlocal
:setlocal
set PATH=...
http://dave.webdev.pgadmin.org/docs/1.6/pg/app-dropdb.html
Friday, July 5, 2013
BaseMap hunt for GEOSERVER
http://blog.geoserver.org/2009/01/30/geoserver-and-openstreetmap/
http://www.geofabrik.de/data/shapefiles.html
http://downloads.cloudmade.com/asia/southern_asia/iran/fars#downloads_breadcrumbs
https://github.com/mitchelljj/openstreetmap-sld
https://github.com/dwins/mapnik2geotools
https://github.com/fotographs/OSM-Styles-for-GeoServer
https://github.com/mapnik/mapnik/wiki/WindowsInstallation
http://skipperkongen.dk/2011/01/20/how-to-import-open-street-map-data-into-postgresql/
http://downloads.cloudmade.com/
https://github.com/search?q=osm-styles-for-geoserver recomended by consultant
Styles I used : https://github.com/fotographs/OSM-Styles-for-GeoServer/tree/master/sld
http://www.geofabrik.de/data/shapefiles.html
http://downloads.cloudmade.com/asia/southern_asia/iran/fars#downloads_breadcrumbs
https://github.com/mitchelljj/openstreetmap-sld
https://github.com/dwins/mapnik2geotools
https://github.com/fotographs/OSM-Styles-for-GeoServer
https://github.com/mapnik/mapnik/wiki/WindowsInstallation
http://skipperkongen.dk/2011/01/20/how-to-import-open-street-map-data-into-postgresql/
http://downloads.cloudmade.com/
https://github.com/search?q=osm-styles-for-geoserver recomended by consultant
Styles I used : https://github.com/fotographs/OSM-Styles-for-GeoServer/tree/master/sld
Tuesday, July 2, 2013
Installing PHP on Windows 7
Installing PHP on Windows 7
Microsoft have released the first public beta for their upcoming Windows 7 operating system. To me it looks surprisingly similar to Vista (which is a good thing and a bad thing ), so I thought that installing PHP on it should be easy, as well. Actually, it was really easy, but since yesterday two people indenpendently from each other asked me how to do it, I thought I'd write down the required steps.
First of all, you need PHP (obviously). Go to the PHP download page and grab the latest non-thread-safe ZIP archive for Windows. As of writing this, the package is called "PHP 5.2.8 Non-thread-safe zip package". Unzip the archive to a folder on your hard disk (I use C:\php5) and create a copy of php.ini-recommended (or php.ini-production in recent PHP versions) called php.ini. There, add the following configuration setting:
This is the minimum setting you need to change to make PHP work with IIS. You may also want to use
Then it's time to install IIS. You need at least the "Business" version of Windows 7, but the currently available beta 1 is Windows 7 Ultimate anyway. Go to Start/Control Panel/Programs/Turn Windows Features on or off and check on the Internet Information Services entry. Activate the World Wide Web Services/Application Development Features/CGI node and also Web Management Tools/IIS Management Console (the latter not shown in the figure).
Now, start the IIS Management Console; just open up the start menu, enter
As a result of this, the Actions panel on the right hand side changes. You now see an option called Add Module Mapping. Clicking on it opens up a dialog which you fill out as you can see in the following figure (you may need to adapt the path used to your local system).
If you do not see the FastCgiModule entry, you probably forgot to check the CGI node when installing IIS. Otherwise, close the Add Module Mapping dialog by clicking on OK. You need to confirm that you want to create a FastCGI application; click Yes.
Finally, create a .php script and put it in the root folder of the IIS site (by default C:\Inetpub\wwwroot; note that you may need additional rights to write into that directory), e.g.phpinfo.php with a simple
cgi.force_redirect = 0
This is the minimum setting you need to change to make PHP work with IIS. You may also want to use
cgi.fix_pathinfo = 1
, fastcgi.impersonate = 1
, and setextension_dir
appropriately.Then it's time to install IIS. You need at least the "Business" version of Windows 7, but the currently available beta 1 is Windows 7 Ultimate anyway. Go to Start/Control Panel/Programs/Turn Windows Features on or off and check on the Internet Information Services entry. Activate the World Wide Web Services/Application Development Features/CGI node and also Web Management Tools/IIS Management Console (the latter not shown in the figure).
Now, start the IIS Management Console; just open up the start menu, enter
inetmgr
and hit Enter. There, navigate to the Sites/Default Web Site/Handler Mappings node and double-click on the "Handler Mappings" entry.As a result of this, the Actions panel on the right hand side changes. You now see an option called Add Module Mapping. Clicking on it opens up a dialog which you fill out as you can see in the following figure (you may need to adapt the path used to your local system).
If you do not see the FastCgiModule entry, you probably forgot to check the CGI node when installing IIS. Otherwise, close the Add Module Mapping dialog by clicking on OK. You need to confirm that you want to create a FastCGI application; click Yes.
Finally, create a .php script and put it in the root folder of the IIS site (by default C:\Inetpub\wwwroot; note that you may need additional rights to write into that directory), e.g.phpinfo.php with a simple
phpinfo()
call in it. Call this script using http://localhost/phpinfo.php
, and you are done!
Subscribe to:
Posts (Atom)