extract PostGIS db backend
This commit is contained in:
parent
c08b481796
commit
d9cbd12c16
@ -44,12 +44,13 @@ public final class MapDatabaseFactory {
|
|||||||
return new org.oscim.database.mapfile.MapDatabase();
|
return new org.oscim.database.mapfile.MapDatabase();
|
||||||
case TEST_READER:
|
case TEST_READER:
|
||||||
return new org.oscim.database.test.MapDatabase();
|
return new org.oscim.database.test.MapDatabase();
|
||||||
case POSTGIS_READER:
|
|
||||||
return new org.oscim.database.postgis.MapDatabase();
|
|
||||||
case PBMAP_READER:
|
case PBMAP_READER:
|
||||||
return new org.oscim.database.pbmap.MapDatabase();
|
return new org.oscim.database.pbmap.MapDatabase();
|
||||||
case OSCIMAP_READER:
|
case OSCIMAP_READER:
|
||||||
return new org.oscim.database.oscimap.MapDatabase();
|
return new org.oscim.database.oscimap.MapDatabase();
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalArgumentException("unknown enum value: " + mapDatabase);
|
throw new IllegalArgumentException("unknown enum value: " + mapDatabase);
|
||||||
|
|||||||
@ -1,384 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,406 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.Entry;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.oscim.core.BoundingBox;
|
|
||||||
import org.oscim.core.GeoPoint;
|
|
||||||
import org.oscim.core.GeometryBuffer;
|
|
||||||
import org.oscim.core.Tag;
|
|
||||||
import org.oscim.database.IMapDatabase;
|
|
||||||
import org.oscim.database.IMapDatabaseCallback;
|
|
||||||
import org.oscim.database.IMapDatabaseCallback.WayData;
|
|
||||||
import org.oscim.database.MapInfo;
|
|
||||||
import org.oscim.database.MapOptions;
|
|
||||||
import org.oscim.database.OpenResult;
|
|
||||||
import org.oscim.database.QueryResult;
|
|
||||||
import org.oscim.generator.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 final GeometryBuffer mGeom = new GeometryBuffer(1 << 14, 1 << 8);
|
|
||||||
|
|
||||||
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),
|
|
||||||
null,
|
|
||||||
0, 0, 0, "de", "comment", "author", null);
|
|
||||||
|
|
||||||
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 final WayData mWay = new WayData();
|
|
||||||
|
|
||||||
|
|
||||||
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()) {
|
|
||||||
mGeom.indexPos = 0;
|
|
||||||
mGeom.pointPos =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 (mGeom.indexPos == 0) {
|
|
||||||
Log.d(TAG, "no index: skip way");
|
|
||||||
continue;
|
|
||||||
} else if (mGeom.indexPos == 1) {
|
|
||||||
mapDatabaseCallback.renderPOI((byte) 0, mTags, mGeom);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// short[] idx = new short[mIndexPos];
|
|
||||||
// System.arraycopy(mIndex, 0, idx, 0, mIndexPos);
|
|
||||||
//
|
|
||||||
if (mGeom.index.length > mGeom.indexPos)
|
|
||||||
mGeom.index[mGeom.indexPos] = -1;
|
|
||||||
|
|
||||||
mWay.geom = mGeom;
|
|
||||||
mWay.tags = mTags;
|
|
||||||
mWay.layer = 0;
|
|
||||||
mWay.closed = polygon;
|
|
||||||
|
|
||||||
mapDatabaseCallback.renderWay(mWay);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
connection = null;
|
|
||||||
return QueryResult.FAILED;
|
|
||||||
}
|
|
||||||
// Log.d(TAG, "rows: " + cnt);
|
|
||||||
return QueryResult.SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getMapProjection() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MapInfo getMapInfo() {
|
|
||||||
return mMapInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isOpen() {
|
|
||||||
return mOpenFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OpenResult open(MapOptions options) {
|
|
||||||
mOpenFile = true;
|
|
||||||
return OpenResult.SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
if (connection != null) {
|
|
||||||
try {
|
|
||||||
connection.close();
|
|
||||||
} catch (SQLException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
connection = 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();
|
|
||||||
mGeom.points[0] = (float) (data.getDouble() * mScale);
|
|
||||||
mGeom.points[1] = (float) (data.getDouble() * mScale);
|
|
||||||
mGeom.index[0] = 2;
|
|
||||||
mGeom.indexPos= 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);
|
|
||||||
mGeom.index[mGeom.indexPos++] = 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++) {
|
|
||||||
mGeom.points[mGeom.pointPos++] = (float) (data.getDouble()) * mScale;
|
|
||||||
mGeom.points[mGeom.pointPos++] = (float) (data.getDouble()) * mScale;
|
|
||||||
if (haveZ)
|
|
||||||
data.getDouble();
|
|
||||||
if (haveM)
|
|
||||||
data.getDouble();
|
|
||||||
}
|
|
||||||
mGeom.index[mGeom.indexPos++] = (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
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,416 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 {
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,139 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user