improve index creating

remove backward compatibility with old indexes

git-svn-id: https://osmand.googlecode.com/svn/trunk@654 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-11-11 20:12:31 +00:00
parent 48f7a63670
commit c970815ac8
11 changed files with 302 additions and 528 deletions

View file

@ -11,6 +11,10 @@ public class ToDoConstants {
// introduce bidforfix on site
// 1. Verify to use query
// !!! Fix phone, site information for POI INDEX
// Move poi index to 1 version and remove backward support (save int coordinates and save for name_en)
// Show in message and test for some indexes !!!
// For 0.5 release
// 101. 1) Introduce shell script to print information about indexes 2)Introduce activity to show active indexes

View file

@ -524,6 +524,9 @@ public class BinaryMapIndexReader {
int tag = WireFormat.getTagFieldNumber(t);
switch (tag) {
case 0:
if(dataObject.getEnName().length() == 0){
dataObject.setEnName(Junidecode.unidecode(dataObject.getName()));
}
end = true;
break;
case OsmandOdb.TransportRouteStop.NAME_EN_FIELD_NUMBER :
@ -580,12 +583,15 @@ public class BinaryMapIndexReader {
switch (tag) {
case 0:
dataObject.setReferencesToRoutes(req.cacheTypes.toArray());
if(dataObject.getEnName().length() == 0){
dataObject.setEnName(Junidecode.unidecode(dataObject.getName()));
}
return dataObject;
case OsmandOdb.TransportStop.ROUTES_FIELD_NUMBER :
req.cacheTypes.add(shift - codedIS.readUInt32());
break;
case OsmandOdb.TransportStop.NAME_EN_FIELD_NUMBER :
dataObject.setName(""+((char) codedIS.readUInt32())); //$NON-NLS-1$
dataObject.setEnName(""+((char) codedIS.readUInt32())); //$NON-NLS-1$
break;
case OsmandOdb.TransportStop.NAME_FIELD_NUMBER :
int i = codedIS.readUInt32();
@ -1211,7 +1217,7 @@ public class BinaryMapIndexReader {
break;
case OsmandOdb.CityIndex.NAME_FIELD_NUMBER :
c.setName(codedIS.readString());
if(c.getEnName() == null){
if(c.getEnName().length() == 0){
c.setEnName(Junidecode.unidecode(c.getName()));
}
break;
@ -1328,7 +1334,7 @@ public class BinaryMapIndexReader {
break;
case OsmandOdb.BuildingIndex.NAME_FIELD_NUMBER :
b.setName(codedIS.readString());
if(b.getEnName() == null){
if(b.getEnName().length() == 0){
b.setEnName(Junidecode.unidecode(b.getName()));
}
break;

View file

@ -13,6 +13,8 @@ public class Amenity extends MapObject {
private String subType;
private AmenityType type;
private String openingHours;
private String phone;
private String site;
public Amenity(Entity entity){
super(entity);
@ -99,6 +101,22 @@ public class Amenity extends MapObject {
return getSimpleFormat(false);
}
public String getSite() {
return site;
}
public void setSite(String site) {
this.site = site;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public void doDataPreparation() {

View file

@ -21,11 +21,6 @@ import net.osmand.data.City;
import net.osmand.data.TransportRoute;
import net.osmand.data.TransportStop;
import net.osmand.data.City.CityType;
import net.osmand.data.index.IndexConstants.IndexBinaryMapRenderObject;
import net.osmand.data.index.IndexConstants.IndexPoiTable;
import net.osmand.data.index.IndexConstants.IndexTransportRoute;
import net.osmand.data.index.IndexConstants.IndexTransportRouteStop;
import net.osmand.data.index.IndexConstants.IndexTransportStop;
import net.osmand.data.preparation.IndexCreator;
import net.osmand.osm.Entity;
import net.osmand.osm.LatLon;
@ -43,32 +38,38 @@ import rtree.Rect;
public class DataIndexWriter {
private static final int BATCH_SIZE = 1000;
public static void insertAmenityIntoPoi(PreparedStatement prep, Map<PreparedStatement, Integer> map, Amenity amenity, int batchSize) throws SQLException {
prep.setLong(IndexPoiTable.ID.ordinal() + 1, amenity.getId());
prep.setDouble(IndexPoiTable.LATITUDE.ordinal() + 1, amenity.getLocation().getLatitude());
prep.setDouble(IndexPoiTable.LONGITUDE.ordinal() + 1, amenity.getLocation().getLongitude());
prep.setString(IndexPoiTable.NAME_EN.ordinal() + 1, amenity.getEnName());
prep.setString(IndexPoiTable.NAME.ordinal() + 1, amenity.getName());
prep.setString(IndexPoiTable.TYPE.ordinal() + 1, AmenityType.valueToString(amenity.getType()));
prep.setString(IndexPoiTable.SUBTYPE.ordinal() + 1, amenity.getSubType());
prep.setString(IndexPoiTable.OPENING_HOURS.ordinal() + 1 , amenity.getOpeningHours());
assert IndexConstants.POI_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
prep.setLong(0, amenity.getId());
prep.setDouble(1, amenity.getLocation().getLatitude());
prep.setDouble(2, amenity.getLocation().getLongitude());
prep.setString(3, amenity.getEnName());
prep.setString(4, amenity.getName());
prep.setString(5, AmenityType.valueToString(amenity.getType()));
prep.setString(6, amenity.getSubType());
prep.setString(7, amenity.getOpeningHours());
prep.setString(8, amenity.getSite());
prep.setString(9, amenity.getPhone());
addBatch(map, prep, batchSize);
}
public static PreparedStatement createStatementAmenityInsert(Connection conn) throws SQLException{
assert IndexPoiTable.values().length == 8;
return conn.prepareStatement(IndexConstants.generatePrepareStatementToInsert(IndexPoiTable.getTable(), 8));
return conn.prepareStatement("INSERT INTO " + IndexConstants.POI_TABLE + "(id, latitude, longitude, name_en, name, type, subtype, opening_hours, site, phone) " + //$NON-NLS-1$//$NON-NLS-2$
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
}
public static void createPoiIndexStructure(Connection conn) throws SQLException{
Statement stat = conn.createStatement();
stat.executeUpdate(IndexConstants.generateCreateSQL(IndexPoiTable.values()));
stat.executeUpdate(IndexConstants.generateCreateIndexSQL(IndexPoiTable.values()));
stat.executeUpdate("create table" + IndexConstants.POI_TABLE + //$NON-NLS-1$
"(id bigint, latitude double, longitude double, name_en varchar(255), name varchar(255), " +
"type varchar(255), subtype varchar(255), opening_hours varchar(255), phone varchar(255), site varchar(255)," +
"primary key(id, type, subtype))");
stat.executeUpdate("create index poi_loc on poi (latitude, longitude, type, subtype)");
stat.executeUpdate("create index poi_id on poi (id, type, subtype)");
if(IndexCreator.usingSQLite()){
stat.execute("PRAGMA user_version = " + IndexConstants.POI_TABLE_VERSION); //$NON-NLS-1$
}
@ -77,11 +78,13 @@ public class DataIndexWriter {
public static PreparedStatement getStreetNodeInsertPreparedStatement(Connection conn) throws SQLException {
assert IndexConstants.STREET_NODE_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
return conn.prepareStatement("insert into street_node (id, latitude, longitude, street, way) values (?, ?, ?, ?, ?)");
}
public static void writeStreetWayNodes(PreparedStatement prepStreetNode, Map<PreparedStatement, Integer> count, Long streetId, Way way, int batchSize)
throws SQLException {
assert IndexConstants.STREET_NODE_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
for (Node n : way.getNodes()) {
if (n == null) {
continue;
@ -96,12 +99,14 @@ public class DataIndexWriter {
}
public static PreparedStatement getBuildingInsertPreparedStatement(Connection conn) throws SQLException {
assert IndexConstants.BUILDING_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
return conn.prepareStatement("insert into building (id, latitude, longitude, name, name_en, street, postcode) values (?, ?, ?, ?, ?, ?, ?)");
}
public static void writeBuilding(PreparedStatement prepBuilding, Map<PreparedStatement, Integer> count, Long streetId,
Building building, int batchSize)
throws SQLException {
assert IndexConstants.BUILDING_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
prepBuilding.setLong(1, building.getId());
prepBuilding.setDouble(2, building.getLocation().getLatitude());
prepBuilding.setDouble(3, building.getLocation().getLongitude());
@ -113,32 +118,36 @@ public class DataIndexWriter {
addBatch(count, prepBuilding);
}
public static PreparedStatement getSearchStreetPreparedStatement(Connection mapConnection) throws SQLException {
assert IndexConstants.STREET_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
return mapConnection.prepareStatement("SELECT ID FROM street WHERE ? = city AND ? = name");
}
public static PreparedStatement getSearchBuildingPreparedStatement(Connection mapConnection) throws SQLException {
assert IndexConstants.BUILDING_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
return mapConnection.prepareStatement("SELECT id FROM building where ? = id");
}
public static PreparedStatement getStreeNodeSearchPreparedStatement(Connection mapConnection) throws SQLException {
assert IndexConstants.STREET_NODE_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
return mapConnection.prepareStatement("SELECT way FROM street_node WHERE ? = way");
}
public static PreparedStatement getUpdateBuildingPostcodePreparedStatement(Connection mapConnection) throws SQLException {
assert IndexConstants.BUILDING_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
return mapConnection.prepareStatement("UPDATE building SET postcode = ? WHERE id = ?");
}
public static PreparedStatement getCityInsertPreparedStatement(Connection conn) throws SQLException{
assert IndexConstants.CITY_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
return conn.prepareStatement("insert into city (id, latitude, longitude, name, name_en, city_type) values (?, ?, ?, ?, ?, ?)");
}
public static void writeCity(PreparedStatement prepCity, Map<PreparedStatement, Integer> count, City city, int batchSize) throws SQLException {
assert IndexConstants.CITY_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
prepCity.setLong(1, city.getId());
prepCity.setDouble(2, city.getLocation().getLatitude());
prepCity.setDouble(3, city.getLocation().getLongitude());
@ -149,11 +158,13 @@ public class DataIndexWriter {
}
public static PreparedStatement getStreetInsertPreparedStatement(Connection conn) throws SQLException{
assert IndexConstants.STREET_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
return conn.prepareStatement("insert into street (id, latitude, longitude, name, name_en, city) values (?, ?, ?, ?, ?, ?)");
}
public static void insertStreetData(PreparedStatement addressStreetStat, long id, String name, String nameEn, double latitude,
double longitude, Long cityId) throws SQLException {
assert IndexConstants.STREET_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
addressStreetStat.setLong(1, id);
addressStreetStat.setString(4, name);
addressStreetStat.setString(5, nameEn);
@ -165,6 +176,10 @@ public class DataIndexWriter {
public static void createAddressIndexStructure(Connection conn) throws SQLException{
Statement stat = conn.createStatement();
assert IndexConstants.CITY_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
assert IndexConstants.STREET_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
assert IndexConstants.STREET_NODE_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
assert IndexConstants.STREET_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
stat.executeUpdate("create table city (id bigint primary key, latitude double, longitude double, " +
"name varchar(255), name_en varchar(255), city_type varchar(32))");
@ -194,18 +209,27 @@ public class DataIndexWriter {
stat.close();
}
public static PreparedStatement createStatementTransportStopInsert(Connection conn) throws SQLException{
assert IndexConstants.TRANSPORT_STOP_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
return conn.prepareStatement("insert into transport_stop(id, latitude, longitude, name, name_en) values(?, ?, ?, ?, ?,)");
}
public static PreparedStatement createStatementTransportRouteStopInsert(Connection conn) throws SQLException{
assert IndexConstants.TRANSPORT_ROUTE_STOP_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
return conn.prepareStatement("insert into transport_route_stop(route, stop, direction, ord) values(?, ?, ?, ?)");
}
private static void writeRouteStops(RTree transportStopsTree, PreparedStatement prepRouteStops, PreparedStatement prepStops, Map<PreparedStatement, Integer> count,
Set<Long> writtenStops, TransportRoute r, List<TransportStop> stops, boolean direction) throws SQLException {
assert IndexConstants.TRANSPORT_STOP_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
assert IndexConstants.TRANSPORT_ROUTE_STOP_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
int i = 0;
for(TransportStop s : stops){
if (!writtenStops.contains(s.getId())) {
assert IndexTransportStop.values().length == 5;
prepStops.setLong(IndexTransportStop.ID.ordinal() + 1, s.getId());
prepStops.setDouble(IndexTransportStop.LATITUDE.ordinal() + 1, s.getLocation().getLatitude());
prepStops.setDouble(IndexTransportStop.LONGITUDE.ordinal() + 1, s.getLocation().getLongitude());
prepStops.setString(IndexTransportStop.NAME.ordinal() + 1, s.getName());
prepStops.setString(IndexTransportStop.NAME_EN.ordinal() + 1, s.getEnName());
prepStops.setLong(1, s.getId());
prepStops.setDouble(2, s.getLocation().getLatitude());
prepStops.setDouble(3, s.getLocation().getLongitude());
prepStops.setString(4, s.getName());
prepStops.setString(5, s.getEnName());
int x = (int) MapUtils.getTileNumberX(24, s.getLocation().getLongitude());
int y = (int) MapUtils.getTileNumberY(24, s.getLocation().getLatitude());
addBatch(count, prepStops);
@ -218,28 +242,31 @@ public class DataIndexWriter {
}
writtenStops.add(s.getId());
}
assert IndexTransportRouteStop.values().length == 4;
prepRouteStops.setLong(IndexTransportRouteStop.ROUTE.ordinal() + 1, r.getId());
prepRouteStops.setLong(IndexTransportRouteStop.STOP.ordinal() + 1, s.getId());
prepRouteStops.setInt(IndexTransportRouteStop.DIRECTION.ordinal() + 1, direction ? 1 : 0);
prepRouteStops.setInt(IndexTransportRouteStop.ORD.ordinal() + 1, i++);
prepRouteStops.setLong(1, r.getId());
prepRouteStops.setLong(2, s.getId());
prepRouteStops.setInt(3, direction ? 1 : 0);
prepRouteStops.setInt(4, i++);
addBatch(count, prepRouteStops);
}
}
public static PreparedStatement createStatementTransportRouteInsert(Connection conn) throws SQLException{
assert IndexConstants.TRANSPORT_ROUTE_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
return conn.prepareStatement("insert into transport_route(id, type, operator, ref, name, name_en, dist) values(?, ?, ?, ?, ?, ?, ?)");
}
public static void insertTransportIntoIndex(PreparedStatement prepRoute, PreparedStatement prepRouteStops,
PreparedStatement prepStops, RTree transportStopsTree,
Set<Long> writtenStops, TransportRoute route, Map<PreparedStatement, Integer> statements,
int batchSize) throws SQLException {
assert IndexTransportRoute.values().length == 7;
prepRoute.setLong(IndexTransportRoute.ID.ordinal() + 1, route.getId());
prepRoute.setString(IndexTransportRoute.TYPE.ordinal() + 1, route.getType());
prepRoute.setString(IndexTransportRoute.OPERATOR.ordinal() + 1, route.getOperator());
prepRoute.setString(IndexTransportRoute.REF.ordinal() + 1, route.getRef());
prepRoute.setString(IndexTransportRoute.NAME.ordinal() + 1, route.getName());
prepRoute.setString(IndexTransportRoute.NAME_EN.ordinal() + 1, route.getEnName());
prepRoute.setInt(IndexTransportRoute.DIST.ordinal() + 1, route.getAvgBothDistance());
assert IndexConstants.TRANSPORT_ROUTE_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
prepRoute.setLong(1, route.getId());
prepRoute.setString(2, route.getType());
prepRoute.setString(3, route.getOperator());
prepRoute.setString(4, route.getRef());
prepRoute.setString(5, route.getName());
prepRoute.setString(6, route.getEnName());
prepRoute.setInt(7, route.getAvgBothDistance());
addBatch(statements, prepRoute);
writeRouteStops(transportStopsTree, prepRouteStops, prepStops, statements, writtenStops, route, route.getForwardStops(), true);
@ -249,37 +276,46 @@ public class DataIndexWriter {
public static void createTransportIndexStructure(Connection conn) throws SQLException{
Statement stat = conn.createStatement();
stat.executeUpdate(IndexConstants.generateCreateSQL(IndexTransportRoute.values()));
stat.executeUpdate(IndexConstants.generateCreateIndexSQL(IndexTransportRoute.values()));
stat.executeUpdate(IndexConstants.generateCreateSQL(IndexTransportRouteStop.values()));
stat.executeUpdate(IndexConstants.generateCreateIndexSQL(IndexTransportRouteStop.values()));
stat.executeUpdate(IndexConstants.generateCreateSQL(IndexTransportStop.values()));
stat.executeUpdate(IndexConstants.generateCreateIndexSQL(IndexTransportStop.values()));
assert IndexConstants.TRANSPORT_ROUTE_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
assert IndexConstants.TRANSPORT_STOP_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
assert IndexConstants.TRANSPORT_ROUTE_STOP_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
stat.executeUpdate("create table transport_route (id bigint primary key, type varchar(255), operator varchar(255)," +
"ref varchar(255), name varchar(255), name_en varchar(255), dist int)");
stat.executeUpdate("create index transport_route_id on transport_route (id)");
stat.executeUpdate("create table transport_route_stop (stop bigint, route bigint, ord int, direction smallint, primary key (route, ord, direction))");
stat.executeUpdate("create index transport_route_stop_stop on transport_route_stop (stop)");
stat.executeUpdate("create index transport_route_stop_route on transport_route_stop (route)");
stat.executeUpdate("create table transport_stop (id bigint primary key, latitude double, longitude double, name varchar(255), name_en varchar(255))");
stat.executeUpdate("create index transport_stop_id on transport_stop (id)");
stat.executeUpdate("create index transport_stop_location on transport_stop (latitude, longitude)");
if(IndexCreator.usingSQLite()){
stat.execute("PRAGMA user_version = " + IndexConstants.TRANSPORT_TABLE_VERSION); //$NON-NLS-1$
}
stat.close();
}
public static void createMapIndexStructure(Connection conn) throws SQLException{
Statement stat = conn.createStatement();
stat.execute(IndexConstants.generateCreateSQL(IndexBinaryMapRenderObject.values()));
stat.execute(IndexConstants.generateCreateIndexSQL(IndexBinaryMapRenderObject.values()));
assert IndexConstants.BINARY_MAP_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
stat.executeUpdate("create table binary_map_objects (id bigint primary key, name varchar(255), " +
"types binary, restrictions binary, nodes binary, highway int)");
stat.executeUpdate("create index binary_map_objects_ind on binary_map_objects (id)");
stat.close();
}
public static PreparedStatement createStatementMapBinaryInsert(Connection conn) throws SQLException{
assert IndexBinaryMapRenderObject.values().length == 6;
return conn.prepareStatement(IndexConstants.generatePrepareStatementToInsert(IndexBinaryMapRenderObject.getTable(), 6));
assert IndexConstants.BINARY_MAP_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
return conn.prepareStatement("insert into binary_map_objects(id, name, types, restrictions, nodes, highway) values(?, ?, ?, ?, ?, ?)");
}
public static void insertBinaryMapRenderObjectIndex(Map<PreparedStatement, Integer> statements,
PreparedStatement mapBinaryStat, RTree mapTree, Entity e, String name,
long id, int type, List<Integer> typeUse, int highwayAttributes, List<Long> restrictions,
boolean inversePath, boolean writeAsPoint, int batchSize) throws SQLException {
assert IndexBinaryMapRenderObject.values().length == 6;
if(e instanceof Relation){
throw new IllegalArgumentException();
}
@ -334,12 +370,15 @@ public class DataIndexWriter {
throw new IllegalStateException(es);
}
if (init) {
mapBinaryStat.setLong(IndexBinaryMapRenderObject.ID.ordinal() + 1, id);
mapBinaryStat.setBytes(IndexBinaryMapRenderObject.TYPES.ordinal() + 1, btypes.toByteArray());
mapBinaryStat.setBytes(IndexBinaryMapRenderObject.RESTRICTIONS.ordinal() + 1, brestrictions.toByteArray());
mapBinaryStat.setBytes(IndexBinaryMapRenderObject.NODES.ordinal() + 1, bnodes.toByteArray());
mapBinaryStat.setInt(IndexBinaryMapRenderObject.HIGHWAY.ordinal() + 1, highwayAttributes);
mapBinaryStat.setString(IndexBinaryMapRenderObject.NAME.ordinal() + 1, name);
assert IndexConstants.BINARY_MAP_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
// conn.prepareStatement("insert into binary_map_objects(id, name, types, restrictions, nodes, highway) values(?, ?, ?, ?, ?, ?)");
mapBinaryStat.setLong(1, id);
mapBinaryStat.setString(2, name);
mapBinaryStat.setBytes(3, btypes.toByteArray());
mapBinaryStat.setBytes(4, brestrictions.toByteArray());
mapBinaryStat.setBytes(5, bnodes.toByteArray());
mapBinaryStat.setInt(6, highwayAttributes);
addBatch(statements, mapBinaryStat);
try {
mapTree.insert(new LeafElement(new Rect(minX, minY, maxX, maxY), id));

View file

@ -5,12 +5,16 @@ public class IndexConstants {
// Important : Every time you change schema of db upgrade version!!!
// If you want that new application support old index : put upgrade code in android app ResourceManager
public final static int TRANSPORT_TABLE_VERSION = 0;
public final static int POI_TABLE_VERSION = 0;
public final static int ADDRESS_TABLE_VERSION = 1;
public final static int POI_TABLE_VERSION = 1;
public final static int BINARY_MAP_VERSION = 1; // starts with 1
public final static int VOICE_VERSION = 0;
// these indexes are deprecated
public final static int TRANSPORT_TABLE_VERSION = 0;
public final static int ADDRESS_TABLE_VERSION = 1;
public static final String POI_INDEX_DIR = "POI/"; //$NON-NLS-1$
public static final String ADDRESS_INDEX_DIR = "Address/"; //$NON-NLS-1$
@ -28,281 +32,21 @@ public class IndexConstants {
public static final String VOICE_INDEX_EXT_ZIP = ".voice.zip"; //$NON-NLS-1$
public static final String BINARY_MAP_INDEX_EXT_ZIP = ".map.zip"; //$NON-NLS-1$
public interface IndexColumn {
public boolean isIndex();
public String getType();
public String getTableName();
}
public static String[] generateColumnNames(IndexColumn[] columns) {
String[] columnNames = new String[columns.length];
for (int i = 0; i < columnNames.length; i++) {
columnNames[i] = columns[i].toString();
}
return columnNames;
}
public static String generateCreateSQL(IndexColumn[] columns){
StringBuilder b = new StringBuilder();
b.append("create table ").append(columns[0].getTableName()).append(" ("); //$NON-NLS-1$ //$NON-NLS-2$
boolean first = true;
for(IndexColumn c : columns){
if(first) {
first = false;
} else {
b.append(", "); //$NON-NLS-1$
}
b.append(c.toString());
if(c.getType() != null){
b.append(" ").append(c.getType()); //$NON-NLS-1$
} else {
b.append(" varchar(255)"); //$NON-NLS-1$
}
}
b.append(" )"); //$NON-NLS-1$
return b.toString();
}
public static String generateSelectSQL(IndexColumn[] select){
return generateSelectSQL(select, null);
}
public static String generateSelectSQL(IndexColumn[] select, String where){
StringBuilder b = new StringBuilder();
b.append("select "); //$NON-NLS-1$
boolean first = true;
for(IndexColumn c : select){
if(first) {
first = false;
} else {
b.append(", "); //$NON-NLS-1$
}
b.append(c.toString());
}
b.append(" FROM ").append(select[0].getTableName()); //$NON-NLS-1$
if(where != null){
b.append(" WHERE " ).append(where); //$NON-NLS-1$
}
b.append(" "); //$NON-NLS-1$
return b.toString();
}
public static String generatePrepareStatementToInsert(String tableName, int numColumns){
StringBuilder b = new StringBuilder();
b.append("insert into ").append(tableName).append(" values ("); //$NON-NLS-1$ //$NON-NLS-2$
for(int i=0; i< numColumns; i++){
if(i > 0){
b.append(", "); //$NON-NLS-1$
}
b.append("?"); //$NON-NLS-1$
}
b.append(")"); //$NON-NLS-1$
return b.toString();
}
public static String generateCreateIndexSQL(IndexColumn[] columns){
StringBuilder b = new StringBuilder();
String tableName = columns[0].getTableName();
b.append("create index ").append(tableName).append("_index ON ").append(tableName).append(" ("); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
boolean first = true;
for(IndexColumn c : columns){
if(!c.isIndex()){
continue;
}
if(first) {
first = false;
} else {
b.append(", "); //$NON-NLS-1$
}
b.append(c.toString());
}
b.append(" ) "); //$NON-NLS-1$
if(first){
return null;
}
return b.toString();
}
// POI index
public enum IndexPoiTable implements IndexColumn {
ID("bigint"), LATITUDE("double", true), LONGITUDE("double", true), OPENING_HOURS, NAME, NAME_EN, TYPE, SUBTYPE; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
boolean index = false;
String type = null;
private IndexPoiTable(){}
private IndexPoiTable(String type){
this.type = type;
}
private IndexPoiTable(String type, boolean index){ this(type); this.index = index;}
public static String getTable(){
return "poi"; //$NON-NLS-1$
}
public String getTableName(){
return getTable();
}
@Override
public String getType() {
return type;
}
@Override
public boolean isIndex() {
return index;
}
}
// Transport Index
public enum IndexTransportStop implements IndexColumn {
ID("bigint", true), LATITUDE("double", true), LONGITUDE("double", true), NAME, NAME_EN; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
boolean index = false;
String type = null;
private IndexTransportStop() {
}
private IndexTransportStop(String type) {
this.type = type;
}
private IndexTransportStop(String type, boolean index) {
this(type);
this.index = index;
}
public static String getTable() {
return "transport_stop"; //$NON-NLS-1$
}
public String getTableName() {
return getTable();
}
@Override
public String getType() {
return type;
}
@Override
public boolean isIndex() {
return index;
}
}
public final static String STREET_NODE_TABLE = "street_node"; //$NON-NLS-1$
public final static String STREET_TABLE = "street"; //$NON-NLS-1$
public final static String CITY_TABLE = "city"; //$NON-NLS-1$
public final static String BUILDING_TABLE = "building"; //$NON-NLS-1$
public enum IndexTransportRouteStop implements IndexColumn {
STOP("bigint", true), ROUTE("bigint", true), ORD("int"), DIRECTION("smallint"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
boolean index = false;
String type = null;
private IndexTransportRouteStop() {
}
private IndexTransportRouteStop(String type) {
this.type = type;
}
private IndexTransportRouteStop(String type, boolean index) {
this(type);
this.index = index;
}
public static String getTable() {
return "transport_route_stop"; //$NON-NLS-1$
}
public String getTableName() {
return getTable();
}
@Override
public String getType() {
return type;
}
@Override
public boolean isIndex() {
return index;
}
}
public final static String POI_TABLE = "poi"; //$NON-NLS-1$
public enum IndexTransportRoute implements IndexColumn {
ID("bigint", true), TYPE(null, true), OPERATOR, REF(null, true), NAME, NAME_EN, DIST("int"); //$NON-NLS-1$ //$NON-NLS-2$
boolean index = false;
String type = null;
private IndexTransportRoute() {
}
private IndexTransportRoute(String type) {
this.type = type;
}
private IndexTransportRoute(String type, boolean index) {
this(type);
this.index = index;
}
public static String getTable() {
return "transport_route"; //$NON-NLS-1$
}
public String getTableName() {
return getTable();
}
@Override
public String getType() {
return type;
}
@Override
public boolean isIndex() {
return index;
}
}
public final static String BINARY_MAP_TABLE = "binary_map_objects";
public final static String TRANSPORT_STOP_TABLE = "transport_stop"; //$NON-NLS-1$
public final static String TRANSPORT_ROUTE_STOP_TABLE = "transport_route_stop"; //$NON-NLS-1$
public final static String TRANSPORT_ROUTE_TABLE = "transport_route"; //$NON-NLS-1$
public enum IndexBinaryMapRenderObject implements IndexColumn {
ID("bigint", true), NAME, TYPES("BLOB"), RESTRICTIONS("BLOB"), NODES("BLOB"), HIGHWAY("INT"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
boolean index = false;
String type = null;
private IndexBinaryMapRenderObject() {
}
private IndexBinaryMapRenderObject(String type) {
this.type = type;
}
private IndexBinaryMapRenderObject(String type, boolean index) {
this(type);
this.index = index;
}
public static String getTable() {
return "binary_map_objects"; //$NON-NLS-1$
}
public String getTableName() {
return getTable();
}
@Override
public String getType() {
return type;
}
@Override
public boolean isIndex() {
return index;
}
}
}

View file

@ -43,10 +43,6 @@ import net.osmand.data.City.CityType;
import net.osmand.data.index.DataIndexReader;
import net.osmand.data.index.DataIndexWriter;
import net.osmand.data.index.IndexConstants;
import net.osmand.data.index.IndexConstants.IndexBinaryMapRenderObject;
import net.osmand.data.index.IndexConstants.IndexTransportRoute;
import net.osmand.data.index.IndexConstants.IndexTransportRouteStop;
import net.osmand.data.index.IndexConstants.IndexTransportStop;
import net.osmand.impl.ConsoleProgressImplementation;
import net.osmand.osm.Entity;
import net.osmand.osm.LatLon;
@ -95,7 +91,7 @@ public class IndexCreator {
private static final String DERBY_DIALECT = "DERBY";
private static final String H2_DIALECT = "H2";
private static final String SQLITE_DIALECT = "SQLITE";
private static final String CURRENT_DB = H2_DIALECT;
private static final String CURRENT_DB = SQLITE_DIALECT;
public static final int BATCH_SIZE = 1000;
public static final int BATCH_SIZE_OSM = 10000;
@ -292,9 +288,8 @@ public class IndexCreator {
} else {
stat.executeUpdate("drop table if exists node");
}
String longType = usingSQLite() ? "long" : "bigint";
stat.executeUpdate("create table node (id "+longType+", latitude double, longitude double)");
stat.executeUpdate("create index IdIndex ON node (id, latitude, longitude)");
stat.executeUpdate("create table node (id bigint primary key, latitude double, longitude double)");
stat.executeUpdate("create index IdIndex ON node (id)");
if (usingDerby()) {
try {
stat.executeUpdate("drop table ways");
@ -304,8 +299,8 @@ public class IndexCreator {
} else {
stat.executeUpdate("drop table if exists ways");
}
stat.executeUpdate("create table ways (id "+longType+", node "+longType+", ord smallint)");
stat.executeUpdate("create index IdWIndex ON ways (id, node)");
stat.executeUpdate("create table ways (id bigint, node bigint, ord smallint, primary key (id, ord))");
stat.executeUpdate("create index IdWIndex ON ways (id)");
if (usingDerby()) {
try {
stat.executeUpdate("drop table relations");
@ -315,8 +310,8 @@ public class IndexCreator {
} else {
stat.executeUpdate("drop table if exists relations");
}
stat.executeUpdate("create table relations (id "+longType+", member "+longType+", type smallint, role varchar(255), ord smallint)");
stat.executeUpdate("create index IdRIndex ON relations (id, member, type)");
stat.executeUpdate("create table relations (id bigint, member bigint, type smallint, role varchar(255), ord smallint, primary key (id, ord))");
stat.executeUpdate("create index IdRIndex ON relations (id)");
if (usingDerby()) {
try {
stat.executeUpdate("drop table tags");
@ -324,9 +319,9 @@ public class IndexCreator {
// ignore it
}
} else {
stat.executeUpdate("drop table if exists ефпы");
stat.executeUpdate("drop table if exists tags");
}
stat.executeUpdate("create table tags (id "+longType+", type smallint, skeys varchar(255), value varchar(255))");
stat.executeUpdate("create table tags (id bigint, type smallint, skeys varchar(255), value varchar(255), primary key (id, type, skeys))");
stat.executeUpdate("create index IdTIndex ON tags (id, type)");
stat.close();
@ -364,7 +359,9 @@ public class IndexCreator {
try {
if (e instanceof Node) {
currentCountNode++;
allNodes++;
if(!e.getTags().isEmpty()){
allNodes++;
}
prepNode.setLong(1, e.getId());
prepNode.setDouble(2, ((Node) e).getLatitude());
prepNode.setDouble(3, ((Node) e).getLongitude());
@ -759,7 +756,6 @@ public class IndexCreator {
return null;
}
TransportRoute r = new TransportRoute(rel, ref);
convertEnglishName(r);
r.setOperator(operator);
r.setType(route);
@ -777,7 +773,6 @@ public class IndexCreator {
if (e.getValue().contains("stop")) {
if (e.getKey() instanceof Node) {
TransportStop stop = new TransportStop(e.getKey());
convertEnglishName(stop);
boolean forward = e.getValue().contains("forward");
boolean backward = e.getValue().contains("backward");
currentStop++;
@ -931,7 +926,6 @@ public class IndexCreator {
if(hno != null){
Building building = new Building(r.getKey());
building.setName(hno);
convertEnglishName(building);
DataIndexWriter.writeBuilding(addressBuildingStat, pStatements,
streetId, building, BATCH_SIZE);
if(loadInMemory){
@ -958,7 +952,6 @@ public class IndexCreator {
if (!a6.getMemberIds().contains(id)) {
Building building = new Building(border);
building.setName(hno);
convertEnglishName(building);
DataIndexWriter.writeBuilding(addressBuildingStat, pStatements,
streetId, building, BATCH_SIZE);
if(loadInMemory){
@ -1124,7 +1117,8 @@ public class IndexCreator {
if (poiPreparedStatement != null) {
Amenity a = new Amenity(e);
if (a.getLocation() != null) {
convertEnglishName(a);
// do not convert english name
// convertEnglishName(a);
DataIndexWriter.insertAmenityIntoPoi(poiPreparedStatement, pStatements, a, BATCH_SIZE);
}
}
@ -1173,7 +1167,6 @@ public class IndexCreator {
if (idStreet != null) {
Building building = new Building(e);
building.setName(e.getTag(OSMTagKey.ADDR_HOUSE_NUMBER));
convertEnglishName(building);
DataIndexWriter.writeBuilding(addressBuildingStat, pStatements, idStreet, building, BATCH_SIZE);
}
}
@ -1497,7 +1490,6 @@ public class IndexCreator {
if (e instanceof Node && e.getTag(OSMTagKey.PLACE) != null) {
City city = new City((Node) e);
if(city.getType() != null && !Algoritms.isEmpty(city.getName())){
convertEnglishName(city);
if(city.getType() == CityType.CITY || city.getType() == CityType.TOWN){
cityManager.registerObject(((Node) e).getLatitude(), ((Node) e).getLongitude(), city);
} else {
@ -1709,7 +1701,9 @@ public class IndexCreator {
}
}
}
System.out.println("! " + c.getName() + " ! " + f + " " + bCount + " streets " + streets.size());
if(f > 500){
System.out.println("! " + c.getName() + " ! " + f + " " + bCount + " streets " + streets.size());
}
}
writer.endCityIndexes(!writeCities);
@ -1731,8 +1725,7 @@ public class IndexCreator {
public void writeBinaryMapIndex(BinaryMapIndexWriter writer) throws IOException, SQLException {
try {
assert IndexConstants.IndexBinaryMapRenderObject.values().length == 6;
PreparedStatement selectData = mapConnection.prepareStatement("SELECT * FROM " + IndexBinaryMapRenderObject.getTable() + " WHERE id = ?");
PreparedStatement selectData = mapConnection.prepareStatement("SELECT nodes, types, name, highway, restrictions FROM binary_map_objects WHERE id = ?");
writer.startWriteMapIndex(regionName);
@ -1776,9 +1769,10 @@ public class IndexCreator {
selectData.setLong(1, id);
ResultSet rs = selectData.executeQuery();
if (rs.next()) {
writer.writeMapData(id, rs.getBytes(IndexBinaryMapRenderObject.NODES.ordinal()+ 1),
rs.getBytes(IndexBinaryMapRenderObject.TYPES.ordinal()+ 1), rs.getString(IndexBinaryMapRenderObject.NAME.ordinal()+ 1),
rs.getInt(IndexBinaryMapRenderObject.HIGHWAY.ordinal()+ 1), rs.getBytes(IndexBinaryMapRenderObject.RESTRICTIONS.ordinal()+ 1));
// mapConnection.prepareStatement("SELECT nodes, types, name, highway, restrictions FROM binary_map_objects WHERE id = ?");
writer.writeMapData(id, rs.getBytes(1),
rs.getBytes(2), rs.getString(3),
rs.getInt(4), rs.getBytes(5));
} else {
log.error("Something goes wrong with id = " + id);
}
@ -1819,7 +1813,8 @@ public class IndexCreator {
public void writeBinaryTransportIndex(BinaryMapIndexWriter writer) throws IOException, SQLException {
try {
visitedStops = null; // allow gc to collect it
PreparedStatement selectTransportRouteData = mapConnection.prepareStatement("SELECT * FROM " + IndexTransportRoute.getTable());
PreparedStatement selectTransportRouteData = mapConnection.prepareStatement(
"SELECT id, dist, name, name_en, ref, operator, type FROM transport_route");
PreparedStatement selectTransportData = mapConnection.prepareStatement("SELECT S.stop, S.direction," +
" A.latitude, A.longitude, A.name, A.name_en " +
"FROM transport_route_stop S INNER JOIN transport_stop A ON A.id = S.stop WHERE S.route = ? ORDER BY S.ord asc");
@ -1837,16 +1832,16 @@ public class IndexCreator {
List<TransportStop> reverseStops = new ArrayList<TransportStop>();
while(rs.next()){
long idRoute = rs.getLong(IndexTransportRoute.ID.ordinal() + 1);
int dist = rs.getInt(IndexTransportRoute.DIST.ordinal() + 1);
String routeName = rs.getString(IndexTransportRoute.NAME.ordinal() + 1);
String routeEnName = rs.getString(IndexTransportRoute.NAME_EN.ordinal() + 1);
long idRoute = rs.getLong(1);
int dist = rs.getInt(2);
String routeName = rs.getString(3);
String routeEnName = rs.getString(4);
if(routeEnName != null && routeEnName.equals(Junidecode.unidecode(routeName))){
routeEnName = null;
}
String ref = rs.getString(IndexTransportRoute.REF.ordinal() + 1);
String operator = rs.getString(IndexTransportRoute.OPERATOR.ordinal() + 1);
String type = rs.getString(IndexTransportRoute.TYPE.ordinal() + 1);
String ref = rs.getString(5);
String operator = rs.getString(6);
String type = rs.getString(7);
selectTransportData.setLong(1, idRoute);
ResultSet rset = selectTransportData.executeQuery();
@ -1973,13 +1968,6 @@ public class IndexCreator {
private void convertEnglishName(MapObject o){
String name = o.getName();
if(name != null && (o.getEnName() == null || o.getEnName().isEmpty())){
o.setEnName(Junidecode.unidecode(name));
}
}
public String getRTreeMapIndexNonPackFileName(){
return mapFile.getAbsolutePath()+".rtree";
}
@ -2148,16 +2136,15 @@ public class IndexCreator {
// 4. packing map rtree indexes
if (indexMap) {
progress.setGeneralProgress("[90 of 100]");
progress.startTask("Serializing map data...", -1);
progress.startTask("Packing rtree map data...", -1);
for (int i = 0; i < MAP_ZOOMS.length - 1; i++) {
mapTree[i] = packRtreeFile(mapTree[i], getRTreeMapIndexNonPackFileName() + i, getRTreeMapIndexPackFileName() + i);
}
log.info("Finish packing RTree files");
}
if(indexTransport){
progress.setGeneralProgress("[90 of 100]");
progress.startTask("Serializing transport data...", -1);
progress.startTask("Packing rtree transport data...", -1);
transportStopsTree = packRtreeFile(transportStopsTree, getRTreeTransportStopsFileName(), getRTreeTransportStopsPackFileName());
}
}
@ -2468,12 +2455,9 @@ public class IndexCreator {
} catch (RTreeException e) {
throw new IOException(e);
}
transRouteStat = mapConnection.prepareStatement(IndexConstants.generatePrepareStatementToInsert(IndexTransportRoute
.getTable(), IndexTransportRoute.values().length));
transRouteStopsStat = mapConnection.prepareStatement(IndexConstants.generatePrepareStatementToInsert(
IndexTransportRouteStop.getTable(), IndexTransportRouteStop.values().length));
transStopsStat = mapConnection.prepareStatement(IndexConstants.generatePrepareStatementToInsert(IndexTransportStop
.getTable(), IndexTransportStop.values().length));
transRouteStat = DataIndexWriter.createStatementTransportRouteInsert(mapConnection);
transRouteStopsStat = DataIndexWriter.createStatementTransportRouteStopInsert(mapConnection);
transStopsStat = DataIndexWriter.createStatementTransportStopInsert(mapConnection);
pStatements.put(transRouteStat, 0);
pStatements.put(transRouteStopsStat, 0);
pStatements.put(transStopsStat, 0);
@ -2521,8 +2505,8 @@ public class IndexCreator {
creator.recreateOnlyBinaryFile = false;
creator.deleteDatabaseIndexes = false;
creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/minsk.tmp.odb"));
creator.generateIndexes(new File("e:/Information/OSM maps/belarus osm/minsk.osm"), new ConsoleProgressImplementation(3), null);
// creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/minsk.tmp.odb"));
// creator.generateIndexes(new File("e:/Information/OSM maps/belarus osm/minsk.osm"), new ConsoleProgressImplementation(3), null);
// creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/belarus_nodes.tmp.odb"));
// creator.generateIndexes(new File("e:/Information/OSM maps/belarus osm/belarus.osm.bz2"), new ConsoleProgressImplementation(3), null);
@ -2537,8 +2521,8 @@ public class IndexCreator {
// creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/den_haag.tmp.odb"));
// creator.generateIndexes(new File("e:/Information/OSM maps/osm_map/den_haag.osm"), new ConsoleProgressImplementation(3), null);
// creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/netherlands.tmp.odb"));
// creator.generateIndexes(new File("e:/Information/OSM maps/osm_map/netherlands.osm.bz2"), new ConsoleProgressImplementation(1), null);
creator.setNodesDBFile(new File("e:/Information/OSM maps/osmand/netherlands.tmp.odb"));
creator.generateIndexes(new File("e:/Information/OSM maps/osm_map/netherlands.osm.bz2"), new ConsoleProgressImplementation(1), null);
// creator.generateIndexes(new File("e:/Information/OSM maps/osm_map/forest_complex.osm"), new ConsoleProgressImplementation(25), null);

View file

@ -5,17 +5,19 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import net.osmand.data.Amenity;
import net.osmand.data.AmenityType;
import net.osmand.data.index.IndexConstants;
import net.osmand.data.index.IndexConstants.IndexPoiTable;
import net.osmand.osm.Entity;
import net.osmand.osm.LatLon;
import net.osmand.osm.Node;
import net.osmand.osm.io.IOsmStorageFilter;
import net.osmand.osm.io.OsmBaseStorage;
import net.sf.junidecode.Junidecode;
import org.apache.commons.logging.Log;
import org.xml.sax.SAXException;
@ -32,7 +34,7 @@ public class AmenityIndexRepository extends BaseLocationIndexRepository<Amenity>
private String cFilterId;
private final String[] columns = IndexConstants.generateColumnNames(IndexPoiTable.values());
private final String[] columns = new String[]{"id", "latitude", "longitude", "name", "name_en", "type", "subtype", "opening_hours"}; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$//$NON-NLS-6$//$NON-NLS-7$//$NON-NLS-8$
public List<Amenity> searchAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int limit, PoiFilter filter, List<Amenity> amenities){
long now = System.currentTimeMillis();
String squery = "? < latitude AND latitude < ? AND ? < longitude AND longitude < ?"; //$NON-NLS-1$
@ -46,20 +48,23 @@ public class AmenityIndexRepository extends BaseLocationIndexRepository<Amenity>
if(limit != -1){
squery += " ORDER BY RANDOM() LIMIT " +limit; //$NON-NLS-1$
}
Cursor query = db.query(IndexPoiTable.getTable(), columns, squery,
Cursor query = db.query(IndexConstants.POI_TABLE, columns, squery,
new String[]{Double.toString(bottomLatitude),
Double.toString(topLatitude), Double.toString(leftLongitude), Double.toString(rightLongitude)}, null, null, null);
if(query.moveToFirst()){
do {
Amenity am = new Amenity();
am.setId(query.getLong(IndexPoiTable.ID.ordinal()));
am.setLocation(query.getDouble(IndexPoiTable.LATITUDE.ordinal()),
query.getDouble(IndexPoiTable.LONGITUDE.ordinal()));
am.setName(query.getString(IndexPoiTable.NAME.ordinal() ));
am.setEnName(query.getString(IndexPoiTable.NAME_EN.ordinal()));
am.setType(AmenityType.fromString(query.getString(IndexPoiTable.TYPE.ordinal())));
am.setSubType(query.getString(IndexPoiTable.SUBTYPE.ordinal()));
am.setOpeningHours(query.getString(IndexPoiTable.OPENING_HOURS.ordinal()));
am.setId(query.getLong(0));
am.setLocation(query.getDouble(1),
query.getDouble(2));
am.setName(query.getString(3 ));
am.setEnName(query.getString(4));
if(am.getEnName().length() == 0){
am.setEnName(Junidecode.unidecode(am.getName()));
}
am.setType(AmenityType.fromString(query.getString(5)));
am.setSubType(query.getString(6));
am.setOpeningHours(query.getString(7));
amenities.add(am);
if(limit != -1 && amenities.size() >= limit){
break;
@ -75,32 +80,34 @@ public class AmenityIndexRepository extends BaseLocationIndexRepository<Amenity>
return amenities;
}
public boolean addAmenity(long id, double latitude, double longitude, String name, String nameEn, AmenityType t, String subType, String openingHours){
assert IndexPoiTable.values().length == 8;
db.execSQL("INSERT INTO " + IndexPoiTable.getTable() + " VALUES (?, ?, ?, ?, ?, ?, ?, ?)", //$NON-NLS-1$ //$NON-NLS-2$
new Object[]{id, latitude, longitude, openingHours, name, nameEn,AmenityType.valueToString(t), subType});
public boolean addAmenity(Amenity a){
insertAmenities(Collections.singleton(a));
return true;
}
public boolean updateAmenity(long id, double latitude, double longitude, String name, String nameEn, AmenityType t, String subType, String openingHours){
public boolean updateAmenity(Amenity a){
StringBuilder b = new StringBuilder();
b.append("UPDATE " + IndexPoiTable.getTable() + " SET "); //$NON-NLS-1$ //$NON-NLS-2$
b.append(IndexPoiTable.LATITUDE.name()).append(" = ?").append(", "). //$NON-NLS-1$ //$NON-NLS-2$
append(IndexPoiTable.LONGITUDE.name()).append(" = ?").append(", "). //$NON-NLS-1$ //$NON-NLS-2$
append(IndexPoiTable.OPENING_HOURS.name()).append(" = ?").append(", "). //$NON-NLS-1$ //$NON-NLS-2$
append(IndexPoiTable.NAME.name()).append(" = ?").append(", "). //$NON-NLS-1$ //$NON-NLS-2$
append(IndexPoiTable.NAME_EN.name()).append(" = ?").append(", "). //$NON-NLS-1$ //$NON-NLS-2$
append(IndexPoiTable.TYPE.name()).append(" = ?").append(", "). //$NON-NLS-1$ //$NON-NLS-2$
append(IndexPoiTable.SUBTYPE.name()).append(" = ?").append(" "). //$NON-NLS-1$ //$NON-NLS-2$
append(" WHERE ").append(IndexPoiTable.ID.name()).append(" = ?"); //$NON-NLS-1$ //$NON-NLS-2$
b.append("UPDATE " + IndexConstants.POI_TABLE + " SET "); //$NON-NLS-1$ //$NON-NLS-2$
b.append(" latitude = ?, "). //$NON-NLS-1$
append(" longitude = ?, "). //$NON-NLS-1$
append(" opening_hours = ?, "). //$NON-NLS-1$
append(" name = ?, "). //$NON-NLS-1$
append(" name_en = ?, ").//$NON-NLS-1$
append(" type = ?, "). //$NON-NLS-1$
append(" subtype = ? "). //$NON-NLS-1$
append(" site = ? "). //$NON-NLS-1$
append(" phone = ? "). //$NON-NLS-1$
append(" WHERE append( id = ?"); //$NON-NLS-1$
db.execSQL(b.toString(),
new Object[]{latitude, longitude, openingHours, name, nameEn,AmenityType.valueToString(t), subType, id});
new Object[] { a.getLocation().getLatitude(), a.getLocation().getLongitude(),
a.getOpeningHours(), a.getName(), a.getEnName(), AmenityType.valueToString(a.getType()), a.getSubType(),
a.getSite(), a.getPhone(), a.getId()});
return true;
}
public boolean deleteAmenity(long id){
db.execSQL("DELETE FROM " + IndexPoiTable.getTable()+ " WHERE id="+id); //$NON-NLS-1$ //$NON-NLS-2$
db.execSQL("DELETE FROM " + IndexConstants.POI_TABLE+ " WHERE id="+id); //$NON-NLS-1$ //$NON-NLS-2$
return true;
}
@ -151,32 +158,37 @@ public class AmenityIndexRepository extends BaseLocationIndexRepository<Amenity>
}
public boolean initialize(final IProgress progress, File file) {
return super.initialize(progress, file, IndexConstants.POI_TABLE_VERSION, IndexPoiTable.getTable());
return super.initialize(progress, file, IndexConstants.POI_TABLE_VERSION, IndexConstants.POI_TABLE);
}
public boolean updateAmenities(List<Amenity> amenities, double leftLon, double topLat, double rightLon, double bottomLat){
String latCol = IndexPoiTable.LATITUDE.name();
String lonCol = IndexPoiTable.LONGITUDE.name();
db.execSQL("DELETE FROM " + IndexPoiTable.getTable() + " WHERE " + //$NON-NLS-1$ //$NON-NLS-2$
lonCol + ">= ? AND ? >=" + lonCol + " AND " + //$NON-NLS-1$//$NON-NLS-2$
latCol + ">= ? AND ? >=" + latCol, new Double[] { leftLon, rightLon, bottomLat, topLat }); //$NON-NLS-1$
db.execSQL("DELETE FROM " + IndexConstants.POI_TABLE + " WHERE " + //$NON-NLS-1$ //$NON-NLS-2$
" longitude >= ? AND ? >= longitude AND " + //$NON-NLS-1$
" latitude >= ? AND ? >= latitude ", new Double[] { leftLon, rightLon, bottomLat, topLat }); //$NON-NLS-1$
SQLiteStatement stat = db.compileStatement(IndexConstants.generatePrepareStatementToInsert(IndexPoiTable.getTable(), 8));
insertAmenities(amenities);
return true;
}
private void insertAmenities(Collection<Amenity> amenities) {
SQLiteStatement stat = db.compileStatement("INSERT INTO " + IndexConstants.POI_TABLE + //$NON-NLS-1$
"(id, latitude, longitude, name_en, name, type, subtype, opening_hours, site, phone) values(?,?,?,?,?,?,?,?,?)"); //$NON-NLS-1$
for (Amenity a : amenities) {
stat.bindLong(IndexPoiTable.ID.ordinal() + 1, a.getId());
stat.bindDouble(IndexPoiTable.LATITUDE.ordinal() + 1, a.getLocation().getLatitude());
stat.bindDouble(IndexPoiTable.LONGITUDE.ordinal() + 1, a.getLocation().getLongitude());
bindString(stat, IndexPoiTable.NAME_EN.ordinal() + 1, a.getEnName());
bindString(stat, IndexPoiTable.NAME.ordinal() + 1, a.getName());
bindString(stat, IndexPoiTable.TYPE.ordinal() + 1, AmenityType.valueToString(a.getType()));
bindString(stat, IndexPoiTable.SUBTYPE.ordinal() + 1, a.getSubType());
bindString(stat, IndexPoiTable.OPENING_HOURS.ordinal() + 1 , a.getOpeningHours());
stat.bindLong(1, a.getId());
stat.bindDouble(2, a.getLocation().getLatitude());
stat.bindDouble(3, a.getLocation().getLongitude());
bindString(stat, 4, a.getEnName());
bindString(stat, 5, a.getName());
bindString(stat, 6, AmenityType.valueToString(a.getType()));
bindString(stat, 7, a.getSubType());
bindString(stat, 8 , a.getOpeningHours());
bindString(stat, 9, a.getSite());
bindString(stat, 10, a.getPhone());
stat.execute();
}
stat.close();
return true;
}
private final static String SITE_API = "http://api.openstreetmap.org/"; //$NON-NLS-1$
@ -203,7 +215,11 @@ public class AmenityIndexRepository extends BaseLocationIndexRepository<Amenity>
});
st.parseOSM(is, null, null, false);
for (Entity e : amen) {
amenities.add(new Amenity(e));
Amenity am = new Amenity(e);
if(am.getEnName().length() == 0){
am.setEnName(Junidecode.unidecode(am.getName()));
}
amenities.add(am);
}
log.info("Loaded " +amenities.size() + " amenities"); //$NON-NLS-1$//$NON-NLS-2$
} catch (IOException e) {

View file

@ -11,6 +11,7 @@ import net.osmand.activities.OsmandApplication;
import net.osmand.data.Amenity;
import net.osmand.data.AmenityType;
import net.osmand.osm.MapUtils;
import net.sf.junidecode.Junidecode;
import org.apache.commons.logging.Log;
import org.xmlpull.v1.XmlPullParser;
@ -91,7 +92,7 @@ public class NameFinderPoiFilter extends PoiFilter {
a.setId(Long.parseLong(parser.getAttributeValue("", "id"))); //$NON-NLS-1$ //$NON-NLS-2$
String name = parser.getAttributeValue("", "name"); //$NON-NLS-1$//$NON-NLS-2$
a.setName(name);
a.setEnName(name);
a.setEnName(Junidecode.unidecode(name));
a.setType(AmenityType.OTHER);
a.setSubType(parser.getAttributeValue("", "category")); //$NON-NLS-1$//$NON-NLS-2$
searchedAmenities.add(a);

View file

@ -9,7 +9,7 @@ import java.util.Map;
import net.osmand.activities.OsmandApplication;
import net.osmand.data.Amenity;
import net.osmand.data.AmenityType;
import net.osmand.data.index.IndexConstants.IndexPoiTable;
import net.osmand.data.index.IndexConstants;
import net.osmand.osm.MapUtils;
public class PoiFilter {
@ -170,6 +170,7 @@ public class PoiFilter {
if(areAllTypesAccepted()){
return null;
}
assert IndexConstants.POI_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$
if(acceptedTypes.size() == 0){
return "1 > 1"; //$NON-NLS-1$
}
@ -182,12 +183,10 @@ public class PoiFilter {
} else {
b.append(" OR "); //$NON-NLS-1$
}
b.append("("); //$NON-NLS-1$
b.append(IndexPoiTable.TYPE.name().toLowerCase()).append(" = '").append(AmenityType.valueToString(a)).append("'"); //$NON-NLS-1$ //$NON-NLS-2$
b.append("(type = '").append(AmenityType.valueToString(a)).append("'"); //$NON-NLS-1$ //$NON-NLS-2$
if(acceptedTypes.get(a) != null){
List<String> list = acceptedTypes.get(a);
b.append(" AND "); //$NON-NLS-1$
b.append(IndexPoiTable.SUBTYPE.name().toLowerCase()).append(" IN ("); //$NON-NLS-1$
b.append(" AND subtype IN ("); //$NON-NLS-1$
boolean bfirst = true;
for(String s : list){
if(bfirst){

View file

@ -12,9 +12,6 @@ import java.util.Map;
import net.osmand.data.TransportRoute;
import net.osmand.data.TransportStop;
import net.osmand.data.index.IndexConstants;
import net.osmand.data.index.IndexConstants.IndexTransportRoute;
import net.osmand.data.index.IndexConstants.IndexTransportRouteStop;
import net.osmand.data.index.IndexConstants.IndexTransportStop;
import net.osmand.osm.LatLon;
import net.osmand.osm.MapUtils;
@ -25,13 +22,15 @@ import android.database.Cursor;
public class TransportIndexRepositoryOdb extends BaseLocationIndexRepository<TransportStop> implements TransportIndexRepository {
private static final Log log = LogUtil.getLog(TransportIndexRepositoryOdb.class);
private final static String TRANSPORT_STOP_TABLE = IndexConstants.TRANSPORT_STOP_TABLE;
private final static String TRANSPORT_ROUTE_STOP_TABLE = IndexConstants.TRANSPORT_ROUTE_STOP_TABLE;
private final static String TRANSPORT_ROUTE_TABLE = IndexConstants.TRANSPORT_ROUTE_TABLE;
public boolean initialize(final IProgress progress, File file) {
return super.initialize(progress, file, IndexConstants.TRANSPORT_TABLE_VERSION, IndexTransportStop.getTable());
return super.initialize(progress, file, IndexConstants.TRANSPORT_TABLE_VERSION, TRANSPORT_STOP_TABLE);
}
private final String[] columns = IndexConstants.generateColumnNames(IndexTransportStop.values());
private final String[] columns = new String[]{"id", "latitude", "longitude", "name", "name_en"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
public List<TransportStop> searchTransportStops(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int limit, List<TransportStop> stops){
long now = System.currentTimeMillis();
String squery = "? < latitude AND latitude < ? AND ? < longitude AND longitude < ?"; //$NON-NLS-1$
@ -39,17 +38,17 @@ public class TransportIndexRepositoryOdb extends BaseLocationIndexRepository<Tra
if(limit != -1){
squery += " ORDER BY RANDOM() LIMIT " +limit; //$NON-NLS-1$
}
Cursor query = db.query(IndexTransportStop.getTable(), columns, squery,
Cursor query = db.query(TRANSPORT_STOP_TABLE, columns, squery,
new String[]{Double.toString(bottomLatitude),
Double.toString(topLatitude), Double.toString(leftLongitude), Double.toString(rightLongitude)}, null, null, null);
if(query.moveToFirst()){
do {
TransportStop st = new TransportStop();
st.setId(query.getLong(IndexTransportStop.ID.ordinal()));
st.setLocation(query.getDouble(IndexTransportStop.LATITUDE.ordinal()),
query.getDouble(IndexTransportStop.LONGITUDE.ordinal()));
st.setName(query.getString(IndexTransportStop.NAME.ordinal() ));
st.setEnName(query.getString(IndexTransportStop.NAME_EN.ordinal()));
st.setId(query.getLong(0));
st.setLocation(query.getDouble(1),
query.getDouble(2));
st.setName(query.getString(3 ));
st.setEnName(query.getString(4));
stops.add(st);
if(limit != -1 && stops.size() >= limit){
break;
@ -81,12 +80,8 @@ public class TransportIndexRepositoryOdb extends BaseLocationIndexRepository<Tra
if (cacheSQLRouteDescriptions == null) {
StringBuilder sql = new StringBuilder(200);
sql.append("SELECT DISTINCT ").append(IndexTransportRoute.REF).append(",").append(IndexTransportRoute.TYPE) //$NON-NLS-1$//$NON-NLS-2$
.append(",").append(IndexTransportRoute.NAME).append(",").append(IndexTransportRoute.NAME_EN); //$NON-NLS-1$ //$NON-NLS-2$
sql.append(" FROM ").append(IndexTransportRoute.getTable()).append(" JOIN ").append(IndexTransportRouteStop.getTable()); //$NON-NLS-1$ //$NON-NLS-2$
sql.append(" ON ").append(IndexTransportRoute.getTable()).append(".").append(IndexTransportRoute.ID).append(" = "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
sql.append(IndexTransportRouteStop.getTable()).append(".").append(IndexTransportRouteStop.ROUTE); //$NON-NLS-1$
sql.append(" WHERE ").append(IndexTransportRouteStop.STOP).append(" = ?"); //$NON-NLS-1$ //$NON-NLS-2$
sql.append("SELECT DISTINCT ref, type, name, name_en FROM ").append(TRANSPORT_ROUTE_TABLE).append(" JOIN ").append(TRANSPORT_ROUTE_STOP_TABLE); //$NON-NLS-1$ //$NON-NLS-2$
sql.append(" ON transport_route.id = transport_route_stop.route WHERE transport_route_stop.stop = ?"); //$NON-NLS-1$
cacheSQLRouteDescriptions = sql.toString();
}
Cursor query = db.rawQuery(cacheSQLRouteDescriptions, new String[] { stop.getId() + "" }); //$NON-NLS-1$
@ -133,36 +128,17 @@ public class TransportIndexRepositoryOdb extends BaseLocationIndexRepository<Tra
double bottomLatitude = MapUtils.getLatitudeFromTile(zoom, tileNumberY + 0.5);
double leftLongitude = MapUtils.getLongitudeFromTile(zoom, tileNumberX - 0.5);
double rightLongitude = MapUtils.getLongitudeFromTile(zoom, tileNumberX + 0.5);
assert IndexTransportRoute.values().length == 7;
int shift = IndexTransportRoute.values().length;
assert IndexTransportStop.values().length == 5;
int shift2 = IndexTransportStop.values().length;
if(cacheSQLRoutes == null){
StringBuilder sql = new StringBuilder(200);
sql.append("SELECT "); //$NON-NLS-1$
String[] cols = IndexConstants.generateColumnNames(IndexTransportRoute.values());
for(int i=0; i<cols.length; i++){
if(i>0){
sql.append(", "); //$NON-NLS-1$
}
sql.append(IndexTransportRoute.getTable()).append(".").append(cols[i]); //$NON-NLS-1$
}
cols = IndexConstants.generateColumnNames(IndexTransportStop.values());
for(int i=0; i<cols.length; i++){
sql.append(", ").append(IndexTransportStop.getTable()).append(".").append(cols[i]); //$NON-NLS-1$ //$NON-NLS-2$
}
sql.append(", ").append(IndexTransportRouteStop.getTable()).append(".").append(IndexTransportRouteStop.DIRECTION); //$NON-NLS-1$ //$NON-NLS-2$
sql.append(" FROM ").append(IndexTransportStop.getTable()); //$NON-NLS-1$
sql.append("SELECT R.id, R.dist, R.name, R.name_en, R.ref, R.operator, R.type, "); //$NON-NLS-1$
sql.append("T.id, T.name, T.name_en, T.latitude, T.longitude, TR.direction "); //$NON-NLS-1$
sql.append(" FROM ").append(TRANSPORT_STOP_TABLE).append(" T "); //$NON-NLS-1$ //$NON-NLS-2$
// join with stops table
sql.append(" JOIN ").append(IndexTransportRouteStop.getTable()); //$NON-NLS-1$
sql.append(" ON ").append(IndexTransportStop.getTable()).append(".").append(IndexTransportStop.ID); //$NON-NLS-1$ //$NON-NLS-2$
sql.append(" = ").append(IndexTransportRouteStop.getTable()).append(".").append(IndexTransportRouteStop.STOP); //$NON-NLS-1$ //$NON-NLS-2$
sql.append(" JOIN ").append(TRANSPORT_ROUTE_STOP_TABLE).append(" TR "); //$NON-NLS-1$ //$NON-NLS-2$
sql.append(" ON T.id = TR.stop "); //$NON-NLS-1$
// join with route table
sql.append(" JOIN ").append(IndexTransportRoute.getTable()); //$NON-NLS-1$
sql.append(" ON ").append(IndexTransportRoute.getTable()).append(".").append(IndexTransportRoute.ID); //$NON-NLS-1$ //$NON-NLS-2$
sql.append(" = ").append(IndexTransportRouteStop.getTable()).append(".").append(IndexTransportRouteStop.ROUTE); //$NON-NLS-1$ //$NON-NLS-2$
sql.append(" JOIN ").append(TRANSPORT_ROUTE_TABLE).append(" R "); //$NON-NLS-1$ //$NON-NLS-2$
sql.append(" ON R.id = TR.route "); //$NON-NLS-1$
sql.append(" WHERE ").append("? < latitude AND latitude < ? AND ? < longitude AND longitude < ?"); //$NON-NLS-1$ //$NON-NLS-2$
cacheSQLRoutes = sql.toString();
}
@ -173,20 +149,19 @@ public class TransportIndexRepositoryOdb extends BaseLocationIndexRepository<Tra
if (query.moveToFirst()) {
do {
TransportRoute route = new TransportRoute();
route.setId(query.getLong(IndexTransportRoute.ID.ordinal()));
route.setDistance(query.getInt(IndexTransportRoute.DIST.ordinal()));
route.setName(query.getString(IndexTransportRoute.NAME.ordinal()));
route.setEnName(query.getString(IndexTransportRoute.NAME_EN.ordinal()));
route.setRef(query.getString(IndexTransportRoute.REF.ordinal()));
route.setOperator(query.getString(IndexTransportRoute.OPERATOR.ordinal()));
route.setType(query.getString(IndexTransportRoute.TYPE.ordinal()));
route.setId(query.getLong(0));
route.setDistance(query.getInt(1));
route.setName(query.getString(2));
route.setEnName(query.getString(3));
route.setRef(query.getString(4));
route.setOperator(query.getString(5));
route.setType(query.getString(6));
TransportStop s = new TransportStop();
s.setId(query.getLong(shift + IndexTransportStop.ID.ordinal()));
s.setName(query.getString(shift + IndexTransportStop.NAME.ordinal()));
s.setEnName(query.getString(shift + IndexTransportStop.NAME_EN.ordinal()));
s.setLocation(query.getDouble(shift + IndexTransportStop.LATITUDE.ordinal()),
query.getDouble(shift + IndexTransportStop.LONGITUDE.ordinal()));
boolean direction = query.getInt(shift2 + shift) > 0;
s.setId(query.getLong(7));
s.setName(query.getString(8));
s.setEnName(query.getString(9));
s.setLocation(query.getDouble(10), query.getDouble(11));
boolean direction = query.getInt(12) > 0;
long idToPut = route.getId() << 1 + (direction ? 1 : 0);
if(registeredRoutes.containsKey(idToPut)){
TransportStop st = registeredRoutes.get(idToPut).getStart();
@ -227,21 +202,12 @@ public class TransportIndexRepositoryOdb extends BaseLocationIndexRepository<Tra
}
long now = System.currentTimeMillis();
StringBuilder sql = new StringBuilder(200);
sql.append("SELECT "); //$NON-NLS-1$
String[] cols = IndexConstants.generateColumnNames(IndexTransportStop.values());
for (int i = 0; i < cols.length; i++) {
if (i > 0) {
sql.append(", "); //$NON-NLS-1$
}
sql.append(IndexTransportStop.getTable()).append(".").append(cols[i]); //$NON-NLS-1$
}
sql.append(", ").append(IndexTransportRouteStop.getTable()).append(".").append(IndexTransportRouteStop.ROUTE); //$NON-NLS-1$ //$NON-NLS-2$
sql.append(", ").append(IndexTransportRouteStop.getTable()).append(".").append(IndexTransportRouteStop.DIRECTION); //$NON-NLS-1$ //$NON-NLS-2$
sql.append(" FROM ").append(IndexTransportStop.getTable()); //$NON-NLS-1$
sql.append("SELECT T.id, T.latitude, T.longitude, T.name, T.name_en, "); //$NON-NLS-1$
sql.append(" TR.route, TR.direction " ); //$NON-NLS-1$
sql.append(" FROM ").append(TRANSPORT_STOP_TABLE).append(" T "); //$NON-NLS-1$ //$NON-NLS-2$
// join with stops table
sql.append(" JOIN ").append(IndexTransportRouteStop.getTable()); //$NON-NLS-1$
sql.append(" ON ").append(IndexTransportStop.getTable()).append(".").append(IndexTransportStop.ID); //$NON-NLS-1$ //$NON-NLS-2$
sql.append(" = ").append(IndexTransportRouteStop.getTable()).append(".").append(IndexTransportRouteStop.STOP); //$NON-NLS-1$ //$NON-NLS-2$
sql.append(" JOIN ").append(TRANSPORT_ROUTE_STOP_TABLE).append(" TR "); //$NON-NLS-1$ //$NON-NLS-2$
sql.append(" ON T.id = TR.stop "); //$NON-NLS-1$
sql.append(" WHERE "); //$NON-NLS-1$
boolean f = true;
@ -251,16 +217,14 @@ public class TransportIndexRepositoryOdb extends BaseLocationIndexRepository<Tra
} else {
sql.append(" OR "); //$NON-NLS-1$
}
sql.append("("); //$NON-NLS-1$
sql.append(IndexTransportRouteStop.getTable()).append(".").append(IndexTransportRouteStop.ROUTE); //$NON-NLS-1$
sql.append("(TR.route"); //$NON-NLS-1$
sql.append(" = ").append(il.getRoute().getId()); //$NON-NLS-1$
sql.append(" AND ").append(IndexTransportRouteStop.getTable()).append(".").append(IndexTransportRouteStop.DIRECTION); //$NON-NLS-1$ //$NON-NLS-2$
sql.append(" AND TR.direction"); //$NON-NLS-1$
sql.append(" = ").append(il.getDirection() ? 1 : 0); //$NON-NLS-1$
sql.append(")"); //$NON-NLS-1$
}
sql.append(" ORDER BY ").append(IndexTransportRouteStop.getTable()).append(".").append(IndexTransportRouteStop.ORD).append(" ASC"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
sql.append(" ORDER BY TR.ord asc"); //$NON-NLS-1$
int qShift = IndexTransportStop.values().length;
Map<Long, TransportStop> distanceToLoc = new LinkedHashMap<Long, TransportStop>();
@ -270,19 +234,18 @@ public class TransportIndexRepositoryOdb extends BaseLocationIndexRepository<Tra
do {
TransportStop st = null;
long routeId = query.getLong(qShift);
int direction = query.getInt(qShift + 1);
long routeId = query.getLong(5);
int direction = query.getInt(6);
long id = routeId << 1 + direction;
boolean found = distanceToLoc.containsKey(id);
RouteInfoLocation i = registeredRoutes.get(id);
if (found) {
st = new TransportStop();
st.setId(query.getLong(IndexTransportStop.ID.ordinal()));
st.setLocation(query.getDouble(IndexTransportStop.LATITUDE.ordinal()), query.getDouble(IndexTransportStop.LONGITUDE
.ordinal()));
st.setName(query.getString(IndexTransportStop.NAME.ordinal()));
st.setEnName(query.getString(IndexTransportStop.NAME_EN.ordinal()));
} else if (query.getLong(IndexTransportStop.ID.ordinal()) == i.getStart().getId()) {
st.setId(query.getLong(0));
st.setLocation(query.getDouble(1), query.getDouble(2));
st.setName(query.getString(3));
st.setEnName(query.getString(4));
} else if (query.getLong(0) == i.getStart().getId()) {
st = i.getStart();
found = true;
distanceToLoc.put(id, st);

View file

@ -576,9 +576,9 @@ public class EditingPOIActivity {
Amenity a = new Amenity(n);
for(AmenityIndexRepository r: repos){
if(changed){
r.updateAmenity(a.getId(), n.getLatitude(), n.getLongitude(), a.getName(), a.getEnName(), a.getType(), a.getSubType(), a.getOpeningHours());
r.updateAmenity(a);
} else {
r.addAmenity(a.getId(), n.getLatitude(), n.getLongitude(), a.getName(), a.getEnName(), a.getType(), a.getSubType(), a.getOpeningHours());
r.addAmenity(a);
}
r.clearCache();
}