switch package org.mapsforge -> org.oscim

This commit is contained in:
Hannes Janetzek
2012-09-12 00:33:39 +02:00
parent 489f07dd5d
commit e2da87d8e0
155 changed files with 548 additions and 535 deletions

View File

@@ -0,0 +1,72 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database;
import java.util.Map;
import org.oscim.view.mapgenerator.JobTile;
/**
*
*
*/
public interface IMapDatabase {
/**
* Starts a database query with the given parameters.
*
* @param tile
* the tile to read.
* @param mapDatabaseCallback
* the callback which handles the extracted map elements.
* @return true if successful
*/
public abstract QueryResult executeQuery(JobTile tile,
IMapDatabaseCallback mapDatabaseCallback);
/**
* @return the metadata for the current map file.
* @throws IllegalStateException
* if no map is currently opened.
*/
public abstract MapInfo getMapInfo();
/**
* @return true if a map database is currently opened, false otherwise.
*/
public abstract boolean isOpen();
/**
* Opens MapDatabase
*
* @param options
* the options.
* @return a OpenResult containing an error message in case of a failure.
*/
public abstract OpenResult open(Map<String, String> options);
/**
* Closes the map file and destroys all internal caches. Has no effect if no map file is currently opened.
*/
public abstract void close();
public abstract String getMapProjection();
/**
* Cancel loading
*/
public abstract void cancel();
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database;
import org.oscim.core.Tag;
import org.oscim.database.mapfile.MapDatabase;
/**
* Callback methods which can be triggered from the {@link MapDatabase}.
*/
public interface IMapDatabaseCallback {
/**
* Renders a single point of interest node (POI).
*
* @param layer
* the layer of the node.
* @param latitude
* the latitude of the node.
* @param longitude
* the longitude of the node.
* @param tags
* the tags of the node.
*/
void renderPointOfInterest(byte layer, float latitude, float longitude, Tag[] tags);
/**
* Renders water background for the current tile.
*/
void renderWaterBackground();
/**
* Renders a single way or area (closed way).
*
* @param layer
* the layer of the way.
* @param tags
* the tags of the way.
* @param wayNodes
* the geographical coordinates of the way nodes in the order longitude/latitude.
* @param wayLength
* length of way data in wayNodes
* @param changed
* tags have changed since last call (just an optional hint)
*/
void renderWay(byte layer, Tag[] tags, float[] wayNodes, short[] wayLength,
boolean changed);
boolean checkWay(Tag[] tags, boolean closed);
}

View File

@@ -0,0 +1,19 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database;
public interface IMapTileData {
}

View File

@@ -0,0 +1,78 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database;
import android.util.AttributeSet;
/**
*
*
*/
public final class MapDatabaseFactory {
private static final String MAP_DATABASE_ATTRIBUTE_NAME = "mapDatabase";
/**
* @param attributeSet
* A collection of attributes which includes the desired MapGenerator.
* @return a new MapGenerator instance.
*/
public static IMapDatabase createMapDatabase(AttributeSet attributeSet) {
String mapDatabaseName = attributeSet.getAttributeValue(null,
MAP_DATABASE_ATTRIBUTE_NAME);
if (mapDatabaseName == null) {
return new org.oscim.database.postgis.MapDatabase();
}
MapDatabases mapDatabaseInternal = MapDatabases.valueOf(mapDatabaseName);
return MapDatabaseFactory.createMapDatabase(mapDatabaseInternal);
}
public static MapDatabases getMapDatabase(AttributeSet attributeSet) {
String mapDatabaseName = attributeSet.getAttributeValue(null,
MAP_DATABASE_ATTRIBUTE_NAME);
if (mapDatabaseName == null) {
return MapDatabases.PBMAP_READER;
}
return MapDatabases.valueOf(mapDatabaseName);
}
/**
* @param mapDatabase
* the internal MapDatabase implementation.
* @return a new MapGenerator instance.
*/
public static IMapDatabase createMapDatabase(MapDatabases mapDatabase) {
switch (mapDatabase) {
case MAP_READER:
return new org.oscim.database.mapfile.MapDatabase();
case TEST_READER:
return new org.oscim.database.test.MapDatabase();
case POSTGIS_READER:
return new org.oscim.database.postgis.MapDatabase();
case PBMAP_READER:
return new org.oscim.database.pbmap.MapDatabase();
}
throw new IllegalArgumentException("unknown enum value: " + mapDatabase);
}
private MapDatabaseFactory() {
throw new IllegalStateException();
}
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database;
/**
* MapDatabase Implementations
*/
public enum MapDatabases {
/**
* ...
*/
MAP_READER,
/**
* ...
*/
TEST_READER,
/**
* ...
*/
POSTGIS_READER,
/**
* ...
*/
PBMAP_READER,
}

View File

@@ -0,0 +1,120 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database;
import org.oscim.core.BoundingBox;
import org.oscim.core.GeoPoint;
import org.oscim.database.mapfile.MapDatabase;
/**
* Contains the immutable metadata of a map file.
*
* @see MapDatabase#getMapInfo()
*/
public class MapInfo {
/**
* The bounding box of the map file.
*/
public final BoundingBox boundingBox;
/**
* The comment field of the map file (may be null).
*/
public final String comment;
/**
* The created by field of the map file (may be null).
*/
public final String createdBy;
/**
* The size of the map file, measured in bytes.
*/
public final long fileSize;
/**
* The file version number of the map file.
*/
public final int fileVersion;
/**
* The preferred language for names as defined in ISO 3166-1 (may be null).
*/
public final String languagePreference;
/**
* The center point of the map file.
*/
public final GeoPoint mapCenter;
/**
* The date of the map data in milliseconds since January 1, 1970.
*/
public final long mapDate;
/**
* The name of the projection used in the map file.
*/
public final String projectionName;
/**
* The map start position from the file header (may be null).
*/
public final GeoPoint startPosition;
/**
* The map start zoom level from the file header (may be null).
*/
public final Byte startZoomLevel;
/**
* @param bbox
* ...
* @param zoom
* ...
* @param start
* ...
* @param projection
* ...
* @param date
* ...
* @param size
* ...
* @param version
* ...
* @param language
* ...
* @param comment
* ...
* @param createdBy
* ...
*/
public MapInfo(BoundingBox bbox, Byte zoom, GeoPoint start, String projection,
long date, long size, int version, String language, String comment, String createdBy) {
this.startZoomLevel = zoom;
this.startPosition = start;
this.projectionName = projection;
this.mapDate = date;
this.boundingBox = bbox;
this.mapCenter = bbox.getCenterPoint();
this.languagePreference = language;
this.fileSize = size;
this.fileVersion = version;
this.comment = comment;
this.createdBy = createdBy;
}
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database;
/**
* A FileOpenResult is a simple DTO which is returned by IMapDatabase#openFile(File).
*/
public class OpenResult {
/**
* Singleton for a FileOpenResult instance with {@code success=true}.
*/
public static final OpenResult SUCCESS = new OpenResult();
private final String errorMessage;
private final boolean success;
/**
* @param errorMessage
* a textual message describing the error, must not be null.
*/
public OpenResult(String errorMessage) {
if (errorMessage == null) {
throw new IllegalArgumentException("error message must not be null");
}
this.success = false;
this.errorMessage = errorMessage;
}
/**
*
*/
public OpenResult() {
this.success = true;
this.errorMessage = null;
}
/**
* @return a textual error description (might be null).
*/
public String getErrorMessage() {
return this.errorMessage;
}
/**
* @return true if the file could be opened successfully, false otherwise.
*/
public boolean isSuccess() {
return this.success;
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("FileOpenResult [success=");
stringBuilder.append(this.success);
stringBuilder.append(", errorMessage=");
stringBuilder.append(this.errorMessage);
stringBuilder.append("]");
return stringBuilder.toString();
}
}

View File

@@ -0,0 +1,22 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database;
public enum QueryResult {
SUCCESS,
FAILED,
TILE_NOT_FOUND,
DELAYED,
}

View File

@@ -0,0 +1,91 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile;
/**
* This utility class contains methods to convert byte arrays to numbers.
*/
final class Deserializer {
/**
* Converts five bytes of a byte array to an unsigned long.
* <p>
* The byte order is big-endian.
*
* @param buffer
* the byte array.
* @param offset
* the offset in the array.
* @return the long value.
*/
static long getFiveBytesLong(byte[] buffer, int offset) {
return (buffer[offset] & 0xffL) << 32 | (buffer[offset + 1] & 0xffL) << 24 | (buffer[offset + 2] & 0xffL) << 16
| (buffer[offset + 3] & 0xffL) << 8 | (buffer[offset + 4] & 0xffL);
}
/**
* Converts four bytes of a byte array to a signed int.
* <p>
* The byte order is big-endian.
*
* @param buffer
* the byte array.
* @param offset
* the offset in the array.
* @return the int value.
*/
static int getInt(byte[] buffer, int offset) {
return buffer[offset] << 24 | (buffer[offset + 1] & 0xff) << 16 | (buffer[offset + 2] & 0xff) << 8
| (buffer[offset + 3] & 0xff);
}
/**
* Converts eight bytes of a byte array to a signed long.
* <p>
* The byte order is big-endian.
*
* @param buffer
* the byte array.
* @param offset
* the offset in the array.
* @return the long value.
*/
static long getLong(byte[] buffer, int offset) {
return (buffer[offset] & 0xffL) << 56 | (buffer[offset + 1] & 0xffL) << 48 | (buffer[offset + 2] & 0xffL) << 40
| (buffer[offset + 3] & 0xffL) << 32 | (buffer[offset + 4] & 0xffL) << 24
| (buffer[offset + 5] & 0xffL) << 16 | (buffer[offset + 6] & 0xffL) << 8 | (buffer[offset + 7] & 0xffL);
}
/**
* Converts two bytes of a byte array to a signed int.
* <p>
* The byte order is big-endian.
*
* @param buffer
* the byte array.
* @param offset
* the offset in the array.
* @return the int value.
*/
static int getShort(byte[] buffer, int offset) {
return buffer[offset] << 8 | (buffer[offset + 1] & 0xff);
}
/**
* Private constructor to prevent instantiation from other classes.
*/
private Deserializer() {
throw new IllegalStateException();
}
}

View File

@@ -0,0 +1,119 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.oscim.core.LRUCache;
import org.oscim.database.mapfile.header.SubFileParameter;
/**
* A cache for database index blocks with a fixed size and LRU policy.
*/
class IndexCache {
/**
* Number of index entries that one index block consists of.
*/
private static final int INDEX_ENTRIES_PER_BLOCK = 128;
private static final Logger LOG = Logger.getLogger(IndexCache.class.getName());
/**
* Maximum size in bytes of one index block.
*/
private static final int SIZE_OF_INDEX_BLOCK = INDEX_ENTRIES_PER_BLOCK * SubFileParameter.BYTES_PER_INDEX_ENTRY;
private final Map<IndexCacheEntryKey, byte[]> map;
private final RandomAccessFile randomAccessFile;
/**
* @param randomAccessFile
* the map file from which the index should be read and cached.
* @param capacity
* the maximum number of entries in the cache.
* @throws IllegalArgumentException
* if the capacity is negative.
*/
IndexCache(RandomAccessFile randomAccessFile, int capacity) {
this.randomAccessFile = randomAccessFile;
this.map = new LRUCache<IndexCacheEntryKey, byte[]>(capacity);
}
/**
* Destroy the cache at the end of its lifetime.
*/
void destroy() {
this.map.clear();
}
/**
* Returns the index entry of a block in the given map file. If the required index entry is not cached, it will be
* read from the map file index and put in the cache.
*
* @param subFileParameter
* the parameters of the map file for which the index entry is needed.
* @param blockNumber
* the number of the block in the map file.
* @return the index entry or -1 if the block number is invalid.
*/
long getIndexEntry(SubFileParameter subFileParameter, long blockNumber) {
try {
// check if the block number is out of bounds
if (blockNumber >= subFileParameter.numberOfBlocks) {
return -1;
}
// calculate the index block number
long indexBlockNumber = blockNumber / INDEX_ENTRIES_PER_BLOCK;
// create the cache entry key for this request
IndexCacheEntryKey indexCacheEntryKey = new IndexCacheEntryKey(subFileParameter, indexBlockNumber);
// check for cached index block
byte[] indexBlock = this.map.get(indexCacheEntryKey);
if (indexBlock == null) {
// cache miss, seek to the correct index block in the file and read it
long indexBlockPosition = subFileParameter.indexStartAddress + indexBlockNumber * SIZE_OF_INDEX_BLOCK;
int remainingIndexSize = (int) (subFileParameter.indexEndAddress - indexBlockPosition);
int indexBlockSize = Math.min(SIZE_OF_INDEX_BLOCK, remainingIndexSize);
indexBlock = new byte[indexBlockSize];
this.randomAccessFile.seek(indexBlockPosition);
if (this.randomAccessFile.read(indexBlock, 0, indexBlockSize) != indexBlockSize) {
LOG.warning("reading the current index block has failed");
return -1;
}
// put the index block in the map
this.map.put(indexCacheEntryKey, indexBlock);
}
// calculate the address of the index entry inside the index block
long indexEntryInBlock = blockNumber % INDEX_ENTRIES_PER_BLOCK;
int addressInIndexBlock = (int) (indexEntryInBlock * SubFileParameter.BYTES_PER_INDEX_ENTRY);
// return the real index entry
return Deserializer.getFiveBytesLong(indexBlock, addressInIndexBlock);
} catch (IOException e) {
LOG.log(Level.SEVERE, null, e);
return -1;
}
}
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile;
import org.oscim.database.mapfile.header.SubFileParameter;
/**
* An immutable container class which is the key for the index cache.
*/
class IndexCacheEntryKey {
private final int hashCodeValue;
private final long indexBlockNumber;
private final SubFileParameter subFileParameter;
/**
* Creates an immutable key to be stored in a map.
*
* @param subFileParameter
* the parameters of the map file.
* @param indexBlockNumber
* the number of the index block.
*/
IndexCacheEntryKey(SubFileParameter subFileParameter, long indexBlockNumber) {
this.subFileParameter = subFileParameter;
this.indexBlockNumber = indexBlockNumber;
this.hashCodeValue = calculateHashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (!(obj instanceof IndexCacheEntryKey)) {
return false;
}
IndexCacheEntryKey other = (IndexCacheEntryKey) obj;
if (this.subFileParameter == null && other.subFileParameter != null) {
return false;
} else if (this.subFileParameter != null && !this.subFileParameter.equals(other.subFileParameter)) {
return false;
} else if (this.indexBlockNumber != other.indexBlockNumber) {
return false;
}
return true;
}
@Override
public int hashCode() {
return this.hashCodeValue;
}
/**
* @return the hash code of this object.
*/
private int calculateHashCode() {
int result = 7;
result = 31 * result + ((this.subFileParameter == null) ? 0 : this.subFileParameter.hashCode());
result = 31 * result + (int) (this.indexBlockNumber ^ (this.indexBlockNumber >>> 32));
return result;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,167 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile;
import org.oscim.core.Tile;
import org.oscim.database.mapfile.header.SubFileParameter;
final class QueryCalculations {
private static int getFirstLevelTileBitmask(Tile tile) {
if (tile.tileX % 2 == 0 && tile.tileY % 2 == 0) {
// upper left quadrant
return 0xcc00;
} else if (tile.tileX % 2 == 1 && tile.tileY % 2 == 0) {
// upper right quadrant
return 0x3300;
} else if (tile.tileX % 2 == 0 && tile.tileY % 2 == 1) {
// lower left quadrant
return 0xcc;
} else {
// lower right quadrant
return 0x33;
}
}
private static int getSecondLevelTileBitmaskLowerLeft(long subtileX, long subtileY) {
if (subtileX % 2 == 0 && subtileY % 2 == 0) {
// upper left sub-tile
return 0x80;
} else if (subtileX % 2 == 1 && subtileY % 2 == 0) {
// upper right sub-tile
return 0x40;
} else if (subtileX % 2 == 0 && subtileY % 2 == 1) {
// lower left sub-tile
return 0x8;
} else {
// lower right sub-tile
return 0x4;
}
}
private static int getSecondLevelTileBitmaskLowerRight(long subtileX, long subtileY) {
if (subtileX % 2 == 0 && subtileY % 2 == 0) {
// upper left sub-tile
return 0x20;
} else if (subtileX % 2 == 1 && subtileY % 2 == 0) {
// upper right sub-tile
return 0x10;
} else if (subtileX % 2 == 0 && subtileY % 2 == 1) {
// lower left sub-tile
return 0x2;
} else {
// lower right sub-tile
return 0x1;
}
}
private static int getSecondLevelTileBitmaskUpperLeft(long subtileX, long subtileY) {
if (subtileX % 2 == 0 && subtileY % 2 == 0) {
// upper left sub-tile
return 0x8000;
} else if (subtileX % 2 == 1 && subtileY % 2 == 0) {
// upper right sub-tile
return 0x4000;
} else if (subtileX % 2 == 0 && subtileY % 2 == 1) {
// lower left sub-tile
return 0x800;
} else {
// lower right sub-tile
return 0x400;
}
}
private static int getSecondLevelTileBitmaskUpperRight(long subtileX, long subtileY) {
if (subtileX % 2 == 0 && subtileY % 2 == 0) {
// upper left sub-tile
return 0x2000;
} else if (subtileX % 2 == 1 && subtileY % 2 == 0) {
// upper right sub-tile
return 0x1000;
} else if (subtileX % 2 == 0 && subtileY % 2 == 1) {
// lower left sub-tile
return 0x200;
} else {
// lower right sub-tile
return 0x100;
}
}
static void calculateBaseTiles(QueryParameters queryParameters, Tile tile, SubFileParameter subFileParameter) {
if (tile.zoomLevel < subFileParameter.baseZoomLevel) {
// calculate the XY numbers of the upper left and lower right sub-tiles
int zoomLevelDifference = subFileParameter.baseZoomLevel - tile.zoomLevel;
queryParameters.fromBaseTileX = tile.tileX << zoomLevelDifference;
queryParameters.fromBaseTileY = tile.tileY << zoomLevelDifference;
queryParameters.toBaseTileX = queryParameters.fromBaseTileX + (1 << zoomLevelDifference) - 1;
queryParameters.toBaseTileY = queryParameters.fromBaseTileY + (1 << zoomLevelDifference) - 1;
queryParameters.useTileBitmask = false;
} else if (tile.zoomLevel > subFileParameter.baseZoomLevel) {
// calculate the XY numbers of the parent base tile
int zoomLevelDifference = tile.zoomLevel - subFileParameter.baseZoomLevel;
queryParameters.fromBaseTileX = tile.tileX >>> zoomLevelDifference;
queryParameters.fromBaseTileY = tile.tileY >>> zoomLevelDifference;
queryParameters.toBaseTileX = queryParameters.fromBaseTileX;
queryParameters.toBaseTileY = queryParameters.fromBaseTileY;
queryParameters.useTileBitmask = true;
queryParameters.queryTileBitmask = calculateTileBitmask(tile, zoomLevelDifference);
} else {
// use the tile XY numbers of the requested tile
queryParameters.fromBaseTileX = tile.tileX;
queryParameters.fromBaseTileY = tile.tileY;
queryParameters.toBaseTileX = queryParameters.fromBaseTileX;
queryParameters.toBaseTileY = queryParameters.fromBaseTileY;
queryParameters.useTileBitmask = false;
}
}
static void calculateBlocks(QueryParameters queryParameters, SubFileParameter subFileParameter) {
// calculate the blocks in the file which need to be read
queryParameters.fromBlockX = Math.max(queryParameters.fromBaseTileX - subFileParameter.boundaryTileLeft, 0);
queryParameters.fromBlockY = Math.max(queryParameters.fromBaseTileY - subFileParameter.boundaryTileTop, 0);
queryParameters.toBlockX = Math.min(queryParameters.toBaseTileX - subFileParameter.boundaryTileLeft,
subFileParameter.blocksWidth - 1);
queryParameters.toBlockY = Math.min(queryParameters.toBaseTileY - subFileParameter.boundaryTileTop,
subFileParameter.blocksHeight - 1);
}
static int calculateTileBitmask(Tile tile, int zoomLevelDifference) {
if (zoomLevelDifference == 1) {
return getFirstLevelTileBitmask(tile);
}
// calculate the XY numbers of the second level sub-tile
long subtileX = tile.tileX >>> (zoomLevelDifference - 2);
long subtileY = tile.tileY >>> (zoomLevelDifference - 2);
// calculate the XY numbers of the parent tile
long parentTileX = subtileX >>> 1;
long parentTileY = subtileY >>> 1;
// determine the correct bitmask for all 16 sub-tiles
if (parentTileX % 2 == 0 && parentTileY % 2 == 0) {
return getSecondLevelTileBitmaskUpperLeft(subtileX, subtileY);
} else if (parentTileX % 2 == 1 && parentTileY % 2 == 0) {
return getSecondLevelTileBitmaskUpperRight(subtileX, subtileY);
} else if (parentTileX % 2 == 0 && parentTileY % 2 == 1) {
return getSecondLevelTileBitmaskLowerLeft(subtileX, subtileY);
} else {
return getSecondLevelTileBitmaskLowerRight(subtileX, subtileY);
}
}
private QueryCalculations() {
throw new IllegalStateException();
}
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile;
class QueryParameters {
long fromBaseTileX;
long fromBaseTileY;
long fromBlockX;
long fromBlockY;
int queryTileBitmask;
int queryZoomLevel;
long toBaseTileX;
long toBaseTileY;
long toBlockX;
long toBlockY;
boolean useTileBitmask;
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("QueryParameters [fromBaseTileX=");
stringBuilder.append(this.fromBaseTileX);
stringBuilder.append(", fromBaseTileY=");
stringBuilder.append(this.fromBaseTileY);
stringBuilder.append(", fromBlockX=");
stringBuilder.append(this.fromBlockX);
stringBuilder.append(", fromBlockY=");
stringBuilder.append(this.fromBlockY);
stringBuilder.append(", queryTileBitmask=");
stringBuilder.append(this.queryTileBitmask);
stringBuilder.append(", queryZoomLevel=");
stringBuilder.append(this.queryZoomLevel);
stringBuilder.append(", toBaseTileX=");
stringBuilder.append(this.toBaseTileX);
stringBuilder.append(", toBaseTileY=");
stringBuilder.append(this.toBaseTileY);
stringBuilder.append(", toBlockX=");
stringBuilder.append(this.toBlockX);
stringBuilder.append(", toBlockY=");
stringBuilder.append(this.toBlockY);
stringBuilder.append(", useTileBitmask=");
stringBuilder.append(this.useTileBitmask);
stringBuilder.append("]");
return stringBuilder.toString();
}
}

View File

@@ -0,0 +1,535 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
import java.util.logging.Logger;
import org.oscim.core.Tag;
/**
* Reads from a {@link RandomAccessFile} into a buffer and decodes the data.
*/
public class ReadBuffer {
private static final String CHARSET_UTF8 = "UTF-8";
private static final Logger LOG = Logger.getLogger(ReadBuffer.class.getName());
/**
* Maximum buffer size which is supported by this implementation.
*/
static final int MAXIMUM_BUFFER_SIZE = 8000000;
private byte[] mBufferData;
private int mBufferPosition;
private final RandomAccessFile mInputFile;
ReadBuffer(RandomAccessFile inputFile) {
mInputFile = inputFile;
}
/**
* Returns one signed byte from the read buffer.
*
* @return the byte value.
*/
public byte readByte() {
return mBufferData[mBufferPosition++];
}
/**
* Reads the given amount of bytes from the file into the read buffer and resets the internal buffer position. If
* the capacity of the read buffer is too small, a larger one is created automatically.
*
* @param length
* the amount of bytes to read from the file.
* @return true if the whole data was read successfully, false otherwise.
* @throws IOException
* if an error occurs while reading the file.
*/
public boolean readFromFile(int length) throws IOException {
// ensure that the read buffer is large enough
if (mBufferData == null || mBufferData.length < length) {
// ensure that the read buffer is not too large
if (length > MAXIMUM_BUFFER_SIZE) {
LOG.warning("invalid read length: " + length);
return false;
}
mBufferData = new byte[length];
}
mBufferPosition = 0;
// reset the buffer position and read the data into the buffer
// bufferPosition = 0;
return mInputFile.read(mBufferData, 0, length) == length;
}
/**
* Converts four bytes from the read buffer to a signed int.
* <p>
* The byte order is big-endian.
*
* @return the int value.
*/
public int readInt() {
int pos = mBufferPosition;
byte[] data = mBufferData;
mBufferPosition += 4;
return data[pos] << 24
| (data[pos + 1] & 0xff) << 16
| (data[pos + 2] & 0xff) << 8
| (data[pos + 3] & 0xff);
}
/**
* Converts eight bytes from the read buffer to a signed long.
* <p>
* The byte order is big-endian.
*
* @return the long value.
*/
public long readLong() {
int pos = mBufferPosition;
byte[] data = mBufferData;
mBufferPosition += 8;
return (data[pos] & 0xffL) << 56
| (data[pos + 1] & 0xffL) << 48
| (data[pos + 2] & 0xffL) << 40
| (data[pos + 3] & 0xffL) << 32
| (data[pos + 4] & 0xffL) << 24
| (data[pos + 5] & 0xffL) << 16
| (data[pos + 6] & 0xffL) << 8
| (data[pos + 7] & 0xffL);
}
/**
* Converts two bytes from the read buffer to a signed int.
* <p>
* The byte order is big-endian.
*
* @return the int value.
*/
public int readShort() {
mBufferPosition += 2;
return mBufferData[mBufferPosition - 2] << 8 | (mBufferData[mBufferPosition - 1] & 0xff);
}
/**
* Converts a variable amount of bytes from the read buffer to a signed int.
* <p>
* The first bit is for continuation info, the other six (last byte) or seven (all other bytes) bits are for data.
* The second bit in the last byte indicates the sign of the number.
*
* @return the value.
*/
public int readSignedInt() {
int pos = mBufferPosition;
byte[] data = mBufferData;
int flag;
if ((data[pos] & 0x80) == 0) {
mBufferPosition += 1;
flag = ((data[pos] & 0x40) >> 6);
return ((data[pos] & 0x3f) ^ -flag) + flag;
}
if ((data[pos + 1] & 0x80) == 0) {
mBufferPosition += 2;
flag = ((data[pos + 1] & 0x40) >> 6);
return (((data[pos] & 0x7f)
| (data[pos + 1] & 0x3f) << 7) ^ -flag) + flag;
}
if ((data[pos + 2] & 0x80) == 0) {
mBufferPosition += 3;
flag = ((data[pos + 2] & 0x40) >> 6);
return (((data[pos] & 0x7f)
| (data[pos + 1] & 0x7f) << 7
| (data[pos + 2] & 0x3f) << 14) ^ -flag) + flag;
}
if ((data[pos + 3] & 0x80) == 0) {
mBufferPosition += 4;
flag = ((data[pos + 3] & 0x40) >> 6);
return (((data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x7f) << 14)
| ((data[pos + 3] & 0x3f) << 21)) ^ -flag) + flag;
}
mBufferPosition += 5;
flag = ((data[pos + 4] & 0x40) >> 6);
return ((((data[pos] & 0x7f)
| (data[pos + 1] & 0x7f) << 7
| (data[pos + 2] & 0x7f) << 14
| (data[pos + 3] & 0x7f) << 21
| (data[pos + 4] & 0x3f) << 28)) ^ -flag) + flag;
}
/**
* Converts a variable amount of bytes from the read buffer to a signed int array.
* <p>
* The first bit is for continuation info, the other six (last byte) or seven (all other bytes) bits are for data.
* The second bit in the last byte indicates the sign of the number.
*
* @param values
* result values
* @param length
* number of values to read
*/
public void readSignedInt(int[] values, int length) {
int pos = mBufferPosition;
byte[] data = mBufferData;
int flag;
for (int i = 0; i < length; i++) {
if ((data[pos] & 0x80) == 0) {
flag = ((data[pos] & 0x40) >> 6);
values[i] = ((data[pos] & 0x3f) ^ -flag) + flag;
pos += 1;
} else if ((data[pos + 1] & 0x80) == 0) {
flag = ((data[pos + 1] & 0x40) >> 6);
values[i] = (((data[pos] & 0x7f)
| ((data[pos + 1] & 0x3f) << 7)) ^ -flag) + flag;
pos += 2;
} else if ((data[pos + 2] & 0x80) == 0) {
flag = ((data[pos + 2] & 0x40) >> 6);
values[i] = (((data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x3f) << 14)) ^ -flag) + flag;
pos += 3;
} else if ((data[pos + 3] & 0x80) == 0) {
flag = ((data[pos + 3] & 0x40) >> 6);
values[i] = (((data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x7f) << 14)
| ((data[pos + 3] & 0x3f) << 21)) ^ -flag) + flag;
pos += 4;
} else {
flag = ((data[pos + 4] & 0x40) >> 6);
values[i] = ((((data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x7f) << 14)
| ((data[pos + 3] & 0x7f) << 21)
| ((data[pos + 4] & 0x3f) << 28))) ^ -flag) + flag;
pos += 5;
}
}
mBufferPosition = pos;
}
// public void readSignedInt(int[] values, int length) {
// int pos = mBufferPosition;
// byte[] data = mBufferData;
//
// for (int i = 0; i < length; i++) {
//
// if ((data[pos] & 0x80) == 0) {
// if ((data[pos] & 0x40) != 0)
// values[i] = -(data[pos] & 0x3f);
// else
// values[i] = (data[pos] & 0x3f);
// pos += 1;
// } else if ((data[pos + 1] & 0x80) == 0) {
// if ((data[pos + 1] & 0x40) != 0)
// values[i] = -((data[pos] & 0x7f)
// | ((data[pos + 1] & 0x3f) << 7));
// else
// values[i] = (data[pos] & 0x7f)
// | ((data[pos + 1] & 0x3f) << 7);
// pos += 2;
// } else if ((data[pos + 2] & 0x80) == 0) {
// if ((data[pos + 2] & 0x40) != 0)
// values[i] = -((data[pos] & 0x7f)
// | ((data[pos + 1] & 0x7f) << 7)
// | ((data[pos + 2] & 0x3f) << 14));
// else
// values[i] = (data[pos] & 0x7f)
// | ((data[pos + 1] & 0x7f) << 7)
// | ((data[pos + 2] & 0x3f) << 14);
// pos += 3;
// } else if ((data[pos + 3] & 0x80) == 0) {
// if ((data[pos + 3] & 0x40) != 0)
// values[i] = -((data[pos] & 0x7f)
// | ((data[pos + 1] & 0x7f) << 7)
// | ((data[pos + 2] & 0x7f) << 14)
// | ((data[pos + 3] & 0x3f) << 21));
// else
// values[i] = (data[pos] & 0x7f)
// | ((data[pos + 1] & 0x7f) << 7)
// | ((data[pos + 2] & 0x7f) << 14)
// | ((data[pos + 3] & 0x3f) << 21);
// pos += 4;
// } else {
// if ((data[pos + 4] & 0x40) != 0)
// values[i] = -((data[pos] & 0x7f)
// | ((data[pos + 1] & 0x7f) << 7)
// | ((data[pos + 2] & 0x7f) << 14)
// | ((data[pos + 3] & 0x7f) << 21)
// | ((data[pos + 4] & 0x3f) << 28));
// else
// values[i] = ((data[pos] & 0x7f)
// | ((data[pos + 1] & 0x7f) << 7)
// | ((data[pos + 2] & 0x7f) << 14)
// | ((data[pos + 3] & 0x7f) << 21)
// | ((data[pos + 4] & 0x3f) << 28));
// pos += 5;
// }
// }
//
// mBufferPosition = pos;
// }
/**
* Converts a variable amount of bytes from the read buffer to an unsigned int.
* <p>
* The first bit is for continuation info, the other seven bits are for data.
*
* @return the int value.
*/
public int readUnsignedInt() {
int pos = mBufferPosition;
byte[] data = mBufferData;
if ((data[pos] & 0x80) == 0) {
mBufferPosition += 1;
return (data[pos] & 0x7f);
}
if ((data[pos + 1] & 0x80) == 0) {
mBufferPosition += 2;
return (data[pos] & 0x7f)
| (data[pos + 1] & 0x7f) << 7;
}
if ((data[pos + 2] & 0x80) == 0) {
mBufferPosition += 3;
return (data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x7f) << 14);
}
if ((data[pos + 3] & 0x80) == 0) {
mBufferPosition += 4;
return (data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x7f) << 14)
| ((data[pos + 3] & 0x7f) << 21);
}
mBufferPosition += 5;
return (data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x7f) << 14)
| ((data[pos + 3] & 0x7f) << 21)
| ((data[pos + 4] & 0x7f) << 28);
}
/**
* Decodes a variable amount of bytes from the read buffer to a string.
*
* @return the UTF-8 decoded string (may be null).
*/
public String readUTF8EncodedString() {
return readUTF8EncodedString(readUnsignedInt());
}
/**
* @return ...
*/
public int getPositionAndSkip() {
int pos = mBufferPosition;
int length = readUnsignedInt();
skipBytes(length);
return pos;
}
/**
* Decodes the given amount of bytes from the read buffer to a string.
*
* @param stringLength
* the length of the string in bytes.
* @return the UTF-8 decoded string (may be null).
*/
public String readUTF8EncodedString(int stringLength) {
if (stringLength > 0 && mBufferPosition + stringLength <= mBufferData.length) {
mBufferPosition += stringLength;
try {
return new String(mBufferData, mBufferPosition - stringLength, stringLength, CHARSET_UTF8);
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}
LOG.warning("invalid string length: " + stringLength);
return null;
}
/**
* Decodes a variable amount of bytes from the read buffer to a string.
*
* @param position
* buffer offset position of string
* @return the UTF-8 decoded string (may be null).
*/
public String readUTF8EncodedStringAt(int position) {
int curPosition = mBufferPosition;
mBufferPosition = position;
String result = readUTF8EncodedString(readUnsignedInt());
mBufferPosition = curPosition;
return result;
}
/**
* @return the current buffer position.
*/
int getBufferPosition() {
return mBufferPosition;
}
/**
* @return the current size of the read buffer.
*/
int getBufferSize() {
return mBufferData.length;
}
/**
* Sets the buffer position to the given offset.
*
* @param bufferPosition
* the buffer position.
*/
void setBufferPosition(int bufferPosition) {
mBufferPosition = bufferPosition;
}
/**
* Skips the given number of bytes in the read buffer.
*
* @param bytes
* the number of bytes to skip.
*/
void skipBytes(int bytes) {
mBufferPosition += bytes;
}
Tag[] readTags(Tag[] wayTags, byte numberOfTags) {
Tag[] tags = new Tag[numberOfTags];
int maxTag = wayTags.length;
for (byte i = 0; i < numberOfTags; i++) {
int tagId = readUnsignedInt();
if (tagId < 0 || tagId >= maxTag) {
LOG.warning("invalid tag ID: " + tagId);
return null;
}
tags[i] = wayTags[tagId];
}
return tags;
}
private static final int WAY_NUMBER_OF_TAGS_BITMASK = 0x0f;
int lastTagPosition;
int skipWays(int queryTileBitmask, int elements) {
int pos = mBufferPosition;
byte[] data = mBufferData;
int cnt = elements;
int skip;
lastTagPosition = -1;
while (cnt > 0) {
// read way size (unsigned int)
if ((data[pos] & 0x80) == 0) {
skip = (data[pos] & 0x7f);
pos += 1;
} else if ((data[pos + 1] & 0x80) == 0) {
skip = (data[pos] & 0x7f)
| (data[pos + 1] & 0x7f) << 7;
pos += 2;
} else if ((data[pos + 2] & 0x80) == 0) {
skip = (data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x7f) << 14);
pos += 3;
} else if ((data[pos + 3] & 0x80) == 0) {
skip = (data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x7f) << 14)
| ((data[pos + 3] & 0x7f) << 21);
pos += 4;
} else {
skip = (data[pos] & 0x7f)
| ((data[pos + 1] & 0x7f) << 7)
| ((data[pos + 2] & 0x7f) << 14)
| ((data[pos + 3] & 0x7f) << 21)
| ((data[pos + 4] & 0x7f) << 28);
pos += 5;
}
// invalid way size
if (skip < 0) {
mBufferPosition = pos;
return -1;
}
// check if way matches queryTileBitmask
if ((((data[pos] << 8) | (data[pos + 1] & 0xff)) & queryTileBitmask) == 0) {
// remember last tags position
if ((data[pos + 2] & WAY_NUMBER_OF_TAGS_BITMASK) != 0)
lastTagPosition = pos + 2;
pos += skip;
cnt--;
} else {
pos += 2;
break;
}
}
mBufferPosition = pos;
return cnt;
}
}

