Simple web service for turning a lat/lon into a block name (e.g. "5th avenue between president st and union st") using OpenStreetMap data
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


OpenStreetBlock is a simple web service for turning a lat/lon into a block name using OpenStreetMap data.

OpenStreetBlock depends on:
* PostgreSQL
* PostGIS
* Apache
* Osmosis
* osm2pgsql
* git (to get the code)

FGI my friend

Why PHP?  Errr, well, ummm, hey, what's that over there?

1. Install all the above dependencies
2. Get the code (for read-only download: "git clone git://")
3. In the openstreetblock directory, mv to
4. Edit to reflect your local configuration parameters (especially, your database connection)
5. Get, process, and load OpenStreetMap data as described below
6. Send requests to the osb.php script, as described in index.php

1. Get some OpenStreetMap data in raw XML format (i.e. a .osm file).  
Easiest way is to:
- Go to
- Navigate to a pan/zoom for which you want data
- Click the "Export" tab
- Select the OpenStreetMap XML Data option
- Hit "Export"
- When this fails, because you have chosen too large a bounding box, copy the bbox=BBOX out of the resulting URL
- Use this bounding box to request bulk OSM data:
  wget --timeout=SOME_LARGE_VALUE -O MY_FILE.osm "
- Keep trying this until it eventually works...

A reasonable BBOX for New York City (less Staten Island) could be:

So the request could be executed with:
   wget --timeout=3600 -O nyc.osm ",40.54,-73.709,40.92"

2. Create a PostGIS-enabled database in your PostgreSQL instance.
   Assume henceforth that this database was named 'osb'

3. Use osm2pgsql to load the .osm file into PSQL:
   osm2pgsql -d osb -l -s -p osm MY_FILE.osm
   (may also need flags for host, username, password, etc)

   from this we will use only the following tables:

4. Use osmosis to load the .osm file into PSQL another way:

   Create the schema osmosis looks for (to do this will require the 'hstore' psql module):
   cat /usr/share/doc/osmosis/examples/pgsql_simple_schema_0.6.sql | psql osb
   cat /usr/share/doc/osmosis/examples/pgsql_simple_schema_0.6_linestring.sql | psql osb
   cat /usr/share/doc/osmosis/examples/pgsql_simple_schema_0.6_bbox.sql | psql osb

   Then import using osmosis:
   osmosis --read-xml MY_FILE.osm --write-pgsql database=osb host=HOST user=USER
   (likewise for more DB flags.  Note, osmosis has no flag for DB port)

   From this we will use only:

5.  You probably want to VACUUM ANALYZE the whole thing after importing.