org.ka2ddo.yaac.osm
Class OsmXmlSegmenter

java.lang.Object
  extended by org.ka2ddo.yaac.osm.OsmXmlSegmenter

public class OsmXmlSegmenter
extends java.lang.Object

This class parses an OpenStreetMaps compressed XML file into a series of one-degree "square" tiles of map data, stored in a compact binary format suitable for efficient and fast rendering.

Special Java command-line parameters can be defined with the -D option to alter the operation of this class. These are:


Constructor Summary
OsmXmlSegmenter()
           
 
Method Summary
 java.lang.String checkDiskSpace(java.lang.String rootTilePath, long filesize)
          Check if sufficient disk space is available to import the OSM file.
static boolean downloadTileFile(java.lang.String hostIpAddress, java.io.File tileDir, int bLat, int bLon, java.lang.String suffix, StatusListener pd, long[] numBytesTransferred, long[] totalTransferTime, boolean refreshExisting)
          Download one tile file (ways or nodes) from a specific tile directory.
static void loadPrecompiledTiles(double radius, double lat, double lon, ChangeSet copiedServerChangeSet, boolean showProgressDialog, boolean refreshExisting)
          Download already-imported tiles from the program author's website and store them in the local tile directory.
 void parseXml(NonshareableCountingBufferedDataInputStream bzippedXmlStream, long inputStreamLength, java.lang.String filename, java.lang.String rootTilePath, double leftLongitude, double rightLongitude, double topLatitude, double bottomLongitude, boolean useFixMe, StatusListener listener)
          Parse a a compressed XML file into YAAC's version of OpenStreetMap tiles.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OsmXmlSegmenter

public OsmXmlSegmenter()
Method Detail

checkDiskSpace

public java.lang.String checkDiskSpace(java.lang.String rootTilePath,
                                       long filesize)
Check if sufficient disk space is available to import the OSM file.

Parameters:
rootTilePath - String directory path where the tiles files are to be stored
filesize - long byte-count size of the OSM file to read (to estimate resulting tile size)
Returns:
error message if not enough disk space, or null if no apparent problem

parseXml

public void parseXml(NonshareableCountingBufferedDataInputStream bzippedXmlStream,
                     long inputStreamLength,
                     java.lang.String filename,
                     java.lang.String rootTilePath,
                     double leftLongitude,
                     double rightLongitude,
                     double topLatitude,
                     double bottomLongitude,
                     boolean useFixMe,
                     StatusListener listener)
              throws java.io.IOException,
                     javax.xml.parsers.ParserConfigurationException,
                     org.xml.sax.SAXException
Parse a a compressed XML file into YAAC's version of OpenStreetMap tiles.

Parameters:
bzippedXmlStream - NonshareableCountingBufferedDataInputStream reading a BZIP2-compressed XML file
inputStreamLength - number of bytes in the compressed file (used to control the progress indicator)
filename - name of the file containing the OSM data
rootTilePath - String pathname of the configured tile directory
leftLongitude - left longitude bounding box value in degrees East
rightLongitude - right longitude bounding box value in degrees East
topLatitude - top latitude bounding box value in degrees North
bottomLongitude - bottom latitude bounding box value in degrees North
useFixMe - boolean true if FIXME-tagged elements of the OSM data are to be included
listener - StatusListener to receive progress report of the import
Throws:
java.io.IOException - if the input file cannot be read or any of the output files cannot be written
javax.xml.parsers.ParserConfigurationException - if the Java runtime's XML parser cannot handle its configuration parameters
org.xml.sax.SAXException - if the XML parser cannot decode

loadPrecompiledTiles

public static void loadPrecompiledTiles(double radius,
                                        double lat,
                                        double lon,
                                        ChangeSet copiedServerChangeSet,
                                        boolean showProgressDialog,
                                        boolean refreshExisting)
Download already-imported tiles from the program author's website and store them in the local tile directory. Note this does not check if the tiles are already up-to-date; the UI dialog that invokes this is supposed to give the user the opportunity to check this before actually starting a download. This also checks the ShowUnlabeledWays property of the OSMLayer class to see if extra tile files of untyped/unlabeled map data should be downloaded.

Parameters:
radius - radius in kilometers around the center point to be downloaded
lat - center point latitude in degrees North
lon - center point longitude in degrees East
copiedServerChangeSet - the ChangeSet already downloaded from the tile webserver to let the user decide whether to update or not
showProgressDialog - boolean true if a progress dialog should be launched to show the progress of this; should normally be true, but the configuration wizard sets it to false to not confuse the neophyte user while they are still configuring their installation
refreshExisting - if boolean true, ignore the radius, lat, and lon parameters, and just refresh every tile currently existing in the local tiledir with the version from the webserver

downloadTileFile

public static boolean downloadTileFile(java.lang.String hostIpAddress,
                                       java.io.File tileDir,
                                       int bLat,
                                       int bLon,
                                       java.lang.String suffix,
                                       StatusListener pd,
                                       long[] numBytesTransferred,
                                       long[] totalTransferTime,
                                       boolean refreshExisting)
                                throws java.io.IOException
Download one tile file (ways or nodes) from a specific tile directory. The parent directory for the tile directory can be overridden from the default by defining the Java property dated.tile.dir to be the directory name.

Parameters:
hostIpAddress - String of numeric IP address of webserver (to avoid repeated lookups)
tileDir - root directory of the tile hierarchy
bLat - latitude of tile (degrees only)
bLon - longitude of tile (degrees only)
suffix - file suffix ".ways" or ".nodes"
pd - StatusListener to receive progress reports (or null if progress is not to be reported)
numBytesTransferred - OUT parameter to accumulate the number of data bytes transferred
totalTransferTime - OUT parameter to accumulate the time spent transferring data (in milliseconds)
refreshExisting - if boolean true, skip downloading tiles that did not exist previously
Returns:
boolean true if a tile was downloaded, false if new tile does not exist
Throws:
java.io.IOException - if data cannot be transferred for some reason