View File

@@ -0,0 +1,251 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile.header;
import java.io.IOException;
import org.oscim.database.OpenResult;
import org.oscim.database.mapfile.ReadBuffer;
/**
* Reads and validates the header data from a binary map file.
*/
public class MapFileHeader {
/**
* Maximum valid base zoom level of a sub-file.
*/
private static final int BASE_ZOOM_LEVEL_MAX = 20;
/**
* Minimum size of the file header in bytes.
*/
private static final int HEADER_SIZE_MIN = 70;
/**
* Length of the debug signature at the beginning of the index.
*/
private static final byte SIGNATURE_LENGTH_INDEX = 16;
/**
* A single whitespace character.
*/
private static final char SPACE = ' ';
private MapFileInfo mapFileInfo;
private SubFileParameter[] subFileParameters;
private byte zoomLevelMaximum;
private byte zoomLevelMinimum;
/**
* @return a MapFileInfo containing the header data.
*/
public MapFileInfo getMapFileInfo() {
return this.mapFileInfo;
}
/**
* @param zoomLevel
* the originally requested zoom level.
* @return the closest possible zoom level which is covered by a sub-file.
*/
public byte getQueryZoomLevel(byte zoomLevel) {
if (zoomLevel > this.zoomLevelMaximum) {
return this.zoomLevelMaximum;
} else if (zoomLevel < this.zoomLevelMinimum) {
return this.zoomLevelMinimum;
}
return zoomLevel;
}
/**
* @param queryZoomLevel
* the zoom level for which the sub-file parameters are needed.
* @return the sub-file parameters for the given zoom level.
*/
public SubFileParameter getSubFileParameter(int queryZoomLevel) {
return this.subFileParameters[queryZoomLevel];
}
/**
* Reads and validates the header block from the map file.
*
* @param readBuffer
* the ReadBuffer for the file data.
* @param fileSize
* the size of the map file in bytes.
* @return a FileOpenResult containing an error message in case of a failure.
* @throws IOException
* if an error occurs while reading the file.
*/
public OpenResult readHeader(ReadBuffer readBuffer, long fileSize) throws IOException {
OpenResult openResult = RequiredFields.readMagicByte(readBuffer);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = RequiredFields.readRemainingHeader(readBuffer);
if (!openResult.isSuccess()) {
return openResult;
}
MapFileInfoBuilder mapFileInfoBuilder = new MapFileInfoBuilder();
openResult = RequiredFields.readFileVersion(readBuffer, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = RequiredFields.readFileSize(readBuffer, fileSize, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = RequiredFields.readMapDate(readBuffer, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = RequiredFields.readBoundingBox(readBuffer, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = RequiredFields.readTilePixelSize(readBuffer, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = RequiredFields.readProjectionName(readBuffer, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = OptionalFields.readOptionalFields(readBuffer, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = RequiredFields.readPoiTags(readBuffer, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = RequiredFields.readWayTags(readBuffer, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = readSubFileParameters(readBuffer, fileSize, mapFileInfoBuilder);
if (!openResult.isSuccess()) {
return openResult;
}
this.mapFileInfo = mapFileInfoBuilder.build();
return OpenResult.SUCCESS;
}
private OpenResult readSubFileParameters(ReadBuffer readBuffer, long fileSize,
MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the number of sub-files (1 byte)
byte numberOfSubFiles = readBuffer.readByte();
if (numberOfSubFiles < 1) {
return new OpenResult("invalid number of sub-files: " + numberOfSubFiles);
}
mapFileInfoBuilder.numberOfSubFiles = numberOfSubFiles;
SubFileParameter[] tempSubFileParameters = new SubFileParameter[numberOfSubFiles];
this.zoomLevelMinimum = Byte.MAX_VALUE;
this.zoomLevelMaximum = Byte.MIN_VALUE;
// get and check the information for each sub-file
for (byte currentSubFile = 0; currentSubFile < numberOfSubFiles; ++currentSubFile) {
SubFileParameterBuilder subFileParameterBuilder = new SubFileParameterBuilder();
// get and check the base zoom level (1 byte)
byte baseZoomLevel = readBuffer.readByte();
if (baseZoomLevel < 0 || baseZoomLevel > BASE_ZOOM_LEVEL_MAX) {
return new OpenResult("invalid base zooom level: " + baseZoomLevel);
}
subFileParameterBuilder.baseZoomLevel = baseZoomLevel;
// get and check the minimum zoom level (1 byte)
byte zoomLevelMin = readBuffer.readByte();
if (zoomLevelMin < 0 || zoomLevelMin > 22) {
return new OpenResult("invalid minimum zoom level: " + zoomLevelMin);
}
subFileParameterBuilder.zoomLevelMin = zoomLevelMin;
// get and check the maximum zoom level (1 byte)
byte zoomLevelMax = readBuffer.readByte();
if (zoomLevelMax < 0 || zoomLevelMax > 22) {
return new OpenResult("invalid maximum zoom level: " + zoomLevelMax);
}
subFileParameterBuilder.zoomLevelMax = zoomLevelMax;
// check for valid zoom level range
if (zoomLevelMin > zoomLevelMax) {
return new OpenResult("invalid zoom level range: " + zoomLevelMin + SPACE + zoomLevelMax);
}
// get and check the start address of the sub-file (8 bytes)
long startAddress = readBuffer.readLong();
if (startAddress < HEADER_SIZE_MIN || startAddress >= fileSize) {
return new OpenResult("invalid start address: " + startAddress);
}
subFileParameterBuilder.startAddress = startAddress;
long indexStartAddress = startAddress;
if (mapFileInfoBuilder.optionalFields.isDebugFile) {
// the sub-file has an index signature before the index
indexStartAddress += SIGNATURE_LENGTH_INDEX;
}
subFileParameterBuilder.indexStartAddress = indexStartAddress;
// get and check the size of the sub-file (8 bytes)
long subFileSize = readBuffer.readLong();
if (subFileSize < 1) {
return new OpenResult("invalid sub-file size: " + subFileSize);
}
subFileParameterBuilder.subFileSize = subFileSize;
subFileParameterBuilder.boundingBox = mapFileInfoBuilder.boundingBox;
// add the current sub-file to the list of sub-files
tempSubFileParameters[currentSubFile] = subFileParameterBuilder.build();
updateZoomLevelInformation(tempSubFileParameters[currentSubFile]);
}
// create and fill the lookup table for the sub-files
this.subFileParameters = new SubFileParameter[this.zoomLevelMaximum + 1];
for (int currentMapFile = 0; currentMapFile < numberOfSubFiles; ++currentMapFile) {
SubFileParameter subFileParameter = tempSubFileParameters[currentMapFile];
for (byte zoomLevel = subFileParameter.zoomLevelMin; zoomLevel <= subFileParameter.zoomLevelMax; ++zoomLevel) {
this.subFileParameters[zoomLevel] = subFileParameter;
}
}
return OpenResult.SUCCESS;
}
private void updateZoomLevelInformation(SubFileParameter subFileParameter) {
// update the global minimum and maximum zoom level information
if (this.zoomLevelMinimum > subFileParameter.zoomLevelMin) {
this.zoomLevelMinimum = subFileParameter.zoomLevelMin;
}
if (this.zoomLevelMaximum < subFileParameter.zoomLevelMax) {
this.zoomLevelMaximum = subFileParameter.zoomLevelMax;
}
}
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile.header;
import org.oscim.core.Tag;
import org.oscim.database.mapfile.MapDatabase;
/**
* Contains the immutable metadata of a map file.
*
* @see MapDatabase#getMapInfo()
*/
public class MapFileInfo extends org.oscim.database.MapInfo {
/**
* True if the map file includes debug information, false otherwise.
*/
public final boolean debugFile;
/**
* The number of sub-files in the map file.
*/
public final byte numberOfSubFiles;
/**
* The POI tags.
*/
public final Tag[] poiTags;
/**
* The way tags.
*/
public final Tag[] wayTags;
/**
* The size of the tiles in pixels.
*/
public final int tilePixelSize;
MapFileInfo(MapFileInfoBuilder mapFileInfoBuilder) {
super(mapFileInfoBuilder.boundingBox,
mapFileInfoBuilder.optionalFields.startZoomLevel,
mapFileInfoBuilder.optionalFields.startPosition,
mapFileInfoBuilder.projectionName,
mapFileInfoBuilder.mapDate,
mapFileInfoBuilder.fileSize,
mapFileInfoBuilder.fileVersion,
mapFileInfoBuilder.optionalFields.languagePreference,
mapFileInfoBuilder.optionalFields.comment,
mapFileInfoBuilder.optionalFields.createdBy);
debugFile = mapFileInfoBuilder.optionalFields.isDebugFile;
numberOfSubFiles = mapFileInfoBuilder.numberOfSubFiles;
poiTags = mapFileInfoBuilder.poiTags;
tilePixelSize = mapFileInfoBuilder.tilePixelSize;
wayTags = mapFileInfoBuilder.wayTags;
}
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile.header;
import org.oscim.core.BoundingBox;
import org.oscim.core.Tag;
class MapFileInfoBuilder {
BoundingBox boundingBox;
long fileSize;
int fileVersion;
long mapDate;
byte numberOfSubFiles;
OptionalFields optionalFields;
Tag[] poiTags;
String projectionName;
int tilePixelSize;
Tag[] wayTags;
MapFileInfo build() {
return new MapFileInfo(this);
}
}

View File

@@ -0,0 +1,163 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile.header;
import org.oscim.core.GeoPoint;
import org.oscim.database.OpenResult;
import org.oscim.database.mapfile.ReadBuffer;
final class OptionalFields {
/**
* Bitmask for the comment field in the file header.
*/
private static final int HEADER_BITMASK_COMMENT = 0x08;
/**
* Bitmask for the created by field in the file header.
*/
private static final int HEADER_BITMASK_CREATED_BY = 0x04;
/**
* Bitmask for the debug flag in the file header.
*/
private static final int HEADER_BITMASK_DEBUG = 0x80;
/**
* Bitmask for the language preference field in the file header.
*/
private static final int HEADER_BITMASK_LANGUAGE_PREFERENCE = 0x10;
/**
* Bitmask for the start position field in the file header.
*/
private static final int HEADER_BITMASK_START_POSITION = 0x40;
/**
* Bitmask for the start zoom level field in the file header.
*/
private static final int HEADER_BITMASK_START_ZOOM_LEVEL = 0x20;
/**
* The length of the language preference string.
*/
private static final int LANGUAGE_PREFERENCE_LENGTH = 2;
/**
* Maximum valid start zoom level.
*/
private static final int START_ZOOM_LEVEL_MAX = 22;
static OpenResult readOptionalFields(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
OptionalFields optionalFields = new OptionalFields(readBuffer.readByte());
mapFileInfoBuilder.optionalFields = optionalFields;
OpenResult openResult = optionalFields.readOptionalFields(readBuffer);
if (!openResult.isSuccess()) {
return openResult;
}
return OpenResult.SUCCESS;
}
String comment;
String createdBy;
final boolean hasComment;
final boolean hasCreatedBy;
final boolean hasLanguagePreference;
final boolean hasStartPosition;
final boolean hasStartZoomLevel;
final boolean isDebugFile;
String languagePreference;
GeoPoint startPosition;
Byte startZoomLevel;
private OptionalFields(byte flags) {
this.isDebugFile = (flags & HEADER_BITMASK_DEBUG) != 0;
this.hasStartPosition = (flags & HEADER_BITMASK_START_POSITION) != 0;
this.hasStartZoomLevel = (flags & HEADER_BITMASK_START_ZOOM_LEVEL) != 0;
this.hasLanguagePreference = (flags & HEADER_BITMASK_LANGUAGE_PREFERENCE) != 0;
this.hasComment = (flags & HEADER_BITMASK_COMMENT) != 0;
this.hasCreatedBy = (flags & HEADER_BITMASK_CREATED_BY) != 0;
}
private OpenResult readLanguagePreference(ReadBuffer readBuffer) {
if (this.hasLanguagePreference) {
String countryCode = readBuffer.readUTF8EncodedString();
if (countryCode.length() != LANGUAGE_PREFERENCE_LENGTH) {
return new OpenResult("invalid language preference: " + countryCode);
}
this.languagePreference = countryCode;
}
return OpenResult.SUCCESS;
}
private OpenResult readMapStartPosition(ReadBuffer readBuffer) {
if (this.hasStartPosition) {
// get and check the start position latitude (4 byte)
int mapStartLatitude = readBuffer.readInt();
if (mapStartLatitude < RequiredFields.LATITUDE_MIN || mapStartLatitude > RequiredFields.LATITUDE_MAX) {
return new OpenResult("invalid map start latitude: " + mapStartLatitude);
}
// get and check the start position longitude (4 byte)
int mapStartLongitude = readBuffer.readInt();
if (mapStartLongitude < RequiredFields.LONGITUDE_MIN || mapStartLongitude > RequiredFields.LONGITUDE_MAX) {
return new OpenResult("invalid map start longitude: " + mapStartLongitude);
}
this.startPosition = new GeoPoint(mapStartLatitude, mapStartLongitude);
}
return OpenResult.SUCCESS;
}
private OpenResult readMapStartZoomLevel(ReadBuffer readBuffer) {
if (this.hasStartZoomLevel) {
// get and check the start zoom level (1 byte)
byte mapStartZoomLevel = readBuffer.readByte();
if (mapStartZoomLevel < 0 || mapStartZoomLevel > START_ZOOM_LEVEL_MAX) {
return new OpenResult("invalid map start zoom level: " + mapStartZoomLevel);
}
this.startZoomLevel = Byte.valueOf(mapStartZoomLevel);
}
return OpenResult.SUCCESS;
}
private OpenResult readOptionalFields(ReadBuffer readBuffer) {
OpenResult openResult = readMapStartPosition(readBuffer);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = readMapStartZoomLevel(readBuffer);
if (!openResult.isSuccess()) {
return openResult;
}
openResult = readLanguagePreference(readBuffer);
if (!openResult.isSuccess()) {
return openResult;
}
if (this.hasComment) {
this.comment = readBuffer.readUTF8EncodedString();
}
if (this.hasCreatedBy) {
this.createdBy = readBuffer.readUTF8EncodedString();
}
return OpenResult.SUCCESS;
}
}

View File

@@ -0,0 +1,235 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile.header;
import java.io.IOException;
import org.oscim.core.BoundingBox;
import org.oscim.core.Tag;
import org.oscim.database.OpenResult;
import org.oscim.database.mapfile.ReadBuffer;
final class RequiredFields {
/**
* Magic byte at the beginning of a valid binary map file.
*/
private static final String BINARY_OSM_MAGIC_BYTE = "mapsforge binary OSM";
/**
* Maximum size of the file header in bytes.
*/
private static final int HEADER_SIZE_MAX = 1000000;
/**
* Minimum size of the file header in bytes.
*/
private static final int HEADER_SIZE_MIN = 70;
/**
* The name of the Mercator projection as stored in the file header.
*/
private static final String MERCATOR = "Mercator";
/**
* A single whitespace character.
*/
private static final char SPACE = ' ';
/**
* Version of the map file format which is supported by this implementation.
*/
private static final int SUPPORTED_FILE_VERSION = 4;
/**
* The maximum latitude values in microdegrees.
*/
static final int LATITUDE_MAX = 90000000;
/**
* The minimum latitude values in microdegrees.
*/
static final int LATITUDE_MIN = -90000000;
/**
* The maximum longitude values in microdegrees.
*/
static final int LONGITUDE_MAX = 180000000;
/**
* The minimum longitude values in microdegrees.
*/
static final int LONGITUDE_MIN = -180000000;
static OpenResult readBoundingBox(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the minimum latitude (4 bytes)
int minLatitude = readBuffer.readInt();
if (minLatitude < LATITUDE_MIN || minLatitude > LATITUDE_MAX) {
return new OpenResult("invalid minimum latitude: " + minLatitude);
}
// get and check the minimum longitude (4 bytes)
int minLongitude = readBuffer.readInt();
if (minLongitude < LONGITUDE_MIN || minLongitude > LONGITUDE_MAX) {
return new OpenResult("invalid minimum longitude: " + minLongitude);
}
// get and check the maximum latitude (4 bytes)
int maxLatitude = readBuffer.readInt();
if (maxLatitude < LATITUDE_MIN || maxLatitude > LATITUDE_MAX) {
return new OpenResult("invalid maximum latitude: " + maxLatitude);
}
// get and check the maximum longitude (4 bytes)
int maxLongitude = readBuffer.readInt();
if (maxLongitude < LONGITUDE_MIN || maxLongitude > LONGITUDE_MAX) {
return new OpenResult("invalid maximum longitude: " + maxLongitude);
}
// check latitude and longitude range
if (minLatitude > maxLatitude) {
return new OpenResult("invalid latitude range: " + minLatitude + SPACE + maxLatitude);
} else if (minLongitude > maxLongitude) {
return new OpenResult("invalid longitude range: " + minLongitude + SPACE + maxLongitude);
}
mapFileInfoBuilder.boundingBox = new BoundingBox(minLatitude, minLongitude, maxLatitude, maxLongitude);
return OpenResult.SUCCESS;
}
static OpenResult readFileSize(ReadBuffer readBuffer, long fileSize, MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the file size (8 bytes)
long headerFileSize = readBuffer.readLong();
if (headerFileSize != fileSize) {
return new OpenResult("invalid file size: " + headerFileSize);
}
mapFileInfoBuilder.fileSize = fileSize;
return OpenResult.SUCCESS;
}
static OpenResult readFileVersion(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the file version (4 bytes)
int fileVersion = readBuffer.readInt();
if (fileVersion != SUPPORTED_FILE_VERSION) {
return new OpenResult("unsupported file version: " + fileVersion);
}
mapFileInfoBuilder.fileVersion = fileVersion;
return OpenResult.SUCCESS;
}
static OpenResult readMagicByte(ReadBuffer readBuffer) throws IOException {
// read the the magic byte and the file header size into the buffer
int magicByteLength = BINARY_OSM_MAGIC_BYTE.length();
if (!readBuffer.readFromFile(magicByteLength + 4)) {
return new OpenResult("reading magic byte has failed");
}
// get and check the magic byte
String magicByte = readBuffer.readUTF8EncodedString(magicByteLength);
if (!BINARY_OSM_MAGIC_BYTE.equals(magicByte)) {
return new OpenResult("invalid magic byte: " + magicByte);
}
return OpenResult.SUCCESS;
}
static OpenResult readMapDate(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the the map date (8 bytes)
long mapDate = readBuffer.readLong();
// is the map date before 2010-01-10 ?
if (mapDate < 1200000000000L) {
return new OpenResult("invalid map date: " + mapDate);
}
mapFileInfoBuilder.mapDate = mapDate;
return OpenResult.SUCCESS;
}
static OpenResult readPoiTags(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the number of POI tags (2 bytes)
int numberOfPoiTags = readBuffer.readShort();
if (numberOfPoiTags < 0) {
return new OpenResult("invalid number of POI tags: " + numberOfPoiTags);
}
Tag[] poiTags = new Tag[numberOfPoiTags];
for (int currentTagId = 0; currentTagId < numberOfPoiTags; ++currentTagId) {
// get and check the POI tag
String tag = readBuffer.readUTF8EncodedString();
if (tag == null) {
return new OpenResult("POI tag must not be null: " + currentTagId);
}
poiTags[currentTagId] = new Tag(tag);
}
mapFileInfoBuilder.poiTags = poiTags;
return OpenResult.SUCCESS;
}
static OpenResult readProjectionName(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the projection name
String projectionName = readBuffer.readUTF8EncodedString();
if (!MERCATOR.equals(projectionName)) {
return new OpenResult("unsupported projection: " + projectionName);
}
mapFileInfoBuilder.projectionName = projectionName;
return OpenResult.SUCCESS;
}
static OpenResult readRemainingHeader(ReadBuffer readBuffer) throws IOException {
// get and check the size of the remaining file header (4 bytes)
int remainingHeaderSize = readBuffer.readInt();
if (remainingHeaderSize < HEADER_SIZE_MIN || remainingHeaderSize > HEADER_SIZE_MAX) {
return new OpenResult("invalid remaining header size: " + remainingHeaderSize);
}
// read the header data into the buffer
if (!readBuffer.readFromFile(remainingHeaderSize)) {
return new OpenResult("reading header data has failed: " + remainingHeaderSize);
}
return OpenResult.SUCCESS;
}
static OpenResult readTilePixelSize(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the tile pixel size (2 bytes)
int tilePixelSize = readBuffer.readShort();
// if (tilePixelSize != Tile.TILE_SIZE) {
// return new FileOpenResult("unsupported tile pixel size: " + tilePixelSize);
// }
mapFileInfoBuilder.tilePixelSize = tilePixelSize;
return OpenResult.SUCCESS;
}
static OpenResult readWayTags(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the number of way tags (2 bytes)
int numberOfWayTags = readBuffer.readShort();
if (numberOfWayTags < 0) {
return new OpenResult("invalid number of way tags: " + numberOfWayTags);
}
Tag[] wayTags = new Tag[numberOfWayTags];
for (int currentTagId = 0; currentTagId < numberOfWayTags; ++currentTagId) {
// get and check the way tag
String tag = readBuffer.readUTF8EncodedString();
if (tag == null) {
return new OpenResult("way tag must not be null: " + currentTagId);
}
wayTags[currentTagId] = new Tag(tag);
}
mapFileInfoBuilder.wayTags = wayTags;
return OpenResult.SUCCESS;
}
private RequiredFields() {
throw new IllegalStateException();
}
}

View File

@@ -0,0 +1,213 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile.header;
import org.oscim.core.MercatorProjection;
/**
* Holds all parameters of a sub-file.
*/
public class SubFileParameter {
/**
* Number of bytes a single index entry consists of.
*/
public static final byte BYTES_PER_INDEX_ENTRY = 5;
/**
* Divisor for converting coordinates stored as integers to double values.
*/
private static final double COORDINATES_DIVISOR = 1000000d;
/**
* Base zoom level of the sub-file, which equals to one block.
*/
public final byte baseZoomLevel;
/**
* Size of the entries table at the beginning of each block in bytes.
*/
public final int blockEntriesTableSize;
/**
* Vertical amount of blocks in the grid.
*/
public final long blocksHeight;
/**
* Horizontal amount of blocks in the grid.
*/
public final long blocksWidth;
/**
* Y number of the tile at the bottom boundary in the grid.
*/
public final long boundaryTileBottom;
/**
* X number of the tile at the left boundary in the grid.
*/
public final long boundaryTileLeft;
/**
* X number of the tile at the right boundary in the grid.
*/
public final long boundaryTileRight;
/**
* Y number of the tile at the top boundary in the grid.
*/
public final long boundaryTileTop;
/**
* Absolute end address of the index in the enclosing file.
*/
public final long indexEndAddress;
/**
* Absolute start address of the index in the enclosing file.
*/
public final long indexStartAddress;
/**
* Total number of blocks in the grid.
*/
public final long numberOfBlocks;
/**
* Absolute start address of the sub-file in the enclosing file.
*/
public final long startAddress;
/**
* Size of the sub-file in bytes.
*/
public final long subFileSize;
/**
* Maximum zoom level for which the block entries tables are made.
*/
public final byte zoomLevelMax;
/**
* Minimum zoom level for which the block entries tables are made.
*/
public final byte zoomLevelMin;
/**
* Stores the hash code of this object.
*/
private final int hashCodeValue;
SubFileParameter(SubFileParameterBuilder subFileParameterBuilder) {
this.startAddress = subFileParameterBuilder.startAddress;
this.indexStartAddress = subFileParameterBuilder.indexStartAddress;
this.subFileSize = subFileParameterBuilder.subFileSize;
this.baseZoomLevel = subFileParameterBuilder.baseZoomLevel;
this.zoomLevelMin = subFileParameterBuilder.zoomLevelMin;
this.zoomLevelMax = subFileParameterBuilder.zoomLevelMax;
this.hashCodeValue = calculateHashCode();
// calculate the XY numbers of the boundary tiles in this sub-file
this.boundaryTileBottom = MercatorProjection.latitudeToTileY(subFileParameterBuilder.boundingBox.minLatitudeE6
/ COORDINATES_DIVISOR, this.baseZoomLevel);
this.boundaryTileLeft = MercatorProjection.longitudeToTileX(subFileParameterBuilder.boundingBox.minLongitudeE6
/ COORDINATES_DIVISOR, this.baseZoomLevel);
this.boundaryTileTop = MercatorProjection.latitudeToTileY(subFileParameterBuilder.boundingBox.maxLatitudeE6
/ COORDINATES_DIVISOR, this.baseZoomLevel);
this.boundaryTileRight = MercatorProjection.longitudeToTileX(subFileParameterBuilder.boundingBox.maxLongitudeE6
/ COORDINATES_DIVISOR, this.baseZoomLevel);
// calculate the horizontal and vertical amount of blocks in this sub-file
this.blocksWidth = this.boundaryTileRight - this.boundaryTileLeft + 1;
this.blocksHeight = this.boundaryTileBottom - this.boundaryTileTop + 1;
// calculate the total amount of blocks in this sub-file
this.numberOfBlocks = this.blocksWidth * this.blocksHeight;
this.indexEndAddress = this.indexStartAddress + this.numberOfBlocks * BYTES_PER_INDEX_ENTRY;
// calculate the size of the tile entries table
this.blockEntriesTableSize = 2 * (this.zoomLevelMax - this.zoomLevelMin + 1) * 2;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (!(obj instanceof SubFileParameter)) {
return false;
}
SubFileParameter other = (SubFileParameter) obj;
if (this.startAddress != other.startAddress) {
return false;
} else if (this.subFileSize != other.subFileSize) {
return false;
} else if (this.baseZoomLevel != other.baseZoomLevel) {
return false;
}
return true;
}
@Override
public int hashCode() {
return this.hashCodeValue;
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("SubFileParameter [baseZoomLevel=");
stringBuilder.append(this.baseZoomLevel);
stringBuilder.append(", blockEntriesTableSize=");
stringBuilder.append(this.blockEntriesTableSize);
stringBuilder.append(", blocksHeight=");
stringBuilder.append(this.blocksHeight);
stringBuilder.append(", blocksWidth=");
stringBuilder.append(this.blocksWidth);
stringBuilder.append(", boundaryTileBottom=");
stringBuilder.append(this.boundaryTileBottom);
stringBuilder.append(", boundaryTileLeft=");
stringBuilder.append(this.boundaryTileLeft);
stringBuilder.append(", boundaryTileRight=");
stringBuilder.append(this.boundaryTileRight);
stringBuilder.append(", boundaryTileTop=");
stringBuilder.append(this.boundaryTileTop);
stringBuilder.append(", indexStartAddress=");
stringBuilder.append(this.indexStartAddress);
stringBuilder.append(", numberOfBlocks=");
stringBuilder.append(this.numberOfBlocks);
stringBuilder.append(", startAddress=");
stringBuilder.append(this.startAddress);
stringBuilder.append(", subFileSize=");
stringBuilder.append(this.subFileSize);
stringBuilder.append(", zoomLevelMax=");
stringBuilder.append(this.zoomLevelMax);
stringBuilder.append(", zoomLevelMin=");
stringBuilder.append(this.zoomLevelMin);
stringBuilder.append("]");
return stringBuilder.toString();
}
/**
* @return the hash code of this object.
*/
private int calculateHashCode() {
int result = 7;
result = 31 * result + (int) (this.startAddress ^ (this.startAddress >>> 32));
result = 31 * result + (int) (this.subFileSize ^ (this.subFileSize >>> 32));
result = 31 * result + this.baseZoomLevel;
return result;
}
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.mapfile.header;
import org.oscim.core.BoundingBox;
class SubFileParameterBuilder {
byte baseZoomLevel;
BoundingBox boundingBox;
long indexStartAddress;
long startAddress;
long subFileSize;
byte zoomLevelMax;
byte zoomLevelMin;
SubFileParameter build() {
return new SubFileParameter(this);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,958 @@
/*
* Copyright 2012 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.pbmap;
import org.oscim.core.Tag;
public class Tags {
public final static int MAX = 654;
public final static int LIMIT = 1024;
private static final String s_limited = "limited".intern();
private static final String s_chain = "chain".intern();
private static final String s_viaduct = "viaduct".intern();
private static final String s_department_store = "department_store".intern();
private static final String s_factory = "factory".intern();
private static final String s_recreation_ground = "recreation_ground".intern();
private static final String s_nature_reserve = "nature_reserve".intern();
private static final String s_apartment = "apartment".intern();
private static final String s_preserved = "preserved".intern();
private static final String s_stationery = "stationery".intern();
private static final String s_gravel = "gravel".intern();
private static final String s_hill = "hill".intern();
private static final String s_water_well = "water_well".intern();
private static final String s_garden = "garden".intern();
private static final String s_permissive = "permissive".intern();
private static final String s_deli = "deli".intern();
private static final String s_industrial_retail = "industrial;retail".intern();
private static final String s_city_wall = "city_wall".intern();
private static final String s_artwork = "artwork".intern();
private static final String s_chapel = "chapel".intern();
private static final String s_school = "school".intern();
private static final String s_caravan_site = "caravan_site".intern();
private static final String s_reservoir_watershed = "reservoir_watershed".intern();
private static final String s_local_authority = "local_authority".intern();
private static final String s_miniature_golf = "miniature_golf".intern();
private static final String s_bus_stop = "bus_stop".intern();
private static final String s_convenience = "convenience".intern();
private static final String s_kissing_gate = "kissing_gate".intern();
private static final String s_subway = "subway".intern();
private static final String s_cutline = "cutline".intern();
private static final String s_disused = "disused".intern();
private static final String s_clothes = "clothes".intern();
private static final String s_bicycle = "bicycle".intern();
private static final String s_meadow = "meadow".intern();
private static final String s_fence = "fence".intern();
private static final String s_video = "video".intern();
private static final String s_monorail = "monorail".intern();
private static final String s_clock = "clock".intern();
private static final String s_dirt = "dirt".intern();
private static final String s_border_control = "border_control".intern();
private static final String s_access = "access".intern();
private static final String s_public = "public".intern();
private static final String s_fast_food = "fast_food".intern();
private static final String s_transportation = "transportation".intern();
private static final String s_commercial = "commercial".intern();
private static final String s_water = "water".intern();
private static final String s_beacon = "beacon".intern();
private static final String s_trunk = "trunk".intern();
private static final String s_path = "path".intern();
private static final String s_bicycle_rental = "bicycle_rental".intern();
private static final String s_miniature = "miniature".intern();
private static final String s_car_parts = "car_parts".intern();
private static final String s_light_rail = "light_rail".intern();
private static final String s_military = "military".intern();
private static final String s_bog = "bog".intern();
private static final String s_hiking = "hiking".intern();
private static final String s_lift_gate = "lift_gate".intern();
private static final String s_private = "private".intern();
private static final String s_county = "county".intern();
private static final String s_secondary_link = "secondary_link".intern();
private static final String s_marker = "marker".intern();
private static final String s_islet = "islet".intern();
private static final String s_holding_position = "holding_position".intern();
private static final String s_tertiary = "tertiary".intern();
private static final String s_water_park = "water_park".intern();
private static final String s_stream = "stream".intern();
private static final String s_hospital = "hospital".intern();
private static final String s_destination = "destination".intern();
private static final String s_MDF = "MDF".intern();
private static final String s_sports = "sports".intern();
private static final String s_vineyard = "vineyard".intern();
private static final String s_music = "music".intern();
private static final String s_6 = "6".intern();
private static final String s_entrance = "entrance".intern();
private static final String s_beauty = "beauty".intern();
private static final String s_give_way = "give_way".intern();
private static final String s_kiosk = "kiosk".intern();
private static final String s_stone = "stone".intern();
private static final String s_grass_paver = "grass_paver".intern();
private static final String s_deciduous = "deciduous".intern();
private static final String s_train = "train".intern();
private static final String s_organic = "organic".intern();
private static final String s_farmyard = "farmyard".intern();
private static final String s_riverbank = "riverbank".intern();
private static final String s_doityourself = "doityourself".intern();
private static final String s_town = "town".intern();
private static final String s_dog_park = "dog_park".intern();
private static final String s_village_green = "village_green".intern();
private static final String s_tunnel = "tunnel".intern();
private static final String s_car = "car".intern();
private static final String s_roof = "roof".intern();
private static final String s_mall = "mall".intern();
private static final String s_ferry_terminal = "ferry_terminal".intern();
private static final String s_cave_entrance = "cave_entrance".intern();
private static final String s_detached = "detached".intern();
private static final String s_concrete_plates = "concrete:plates".intern();
private static final String s_public_building = "public_building".intern();
private static final String s_buffer_stop = "buffer_stop".intern();
private static final String s_lock = "lock".intern();
private static final String s_dolphin = "dolphin".intern();
private static final String s_taxiway = "taxiway".intern();
private static final String s_hunting_stand = "hunting_stand".intern();
private static final String s_estate_agent = "estate_agent".intern();
private static final String s_station = "station".intern();
private static final String s_car_repair = "car_repair".intern();
private static final String s_dyke = "dyke".intern();
private static final String s_hangar = "hangar".intern();
private static final String s_information = "information".intern();
private static final String s_1 = "1".intern();
private static final String s_forest = "forest".intern();
private static final String s_gate = "gate".intern();
private static final String s_beach = "beach".intern();
private static final String s_laundry = "laundry".intern();
private static final String s_speed_camera = "speed_camera".intern();
private static final String s_staircase = "staircase".intern();
private static final String s_farm = "farm".intern();
private static final String s_stop = "stop".intern();
private static final String s_bump_gate = "bump_gate".intern();
private static final String s_motorway = "motorway".intern();
private static final String s_water_tower = "water_tower".intern();
private static final String s_abutters = "abutters".intern();
private static final String s_driving_school = "driving_school".intern();
private static final String s_natural = "natural".intern();
private static final String s_orchard = "orchard".intern();
private static final String s_wheelchair = "wheelchair".intern();
private static final String s_swimming_pool = "swimming_pool".intern();
private static final String s_switch = "switch".intern();
private static final String s_block = "block".intern();
private static final String s_turnstile = "turnstile".intern();
private static final String s_camp_site = "camp_site".intern();
private static final String s_shoes = "shoes".intern();
private static final String s_reservoir = "reservoir".intern();
private static final String s_pebblestone = "pebblestone".intern();
private static final String s_stile = "stile".intern();
private static final String s_embassy = "embassy".intern();
private static final String s_postal_code = "postal_code".intern();
private static final String s_retaining_wall = "retaining_wall".intern();
private static final String s_bridleway = "bridleway".intern();
private static final String s_pitch = "pitch".intern();
private static final String s_agricultural = "agricultural".intern();
private static final String s_post_office = "post_office".intern();
private static final String s_parking_fuel = "parking;fuel".intern();
private static final String s_bureau_de_change = "bureau_de_change".intern();
private static final String s_mini_roundabout = "mini_roundabout".intern();
private static final String s_hov = "hov".intern();
private static final String s_police = "police".intern();
private static final String s_courthouse = "courthouse".intern();
private static final String s_raceway = "raceway".intern();
private static final String s_kindergarten = "kindergarten".intern();
private static final String s_attraction = "attraction".intern();
private static final String s_marsh = "marsh".intern();
private static final String s_reservoir_covered = "reservoir_covered".intern();
private static final String s_petroleum_well = "petroleum_well".intern();
private static final String s_silo = "silo".intern();
private static final String s_toys = "toys".intern();
private static final String s_apron = "apron".intern();
private static final String s_halt = "halt".intern();
private static final String s_dam = "dam".intern();
private static final String s_golf_course = "golf_course".intern();
private static final String s_detour = "detour".intern();
private static final String s_tree_row = "tree_row".intern();
private static final String s_copyshop = "copyshop".intern();
private static final String s_milestone = "milestone".intern();
private static final String s_foot = "foot".intern();
private static final String s_tourism = "tourism".intern();
private static final String s_bank = "bank".intern();
private static final String s_dry_cleaning = "dry_cleaning".intern();
private static final String s_tram = "tram".intern();
private static final String s_trolleybus = "trolleybus".intern();
private static final String s_university = "university".intern();
private static final String s_hampshire_gate = "hampshire_gate".intern();
private static final String s_embankment = "embankment".intern();
private static final String s_rock = "rock".intern();
private static final String s_crossing = "crossing".intern();
private static final String s_volcano = "volcano".intern();
private static final String s_greengrocer = "greengrocer".intern();
private static final String s_kerb = "kerb".intern();
private static final String s_waste_disposal = "waste_disposal".intern();
private static final String s_grave_yard = "grave_yard".intern();
private static final String s_coniferous = "coniferous".intern();
private static final String s_house = "house".intern();
private static final String s_books = "books".intern();
private static final String s_neighbourhood = "neighbourhood".intern();
private static final String s_hostel = "hostel".intern();
private static final String s_alcohol = "alcohol".intern();
private static final String s_restricted = "restricted".intern();
private static final String s_motel = "motel".intern();
private static final String s_sand = "sand".intern();
private static final String s_fishmonger = "fishmonger".intern();
private static final String s_fountain = "fountain".intern();
private static final String s_playground = "playground".intern();
private static final String s_7 = "7".intern();
private static final String s_parking_aisle = "parking_aisle".intern();
private static final String s_protected_area = "protected_area".intern();
private static final String s_electronics = "electronics".intern();
private static final String s_Paved = "Paved".intern();
private static final String s_highway = "highway".intern();
private static final String s_fine_gravel = "fine_gravel".intern();
private static final String s_barrier = "barrier".intern();
private static final String s_hairdresser = "hairdresser".intern();
private static final String s_post_box = "post_box".intern();
private static final String s_pub = "pub".intern();
private static final String s_coastline = "coastline".intern();
private static final String s_marina = "marina".intern();
private static final String s_reedbed = "reedbed".intern();
private static final String s_biergarten = "biergarten".intern();
private static final String s_dismantled = "dismantled".intern();
private static final String s_farmland = "farmland".intern();
private static final String s_yard = "yard".intern();
private static final String s_route = "route".intern();
private static final String s_atm = "atm".intern();
private static final String s_place = "place".intern();
private static final String s_bus_station = "bus_station".intern();
private static final String s_retail = "retail".intern();
private static final String s_industrial = "industrial".intern();
private static final String s_municipality = "municipality".intern();
private static final String s_primary = "primary".intern();
private static final String s_nursing_home = "nursing_home".intern();
private static final String s_florist = "florist".intern();
private static final String s_ditch = "ditch".intern();
private static final String s_national_park = "national_park".intern();
private static final String s_city = "city".intern();
private static final String s_confectionery = "confectionery".intern();
private static final String s_service = "service".intern();
private static final String s_unknown = "unknown".intern();
private static final String s_cycle_barrier = "cycle_barrier".intern();
private static final String s_elevator = "elevator".intern();
private static final String s_2 = "2".intern();
private static final String s_car_rental = "car_rental".intern();
private static final String s_flagpole = "flagpole".intern();
private static final String s_cabin = "cabin".intern();
private static final String s_paved = "paved".intern();
private static final String s_guest_house = "guest_house".intern();
private static final String s_mobile_phone = "mobile_phone".intern();
private static final String s_lot = "lot".intern();
private static final String s_quarry = "quarry".intern();
private static final String s_train_station = "train_station".intern();
private static final String s_hotel = "hotel".intern();
private static final String s_park = "park".intern();
private static final String s_hut = "hut".intern();
private static final String s_dentist = "dentist".intern();
private static final String s_doctors = "doctors".intern();
private static final String s_greenhouse = "greenhouse".intern();
private static final String s_11 = "11".intern();
private static final String s_10 = "10".intern();
private static final String s_theme_park = "theme_park".intern();
private static final String s_tree = "tree".intern();
private static final String s_shower = "shower".intern();
private static final String s_siding = "siding".intern();
private static final String s_aeroway = "aeroway".intern();
private static final String s_emergency_access_point = "emergency_access_point"
.intern();
private static final String s_watermill = "watermill".intern();
private static final String s_college = "college".intern();
private static final String s_landuse = "landuse".intern();
private static final String s_tracktype = "tracktype".intern();
private static final String s_ferry = "ferry".intern();
private static final String s_bridge = "bridge".intern();
private static final String s_vacant = "vacant".intern();
private static final String s_cattle_grid = "cattle_grid".intern();
private static final String s_brownfield = "brownfield".intern();
private static final String s_allotments = "allotments".intern();
private static final String s_alley = "alley".intern();
private static final String s_pedestrian = "pedestrian".intern();
private static final String s_borough = "borough".intern();
private static final String s_bare_rock = "bare_rock".intern();
private static final String s_motorcycle = "motorcycle".intern();
private static final String s_bakery = "bakery".intern();
private static final String s_zoo = "zoo".intern();
private static final String s_scree = "scree".intern();
private static final String s_fire_station = "fire_station".intern();
private static final String s_theatre = "theatre".intern();
private static final String s_track = "track".intern();
private static final String s_reinforced_slope = "reinforced_slope".intern();
private static final String s_slipway = "slipway".intern();
private static final String s_mangrove = "mangrove".intern();
private static final String s_aerodrome = "aerodrome".intern();
private static final String s_byway = "byway".intern();
private static final String s_metal = "metal".intern();
private static final String s_swamp = "swamp".intern();
private static final String s_construction = "construction".intern();
private static final String s_grassland = "grassland".intern();
private static final String s_shop = "shop".intern();
private static final String s_soakhole = "soakhole".intern();
private static final String s_asphalt = "asphalt".intern();
private static final String s_social_facility = "social_facility".intern();
private static final String s_isolated_dwelling = "isolated_dwelling".intern();
private static final String s_hamlet = "hamlet".intern();
private static final String s_picnic_table = "picnic_table".intern();
private static final String s_artificial = "artificial".intern();
private static final String s_earth = "earth".intern();
private static final String s_grit_bin = "grit_bin".intern();
private static final String s_ground = "ground".intern();
private static final String s_groyne = "groyne".intern();
private static final String s_office = "office".intern();
private static final String s_state = "state".intern();
private static final String s_terminal = "terminal".intern();
private static final String s_wood = "wood".intern();
private static final String s_fuel = "fuel".intern();
private static final String s_8 = "8".intern();
private static final String s_garden_centre = "garden_centre".intern();
private static final String s_horse_riding = "horse_riding".intern();
private static final String s_viewpoint = "viewpoint".intern();
private static final String s_designated = "designated".intern();
private static final String s_leisure = "leisure".intern();
private static final String s_waste_basket = "waste_basket".intern();
private static final String s_hifi = "hifi".intern();
private static final String s_hedge = "hedge".intern();
private static final String s_spur = "spur".intern();
private static final String s_chimney = "chimney".intern();
private static final String s_secondary = "secondary".intern();
private static final String s_rest_area = "rest_area".intern();
private static final String s_bar = "bar".intern();
private static final String s_bay = "bay".intern();
private static final String s_common = "common".intern();
private static final String s_river = "river".intern();
private static final String s_ruins = "ruins".intern();
private static final String s_terrace = "terrace".intern();
private static final String s_art = "art".intern();
private static final String s_residental = "residental".intern();
private static final String s_newsagent = "newsagent".intern();
private static final String s_turntable = "turntable".intern();
private static final String s_computer = "computer".intern();
private static final String s_wetland = "wetland".intern();
private static final String s_driveway = "driveway".intern();
private static final String s_parking = "parking".intern();
private static final String s_compacted = "compacted".intern();
private static final String s_barn = "barn".intern();
private static final String s_alpine_hut = "alpine_hut".intern();
private static final String s_wire_fence = "wire_fence".intern();
private static final String s_unpaved = "unpaved".intern();
private static final String s_dormitory = "dormitory".intern();
private static final String s_mud = "mud".intern();
private static final String s_3 = "3".intern();
private static final String s_semi = "semi".intern();
private static final String s_boundary = "boundary".intern();
private static final String s_field_boundary = "field_boundary".intern();
private static final String s_beverages = "beverages".intern();
private static final String s_supermarket = "supermarket".intern();
private static final String s_store = "store".intern();
private static final String s_restaurant = "restaurant".intern();
private static final String s_region = "region".intern();
private static final String s_variety_store = "variety_store".intern();
private static final String s_saltmarsh = "saltmarsh".intern();
private static final String s_landform = "landform".intern();
private static final String s_helipad = "helipad".intern();
private static final String s_railway = "railway".intern();
private static final String s_greenhouse_horticulture = "greenhouse_horticulture"
.intern();
private static final String s_wall = "wall".intern();
private static final String s_recycling = "recycling".intern();
private static final String s_passing_place = "passing_place".intern();
private static final String s_church = "church".intern();
private static final String s_pharmacy = "pharmacy".intern();
private static final String s_lighthouse = "lighthouse".intern();
private static final String s_platform = "platform".intern();
private static final String s_cinema = "cinema".intern();
private static final String s_political = "political".intern();
private static final String s_stadium = "stadium".intern();
private static final String s_basin = "basin".intern();
private static final String s_gasometer = "gasometer".intern();
private static final String s_bicycle_parking = "bicycle_parking".intern();
private static final String s_bbq = "bbq".intern();
private static final String s_incline_steep = "incline_steep".intern();
private static final String s_drinking_water = "drinking_water".intern();
private static final String s_living_street = "living_street".intern();
private static final String s_chalet = "chalet".intern();
private static final String s_narrow_gauge = "narrow_gauge".intern();
private static final String s_prison = "prison".intern();
private static final String s_mine = "mine".intern();
private static final String s_level_crossing = "level_crossing".intern();
private static final String s_water_works = "water_works".intern();
private static final String s_street_lamp = "street_lamp".intern();
private static final String s_main = "main".intern();
private static final String s_tank = "tank".intern();
private static final String s_abandoned = "abandoned".intern();
private static final String s_ski = "ski".intern();
private static final String s_runway = "runway".intern();
private static final String s_parking_space = "parking_space".intern();
private static final String s_dirt_sand = "dirt/sand".intern();
private static final String s_salt_pond = "salt_pond".intern();
private static final String s_hedge_bank = "hedge_bank".intern();
private static final String s_amenity = "amenity".intern();
private static final String s_telephone = "telephone".intern();
private static final String s_surface = "surface".intern();
private static final String s_travel_agency = "travel_agency".intern();
private static final String s_hardware = "hardware".intern();
private static final String s_wastewater_plant = "wastewater_plant".intern();
private static final String s_waterway = "waterway".intern();
private static final String s_butcher = "butcher".intern();
private static final String s_surveillance = "surveillance".intern();
private static final String s_Dirt_Sand = "Dirt/Sand".intern();
private static final String s_9 = "9".intern();
private static final String s_windmill = "windmill".intern();
private static final String s_picnic_site = "picnic_site".intern();
private static final String s_rail = "rail".intern();
private static final String s_cement = "cement".intern();
private static final String s_sauna = "sauna".intern();
private static final String s_suburb = "suburb".intern();
private static final String s_waterfall = "waterfall".intern();
private static final String s_bunker = "bunker".intern();
private static final String s_ice_cream = "ice_cream".intern();
private static final String s_culvert = "culvert".intern();
private static final String s_drain = "drain".intern();
private static final String s_dock = "dock".intern();
private static final String s_glasshouse = "glasshouse".intern();
private static final String s_no = "no".intern();
private static final String s_well = "well".intern();
private static final String s_wet_meadow = "wet_meadow".intern();
private static final String s_concrete = "concrete".intern();
private static final String s_dismount = "dismount".intern();
private static final String s_vending_machine = "vending_machine".intern();
private static final String s_oneway = "oneway".intern();
private static final String s_taxi = "taxi".intern();
private static final String s_outdoor = "outdoor".intern();
private static final String s_proposed = "proposed".intern();
private static final String s_sally_port = "sally_port".intern();
private static final String s_photo = "photo".intern();
private static final String s_plant_nursery = "plant_nursery".intern();
private static final String s_clinic = "clinic".intern();
private static final String s_fishing = "fishing".intern();
private static final String s_yes = "yes".intern();
private static final String s_turning_circle = "turning_circle".intern();
private static final String s_toilets = "toilets".intern();
private static final String s_guard_rail = "guard_rail".intern();
private static final String s_townhall = "townhall".intern();
private static final String s_community_centre = "community_centre".intern();
private static final String s_residential = "residential".intern();
private static final String s_cemetery = "cemetery".intern();
private static final String s_survey_point = "survey_point".intern();
private static final String s_bench = "bench".intern();
private static final String s_4 = "4".intern();
private static final String s_bollard = "bollard".intern();
private static final String s_sports_centre = "sports_centre".intern();
private static final String s_paving_stones_30 = "paving_stones:30".intern();
private static final String s_administrative = "administrative".intern();
private static final String s_Building = "Building".intern();
private static final String s_customers = "customers".intern();
private static final String s_emergency = "emergency".intern();
private static final String s_motorway_junction = "motorway_junction".intern();
private static final String s_grade1 = "grade1".intern();
private static final String s_grade3 = "grade3".intern();
private static final String s_grade2 = "grade2".intern();
private static final String s_grade5 = "grade5".intern();
private static final String s_grade4 = "grade4".intern();
private static final String s_lock_gate = "lock_gate".intern();
private static final String s_furniture = "furniture".intern();
private static final String s_place_of_worship = "place_of_worship".intern();
private static final String s_optician = "optician".intern();
private static final String s_gift = "gift".intern();
private static final String s_parking_entrance = "parking_entrance".intern();
private static final String s_garage = "garage".intern();
private static final String s_tram_stop = "tram_stop".intern();
private static final String s_steps = "steps".intern();
private static final String s_tower = "tower".intern();
private static final String s_works = "works".intern();
private static final String s_shed = "shed".intern();
private static final String s_car_sharing = "car_sharing".intern();
private static final String s_apartments = "apartments".intern();
private static final String s_spring = "spring".intern();
private static final String s_village = "village".intern();
private static final String s_library = "library".intern();
private static final String s_emergency_access = "emergency_access".intern();
private static final String s_home = "home".intern();
private static final String s_farm_auxiliary = "farm_auxiliary".intern();
private static final String s_primary_link = "primary_link".intern();
private static final String s_toll_booth = "toll_booth".intern();
private static final String s_jewelry = "jewelry".intern();
private static final String s_pet = "pet".intern();
private static final String s_veterinary = "veterinary".intern();
private static final String s_man_made = "man_made".intern();
private static final String s_motorway_link = "motorway_link".intern();
private static final String s_offices = "offices".intern();
private static final String s_power = "power".intern();
private static final String s_weir = "weir".intern();
private static final String s_unsurfaced = "unsurfaced".intern();
private static final String s_tertiary_link = "tertiary_link".intern();
private static final String s_trunk_link = "trunk_link".intern();
private static final String s_tyres = "tyres".intern();
private static final String s_paving_stones = "paving_stones".intern();
private static final String s_pipeline = "pipeline".intern();
private static final String s_census = "census".intern();
private static final String s_incline = "incline".intern();
private static final String s_footway = "footway".intern();
private static final String s_drive_through = "drive-through".intern();
private static final String s_island = "island".intern();
private static final String s_monitoring_station = "monitoring_station".intern();
private static final String s_nightclub = "nightclub".intern();
private static final String s_unclassified = "unclassified".intern();
private static final String s_aquaculture = "aquaculture".intern();
private static final String s_mixed = "mixed".intern();
private static final String s_road = "road".intern();
private static final String s_greenfield = "greenfield".intern();
private static final String s_breakwater = "breakwater".intern();
private static final String s_services = "services".intern();
private static final String s_railway_crossing = "railway_crossing".intern();
private static final String s_residentiel1 = "residentiel1".intern();
private static final String s_canal = "canal".intern();
private static final String s__1 = "-1".intern();
private static final String s_ridge = "ridge".intern();
private static final String s_fabric = "fabric".intern();
private static final String s_museum = "museum".intern();
private static final String s_communications_tower = "communications_tower".intern();
private static final String s_semi_detached = "semi-detached".intern();
private static final String s_conservation = "conservation".intern();
private static final String s_way = "way".intern();
private static final String s_wood_fence = "wood_fence".intern();
private static final String s_manufacture = "manufacture".intern();
private static final String s_admin_level = "admin_level".intern();
private static final String s_building_concrete = "building_concrete".intern();
private static final String s_bus = "bus".intern();
private static final String s_collapsed = "collapsed".intern();
private static final String s_ford = "ford".intern();
private static final String s_delivery = "delivery".intern();
private static final String s_garages = "garages".intern();
private static final String s_funeral_directors = "funeral_directors".intern();
private static final String s_land = "land".intern();
private static final String s_interlock = "interlock".intern();
private static final String s_reef = "reef".intern();
private static final String s_crane = "crane".intern();
private static final String s_true = "true".intern();
private static final String s_storage_tank = "storage_tank".intern();
private static final String s_official = "official".intern();
private static final String s_subway_entrance = "subway_entrance".intern();
private static final String s_mtb = "mtb".intern();
private static final String s_grass = "grass".intern();
private static final String s_marketplace = "marketplace".intern();
private static final String s_rapids = "rapids".intern();
private static final String s_car_wash = "car_wash".intern();
private static final String s_general = "general".intern();
private static final String s_cafe = "cafe".intern();
private static final String s_locality = "locality".intern();
private static final String s_glacier = "glacier".intern();
private static final String s_storage = "storage".intern();
private static final String s_cycleway = "cycleway".intern();
private static final String s_forestry = "forestry".intern();
private static final String s_field = "field".intern();
private static final String s_5 = "5".intern();
private static final String s_arts_centre = "arts_centre".intern();
private static final String s_warehouse = "warehouse".intern();
private static final String s_chemist = "chemist".intern();
private static final String s_pier = "pier".intern();
private static final String s_scrub = "scrub".intern();
private static final String s_shelter = "shelter".intern();
private static final String s_emergency_phone = "emergency_phone".intern();
private static final String s_tidalflat = "tidalflat".intern();
private static final String s_cobblestone = "cobblestone".intern();
private static final String s_fell = "fell".intern();
private static final String s_peak = "peak".intern();
private static final String s_charging_station = "charging_station".intern();
private static final String s_cliff = "cliff".intern();
private static final String s_building = "building".intern();
private static final String s_fire_hydrant = "fire_hydrant".intern();
private static final String s_traffic_signals = "traffic_signals".intern();
private static final String s_heath = "heath".intern();
private static final String s_landfill = "landfill".intern();
private static final String s_mast = "mast".intern();
private static final String s_boutique = "boutique".intern();
private static final String s_boat_storage = "boat_storage".intern();
public final static Tag[] tags = {
new Tag(s_building, s_yes, true), new Tag(s_highway, s_residential, true),
new Tag(s_highway, s_service, true), new Tag(s_waterway, s_stream, true),
new Tag(s_highway, s_unclassified, true), new Tag(s_highway, s_track, true),
new Tag(s_oneway, s_yes, true), new Tag(s_natural, s_water, true),
new Tag(s_highway, s_footway, true), new Tag(s_access, s_private, true),
new Tag(s_highway, s_tertiary, true), new Tag(s_highway, s_path, true),
new Tag(s_highway, s_secondary, true), new Tag(s_landuse, s_forest, true),
new Tag(s_bridge, s_yes, true), new Tag(s_natural, s_tree, true),
new Tag(s_surface, s_paved, true), new Tag(s_natural, s_wood, true),
new Tag(s_highway, s_primary, true), new Tag(s_landuse, s_grass, true),
new Tag(s_landuse, s_residential, true), new Tag(s_surface, s_unpaved, true),
new Tag(s_highway, s_bus_stop, true), new Tag(s_surface, s_asphalt, true),
new Tag(s_bicycle, s_yes, true), new Tag(s_amenity, s_parking, true),
new Tag(s_place, s_locality, true), new Tag(s_railway, s_rail, true),
new Tag(s_service, s_parking_aisle, true),
new Tag(s_boundary, s_administrative, true),
new Tag(s_building, s_house, true), new Tag(s_place, s_village, true),
new Tag(s_natural, s_coastline, true), new Tag(s_tracktype, s_grade2, true),
new Tag(s_oneway, s_no, true), new Tag(s_service, s_driveway, true),
new Tag(s_highway, s_turning_circle, true), new Tag(s_place, s_hamlet, true),
new Tag(s_natural, s_wetland, true), new Tag(s_tracktype, s_grade3, true),
new Tag(s_waterway, s_river, true), new Tag(s_highway, s_cycleway, true),
new Tag(s_barrier, s_fence, true), new Tag(s_building, s_residential, true),
new Tag(s_amenity, s_school, true), new Tag(s_highway, s_crossing, true),
new Tag(s_admin_level, s_8, true), new Tag(s_highway, s_trunk, true),
new Tag(s_amenity, s_place_of_worship, true),
new Tag(s_landuse, s_farmland, true), new Tag(s_tracktype, s_grade1, true),
new Tag(s_highway, s_road, true), new Tag(s_landuse, s_farm, true),
new Tag(s_surface, s_gravel, true), new Tag(s_landuse, s_meadow, true),
new Tag(s_highway, s_motorway, true),
new Tag(s_highway, s_traffic_signals, true),
new Tag(s_building, s_hut, true), new Tag(s_highway, s_motorway_link, true),
new Tag(s_tracktype, s_grade4, true), new Tag(s_barrier, s_gate, true),
new Tag(s_highway, s_living_street, true), new Tag(s_bicycle, s_no, true),
new Tag(s_leisure, s_pitch, true), new Tag(s_tunnel, s_yes, true),
new Tag(s_surface, s_ground, true), new Tag(s_highway, s_steps, true),
new Tag(s_natural, s_land, true), new Tag(s_man_made, s_survey_point, true),
new Tag(s_tracktype, s_grade5, true), new Tag(s_waterway, s_ditch, true),
new Tag(s_leisure, s_park, true), new Tag(s_amenity, s_restaurant, true),
new Tag(s_barrier, s_wall, true), new Tag(s_waterway, s_riverbank, true),
new Tag(s_amenity, s_bench, true), new Tag(s_building, s_garage, true),
new Tag(s_natural, s_scrub, true), new Tag(s_highway, s_pedestrian, true),
new Tag(s_natural, s_peak, true), new Tag(s_building, s_entrance, true),
new Tag(s_landuse, s_reservoir, true), new Tag(s_access, s_yes, true),
new Tag(s_bicycle, s_designated, true),
new Tag(s_leisure, s_swimming_pool, true),
new Tag(s_landuse, s_farmyard, true),
new Tag(s_railway, s_level_crossing, true),
new Tag(s_building, s_apartments, true), new Tag(s_surface, s_grass, true),
new Tag(s_wheelchair, s_yes, true), new Tag(s_service, s_alley, true),
new Tag(s_landuse, s_industrial, true), new Tag(s_amenity, s_fuel, true),
new Tag(s_surface, s_dirt, true), new Tag(s_highway, s_trunk_link, true),
new Tag(s_waterway, s_drain, true), new Tag(s_barrier, s_hedge, true),
new Tag(s_amenity, s_grave_yard, true),
new Tag(s_tourism, s_information, true),
new Tag(s_shop, s_supermarket, true),
new Tag(s_highway, s_primary_link, true), new Tag(s_wood, s_deciduous, true),
new Tag(s_leisure, s_playground, true), new Tag(s_building, s_roof, true),
new Tag(s_building, s_industrial, true),
new Tag(s_amenity, s_post_box, true), new Tag(s_waterway, s_canal, true),
new Tag(s_barrier, s_bollard, true), new Tag(s_leisure, s_garden, true),
new Tag(s_wood, s_mixed, true), new Tag(s_landuse, s_cemetery, true),
new Tag(s_landuse, s_orchard, true), new Tag(s_shop, s_convenience, true),
new Tag(s_access, s_permissive, true), new Tag(s_surface, s_concrete, true),
new Tag(s_surface, s_paving_stones, true), new Tag(s_service, s_spur, true),
new Tag(s_building, s_garages, true), new Tag(s_amenity, s_bank, true),
new Tag(s_tourism, s_hotel, true), new Tag(s_access, s_no, true),
new Tag(s_amenity, s_fast_food, true), new Tag(s_man_made, s_pier, true),
new Tag(s_amenity, s_kindergarten, true),
new Tag(s_access, s_agricultural, true),
new Tag(s_surface, s_cobblestone, true), new Tag(s_wheelchair, s_no, true),
new Tag(s_amenity, s_cafe, true), new Tag(s_amenity, s_hospital, true),
new Tag(s_amenity, s_post_office, true),
new Tag(s_amenity, s_public_building, true),
new Tag(s_amenity, s_recycling, true),
new Tag(s_highway, s_street_lamp, true), new Tag(s_man_made, s_tower, true),
new Tag(s_waterway, s_dam, true), new Tag(s_amenity, s_pub, true),
new Tag(s_wood, s_coniferous, true), new Tag(s_access, s_destination, true),
new Tag(s_admin_level, s_6, true), new Tag(s_landuse, s_commercial, true),
new Tag(s_amenity, s_pharmacy, true), new Tag(s_railway, s_abandoned, true),
new Tag(s_service, s_yard, true), new Tag(s_place, s_island, true),
new Tag(s_oneway, s__1, true), new Tag(s_landuse, s_quarry, true),
new Tag(s_landuse, s_vineyard, true),
new Tag(s_highway, s_motorway_junction, true),
new Tag(s_railway, s_station, true), new Tag(s_landuse, s_allotments, true),
new Tag(s_barrier, s_lift_gate, true), new Tag(s_admin_level, s_10, true),
new Tag(s_amenity, s_telephone, true), new Tag(s_place, s_town, true),
new Tag(s_man_made, s_cutline, true), new Tag(s_place, s_suburb, true),
new Tag(s_aeroway, s_taxiway, true), new Tag(s_wheelchair, s_limited, true),
new Tag(s_highway, s_secondary_link, true),
new Tag(s_leisure, s_sports_centre, true),
new Tag(s_amenity, s_bicycle_parking, true),
new Tag(s_surface, s_sand, true), new Tag(s_highway, s_stop, true),
new Tag(s_man_made, s_works, true), new Tag(s_landuse, s_retail, true),
new Tag(s_amenity, s_fire_station, true), new Tag(s_service, s_siding, true),
new Tag(s_amenity, s_toilets, true), new Tag(s_bench, s_yes, true),
new Tag(s_oneway, s_1, true), new Tag(s_surface, s_compacted, true),
new Tag(s_landuse, s_basin, true), new Tag(s_amenity, s_police, true),
new Tag(s_railway, s_tram, true), new Tag(s_route, s_road, true),
new Tag(s_natural, s_cliff, true), new Tag(s_highway, s_construction, true),
new Tag(s_aeroway, s_aerodrome, true), new Tag(s_entrance, s_yes, true),
new Tag(s_man_made, s_storage_tank, true), new Tag(s_amenity, s_atm, true),
new Tag(s_tourism, s_attraction, true), new Tag(s_route, s_bus, true),
new Tag(s_shop, s_bakery, true), new Tag(s_tourism, s_viewpoint, true),
new Tag(s_amenity, s_swimming_pool, true), new Tag(s_natural, s_beach, true),
new Tag(s_tourism, s_picnic_site, true), new Tag(s_oneway, s_true, true),
new Tag(s_highway, s_bridleway, true), new Tag(s_tourism, s_camp_site, true),
new Tag(s_abutters, s_residential, true),
new Tag(s_leisure, s_nature_reserve, true),
new Tag(s_amenity, s_drinking_water, true), new Tag(s_shop, s_clothes, true),
new Tag(s_natural, s_heath, true),
new Tag(s_highway, s_mini_roundabout, true),
new Tag(s_landuse, s_construction, true),
new Tag(s_amenity, s_waste_basket, true),
new Tag(s_railway, s_platform, true), new Tag(s_amenity, s_townhall, true),
new Tag(s_shop, s_hairdresser, true), new Tag(s_amenity, s_shelter, true),
new Tag(s_admin_level, s_9, true),
new Tag(s_building, s_farm_auxiliary, true),
new Tag(s_amenity, s_library, true), new Tag(s_building, s_detached, true),
new Tag(s_admin_level, s_4, true), new Tag(s_landuse, s_village_green, true),
new Tag(s_barrier, s_stile, true), new Tag(s_landuse, s_garages, true),
new Tag(s_amenity, s_bar, true), new Tag(s_railway, s_buffer_stop, true),
new Tag(s_wetland, s_marsh, true), new Tag(s_tourism, s_museum, true),
new Tag(s_barrier, s_cycle_barrier, true), new Tag(s_route, s_bicycle, true),
new Tag(s_railway, s_tram_stop, true),
new Tag(s_amenity, s_parking_space, true),
new Tag(s_barrier, s_retaining_wall, true),
new Tag(s_landuse, s_recreation_ground, true),
new Tag(s_amenity, s_university, true),
new Tag(s_highway, s_tertiary_link, true),
new Tag(s_building, s_terrace, true), new Tag(s_shop, s_car_repair, true),
new Tag(s_amenity, s_hunting_stand, true),
new Tag(s_amenity, s_fountain, true), new Tag(s_man_made, s_pipeline, true),
new Tag(s_wetland, s_swamp, true), new Tag(s_shop, s_car, true),
new Tag(s_bench, s_no, true), new Tag(s_tunnel, s_culvert, true),
new Tag(s_building, s_school, true), new Tag(s_barrier, s_entrance, true),
new Tag(s_railway, s_disused, true), new Tag(s_railway, s_crossing, true),
new Tag(s_building, s_church, true),
new Tag(s_amenity, s_social_facility, true), new Tag(s_natural, s_bay, true),
new Tag(s_shop, s_kiosk, true), new Tag(s_amenity, s_vending_machine, true),
new Tag(s_route, s_hiking, true), new Tag(s_natural, s_spring, true),
new Tag(s_leisure, s_common, true), new Tag(s_railway, s_switch, true),
new Tag(s_waterway, s_rapids, true), new Tag(s_admin_level, s_7, true),
new Tag(s_leisure, s_stadium, true), new Tag(s_leisure, s_track, true),
new Tag(s_place, s_isolated_dwelling, true), new Tag(s_place, s_islet, true),
new Tag(s_waterway, s_weir, true), new Tag(s_amenity, s_doctors, true),
new Tag(s_access, s_designated, true),
new Tag(s_landuse, s_conservation, true),
new Tag(s_waterway, s_artificial, true),
new Tag(s_amenity, s_bus_station, true),
new Tag(s_leisure, s_golf_course, true),
new Tag(s_shop, s_doityourself, true), new Tag(s_building, s_service, true),
new Tag(s_tourism, s_guest_house, true), new Tag(s_aeroway, s_runway, true),
new Tag(s_place, s_city, true), new Tag(s_railway, s_subway, true),
new Tag(s_man_made, s_wastewater_plant, true),
new Tag(s_building, s_commercial, true), new Tag(s_railway, s_halt, true),
new Tag(s_amenity, s_emergency_phone, true),
new Tag(s_building, s_retail, true), new Tag(s_barrier, s_block, true),
new Tag(s_leisure, s_recreation_ground, true),
new Tag(s_access, s_forestry, true), new Tag(s_amenity, s_college, true),
new Tag(s_highway, s_platform, true), new Tag(s_access, s_unknown, true),
new Tag(s_man_made, s_water_tower, true),
new Tag(s_surface, s_pebblestone, true), new Tag(s_bridge, s_viaduct, true),
new Tag(s_shop, s_butcher, true), new Tag(s_shop, s_florist, true),
new Tag(s_boundary, s_landuse, true), new Tag(s_aeroway, s_helipad, true),
new Tag(s_building, s_hangar, true), new Tag(s_natural, s_glacier, true),
new Tag(s_highway, s_proposed, true), new Tag(s_shop, s_mall, true),
new Tag(s_barrier, s_toll_booth, true),
new Tag(s_amenity, s_fire_hydrant, true),
new Tag(s_building, s_manufacture, true), new Tag(s_building, s_farm, true),
new Tag(s_surface, s_wood, true), new Tag(s_amenity, s_car_wash, true),
new Tag(s_amenity, s_dentist, true), new Tag(s_natural, s_marsh, true),
new Tag(s_man_made, s_surveillance, true), new Tag(s_shop, s_bicycle, true),
new Tag(s_route, s_foot, true), new Tag(s_amenity, s_theatre, true),
new Tag(s_building, s_office, true), new Tag(s_railway, s_light_rail, true),
new Tag(s_man_made, s_petroleum_well, true),
new Tag(s_amenity, s_taxi, true), new Tag(s_building, s_greenhouse, true),
new Tag(s_landuse, s_brownfield, true),
new Tag(s_bicycle, s_permissive, true), new Tag(s_admin_level, s_2, true),
new Tag(s_aeroway, s_apron, true), new Tag(s_building, s_cabin, true),
new Tag(s_amenity, s_cinema, true), new Tag(s_access, s_customers, true),
new Tag(s_tourism, s_motel, true), new Tag(s_railway, s_narrow_gauge, true),
new Tag(s_amenity, s_marketplace, true), new Tag(s_shop, s_furniture, true),
new Tag(s_entrance, s_staircase, true), new Tag(s_tourism, s_artwork, true),
new Tag(s_natural, s_grassland, true), new Tag(s_shop, s_books, true),
new Tag(s_admin_level, s_5, true), new Tag(s_man_made, s_groyne, true),
new Tag(s_waterway, s_lock_gate, true),
new Tag(s_highway, s_emergency_access_point, true),
new Tag(s_natural, s_sand, true), new Tag(s_landuse, s_military, true),
new Tag(s_boundary, s_protected_area, true),
new Tag(s_amenity, s_community_centre, true),
new Tag(s_barrier, s_kissing_gate, true),
new Tag(s_highway, s_speed_camera, true),
new Tag(s_boundary, s_national_park, true),
new Tag(s_railway, s_subway_entrance, true),
new Tag(s_man_made, s_silo, true), new Tag(s_shop, s_alcohol, true),
new Tag(s_highway, s_give_way, true), new Tag(s_leisure, s_slipway, true),
new Tag(s_shop, s_electronics, true), new Tag(s_bicycle, s_dismount, true),
new Tag(s_leisure, s_marina, true), new Tag(s_entrance, s_main, true),
new Tag(s_boundary, s_postal_code, true),
new Tag(s_landuse, s_greenhouse_horticulture, true),
new Tag(s_highway, s_milestone, true),
new Tag(s_natural, s_cave_entrance, true),
new Tag(s_landuse, s_landfill, true), new Tag(s_shop, s_chemist, true),
new Tag(s_shop, s_shoes, true), new Tag(s_barrier, s_cattle_grid, true),
new Tag(s_landuse, s_railway, true), new Tag(s_tourism, s_hostel, true),
new Tag(s_tourism, s_chalet, true), new Tag(s_place, s_county, true),
new Tag(s_shop, s_department_store, true), new Tag(s_highway, s_ford, true),
new Tag(s_natural, s_scree, true), new Tag(s_landuse, s_greenfield, true),
new Tag(s_amenity, s_nursing_home, true),
new Tag(s_barrier, s_wire_fence, true),
new Tag(s_access, s_restricted, true),
new Tag(s_man_made, s_reservoir_covered, true),
new Tag(s_amenity, s_bicycle_rental, true), new Tag(s_man_made, s_MDF, true),
new Tag(s_man_made, s_water_well, true), new Tag(s_landuse, s_field, true),
new Tag(s_landuse, s_wood, true), new Tag(s_shop, s_hardware, true),
new Tag(s_tourism, s_alpine_hut, true), new Tag(s_natural, s_tree_row, true),
new Tag(s_tourism, s_caravan_site, true), new Tag(s_bridge, s_no, true),
new Tag(s_wetland, s_bog, true), new Tag(s_amenity, s_courthouse, true),
new Tag(s_route, s_ferry, true), new Tag(s_barrier, s_city_wall, true),
new Tag(s_amenity, s_veterinary, true), new Tag(s_shop, s_jewelry, true),
new Tag(s_building, s_transportation, true),
new Tag(s_amenity, s_arts_centre, true),
new Tag(s_bicycle, s_official, true), new Tag(s_shop, s_optician, true),
new Tag(s_shop, s_yes, true), new Tag(s_building, s_collapsed, true),
new Tag(s_shop, s_garden_centre, true), new Tag(s_man_made, s_chimney, true),
new Tag(s_man_made, s_mine, true), new Tag(s_bench, s_unknown, true),
new Tag(s_railway, s_preserved, true), new Tag(s_building, s_public, true),
new Tag(s_amenity, s_ferry_terminal, true),
new Tag(s_highway, s_raceway, true), new Tag(s_natural, s_rock, true),
new Tag(s_tunnel, s_no, true), new Tag(s_building, s_university, true),
new Tag(s_shop, s_beverages, true),
new Tag(s_amenity, s_waste_disposal, true),
new Tag(s_building, s_warehouse, true),
new Tag(s_leisure, s_water_park, true), new Tag(s_shop, s_gift, true),
new Tag(s_place, s_farm, true), new Tag(s_wetland, s_tidalflat, true),
new Tag(s_waterway, s_waterfall, true), new Tag(s_man_made, s_dolphin, true),
new Tag(s_service, s_drive_through, true),
new Tag(s_amenity, s_nightclub, true), new Tag(s_building, s_shed, true),
new Tag(s_shop, s_greengrocer, true), new Tag(s_natural, s_fell, true),
new Tag(s_wetland, s_wet_meadow, true), new Tag(s_aeroway, s_gate, true),
new Tag(s_shop, s_computer, true), new Tag(s_man_made, s_lighthouse, true),
new Tag(s_wetland, s_reedbed, true), new Tag(s_man_made, s_breakwater, true),
new Tag(s_surface, s_Dirt_Sand, true), new Tag(s_barrier, s_ditch, true),
new Tag(s_barrier, s_yes, true), new Tag(s_amenity, s_biergarten, true),
new Tag(s_shop, s_mobile_phone, true), new Tag(s_route, s_mtb, true),
new Tag(s_amenity, s_grit_bin, true), new Tag(s_amenity, s_bbq, true),
new Tag(s_shop, s_sports, true), new Tag(s_barrier, s_wood_fence, true),
new Tag(s_entrance, s_home, true), new Tag(s_shop, s_laundry, true),
new Tag(s_man_made, s_gasometer, true),
new Tag(s_barrier, s_embankment, true), new Tag(s_shop, s_toys, true),
new Tag(s_wetland, s_saltmarsh, true), new Tag(s_waterway, s_soakhole, true),
new Tag(s_shop, s_travel_agency, true),
new Tag(s_man_made, s_water_works, true), new Tag(s_route, s_railway, true),
new Tag(s_amenity, s_prison, true), new Tag(s_highway, s_rest_area, true),
new Tag(s_shop, s_stationery, true), new Tag(s_admin_level, s_11, true),
new Tag(s_building, s_train_station, true),
new Tag(s_building, s_storage_tank, true),
new Tag(s_man_made, s_windmill, true), new Tag(s_shop, s_beauty, true),
new Tag(s_building, s_semi, true), new Tag(s_highway, s_services, true),
new Tag(s_bicycle, s_private, true), new Tag(s_route, s_ski, true),
new Tag(s_service, s_emergency_access, true),
new Tag(s_building, s_factory, true),
new Tag(s_man_made, s_reinforced_slope, true),
new Tag(s_amenity, s_car_sharing, true), new Tag(s_surface, s_earth, true),
new Tag(s_shop, s_hifi, true), new Tag(s_amenity, s_car_rental, true),
new Tag(s_barrier, s_hedge_bank, true),
new Tag(s_shop, s_confectionery, true), new Tag(s_aeroway, s_terminal, true),
new Tag(s_highway, s_passing_place, true),
new Tag(s_building, s_building, true), new Tag(s_man_made, s_dyke, true),
new Tag(s_building, s_construction, true), new Tag(s_building, s_shop, true),
new Tag(s_natural, s_reef, true), new Tag(s_landuse, s_aquaculture, true),
new Tag(s_shop, s_dry_cleaning, true), new Tag(s_amenity, s_embassy, true),
new Tag(s_shop, s_newsagent, true), new Tag(s_landuse, s_salt_pond, true),
new Tag(s_railway, s_spur, true), new Tag(s_wheelchair, s_unknown, true),
new Tag(s_tourism, s_zoo, true), new Tag(s_man_made, s_waterway, true),
new Tag(s_surface, s_fine_gravel, true), new Tag(s_shop, s_motorcycle, true),
new Tag(s_building, s_Building, true),
new Tag(s_railway, s_construction, true),
new Tag(s_place, s_neighbourhood, true), new Tag(s_route, s_train, true),
new Tag(s_building, s_no, true), new Tag(s_natural, s_mud, true),
new Tag(s_place, s_region, true),
new Tag(s_landuse, s_reservoir_watershed, true),
new Tag(s_boundary, s_marker, true), new Tag(s_man_made, s_beacon, true),
new Tag(s_shop, s_outdoor, true), new Tag(s_access, s_public, true),
new Tag(s_abutters, s_industrial, true), new Tag(s_building, s_barn, true),
new Tag(s_leisure, s_picnic_table, true),
new Tag(s_building, s_hospital, true), new Tag(s_access, s_official, true),
new Tag(s_shop, s_variety_store, true), new Tag(s_man_made, s_crane, true),
new Tag(s_amenity, s_parking_fuel, true), new Tag(s_route, s_tram, true),
new Tag(s_tourism, s_theme_park, true), new Tag(s_shop, s_pet, true),
new Tag(s_building, s_kindergarten, true),
new Tag(s_man_made, s_storage, true), new Tag(s_man_made, s_mast, true),
new Tag(s_amenity, s_parking_entrance, true),
new Tag(s_amenity, s_clock, true),
new Tag(s_landuse, s_industrial_retail, true),
new Tag(s_shop, s_video, true), new Tag(s_access, s_delivery, true),
new Tag(s_amenity, s_driving_school, true), new Tag(s_service, s_yes, true),
new Tag(s_natural, s_bare_rock, true), new Tag(s_building, s_chapel, true),
new Tag(s_natural, s_volcano, true), new Tag(s_waterway, s_dock, true),
new Tag(s_building, s_dormitory, true),
new Tag(s_amenity, s_boat_storage, true), new Tag(s_man_made, s_tank, true),
new Tag(s_man_made, s_flagpole, true),
new Tag(s_surface, s_grass_paver, true), new Tag(s_shop, s_organic, true),
new Tag(s_natural, s_landform, true), new Tag(s_highway, s_unsurfaced, true),
new Tag(s_route, s_power, true), new Tag(s_surface, s_mud, true),
new Tag(s_building, s_building_concrete, true),
new Tag(s_abutters, s_retail, true), new Tag(s_building, s_store, true),
new Tag(s_shop, s_vacant, true), new Tag(s_leisure, s_miniature_golf, true),
new Tag(s_man_made, s_monitoring_station, true),
new Tag(s_natural, s_waterfall, true), new Tag(s_aeroway, s_hangar, true),
new Tag(s_shop, s_boutique, true), new Tag(s_route, s_detour, true),
new Tag(s_building, s_way, true), new Tag(s_railway, s_stop, true),
new Tag(s_amenity, s_ice_cream, true), new Tag(s_building, s_storage, true),
new Tag(s_shop, s_car_parts, true), new Tag(s_natural, s_ridge, true),
new Tag(s_shop, s_tyres, true), new Tag(s_railway, s_dismantled, true),
new Tag(s_amenity, s_shop, true), new Tag(s_landuse, s_plant_nursery, true),
new Tag(s_building, s_residentiel1, true),
new Tag(s_barrier, s_field_boundary, true),
new Tag(s_barrier, s_border_control, true),
new Tag(s_surface, s_Paved, true), new Tag(s_barrier, s_sally_port, true),
new Tag(s_amenity, s_bureau_de_change, true),
new Tag(s_leisure, s_fishing, true),
new Tag(s_amenity, s_charging_station, true),
new Tag(s_building, s_supermarket, true), new Tag(s_highway, s_stile, true),
new Tag(s_amenity, s_sauna, true), new Tag(s_place, s_municipality, true),
new Tag(s_building, s_hotel, true), new Tag(s_surface, s_metal, true),
new Tag(s_highway, s_incline_steep, true),
new Tag(s_shop, s_estate_agent, true), new Tag(s_natural, s_grass, true),
new Tag(s_shop, s_pharmacy, true),
new Tag(s_surface, s_concrete_plates, true),
new Tag(s_shop, s_copyshop, true),
new Tag(s_surface, s_paving_stones_30, true),
new Tag(s_surface, s_interlock, true), new Tag(s_access, s_hov, true),
new Tag(s_highway, s_elevator, true),
new Tag(s_boundary, s_local_authority, true),
new Tag(s_man_made, s_communications_tower, true),
new Tag(s_shop, s_deli, true), new Tag(s_barrier, s_turnstile, true),
new Tag(s_building, s_offices, true), new Tag(s_building, s_bunker, true),
new Tag(s_natural, s_stone, true),
new Tag(s_railway, s_railway_crossing, true),
new Tag(s_leisure, s_dog_park, true),
new Tag(s_building, s_semi_detached, true),
new Tag(s_man_made, s_watermill, true), new Tag(s_route, s_trolleybus, true),
new Tag(s_admin_level, s_3, true), new Tag(s_building, s_block, true),
new Tag(s_barrier, s_guard_rail, true), new Tag(s_bicycle, s_unknown, true),
new Tag(s_highway, s_abandoned, true), new Tag(s_surface, s_dirt_sand, true),
new Tag(s_barrier, s_chain, true), new Tag(s_barrier, s_bump_gate, true),
new Tag(s_building, s_residental, true), new Tag(s_surface, s_cement, true),
new Tag(s_man_made, s_embankment, true), new Tag(s_building, s_ruins, true),
new Tag(s_highway, s_incline, true), new Tag(s_abutters, s_commercial, true),
new Tag(s_barrier, s_hampshire_gate, true), new Tag(s_shop, s_music, true),
new Tag(s_shop, s_funeral_directors, true),
new Tag(s_wetland, s_mangrove, true), new Tag(s_place, s_borough, true),
new Tag(s_building, s_apartment, true), new Tag(s_boundary, s_census, true),
new Tag(s_barrier, s_kerb, true), new Tag(s_building, s_glasshouse, true),
new Tag(s_aeroway, s_holding_position, true),
new Tag(s_shop, s_general, true), new Tag(s_building, s_tank, true),
new Tag(s_railway, s_monorail, true), new Tag(s_service, s_parking, true),
new Tag(s_place, s_state, true), new Tag(s_railway, s_proposed, true),
new Tag(s_shop, s_art, true), new Tag(s_natural, s_hill, true),
new Tag(s_railway, s_turntable, true), new Tag(s_tourism, s_cabin, true),
new Tag(s_shop, s_photo, true), new Tag(s_boundary, s_lot, true),
new Tag(s_shop, s_fishmonger, true), new Tag(s_amenity, s_clinic, true),
new Tag(s_boundary, s_political, true), new Tag(s_man_made, s_well, true),
new Tag(s_highway, s_byway, true), new Tag(s_leisure, s_horse_riding, true),
new Tag(s_service, s_bus, true), new Tag(s_building, s_tower, true),
new Tag(s_entrance, s_service, true), new Tag(s_shop, s_fabric, true),
new Tag(s_railway, s_miniature, true), new Tag(s_abutters, s_mixed, true),
new Tag(s_surface, s_stone, true), new Tag(s_access, s_emergency, true),
new Tag(s_landuse, s_mine, true), new Tag(s_amenity, s_shower, true),
new Tag(s_waterway, s_lock, true)
};
}

View File

@@ -0,0 +1,372 @@
/*
* Geometry.java
*
* PostGIS extension for PostgreSQL JDBC driver - geometry model
*
* (C) 2004 Paul Ramsey, pramsey@refractions.net
*
* (C) 2005 Markus Schaber, markus.schaber@logix-tt.com
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General License as published by the Free
* Software Foundation, either version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General License for more
* details.
*
* You should have received a copy of the GNU Lesser General License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
* http://www.gnu.org.
*
* $Id: Geometry.java 9324 2012-02-27 22:08:12Z pramsey $
*/
package org.oscim.database.postgis;
import java.io.Serializable;
/** The base class of all geometries */
abstract class Geometry implements Serializable {
/* JDK 1.5 Serialization */
private static final long serialVersionUID = 0x100;
// OpenGIS Geometry types as defined in the OGC WKB Spec
// (May we replace this with an ENUM as soon as JDK 1.5
// has gained widespread usage?)
/** Fake type for linear ring */
static final int LINEARRING = 0;
/**
* The OGIS geometry type number for points.
*/
static final int POINT = 1;
/**
* The OGIS geometry type number for lines.
*/
static final int LINESTRING = 2;
/**
* The OGIS geometry type number for polygons.
*/
static final int POLYGON = 3;
/**
* The OGIS geometry type number for aggregate points.
*/
static final int MULTIPOINT = 4;
/**
* The OGIS geometry type number for aggregate lines.
*/
static final int MULTILINESTRING = 5;
/**
* The OGIS geometry type number for aggregate polygons.
*/
static final int MULTIPOLYGON = 6;
/**
* The OGIS geometry type number for feature collections.
*/
static final int GEOMETRYCOLLECTION = 7;
static final String[] ALLTYPES = new String[] {
"", // internally used LinearRing does not have any text in front of
// it
"POINT", "LINESTRING", "POLYGON", "MULTIPOINT", "MULTILINESTRING",
"MULTIPOLYGON", "GEOMETRYCOLLECTION" };
/**
* The Text representations of the geometry types
*
* @param type
* ...
* @return ...
*/
static String getTypeString(int type) {
if (type >= 0 && type <= 7)
return ALLTYPES[type];
throw new IllegalArgumentException("Unknown Geometry type" + type);
}
// Properties common to all geometries
/**
* The dimensionality of this feature (2,3)
*/
int dimension;
/**
* Do we have a measure (4th dimension)
*/
boolean haveMeasure = false;
/**
* The OGIS geometry type of this feature. this is final as it never changes, it is bound to the subclass of the
* instance.
*/
final int type;
/**
* Official UNKNOWN srid value
*/
final static int UNKNOWN_SRID = 0;
/**
* The spacial reference system id of this geometry, default is no srid
*/
int srid = UNKNOWN_SRID;
/**
* Parse a SRID value, anything <= 0 is unknown
*
* @param srid
* ...
* @return ...
*/
static int parseSRID(int srid) {
if (srid < 0) {
/* TODO: raise a warning ? */
return 0;
}
return srid;
}
/**
* Constructor for subclasses
*
* @param type
* has to be given by all subclasses.
*/
protected Geometry(int type) {
this.type = type;
}
/**
* java.lang.Object hashCode implementation
*/
@Override
public int hashCode() {
return dimension | (type * 4) | (srid * 32);
}
/**
* java.lang.Object equals implementation
*/
@Override
public boolean equals(Object other) {
return (other != null) && (other instanceof Geometry)
&& equals((Geometry) other);
}
/**
* geometry specific equals implementation - only defined for non-null values
*
* @param other
* ...
* @return ...
*/
public boolean equals(Geometry other) {
return (other != null) && (this.dimension == other.dimension)
&& (this.type == other.type) && (this.srid == other.srid)
&& (this.haveMeasure == other.haveMeasure)
&& other.getClass().equals(this.getClass())
&& this.equalsintern(other);
}
/**
* Whether test coordinates for geometry - subclass specific code Implementors can assume that dimensin, type, srid
* and haveMeasure are equal, other != null and other is the same subclass.
*
* @param other
* ...
* @return ...
*/
protected abstract boolean equalsintern(Geometry other);
/**
* Return the number of Points of the geometry
*
* @return ...
*/
abstract int numPoints();
/**
* Get the nth Point of the geometry
*
* @param n
* the index of the point, from 0 to numPoints()-1;
* @throws ArrayIndexOutOfBoundsException
* in case of an emtpy geometry or bad index.
*/
// abstract Point getPoint(int n);
//
// /**
// * Same as getPoint(0);
// */
// abstract Point getFirstPoint();
//
// /**
// * Same as getPoint(numPoints()-1);
// */
// abstract Point getLastPoint();
/**
* The OGIS geometry type number of this geometry.
*
* @return ...
*/
int getType() {
return this.type;
}
/**
* Return the Type as String
*
* @return ...
*/
String getTypeString() {
return getTypeString(this.type);
}
/**
* Returns whether we have a measure
*
* @return ....
*/
boolean isMeasured() {
return haveMeasure;
}
/**
* Queries the number of geometric dimensions of this geometry. This does not include measures, as opposed to the
* server.
*
* @return The dimensionality (eg, 2D or 3D) of this geometry.
*/
int getDimension() {
return this.dimension;
}
/**
* The OGIS geometry type number of this geometry.
*
* @return ...
*/
int getSrid() {
return this.srid;
}
/**
* Recursively sets the srid on this geometry and all contained subgeometries
*
* @param srid
* ...
*/
void setSrid(int srid) {
this.srid = srid;
}
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
if (srid != UNKNOWN_SRID) {
sb.append("SRID=");
sb.append(srid);
sb.append(';');
}
outerWKT(sb, true);
return sb.toString();
}
/**
* Render the WKT version of this Geometry (without SRID) into the given StringBuffer.
*
* @param sb
* ...
* @param putM
* ...
*/
void outerWKT(StringBuffer sb, boolean putM) {
sb.append(getTypeString());
if (putM && haveMeasure && dimension == 2) {
sb.append('M');
}
mediumWKT(sb);
}
final void outerWKT(StringBuffer sb) {
outerWKT(sb, true);
}
/**
* Render the WKT without the type name, but including the brackets into the StringBuffer
*
* @param sb
* ...
*/
protected void mediumWKT(StringBuffer sb) {
sb.append('(');
innerWKT(sb);
sb.append(')');
}
/**
* Render the "inner" part of the WKT (inside the brackets) into the StringBuffer.
*
* @param SB
* ...
*/
protected abstract void innerWKT(StringBuffer SB);
/**
* backwards compatibility method
*
* @return ...
*/
String getValue() {
StringBuffer sb = new StringBuffer();
mediumWKT(sb);
return sb.toString();
}
/**
* Do some internal consistency checks on the geometry. Currently, all Geometries must have a valid dimension (2 or
* 3) and a valid type. 2-dimensional Points must have Z=0.0, as well as non-measured Points must have m=0.0.
* Composed geometries must have all equal SRID, dimensionality and measures, as well as that they do not contain
* NULL or inconsistent subgeometries. BinaryParser and WKTParser should only generate consistent geometries.
* BinaryWriter may produce invalid results on inconsistent geometries.
*
* @return true if all checks are passed.
*/
boolean checkConsistency() {
return (dimension >= 2 && dimension <= 3) && (type >= 0 && type <= 7);
}
/**
* Splits the SRID=4711; part of a EWKT rep if present and sets the srid.
*
* @param value
* ...
* @return value without the SRID=4711; part
*/
protected String initSRID(String value) {
String v = value.trim();
if (v.startsWith("SRID=")) {
int index = v.indexOf(';', 5); // sridprefix length is 5
if (index == -1) {
throw new IllegalArgumentException(
"Error parsing Geometry - SRID not delimited with ';' ");
}
this.srid = Integer.parseInt(v.substring(5, index));
return v.substring(index + 1).trim();
}
return v;
}
}

View File

@@ -0,0 +1,397 @@
/*
* Copyright 2012 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.postgis;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import org.oscim.core.BoundingBox;
import org.oscim.core.GeoPoint;
import org.oscim.core.Tag;
import org.oscim.core.WebMercator;
import org.oscim.database.IMapDatabase;
import org.oscim.database.IMapDatabaseCallback;
import org.oscim.database.MapInfo;
import org.oscim.database.OpenResult;
import org.oscim.database.QueryResult;
import org.oscim.view.mapgenerator.JobTile;
import org.postgresql.PGConnection;
import android.util.Log;
/**
*
*
*/
public class MapDatabase implements IMapDatabase {
private final static String TAG = "MapDatabase";
private static final String QUERY = "SELECT tags, geom FROM __get_tile(?,?,?)";
private final float mScale = 1;
private int mCoordPos = 0;
private int mIndexPos = 0;
private float[] mCoords;
private short[] mIndex;
private Tag[] mTags;
private final MapInfo mMapInfo =
new MapInfo(new BoundingBox(-180, -85, 180, 85),
new Byte((byte) 14), new GeoPoint(53.11, 8.85),
WebMercator.NAME,
0, 0, 0, "de", "comment", "author");
private boolean mOpenFile = false;
private Connection connection = null;
private static volatile HashMap<Entry<String, String>, Tag> tagHash =
new HashMap<Entry<String, String>, Tag>(100);
private PreparedStatement prepQuery = null;
private boolean connect() {
Connection conn = null;
String dburl = "jdbc:postgresql://city.informatik.uni-bremen.de:5432/gis-2.0";
Properties dbOpts = new Properties();
dbOpts.setProperty("user", "osm");
dbOpts.setProperty("password", "osm");
dbOpts.setProperty("socketTimeout", "50");
dbOpts.setProperty("tcpKeepAlive", "true");
try {
DriverManager.setLoginTimeout(20);
System.out.println("Creating JDBC connection...");
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(dburl, dbOpts);
connection = conn;
prepQuery = conn.prepareStatement(QUERY);
PGConnection pgconn = (PGConnection) conn;
pgconn.addDataType("hstore", PGHStore.class);
conn.createStatement().execute("set statement_timeout to 60000");
} catch (Exception e) {
System.err.println("Aborted due to error:");
e.printStackTrace();
return false;
}
return true;
}
@Override
public QueryResult executeQuery(JobTile tile, IMapDatabaseCallback mapDatabaseCallback) {
if (connection == null) {
if (!connect())
return QueryResult.FAILED;
}
ResultSet r;
try {
prepQuery.setLong(1, tile.tileX * 256);
prepQuery.setLong(2, tile.tileY * 256);
prepQuery.setInt(3, tile.zoomLevel);
Log.d(TAG, "" + prepQuery.toString());
prepQuery.execute();
r = prepQuery.getResultSet();
} catch (SQLException e) {
e.printStackTrace();
connection = null;
return QueryResult.FAILED;
}
byte[] b = null;
PGHStore h = null;
// int cnt = 0;
try {
while (r != null && r.next()) {
mIndexPos = 0;
mCoordPos = 0;
// cnt++;
try {
Object obj = r.getObject(1);
h = null;
if (obj instanceof PGHStore)
h = (PGHStore) obj;
else {
Log.d(TAG, "no tags: skip way");
continue;
}
b = r.getBytes(2);
} catch (SQLException e) {
e.printStackTrace();
continue;
}
if (b == null) {
// Log.d(TAG, "no geometry: skip way");
continue;
}
mTags = new Tag[h.size()];
int i = 0;
for (Entry<String, String> t : h.entrySet()) {
if (t.getKey() == null) {
Log.d(TAG, "no KEY !!! ");
break;
}
Tag tag = tagHash.get(t);
if (tag == null) {
tag = new Tag(t.getKey(), t.getValue());
tagHash.put(t, tag);
}
mTags[i++] = tag;
}
if (i < mTags.length)
continue;
boolean polygon = parse(b);
if (mIndexPos == 0) {
Log.d(TAG, "no index: skip way");
continue;
} else if (mIndexPos == 1) {
mapDatabaseCallback.renderPointOfInterest((byte) 0, mCoords[1],
mCoords[0], mTags);
} else {
short[] idx = new short[mIndexPos];
System.arraycopy(mIndex, 0, idx, 0, mIndexPos);
mapDatabaseCallback.renderWay((byte) 0, mTags, mCoords, idx, polygon);
}
}
} catch (SQLException e) {
e.printStackTrace();
connection = null;
return QueryResult.FAILED;
}
// Log.d(TAG, "rows: " + cnt);
return QueryResult.SUCCESS;
}
@Override
public String getMapProjection() {
return WebMercator.NAME;
}
@Override
public MapInfo getMapInfo() {
return mMapInfo;
}
@Override
public boolean isOpen() {
return mOpenFile;
}
@Override
public OpenResult open(Map<String, String> options) {
mOpenFile = true;
if (mCoords == null) {
mCoords = new float[100000];
mIndex = new short[100000];
}
return OpenResult.SUCCESS;
}
@Override
public void close() {
if (connection != null) {
try {
connection.close();
} catch (SQLException e1) {
e1.printStackTrace();
} finally {
connection = null;
}
}
mCoords = null;
mIndex = null;
mOpenFile = false;
}
// taken from postgis-java
private static ValueGetter valueGetterForEndian(byte[] bytes) {
if (bytes[0] == ValueGetter.XDR.NUMBER) { // XDR
return new ValueGetter.XDR(bytes);
} else if (bytes[0] == ValueGetter.NDR.NUMBER) {
return new ValueGetter.NDR(bytes);
} else {
throw new IllegalArgumentException("Unknown Endian type:" + bytes[0]);
}
}
/**
* Parse a binary encoded geometry. Is synchronized to protect offset counter. (Unfortunately, Java does not have
* neither call by reference nor multiple return values.)
*
* @param value
* ...
* @return ...
*/
private boolean parse(byte[] value) {
return parseGeometry(valueGetterForEndian(value));
}
private boolean parseGeometry(ValueGetter data) {
byte endian = data.getByte(); // skip and test endian flag
if (endian != data.endian) {
throw new IllegalArgumentException("Endian inconsistency!");
}
int typeword = data.getInt();
int realtype = typeword & 0x1FFFFFFF; // cut off high flag bits
boolean haveZ = (typeword & 0x80000000) != 0;
boolean haveM = (typeword & 0x40000000) != 0;
boolean haveS = (typeword & 0x20000000) != 0;
// int srid = Geometry.UNKNOWN_SRID;
boolean polygon = false;
if (haveS) {
// srid = Geometry.parseSRID(data.getInt());
data.getInt();
}
switch (realtype) {
case Geometry.POINT:
parsePoint(data, haveZ, haveM);
break;
case Geometry.LINESTRING:
parseLineString(data, haveZ, haveM);
break;
case Geometry.POLYGON:
parsePolygon(data, haveZ, haveM);
polygon = true;
break;
case Geometry.MULTIPOINT:
parseMultiPoint(data);
break;
case Geometry.MULTILINESTRING:
parseMultiLineString(data);
break;
case Geometry.MULTIPOLYGON:
parseMultiPolygon(data);
polygon = true;
break;
case Geometry.GEOMETRYCOLLECTION:
parseCollection(data);
break;
default:
throw new IllegalArgumentException("Unknown Geometry Type: " + realtype);
}
// if (srid != Geometry.UNKNOWN_SRID) {
// result.setSrid(srid);
// }
return polygon;
}
private void parsePoint(ValueGetter data, boolean haveZ, boolean haveM) {
// double X = data.getDouble();
// double Y = data.getDouble();
mCoords[0] = (float) (data.getDouble() * mScale);
mCoords[1] = (float) (data.getDouble() * mScale);
mIndex[0] = 2;
mIndexPos = 1;
if (haveZ)
data.getDouble();
if (haveM)
data.getDouble();
}
/**
* Parse an Array of "full" Geometries
*
* @param data
* ...
* @param count
* ...
*/
private void parseGeometryArray(ValueGetter data, int count) {
for (int i = 0; i < count; i++) {
parseGeometry(data);
mIndex[mIndexPos++] = 0;
}
}
//
// private void parsePointArray(ValueGetter data, boolean haveZ, boolean haveM) {
// int count = data.getInt();
// for (int i = 0; i < count; i++) {
// parsePoint(data, haveZ, haveM);
// }
// }
private void parseMultiPoint(ValueGetter data) {
parseGeometryArray(data, data.getInt());
}
private void parseLineString(ValueGetter data, boolean haveZ, boolean haveM) {
int count = data.getInt();
for (int i = 0; i < count; i++) {
mCoords[mCoordPos++] = (float) (data.getDouble()) * mScale;
mCoords[mCoordPos++] = (float) (data.getDouble()) * mScale;
if (haveZ)
data.getDouble();
if (haveM)
data.getDouble();
}
mIndex[mIndexPos++] = (short) (count * 2);
}
private void parsePolygon(ValueGetter data, boolean haveZ, boolean haveM) {
int count = data.getInt();
for (int i = 0; i < count; i++) {
parseLineString(data, haveZ, haveM);
}
}
private void parseMultiLineString(ValueGetter data) {
int count = data.getInt();
parseGeometryArray(data, count);
}
private void parseMultiPolygon(ValueGetter data) {
int count = data.getInt();
parseGeometryArray(data, count);
}
private void parseCollection(ValueGetter data) {
int count = data.getInt();
parseGeometryArray(data, count);
}
@Override
public void cancel() {
// TODO Auto-generated method stub
}
}

View File

@@ -0,0 +1,416 @@
/*
* This file has been copied from the following location:
* http://archives.postgresql.org/pgsql-jdbc/2009-12/msg00037.php
*
* PostgreSQL code is typically under a BSD licence.
* http://jdbc.postgresql.org/license.html
*/
/*-------------------------------------------------------------------------
*
* A preliminary version of a custom type wrapper for hstore data.
* Once it gets some testing and cleanups it will go into the official
* PG JDBC driver, but stick it here for now because we need it sooner.
*
* Copyright (c) 2009, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL$
*
*-------------------------------------------------------------------------
*/
package org.oscim.database.postgis;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.postgresql.util.PGobject;
/**
* This implements a class that handles the PostgreSQL contrib/hstore type
*/
public class PGHStore extends PGobject implements Map<String, String>
{
private final static long serialVersionUID = 1;
private Map<String, String> _map;
/**
* required by the driver
*/
public PGHStore()
{
setType("hstore");
_map = new HashMap<String, String>();
}
/**
* Initialize a hstore with a given string representation
*
* @param value
* String representated hstore
* @throws SQLException
* Is thrown if the string representation has an unknown format
* @see #setValue(String)
*/
public PGHStore(String value)
throws SQLException
{
this();
setValue(value);
}
/**
* @param map
* ...
*/
public PGHStore(Map<String, String> map)
{
this();
setValue(map);
}
/**
* @param map
* ...
*/
public void setValue(Map<String, String> map)
{
_map = map;
}
/**
*/
@Override
public void setValue(String value)
throws SQLException
{
Parser p = new Parser();
_map = p.parse(value);
}
/**
* Returns the stored information as a string
*
* @return String represented hstore
*/
@Override
public String getValue()
{
StringBuffer buf = new StringBuffer();
Iterator<String> i = _map.keySet().iterator();
boolean first = true;
while (i.hasNext()) {
Object key = i.next();
Object val = _map.get(key);
if (first) {
first = false;
} else {
buf.append(',');
}
writeValue(buf, key);
buf.append("=>");
writeValue(buf, val);
}
return buf.toString();
}
private static void writeValue(StringBuffer buf, Object o) {
if (o == null) {
buf.append("NULL");
return;
}
String s = o.toString();
buf.append('"');
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '"' || c == '\\') {
buf.append('\\');
}
buf.append(c);
}
buf.append('"');
}
/**
* Returns whether an object is equal to this one or not
*
* @param obj
* Object to compare with
* @return true if the two hstores are identical
*/
@Override
public boolean equals(Object obj)
{
if (obj == null)
return false;
if (obj == this)
return true;
if (!(obj instanceof PGHStore))
return false;
return _map.equals(((PGHStore) obj)._map);
}
private static class Parser {
private String value;
private int ptr;
private StringBuffer cur;
private boolean escaped;
private List<String> keys;
private List<String> values;
private final static int GV_WAITVAL = 0;
private final static int GV_INVAL = 1;
private final static int GV_INESCVAL = 2;
private final static int GV_WAITESCIN = 3;
private final static int GV_WAITESCESCIN = 4;
private final static int WKEY = 0;
private final static int WVAL = 1;
private final static int WEQ = 2;
private final static int WGT = 3;
private final static int WDEL = 4;
public Parser() {
}
Map<String, String> parse(String val) throws SQLException {
this.value = val;
ptr = 0;
keys = new ArrayList<String>();
values = new ArrayList<String>();
parseHStore();
Map<String, String> map = new HashMap<String, String>();
for (int i = 0; i < keys.size(); i++) {
map.put(keys.get(i), values.get(i));
}
return map;
}
private boolean getValue(boolean ignoreEqual) throws SQLException {
int state = GV_WAITVAL;
cur = new StringBuffer();
escaped = false;
while (true) {
boolean atEnd = (value.length() == ptr);
char c = '\0';
if (!atEnd) {
c = value.charAt(ptr);
}
if (state == GV_WAITVAL) {
if (c == '"') {
escaped = true;
state = GV_INESCVAL;
} else if (c == '\0') {
return false;
} else if (c == '=' && !ignoreEqual) {
throw new SQLException("KJJ");
} else if (c == '\\') {
state = GV_WAITESCIN;
} else if (!Character.isWhitespace(c)) {
cur.append(c);
state = GV_INVAL;
}
} else if (state == GV_INVAL) {
if (c == '\\') {
state = GV_WAITESCIN;
} else if (c == '=' && !ignoreEqual) {
ptr--;
return true;
} else if (c == ',' && ignoreEqual) {
ptr--;
return true;
} else if (Character.isWhitespace(c)) {
return true;
} else if (c == '\0') {
ptr--;
return true;
} else {
cur.append(c);
}
} else if (state == GV_INESCVAL) {
if (c == '\\') {
state = GV_WAITESCESCIN;
} else if (c == '"') {
return true;
} else if (c == '\0') {
throw new SQLException("KJJ, unexpected end of string");
} else {
cur.append(c);
}
} else if (state == GV_WAITESCIN) {
if (c == '\0') {
throw new SQLException("KJJ, unexpected end of string");
}
cur.append(c);
state = GV_INVAL;
} else if (state == GV_WAITESCESCIN) {
if (c == '\0') {
throw new SQLException("KJJ, unexpected end of string");
}
cur.append(c);
state = GV_INESCVAL;
} else {
throw new SQLException("KJJ");
}
ptr++;
}
}
private void parseHStore() throws SQLException {
int state = WKEY;
escaped = false;
while (true) {
char c = '\0';
if (ptr < value.length()) {
c = value.charAt(ptr);
}
if (state == WKEY) {
if (!getValue(false))
return;
keys.add(cur.toString());
cur = null;
state = WEQ;
} else if (state == WEQ) {
if (c == '=') {
state = WGT;
} else if (state == '\0') {
throw new SQLException("KJJ, unexpected end of string");
} else if (!Character.isWhitespace(c)) {
throw new SQLException("KJJ, syntax err");
}
} else if (state == WGT) {
if (c == '>') {
state = WVAL;
} else if (c == '\0') {
throw new SQLException("KJJ, unexpected end of string");
} else {
throw new SQLException("KJJ, syntax err [" + c + "] at " + ptr);
}
} else if (state == WVAL) {
if (!getValue(true)) {
throw new SQLException("KJJ, unexpected end of string");
}
String val = cur.toString();
cur = null;
if (!escaped && "null".equalsIgnoreCase(val)) {
val = null;
}
values.add(val);
state = WDEL;
} else if (state == WDEL) {
if (c == ',')
{
state = WKEY;
} else if (c == '\0') {
return;
} else if (!Character.isWhitespace(c)) {
throw new SQLException("KJJ, syntax err");
}
} else {
throw new SQLException("KJJ unknown state");
}
ptr++;
}
}
}
// Farm out all the work to the real underlying map.
@Override
public void clear() {
_map.clear();
}
@Override
public boolean containsKey(Object key) {
return _map.containsKey(key);
}
@Override
public boolean containsValue(Object val) {
return _map.containsValue(val);
}
@Override
public Set<Map.Entry<String, String>> entrySet() {
return _map.entrySet();
}
@Override
public String get(Object key) {
return _map.get(key);
}
@Override
public int hashCode() {
return _map.hashCode();
}
@Override
public boolean isEmpty() {
return _map.isEmpty();
}
@Override
public Set<String> keySet() {
return _map.keySet();
}
@Override
public String put(String key, String val) {
return _map.put(key, val);
}
@Override
public void putAll(Map<? extends String, ? extends String> m) {
_map.putAll(m);
}
@Override
public String remove(Object key) {
return _map.remove(key);
}
@Override
public int size() {
return _map.size();
}
@Override
public Collection<String> values() {
return _map.values();
}
}

View File

@@ -0,0 +1,21 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.postgis;
import org.oscim.database.IMapTileData;
public class TileData implements IMapTileData {
}

View File

@@ -0,0 +1,132 @@
/*
* ValueGetter.java
*
* PostGIS extension for PostgreSQL JDBC driver - Binary Parser
*
* (C) 2005 Markus Schaber, markus.schaber@logix-tt.com
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General License as published by the Free
* Software Foundation, either version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General License for more
* details.
*
* You should have received a copy of the GNU Lesser General License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
* http://www.gnu.org.
*
* $Id: ValueGetter.java 9324 2012-02-27 22:08:12Z pramsey $
*/
package org.oscim.database.postgis;
abstract class ValueGetter {
byte[] data;
int position;
final byte endian;
ValueGetter(byte[] data, byte endian) {
this.data = data;
this.endian = endian;
}
/**
* Get a byte, should be equal for all endians
*
* @return ...
*/
byte getByte() {
return data[position++];
}
int getInt() {
int res = getInt(position);
position += 4;
return res;
}
long getLong() {
long res = getLong(position);
position += 8;
return res;
}
/**
* Get a 32-Bit integer
*
* @param index
* ...
* @return ...
*/
protected abstract int getInt(int index);
/**
* Get a long value. This is not needed directly, but as a nice side-effect from GetDouble.
*
* @param index
* ...
* @return ...
*/
protected abstract long getLong(int index);
/**
* Get a double.
*
* @return ...
*/
double getDouble() {
long bitrep = getLong();
return Double.longBitsToDouble(bitrep);
}
static class XDR extends ValueGetter {
static final byte NUMBER = 0;
XDR(byte[] data) {
super(data, NUMBER);
}
@Override
protected int getInt(int index) {
return ((data[index] & 0xFF) << 24) + ((data[index + 1] & 0xFF) << 16)
+ ((data[index + 2] & 0xFF) << 8) + (data[index + 3] & 0xFF);
}
@Override
protected long getLong(int index) {
return ((long) (data[index] & 0xFF) << 56) | ((long) (data[index + 1] & 0xFF) << 48)
| ((long) (data[index + 2] & 0xFF) << 40) | ((long) (data[index + 3] & 0xFF) << 32)
| ((long) (data[index + 4] & 0xFF) << 24) | ((long) (data[index + 5] & 0xFF) << 16)
| ((long) (data[index + 6] & 0xFF) << 8) | ((long) (data[index + 7] & 0xFF) << 0);
}
}
static class NDR extends ValueGetter {
static final byte NUMBER = 1;
NDR(byte[] data) {
super(data, NUMBER);
}
@Override
protected int getInt(int index) {
return ((data[index + 3] & 0xFF) << 24) + ((data[index + 2] & 0xFF) << 16)
+ ((data[index + 1] & 0xFF) << 8) + (data[index] & 0xFF);
}
@Override
protected long getLong(int index) {
return ((long) (data[index + 7] & 0xFF) << 56) | ((long) (data[index + 6] & 0xFF) << 48)
| ((long) (data[index + 5] & 0xFF) << 40) | ((long) (data[index + 4] & 0xFF) << 32)
| ((long) (data[index + 3] & 0xFF) << 24) | ((long) (data[index + 2] & 0xFF) << 16)
| ((long) (data[index + 1] & 0xFF) << 8) | ((long) (data[index] & 0xFF) << 0);
}
}
}

View File

@@ -0,0 +1,192 @@
/*
* Copyright 2012 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.database.test;
import java.util.Map;
import org.oscim.core.BoundingBox;
import org.oscim.core.MercatorProjection;
import org.oscim.core.Tag;
import org.oscim.core.Tile;
import org.oscim.database.IMapDatabase;
import org.oscim.database.IMapDatabaseCallback;
import org.oscim.database.MapInfo;
import org.oscim.database.OpenResult;
import org.oscim.database.QueryResult;
import org.oscim.view.mapgenerator.JobTile;
/**
*
*
*/
public class MapDatabase implements IMapDatabase {
private final static String PROJECTION = "Mercator";
private float[] mCoords = new float[20];
private short[] mIndex = new short[2];
// private Tag[] mTags = { new Tag("boundary", "administrative"), new Tag("admin_level", "2") };
private Tag[] mTags = { new Tag("natural", "water") };
private Tag[] mNameTags;
private final MapInfo mMapInfo =
new MapInfo(new BoundingBox(-180, -90, 180, 90),
new Byte((byte) 0), null, PROJECTION, 0, 0, 0, "de", "yo!", "by me");
private boolean mOpenFile = false;
// private static double radius = 6378137;
// private static double D2R = Math.PI / 180;
// private static double HALF_PI = Math.PI / 2;
@Override
public QueryResult executeQuery(JobTile tile, IMapDatabaseCallback mapDatabaseCallback) {
long cx = tile.pixelX + (Tile.TILE_SIZE >> 1);
long cy = tile.pixelY + (Tile.TILE_SIZE >> 1);
// float lon1 = (float) MercatorProjection.pixelXToLongitude(cx - 100, tile.zoomLevel) * 1000000;
// float lon2 = (float) MercatorProjection.pixelXToLongitude(cx + 100, tile.zoomLevel) * 1000000;
// float lat1 = (float) MercatorProjection.pixelYToLatitude(cy - 100, tile.zoomLevel) * 1000000;
// float lat2 = (float) MercatorProjection.pixelYToLatitude(cy + 100, tile.zoomLevel) * 1000000;
float lon1 = (float) MercatorProjection.pixelXToLongitude(cx - 100,
tile.zoomLevel);
float lon2 = (float) MercatorProjection.pixelXToLongitude(cx + 100,
tile.zoomLevel);
float lat1 = (float) MercatorProjection
.pixelYToLatitude(cy - 100, tile.zoomLevel);
float lat2 = (float) MercatorProjection
.pixelYToLatitude(cy + 100, tile.zoomLevel);
// double lonRadians = (D2R * lon1);
// double latRadians = (D2R * lat1);
// spherical mercator projection
// lon1 = (float) (radius * lonRadians);
// lat1 = (float) (radius * Math.log(Math.tan(Math.PI * 0.25 + latRadians * 0.5)));
//
// lonRadians = (D2R * lon2);
// latRadians = (D2R * lat2);
//
// lon2 = (float) (radius * lonRadians);
// lat2 = (float) (radius * Math.log(Math.tan(Math.PI * 0.25 + latRadians * 0.5)));
//
// mCoords[0] = lon1;
// mCoords[1] = lat1;
//
// mCoords[2] = lon2;
// mCoords[3] = lat1;
//
// mCoords[4] = lon2;
// mCoords[5] = lat2;
//
// mCoords[6] = lon1;
// mCoords[7] = lat2;
//
// mCoords[8] = lon1;
// mCoords[9] = lat1;
//
// mIndex[0] = 10;
lon1 = (float) MercatorProjection.pixelXToLongitude(cx - 139, tile.zoomLevel) * 1000000;
lon2 = (float) MercatorProjection.pixelXToLongitude(cx + 139, tile.zoomLevel) * 1000000;
lat1 = (float) MercatorProjection.pixelYToLatitude(cy - 139, tile.zoomLevel) * 1000000;
lat2 = (float) MercatorProjection.pixelYToLatitude(cy + 139, tile.zoomLevel) * 1000000;
mCoords[0] = lon1;
mCoords[1] = lat1;
mCoords[2] = lon2;
mCoords[3] = lat1;
mCoords[4] = lon2;
mCoords[5] = lat2;
mCoords[6] = lon1;
mCoords[7] = lat2;
mCoords[8] = lon1;
mCoords[9] = lat1;
mIndex[0] = 10;
lon1 = (float) MercatorProjection.pixelXToLongitude(cx - 119, tile.zoomLevel) * 1000000;
lon2 = (float) MercatorProjection.pixelXToLongitude(cx + 119, tile.zoomLevel) * 1000000;
lat1 = (float) MercatorProjection.pixelYToLatitude(cy - 119, tile.zoomLevel) * 1000000;
lat2 = (float) MercatorProjection.pixelYToLatitude(cy + 119, tile.zoomLevel) * 1000000;
mCoords[10] = lon1;
mCoords[11] = lat1;
mCoords[12] = lon2;
mCoords[13] = lat1;
mCoords[14] = lon2;
mCoords[15] = lat2;
mCoords[16] = lon1;
mCoords[17] = lat2;
mCoords[18] = lon1;
mCoords[19] = lat1;
mIndex[1] = 10;
mapDatabaseCallback.renderWay((byte) 0, mTags, mCoords, mIndex, true);
lon1 = (float) MercatorProjection.pixelXToLongitude(cx, tile.zoomLevel) * 1000000;
lat1 = (float) MercatorProjection.pixelXToLongitude(cx, tile.zoomLevel) * 1000000;
mNameTags = new Tag[2];
mNameTags[0] = new Tag("place", "city");
mNameTags[1] = new Tag("name", "check one check two, YO!");
mapDatabaseCallback.renderPointOfInterest((byte) 0, (int) lat1, (int) lon1,
mNameTags);
return QueryResult.SUCCESS;
}
@Override
public String getMapProjection() {
return PROJECTION;
}
@Override
public MapInfo getMapInfo() {
return mMapInfo;
}
@Override
public boolean isOpen() {
return mOpenFile;
}
@Override
public OpenResult open(Map<String, String> options) {
mOpenFile = true;
return OpenResult.SUCCESS;
}
@Override
public void close() {
mOpenFile = false;
}
@Override
public void cancel() {
// TODO Auto-generated method stub
}
}