The Java XAPI is a partial implementation of the XAPI read-only OSM server in Java. It is implemented as a servlet and uses pieces of Osmosis to perform the database queries.
See the OSM Wiki for more information about XAPI: http://wiki.openstreetmap.org/wiki/Xapi
These setup steps assume you're working on a Ubuntu 9.x/10.x installation.
-
Make sure you have the required packages installed:
sudo apt-get install postgresql-8.4 postgresql-8.4-postgis postgresql-8.4-hstore-new
-
Set up an Osmosis pgsnapshot 0.6 schema in a PostGIS database:
sudo su - postgres
(These commands are meant to be run as userpostgres
)createdb xapi
createlang plpgsql xapi
createuser xapi
You do want the user to be a superuser.echo "alter role xapi password 'xapi';" | psql -d xapi
psql -d xapi -f /usr/share/postgresql/8.4/contrib/postgis.sql
psql -d xapi -f /usr/share/postgresql/8.4/contrib/spatial_ref_sys.sql
psql -d xapi -f /usr/share/postgresql/8.4/contrib/hstore-new.sql
Under postgresql 9.1 install the package postgresql-contrib-9.1 and run the command psql -d xapi -c "CREATE EXTENSION hstore"
psql -d xapi -f ~/osmosis/package/script/pgsnapshot_schema_0.6.sql
psql -d xapi -f ~/osmosis/package/script/pgsnapshot_schema_0.6_linestring.sql
psql -d xapi -f ~/osmosis/package/script/pgsnapshot_schema_0.6_relcollection.sql
(This is experimental and may not be included in your copy of Osmosis yet.)echo "CREATE INDEX idx_nodes_tags ON nodes USING GIN(tags);" | psql -d xapi
echo "CREATE INDEX idx_ways_tags ON ways USING GIN(tags);" | psql -d xapi
echo "CREATE INDEX idx_relations_tags ON relations USING GIN(tags);" | psql -d xapi
exit
(Brings us back to original user.) -
Import a planet file (or other piece of OSM data)
bzcat planet-latest.osm.bz2 | bin/osmosis --read-xml file="/dev/stdin" --write-pgsql user="xapi" database="xapi"
-
Grab the latest XAPI war and deploy it with a servlet container like Tomcat or Jetty.
I used Maven for the dependency and build management. Make sure you have mvn
installed before
doing any of this.
-
Clone the github xapi-servlet repo
-
Check out the Osmosis SVN code and Compile the JARs by executing
ant publish
from the root osmosis directory. -
Manually install the Osmosis dependencies into your local Maven repository by executing
mvn install:install-file -DgroupId=org.openstreetmap.osmosis -DartifactId=pgsnapshot -Dversion=0.39 -Dpackaging=jar -Dfile=build/binary/osmosis-pgsnapshot.jar
from the Osmosiscore
,pgsnapshot
,hstore-jdbc
andxml
directories. -
Finally, run
mvn compile war:war
from the xapi-servlet directory to generate a deployable servlet war.
- Note that this will fail if you don't have the JSON or PBF Osmosis JARs installed (You're not missing anything: I don't specify how to do that in this readme). To fix that, comment out the two
dependency
blocks in thepom.xml
that mentionpbf
orjson
. At the moment the PBF and JSON output is removed to make it easier to add theplanetDate
timestamp to the output.
See the issues list for all issues, but these limit functionality:
-
Bug 7 - Relation queries ignore any bounding box predicates.
-
Bug 12 - Relations aren't included in the "all elements" query.
-
PBF and JSON support was removed in f0f003 to make it easier to add the
planetDate
functionality.
This app was built on the shoulders of other people's open source code:
- bretth's Osmosis: for the database schema and querying code
- emacsen's xapi-ui: for the HTML debugging page he created to help build XAPI query URLs
- zere (and MapQuest's) help with everything; especially the parser!