From e47d9efe5f2b5fbba8bc3dcbf0a5b39f32d28945 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 22 Sep 2011 23:22:04 +0200 Subject: [PATCH] Update boundary for poi data --- .../osmand/binary/BinaryMapIndexReader.java | 74 ++- .../osmand/binary/BinaryMapIndexWriter.java | 29 +- .../binary/BinaryMapPoiReaderAdapter.java | 101 +++- .../src/net/osmand/binary/OsmandOdb.java | 549 +++++++++++++++++- .../data/preparation/IndexPoiCreator.java | 23 +- DataExtractionOSM/src/osmand_odb.proto | 10 + .../plus/AmenityIndexRepositoryBinary.java | 85 +-- .../src/net/osmand/plus/ResourceManager.java | 19 +- 8 files changed, 718 insertions(+), 172 deletions(-) diff --git a/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java b/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java index 2dd4e274e4..60479811fe 100644 --- a/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java +++ b/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java @@ -20,6 +20,7 @@ import net.osmand.StringMatcher; import net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion; import net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion; import net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex; +import net.osmand.data.Amenity; import net.osmand.data.Building; import net.osmand.data.City; import net.osmand.data.MapObject; @@ -179,6 +180,34 @@ public class BinaryMapIndexReader { return mapIndexes.size() > 0; } + public boolean containsPoiData(){ + return poiIndexes.size() > 0; + } + + public boolean containsPoiData(double latitude, double longitude) { + int x = MapUtils.get31TileNumberX(longitude); + int y = MapUtils.get31TileNumberY(latitude); + for (PoiRegion index : poiIndexes) { + if (index.right31X >= x && index.left31X <= x && index.top31Y <= y && index.bottom31Y >= y) { + return true; + } + } + return false; + } + + public boolean containsPoiData(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude) { + int leftX = MapUtils.get31TileNumberX(leftLongitude); + int rightX = MapUtils.get31TileNumberX(rightLongitude); + int bottomY = MapUtils.get31TileNumberY(bottomLatitude); + int topY = MapUtils.get31TileNumberY(topLatitude); + for (PoiRegion index : poiIndexes) { + if (index.right31X >= leftX && index.left31X <= rightX && index.top31Y <= bottomY && index.bottom31Y >= topY) { + return true; + } + } + return false; + } + public boolean containsMapData(int tile31x, int tile31y, int zoom){ for(MapIndex mapIndex : mapIndexes){ for(MapRoot root : mapIndex.getRoots()){ @@ -890,7 +919,23 @@ public class BinaryMapIndexReader { } } - + + public List searchPoi(SearchRequest req) throws IOException { + req.numberOfVisitedObjects = 0; + req.numberOfAcceptedObjects = 0; + req.numberOfAcceptedSubtrees = 0; + req.numberOfReadSubtrees = 0; + for (PoiRegion poiIndex : poiIndexes) { + codedIS.seek(poiIndex.filePointer); + int old = codedIS.pushLimit(poiIndex.length); + poiAdapter.searchPoiIndex(req.left, req.right, req.top, req.bottom, req, poiIndex); + codedIS.popLimit(old); + } + log.info("Search poi is done. Visit " + req.numberOfVisitedObjects + " objects. Read " + req.numberOfAcceptedObjects + " objects."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + log.info("Read " + req.numberOfReadSubtrees + " subtrees. Go through " + req.numberOfAcceptedSubtrees + " subtrees."); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + return req.getSearchResults(); + } + private List readStringTable() throws IOException{ List list = new ArrayList(); while(true){ @@ -930,6 +975,17 @@ public class BinaryMapIndexReader { } + public static SearchRequest buildSearchPoiRequest(int sleft, int sright, int stop, int sbottom, int zoom){ + SearchRequest request = new SearchRequest(); + request.left = sleft; + request.right = sright; + request.top = stop; + request.bottom = sbottom; + request.zoom = zoom; + return request; + } + + public static SearchRequest buildSearchTransportRequest(int sleft, int sright, int stop, int sbottom, int limit, List stops){ SearchRequest request = new SearchRequest(); if (stops != null) { @@ -1146,11 +1202,19 @@ public class BinaryMapIndexReader { testTransportSearch(reader); PoiRegion poiRegion = reader.getPoiIndexes().get(0); - for (int i = 0; i < poiRegion.categories.size(); i++) { - System.out.println(poiRegion.categories.get(i)); - System.out.println(" " + poiRegion.subcategories.get(i)); + System.out.println(poiRegion.left31X + " " + poiRegion.right31X + " " + poiRegion.bottom31Y + " " + poiRegion.top31Y); +// for (int i = 0; i < poiRegion.categories.size(); i++) { +// System.out.println(poiRegion.categories.get(i)); +// System.out.println(" " + poiRegion.subcategories.get(i)); +// } + int sleft = MapUtils.get31TileNumberX(37.72); + int sright = MapUtils.get31TileNumberX(37.727); + int stop = MapUtils.get31TileNumberY(55.814); + int sbottom = MapUtils.get31TileNumberY(55.81); + List results = reader.searchPoi(buildSearchPoiRequest(sleft, sright, stop, sbottom, 15)); + for(Amenity a : results){ + System.out.println(a.getType() + " " + a.getSubType() + " " + a.getName() + " " + a.getLocation()); } - http://www.openstreetmap.org/?lat=55.81111&lon=37.72368&zoom=16&layers=M System.out.println("MEMORY " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())); //$NON-NLS-1$ System.out.println("Time " + (System.currentTimeMillis() - time)); //$NON-NLS-1$ diff --git a/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexWriter.java b/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexWriter.java index 6c74fb8b4e..eb196937f8 100644 --- a/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexWriter.java +++ b/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexWriter.java @@ -743,7 +743,7 @@ public class BinaryMapIndexWriter { codedOutStream.writeMessage(OsmAndTransportIndex.STRINGTABLE_FIELD_NUMBER, st.build()); } - public long startWritePOIIndex(String name) throws IOException { + public long startWritePOIIndex(String name, int left31, int right31, int bottom31, int top31) throws IOException { pushState(POI_INDEX_INIT, OSMAND_STRUCTURE_INIT); codedOutStream.writeTag(OsmandOdb.OsmAndStructure.POIINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED); stackBounds.push(new Bounds(0, 0, 0, 0)); // for poi index tree @@ -751,6 +751,12 @@ public class BinaryMapIndexWriter { if(name != null){ codedOutStream.writeString(OsmandOdb.OsmAndPoiIndex.NAME_FIELD_NUMBER, name); } + OsmandOdb.OsmAndTileBox.Builder builder = OsmandOdb.OsmAndTileBox.newBuilder(); + builder.setLeft(left31); + builder.setRight(right31); + builder.setTop(top31); + builder.setBottom(bottom31); + codedOutStream.writeMessage(OsmandOdb.OsmAndPoiIndex.BOUNDARIES_FIELD_NUMBER, builder.build()); return startPoiIndex; } @@ -839,7 +845,7 @@ public class BinaryMapIndexWriter { writeInt32Size(); } - public long startWritePoiBox(int zoom, int tileX, int tileY) throws IOException { + public long startWritePoiBox(int zoom, int tileX, int tileY, boolean end) throws IOException { checkPeekState(POI_INDEX_INIT, POI_BOX); if(state.peek() == POI_INDEX_INIT){ codedOutStream.writeTag(OsmandOdb.OsmAndPoiIndex.BOXES_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED); @@ -856,18 +862,18 @@ public class BinaryMapIndexWriter { int pTileX = parentTileX << (zoom - parentZoom); int pTileY = parentTileY << (zoom - parentZoom); - + codedOutStream.writeUInt32(OsmandOdb.OsmAndPoiBox.ZOOM_FIELD_NUMBER, (zoom - parentZoom)); codedOutStream.writeSInt32(OsmandOdb.OsmAndPoiBox.LEFT_FIELD_NUMBER, tileX - pTileX); codedOutStream.writeSInt32(OsmandOdb.OsmAndPoiBox.TOP_FIELD_NUMBER, tileY - pTileY); - codedOutStream.writeUInt32(OsmandOdb.OsmAndPoiBox.ZOOM_FIELD_NUMBER, (zoom - parentZoom)); stackBounds.push(new Bounds(tileX, zoom, tileY, 0 )); - - codedOutStream.writeFixed32(OsmandOdb.OsmAndPoiBox.SHIFTTODATA_FIELD_NUMBER, 0); - codedOutStream.flush(); - long filePointer = raf.getFilePointer() - 4; - - return filePointer; + if (end) { + codedOutStream.writeFixed32(OsmandOdb.OsmAndPoiBox.SHIFTTODATA_FIELD_NUMBER, 0); + codedOutStream.flush(); + long filePointer = raf.getFilePointer() - 4; + return filePointer; + } + return 0; } public void endWritePoiBox() throws IOException { @@ -911,7 +917,4 @@ public class BinaryMapIndexWriter { } - - - } diff --git a/DataExtractionOSM/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java b/DataExtractionOSM/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java index 03dcc0f34b..e425ce501a 100644 --- a/DataExtractionOSM/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java +++ b/DataExtractionOSM/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java @@ -1,8 +1,6 @@ package net.osmand.binary; import gnu.trove.list.array.TIntArrayList; -import gnu.trove.map.hash.TLongObjectHashMap; -import gnu.trove.set.hash.TIntHashSet; import java.io.IOException; import java.util.ArrayList; @@ -29,6 +27,11 @@ public class BinaryMapPoiReaderAdapter { List categories = new ArrayList(); List categoriesType = new ArrayList(); List> subcategories = new ArrayList>(); + + int left31X; + int right31X; + int top31Y; + int bottom31Y; } private CodedInputStreamRAF codedIS; @@ -47,6 +50,32 @@ public class BinaryMapPoiReaderAdapter { return map.readInt(); } + protected void readPoiBoundariesIndex(PoiRegion region) throws IOException { + while(true){ + int t = codedIS.readTag(); + int tag = WireFormat.getTagFieldNumber(t); + switch (tag) { + case 0: + return; + case OsmandOdb.OsmAndTileBox.LEFT_FIELD_NUMBER: + region.left31X = codedIS.readUInt32(); + break; + case OsmandOdb.OsmAndTileBox.RIGHT_FIELD_NUMBER: + region.right31X = codedIS.readUInt32(); + break; + case OsmandOdb.OsmAndTileBox.TOP_FIELD_NUMBER: + region.top31Y = codedIS.readUInt32(); + break; + case OsmandOdb.OsmAndTileBox.BOTTOM_FIELD_NUMBER: + region.bottom31Y = codedIS.readUInt32(); + break; + default: + skipUnknownField(t); + break; + } + } + } + protected void readPoiIndex(PoiRegion region) throws IOException { while(true){ @@ -58,13 +87,19 @@ public class BinaryMapPoiReaderAdapter { case OsmandOdb.OsmAndPoiIndex.NAME_FIELD_NUMBER : region.name = codedIS.readString(); break; - case OsmandOdb.OsmAndPoiIndex.CATEGORIESTABLE_FIELD_NUMBER : + case OsmandOdb.OsmAndPoiIndex.BOUNDARIES_FIELD_NUMBER: { + int length = codedIS.readRawVarint32(); + int oldLimit = codedIS.pushLimit(length); + readPoiBoundariesIndex(region); + codedIS.popLimit(oldLimit); + } + break; + case OsmandOdb.OsmAndPoiIndex.CATEGORIESTABLE_FIELD_NUMBER : { int length = codedIS.readRawVarint32(); - int oldLimit = codedIS.pushLimit(length); readCategory(region); codedIS.popLimit(oldLimit); - break; + } break; case OsmandOdb.OsmAndPoiIndex.BOXES_FIELD_NUMBER : codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); return; @@ -112,7 +147,7 @@ public class BinaryMapPoiReaderAdapter { case 0: return; case OsmandOdb.OsmAndPoiIndex.BOXES_FIELD_NUMBER : - int length = codedIS.readFixed32(); + int length = readInt(); int oldLimit = codedIS.pushLimit(length); readBoxField(left31, right31, top31, bottom31, 0, 0, 0, offsets, req); codedIS.popLimit(oldLimit); @@ -121,7 +156,7 @@ public class BinaryMapPoiReaderAdapter { offsets.sort(); for (int j = 0; j < offsets.size(); j++) { codedIS.seek(offsets.get(j) + indexOffset); - int len = codedIS.readFixed32(); + int len = readInt(); int oldLim = codedIS.pushLimit(len); readPoiData(left31, right31, top31, bottom31, req, region); codedIS.popLimit(oldLim); @@ -159,14 +194,14 @@ public class BinaryMapPoiReaderAdapter { zoom = codedIS.readUInt32(); break; case OsmandOdb.OsmAndPoiBoxData.Y_FIELD_NUMBER : - y= codedIS.readUInt32(); + y = codedIS.readUInt32(); break; case OsmandOdb.OsmAndPoiBoxData.POIDATA_FIELD_NUMBER: int len = codedIS.readRawVarint32(); int oldLim = codedIS.pushLimit(len); readPoiPoint(left31, right31, top31, bottom31, x, y, zoom, req, region); codedIS.popLimit(oldLim); - return; + break; default: skipUnknownField(t); break; @@ -188,13 +223,15 @@ public class BinaryMapPoiReaderAdapter { am.setEnName(Junidecode.unidecode(am.getName())); } req.getSearchResults().add(am); + req.numberOfAcceptedObjects++; return; case OsmandOdb.OsmAndPoiBoxDataAtom.DX_FIELD_NUMBER : x = (codedIS.readSInt32() + (px << (24 - zoom))) << 7; break; case OsmandOdb.OsmAndPoiBoxDataAtom.DY_FIELD_NUMBER : y = (codedIS.readSInt32() + (py << (24 - zoom))) << 7; - if(left31 > x || right31 < x || top31 < y || bottom31 > y){ + req.numberOfVisitedObjects++; + if(left31 > x || right31 < x || top31 > y || bottom31 < y){ codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); return; } @@ -202,7 +239,7 @@ public class BinaryMapPoiReaderAdapter { am.setLocation(MapUtils.get31LatitudeY(y), MapUtils.get31LongitudeX(x)); break; case OsmandOdb.OsmAndPoiBoxDataAtom.CATEGORIES_FIELD_NUMBER : - // TODO add many amenities + // TODO support many amenities type int cat = codedIS.readUInt32(); int subcatId = cat >> SHIFT_BITS_CATEGORY; int catId = cat & CATEGORY_MASK; @@ -210,7 +247,7 @@ public class BinaryMapPoiReaderAdapter { am.setType(region.categoriesType.get(catId)); List subcats = region.subcategories.get(catId); if(subcatId < subcats.size()){ - am.setSubType(subcats.get(catId)); + am.setSubType(subcats.get(subcatId)); } } else { am.setType(AmenityType.OTHER); @@ -243,20 +280,11 @@ public class BinaryMapPoiReaderAdapter { private void readBoxField(int left31, int right31, int top31, int bottom31, int px, int py, int pzoom, TIntArrayList offsets, SearchRequest req) throws IOException { - if(pzoom > 0){ - int x1 = px << (31 - pzoom); - int x2 = (px + 1) << (31 - pzoom); - int y1 = py << (31 - pzoom); - int y2 = (py + 1) << (31 - pzoom); - // check intersection - if(!(left31 <= x2 && x1 <= right31 && bottom31 <= y2 && y1 <= top31)){ - codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); - } - - } + req.numberOfReadSubtrees++; + boolean checkBox = true; int zoom = pzoom; - int y = py; - int x = px; + int dy = py; + int dx = px; while(true){ if(req.isInterrupted()){ return; @@ -270,21 +298,36 @@ public class BinaryMapPoiReaderAdapter { zoom = codedIS.readUInt32() + pzoom; break; case OsmandOdb.OsmAndPoiBox.LEFT_FIELD_NUMBER : - x = codedIS.readSInt32() + px; + dx = codedIS.readSInt32(); break; case OsmandOdb.OsmAndPoiBox.TOP_FIELD_NUMBER: - y = codedIS.readSInt32() + py; + dy = codedIS.readSInt32(); break; case OsmandOdb.OsmAndPoiBox.SUBBOXES_FIELD_NUMBER: - int length = codedIS.readFixed32(); + int x = dx + (px << (zoom - pzoom)); + int y = dy + (py << (zoom - pzoom)); + if(checkBox){ + int xL = x << (31 - zoom); + int xR = (x + 1) << (31 - zoom); + int yT = y << (31 - zoom); + int yB = (y + 1) << (31 - zoom); + // check intersection + if(left31 > xR || xL > right31 || bottom31 < yT || yB < top31){ + codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); + return; + } + req.numberOfAcceptedSubtrees++; + checkBox = false; + } + int length = readInt(); int oldLimit = codedIS.pushLimit(length); readBoxField(left31, right31, top31, bottom31, x, y, zoom, offsets, req); codedIS.popLimit(oldLimit); break; case OsmandOdb.OsmAndPoiBox.SHIFTTODATA_FIELD_NUMBER: - offsets.add(codedIS.readFixed32()); + offsets.add(readInt()); break; default: skipUnknownField(t); diff --git a/DataExtractionOSM/src/net/osmand/binary/OsmandOdb.java b/DataExtractionOSM/src/net/osmand/binary/OsmandOdb.java index 641ff9c45f..ff1c540c51 100644 --- a/DataExtractionOSM/src/net/osmand/binary/OsmandOdb.java +++ b/DataExtractionOSM/src/net/osmand/binary/OsmandOdb.java @@ -10960,6 +10960,411 @@ public final class OsmandOdb { // @@protoc_insertion_point(class_scope:OsmAndTransportIndex) } + public static final class OsmAndTileBox extends + com.google.protobuf.GeneratedMessage { + // Use OsmAndTileBox.newBuilder() to construct. + private OsmAndTileBox() { + initFields(); + } + private OsmAndTileBox(boolean noInit) {} + + private static final OsmAndTileBox defaultInstance; + public static OsmAndTileBox getDefaultInstance() { + return defaultInstance; + } + + public OsmAndTileBox getDefaultInstanceForType() { + return defaultInstance; + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return net.osmand.binary.OsmandOdb.internal_static_OsmAndTileBox_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return net.osmand.binary.OsmandOdb.internal_static_OsmAndTileBox_fieldAccessorTable; + } + + // required uint32 left = 1; + public static final int LEFT_FIELD_NUMBER = 1; + private boolean hasLeft; + private int left_ = 0; + public boolean hasLeft() { return hasLeft; } + public int getLeft() { return left_; } + + // required uint32 right = 2; + public static final int RIGHT_FIELD_NUMBER = 2; + private boolean hasRight; + private int right_ = 0; + public boolean hasRight() { return hasRight; } + public int getRight() { return right_; } + + // required uint32 top = 3; + public static final int TOP_FIELD_NUMBER = 3; + private boolean hasTop; + private int top_ = 0; + public boolean hasTop() { return hasTop; } + public int getTop() { return top_; } + + // required uint32 bottom = 4; + public static final int BOTTOM_FIELD_NUMBER = 4; + private boolean hasBottom; + private int bottom_ = 0; + public boolean hasBottom() { return hasBottom; } + public int getBottom() { return bottom_; } + + private void initFields() { + } + public final boolean isInitialized() { + if (!hasLeft) return false; + if (!hasRight) return false; + if (!hasTop) return false; + if (!hasBottom) return false; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (hasLeft()) { + output.writeUInt32(1, getLeft()); + } + if (hasRight()) { + output.writeUInt32(2, getRight()); + } + if (hasTop()) { + output.writeUInt32(3, getTop()); + } + if (hasBottom()) { + output.writeUInt32(4, getBottom()); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + if (hasLeft()) { + size += com.google.protobuf.CodedOutputStream + .computeUInt32Size(1, getLeft()); + } + if (hasRight()) { + size += com.google.protobuf.CodedOutputStream + .computeUInt32Size(2, getRight()); + } + if (hasTop()) { + size += com.google.protobuf.CodedOutputStream + .computeUInt32Size(3, getTop()); + } + if (hasBottom()) { + size += com.google.protobuf.CodedOutputStream + .computeUInt32Size(4, getBottom()); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + public static net.osmand.binary.OsmandOdb.OsmAndTileBox parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static net.osmand.binary.OsmandOdb.OsmAndTileBox parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static net.osmand.binary.OsmandOdb.OsmAndTileBox parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static net.osmand.binary.OsmandOdb.OsmAndTileBox parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static net.osmand.binary.OsmandOdb.OsmAndTileBox parseFrom(java.io.InputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static net.osmand.binary.OsmandOdb.OsmAndTileBox parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + public static net.osmand.binary.OsmandOdb.OsmAndTileBox parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static net.osmand.binary.OsmandOdb.OsmAndTileBox parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input, extensionRegistry)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static net.osmand.binary.OsmandOdb.OsmAndTileBox parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static net.osmand.binary.OsmandOdb.OsmAndTileBox parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(net.osmand.binary.OsmandOdb.OsmAndTileBox prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder { + private net.osmand.binary.OsmandOdb.OsmAndTileBox result; + + // Construct using net.osmand.binary.OsmandOdb.OsmAndTileBox.newBuilder() + private Builder() {} + + private static Builder create() { + Builder builder = new Builder(); + builder.result = new net.osmand.binary.OsmandOdb.OsmAndTileBox(); + return builder; + } + + protected net.osmand.binary.OsmandOdb.OsmAndTileBox internalGetResult() { + return result; + } + + public Builder clear() { + if (result == null) { + throw new IllegalStateException( + "Cannot call clear() after build()."); + } + result = new net.osmand.binary.OsmandOdb.OsmAndTileBox(); + return this; + } + + public Builder clone() { + return create().mergeFrom(result); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return net.osmand.binary.OsmandOdb.OsmAndTileBox.getDescriptor(); + } + + public net.osmand.binary.OsmandOdb.OsmAndTileBox getDefaultInstanceForType() { + return net.osmand.binary.OsmandOdb.OsmAndTileBox.getDefaultInstance(); + } + + public boolean isInitialized() { + return result.isInitialized(); + } + public net.osmand.binary.OsmandOdb.OsmAndTileBox build() { + if (result != null && !isInitialized()) { + throw newUninitializedMessageException(result); + } + return buildPartial(); + } + + private net.osmand.binary.OsmandOdb.OsmAndTileBox buildParsed() + throws com.google.protobuf.InvalidProtocolBufferException { + if (!isInitialized()) { + throw newUninitializedMessageException( + result).asInvalidProtocolBufferException(); + } + return buildPartial(); + } + + public net.osmand.binary.OsmandOdb.OsmAndTileBox buildPartial() { + if (result == null) { + throw new IllegalStateException( + "build() has already been called on this Builder."); + } + net.osmand.binary.OsmandOdb.OsmAndTileBox returnMe = result; + result = null; + return returnMe; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof net.osmand.binary.OsmandOdb.OsmAndTileBox) { + return mergeFrom((net.osmand.binary.OsmandOdb.OsmAndTileBox)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(net.osmand.binary.OsmandOdb.OsmAndTileBox other) { + if (other == net.osmand.binary.OsmandOdb.OsmAndTileBox.getDefaultInstance()) return this; + if (other.hasLeft()) { + setLeft(other.getLeft()); + } + if (other.hasRight()) { + setRight(other.getRight()); + } + if (other.hasTop()) { + setTop(other.getTop()); + } + if (other.hasBottom()) { + setBottom(other.getBottom()); + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder( + this.getUnknownFields()); + while (true) { + int tag = input.readTag(); + switch (tag) { + case 0: + this.setUnknownFields(unknownFields.build()); + return this; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + this.setUnknownFields(unknownFields.build()); + return this; + } + break; + } + case 8: { + setLeft(input.readUInt32()); + break; + } + case 16: { + setRight(input.readUInt32()); + break; + } + case 24: { + setTop(input.readUInt32()); + break; + } + case 32: { + setBottom(input.readUInt32()); + break; + } + } + } + } + + + // required uint32 left = 1; + public boolean hasLeft() { + return result.hasLeft(); + } + public int getLeft() { + return result.getLeft(); + } + public Builder setLeft(int value) { + result.hasLeft = true; + result.left_ = value; + return this; + } + public Builder clearLeft() { + result.hasLeft = false; + result.left_ = 0; + return this; + } + + // required uint32 right = 2; + public boolean hasRight() { + return result.hasRight(); + } + public int getRight() { + return result.getRight(); + } + public Builder setRight(int value) { + result.hasRight = true; + result.right_ = value; + return this; + } + public Builder clearRight() { + result.hasRight = false; + result.right_ = 0; + return this; + } + + // required uint32 top = 3; + public boolean hasTop() { + return result.hasTop(); + } + public int getTop() { + return result.getTop(); + } + public Builder setTop(int value) { + result.hasTop = true; + result.top_ = value; + return this; + } + public Builder clearTop() { + result.hasTop = false; + result.top_ = 0; + return this; + } + + // required uint32 bottom = 4; + public boolean hasBottom() { + return result.hasBottom(); + } + public int getBottom() { + return result.getBottom(); + } + public Builder setBottom(int value) { + result.hasBottom = true; + result.bottom_ = value; + return this; + } + public Builder clearBottom() { + result.hasBottom = false; + result.bottom_ = 0; + return this; + } + + // @@protoc_insertion_point(builder_scope:OsmAndTileBox) + } + + static { + defaultInstance = new OsmAndTileBox(true); + net.osmand.binary.OsmandOdb.internalForceInit(); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:OsmAndTileBox) + } + public static final class OsmAndPoiIndex extends com.google.protobuf.GeneratedMessage { // Use OsmAndPoiIndex.newBuilder() to construct. @@ -10994,6 +11399,13 @@ public final class OsmandOdb { public boolean hasName() { return hasName; } public java.lang.String getName() { return name_; } + // required .OsmAndTileBox boundaries = 2; + public static final int BOUNDARIES_FIELD_NUMBER = 2; + private boolean hasBoundaries; + private net.osmand.binary.OsmandOdb.OsmAndTileBox boundaries_; + public boolean hasBoundaries() { return hasBoundaries; } + public net.osmand.binary.OsmandOdb.OsmAndTileBox getBoundaries() { return boundaries_; } + // repeated .OsmAndCategoryTable categoriesTable = 3; public static final int CATEGORIESTABLE_FIELD_NUMBER = 3; private java.util.List categoriesTable_ = @@ -11031,9 +11443,12 @@ public final class OsmandOdb { } private void initFields() { + boundaries_ = net.osmand.binary.OsmandOdb.OsmAndTileBox.getDefaultInstance(); } public final boolean isInitialized() { if (!hasName) return false; + if (!hasBoundaries) return false; + if (!getBoundaries().isInitialized()) return false; for (net.osmand.binary.OsmandOdb.OsmAndCategoryTable element : getCategoriesTableList()) { if (!element.isInitialized()) return false; } @@ -11052,6 +11467,9 @@ public final class OsmandOdb { if (hasName()) { output.writeString(1, getName()); } + if (hasBoundaries()) { + output.writeMessage(2, getBoundaries()); + } for (net.osmand.binary.OsmandOdb.OsmAndCategoryTable element : getCategoriesTableList()) { output.writeMessage(3, element); } @@ -11074,6 +11492,10 @@ public final class OsmandOdb { size += com.google.protobuf.CodedOutputStream .computeStringSize(1, getName()); } + if (hasBoundaries()) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(2, getBoundaries()); + } for (net.osmand.binary.OsmandOdb.OsmAndCategoryTable element : getCategoriesTableList()) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(3, element); @@ -11259,6 +11681,9 @@ public final class OsmandOdb { if (other.hasName()) { setName(other.getName()); } + if (other.hasBoundaries()) { + mergeBoundaries(other.getBoundaries()); + } if (!other.categoriesTable_.isEmpty()) { if (result.categoriesTable_.isEmpty()) { result.categoriesTable_ = new java.util.ArrayList(); @@ -11306,6 +11731,15 @@ public final class OsmandOdb { setName(input.readString()); break; } + case 18: { + net.osmand.binary.OsmandOdb.OsmAndTileBox.Builder subBuilder = net.osmand.binary.OsmandOdb.OsmAndTileBox.newBuilder(); + if (hasBoundaries()) { + subBuilder.mergeFrom(getBoundaries()); + } + input.readMessage(subBuilder, extensionRegistry); + setBoundaries(subBuilder.buildPartial()); + break; + } case 26: { net.osmand.binary.OsmandOdb.OsmAndCategoryTable.Builder subBuilder = net.osmand.binary.OsmandOdb.OsmAndCategoryTable.newBuilder(); input.readMessage(subBuilder, extensionRegistry); @@ -11350,6 +11784,43 @@ public final class OsmandOdb { return this; } + // required .OsmAndTileBox boundaries = 2; + public boolean hasBoundaries() { + return result.hasBoundaries(); + } + public net.osmand.binary.OsmandOdb.OsmAndTileBox getBoundaries() { + return result.getBoundaries(); + } + public Builder setBoundaries(net.osmand.binary.OsmandOdb.OsmAndTileBox value) { + if (value == null) { + throw new NullPointerException(); + } + result.hasBoundaries = true; + result.boundaries_ = value; + return this; + } + public Builder setBoundaries(net.osmand.binary.OsmandOdb.OsmAndTileBox.Builder builderForValue) { + result.hasBoundaries = true; + result.boundaries_ = builderForValue.build(); + return this; + } + public Builder mergeBoundaries(net.osmand.binary.OsmandOdb.OsmAndTileBox value) { + if (result.hasBoundaries() && + result.boundaries_ != net.osmand.binary.OsmandOdb.OsmAndTileBox.getDefaultInstance()) { + result.boundaries_ = + net.osmand.binary.OsmandOdb.OsmAndTileBox.newBuilder(result.boundaries_).mergeFrom(value).buildPartial(); + } else { + result.boundaries_ = value; + } + result.hasBoundaries = true; + return this; + } + public Builder clearBoundaries() { + result.hasBoundaries = false; + result.boundaries_ = net.osmand.binary.OsmandOdb.OsmAndTileBox.getDefaultInstance(); + return this; + } + // repeated .OsmAndCategoryTable categoriesTable = 3; public java.util.List getCategoriesTableList() { return java.util.Collections.unmodifiableList(result.categoriesTable_); @@ -14601,6 +15072,11 @@ public final class OsmandOdb { private static com.google.protobuf.GeneratedMessage.FieldAccessorTable internal_static_OsmAndTransportIndex_fieldAccessorTable; + private static com.google.protobuf.Descriptors.Descriptor + internal_static_OsmAndTileBox_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_OsmAndTileBox_fieldAccessorTable; private static com.google.protobuf.Descriptors.Descriptor internal_static_OsmAndPoiIndex_descriptor; private static @@ -14710,29 +15186,32 @@ public final class OsmandOdb { "\024OsmAndTransportIndex\022\014\n\004name\030\001 \001(\t\022 \n\006r" + "outes\030\003 \001(\0132\020.TransportRoutes\022\"\n\005stops\030\006" + " \001(\0132\023.TransportStopsTree\022!\n\013stringTable" + - "\030\t \002(\0132\014.StringTable\"\217\001\n\016OsmAndPoiIndex\022" + - "\014\n\004name\030\001 \002(\t\022-\n\017categoriesTable\030\003 \003(\0132\024" + - ".OsmAndCategoryTable\022\034\n\005boxes\030\006 \003(\0132\r.Os" + - "mAndPoiBox\022\"\n\007poiData\030\t \003(\0132\021.OsmAndPoiB" + - "oxData\"W\n\022IndexedStringTable\022\016\n\006prefix\030\001", - " \001(\t\022\t\n\001s\030\003 \003(\t\022&\n\tsubtables\030\006 \003(\0132\023.Ind" + - "exedStringTable\">\n\023OsmAndCategoryTable\022\020" + - "\n\010category\030\001 \002(\t\022\025\n\rsubcategories\030\003 \003(\t\"" + - "\365\001\n\014OsmAndPoiBox\022\014\n\004zoom\030\001 \002(\r\022\014\n\004left\030\002" + - " \002(\021\022\013\n\003top\030\003 \002(\021\022(\n\ncategories\030\004 \001(\0132\024." + - "OsmAndPoiCategories\022-\n\020includeNamesList\030" + - "\005 \001(\0132\023.IndexedStringTable\022-\n\020excludeNam" + - "esList\030\006 \001(\0132\023.IndexedStringTable\022\037\n\010sub" + - "Boxes\030\n \003(\0132\r.OsmAndPoiBox\022\023\n\013shiftToDat" + - "a\030\016 \001(\007\")\n\023OsmAndPoiCategories\022\022\n\ncatego", - "ries\030\003 \003(\r\"^\n\020OsmAndPoiBoxData\022\014\n\004zoom\030\001" + - " \001(\r\022\t\n\001x\030\002 \001(\r\022\t\n\001y\030\003 \001(\r\022&\n\007poiData\030\005 " + - "\003(\0132\025.OsmAndPoiBoxDataAtom\"\255\001\n\024OsmAndPoi" + - "BoxDataAtom\022\n\n\002dx\030\002 \002(\021\022\n\n\002dy\030\003 \002(\021\022\n\n\002i" + - "d\030\004 \001(\004\022\014\n\004name\030\005 \001(\t\022\016\n\006nameEn\030\006 \001(\t\022\022\n" + - "\ncategories\030\007 \003(\r\022\024\n\014openingHours\030\n \001(\t\022" + - "\014\n\004site\030\013 \001(\t\022\r\n\005phone\030\014 \001(\t\022\014\n\004note\030\r \001" + - "(\tB\023\n\021net.osmand.binary" + "\030\t \002(\0132\014.StringTable\"I\n\rOsmAndTileBox\022\014\n" + + "\004left\030\001 \002(\r\022\r\n\005right\030\002 \002(\r\022\013\n\003top\030\003 \002(\r\022" + + "\016\n\006bottom\030\004 \002(\r\"\263\001\n\016OsmAndPoiIndex\022\014\n\004na" + + "me\030\001 \002(\t\022\"\n\nboundaries\030\002 \002(\0132\016.OsmAndTil" + + "eBox\022-\n\017categoriesTable\030\003 \003(\0132\024.OsmAndCa", + "tegoryTable\022\034\n\005boxes\030\006 \003(\0132\r.OsmAndPoiBo" + + "x\022\"\n\007poiData\030\t \003(\0132\021.OsmAndPoiBoxData\"W\n" + + "\022IndexedStringTable\022\016\n\006prefix\030\001 \001(\t\022\t\n\001s" + + "\030\003 \003(\t\022&\n\tsubtables\030\006 \003(\0132\023.IndexedStrin" + + "gTable\">\n\023OsmAndCategoryTable\022\020\n\010categor" + + "y\030\001 \002(\t\022\025\n\rsubcategories\030\003 \003(\t\"\365\001\n\014OsmAn" + + "dPoiBox\022\014\n\004zoom\030\001 \002(\r\022\014\n\004left\030\002 \002(\021\022\013\n\003t" + + "op\030\003 \002(\021\022(\n\ncategories\030\004 \001(\0132\024.OsmAndPoi" + + "Categories\022-\n\020includeNamesList\030\005 \001(\0132\023.I" + + "ndexedStringTable\022-\n\020excludeNamesList\030\006 ", + "\001(\0132\023.IndexedStringTable\022\037\n\010subBoxes\030\n \003" + + "(\0132\r.OsmAndPoiBox\022\023\n\013shiftToData\030\016 \001(\007\")" + + "\n\023OsmAndPoiCategories\022\022\n\ncategories\030\003 \003(" + + "\r\"^\n\020OsmAndPoiBoxData\022\014\n\004zoom\030\001 \001(\r\022\t\n\001x" + + "\030\002 \001(\r\022\t\n\001y\030\003 \001(\r\022&\n\007poiData\030\005 \003(\0132\025.Osm" + + "AndPoiBoxDataAtom\"\255\001\n\024OsmAndPoiBoxDataAt" + + "om\022\n\n\002dx\030\002 \002(\021\022\n\n\002dy\030\003 \002(\021\022\n\n\002id\030\004 \001(\004\022\014" + + "\n\004name\030\005 \001(\t\022\016\n\006nameEn\030\006 \001(\t\022\022\n\ncategori" + + "es\030\007 \003(\r\022\024\n\014openingHours\030\n \001(\t\022\014\n\004site\030\013" + + " \001(\t\022\r\n\005phone\030\014 \001(\t\022\014\n\004note\030\r \001(\tB\023\n\021net", + ".osmand.binary" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { @@ -14915,16 +15394,24 @@ public final class OsmandOdb { new java.lang.String[] { "Name", "Routes", "Stops", "StringTable", }, net.osmand.binary.OsmandOdb.OsmAndTransportIndex.class, net.osmand.binary.OsmandOdb.OsmAndTransportIndex.Builder.class); - internal_static_OsmAndPoiIndex_descriptor = + internal_static_OsmAndTileBox_descriptor = getDescriptor().getMessageTypes().get(22); + internal_static_OsmAndTileBox_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_OsmAndTileBox_descriptor, + new java.lang.String[] { "Left", "Right", "Top", "Bottom", }, + net.osmand.binary.OsmandOdb.OsmAndTileBox.class, + net.osmand.binary.OsmandOdb.OsmAndTileBox.Builder.class); + internal_static_OsmAndPoiIndex_descriptor = + getDescriptor().getMessageTypes().get(23); internal_static_OsmAndPoiIndex_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_OsmAndPoiIndex_descriptor, - new java.lang.String[] { "Name", "CategoriesTable", "Boxes", "PoiData", }, + new java.lang.String[] { "Name", "Boundaries", "CategoriesTable", "Boxes", "PoiData", }, net.osmand.binary.OsmandOdb.OsmAndPoiIndex.class, net.osmand.binary.OsmandOdb.OsmAndPoiIndex.Builder.class); internal_static_IndexedStringTable_descriptor = - getDescriptor().getMessageTypes().get(23); + getDescriptor().getMessageTypes().get(24); internal_static_IndexedStringTable_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_IndexedStringTable_descriptor, @@ -14932,7 +15419,7 @@ public final class OsmandOdb { net.osmand.binary.OsmandOdb.IndexedStringTable.class, net.osmand.binary.OsmandOdb.IndexedStringTable.Builder.class); internal_static_OsmAndCategoryTable_descriptor = - getDescriptor().getMessageTypes().get(24); + getDescriptor().getMessageTypes().get(25); internal_static_OsmAndCategoryTable_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_OsmAndCategoryTable_descriptor, @@ -14940,7 +15427,7 @@ public final class OsmandOdb { net.osmand.binary.OsmandOdb.OsmAndCategoryTable.class, net.osmand.binary.OsmandOdb.OsmAndCategoryTable.Builder.class); internal_static_OsmAndPoiBox_descriptor = - getDescriptor().getMessageTypes().get(25); + getDescriptor().getMessageTypes().get(26); internal_static_OsmAndPoiBox_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_OsmAndPoiBox_descriptor, @@ -14948,7 +15435,7 @@ public final class OsmandOdb { net.osmand.binary.OsmandOdb.OsmAndPoiBox.class, net.osmand.binary.OsmandOdb.OsmAndPoiBox.Builder.class); internal_static_OsmAndPoiCategories_descriptor = - getDescriptor().getMessageTypes().get(26); + getDescriptor().getMessageTypes().get(27); internal_static_OsmAndPoiCategories_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_OsmAndPoiCategories_descriptor, @@ -14956,7 +15443,7 @@ public final class OsmandOdb { net.osmand.binary.OsmandOdb.OsmAndPoiCategories.class, net.osmand.binary.OsmandOdb.OsmAndPoiCategories.Builder.class); internal_static_OsmAndPoiBoxData_descriptor = - getDescriptor().getMessageTypes().get(27); + getDescriptor().getMessageTypes().get(28); internal_static_OsmAndPoiBoxData_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_OsmAndPoiBoxData_descriptor, @@ -14964,7 +15451,7 @@ public final class OsmandOdb { net.osmand.binary.OsmandOdb.OsmAndPoiBoxData.class, net.osmand.binary.OsmandOdb.OsmAndPoiBoxData.Builder.class); internal_static_OsmAndPoiBoxDataAtom_descriptor = - getDescriptor().getMessageTypes().get(28); + getDescriptor().getMessageTypes().get(29); internal_static_OsmAndPoiBoxDataAtom_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_OsmAndPoiBoxDataAtom_descriptor, diff --git a/DataExtractionOSM/src/net/osmand/data/preparation/IndexPoiCreator.java b/DataExtractionOSM/src/net/osmand/data/preparation/IndexPoiCreator.java index 2ef92be7db..741ab39ce4 100644 --- a/DataExtractionOSM/src/net/osmand/data/preparation/IndexPoiCreator.java +++ b/DataExtractionOSM/src/net/osmand/data/preparation/IndexPoiCreator.java @@ -23,6 +23,7 @@ import java.util.TreeMap; import net.osmand.Algoritms; import net.osmand.IProgress; import net.osmand.binary.BinaryMapIndexWriter; +import net.osmand.binary.BinaryMapPoiReaderAdapter; import net.osmand.data.Amenity; import net.osmand.data.AmenityType; import net.osmand.data.IndexConstants; @@ -41,9 +42,9 @@ public class IndexPoiCreator extends AbstractIndexPartCreator { private Connection poiConnection; private File poiIndexFile; private PreparedStatement poiPreparedStatement; - private static final int ZOOM_TO_SAVE_END = 15; + private static final int ZOOM_TO_SAVE_END = 16; private static final int ZOOM_TO_SAVE_START = 6; - private static final int SHIFT_BYTES_CATEGORY = 7; + private List tempAmenityList = new ArrayList(); @@ -167,7 +168,7 @@ public class IndexPoiCreator extends AbstractIndexPartCreator { if (subcatInd == null) { throw new IllegalArgumentException("Unknown subcategory " + sub + " category " + category); } - types.add((subcatInd << SHIFT_BYTES_CATEGORY) | catInd); + types.add((subcatInd << BinaryMapPoiReaderAdapter.SHIFT_BITS_CATEGORY) | catInd); } } else { subcategory = subcategory.trim(); @@ -175,7 +176,7 @@ public class IndexPoiCreator extends AbstractIndexPartCreator { if (subcatInd == null) { throw new IllegalArgumentException("Unknown subcategory " + subcategory + " category " + category); } - types.add((subcatInd << SHIFT_BYTES_CATEGORY) | catInd); + types.add((subcatInd << BinaryMapPoiReaderAdapter.SHIFT_BITS_CATEGORY) | catInd); } } @@ -208,7 +209,14 @@ public class IndexPoiCreator extends AbstractIndexPartCreator { stat.close(); // 1. write header - long startFpPoiIndex = writer.startWritePOIIndex(regionName); + rs = poiConnection.createStatement().executeQuery("SELECT max(x), min(x), max(y), min(y) FROM poi"); + rs.next(); + int right31 = rs.getInt(1); + int left31 = rs.getInt(2); + int bottom31 = rs.getInt(3); + int top31 = rs.getInt(4); + rs.close(); + long startFpPoiIndex = writer.startWritePOIIndex(regionName, left31, right31, bottom31, top31); // 2. write categories table Map catIndexes = writer.writePOICategoriesTable(categories); @@ -309,8 +317,9 @@ public class IndexPoiCreator extends AbstractIndexPartCreator { long l = tree.getNode(); int x = (int) (l >> 31); int y = (int) (l & ((1 << 31) - 1)); - long fp = writer.startWritePoiBox(zoom, x, y); - if (zoom < ZOOM_TO_SAVE_END) { + boolean end = zoom == ZOOM_TO_SAVE_END; + long fp = writer.startWritePoiBox(zoom, x, y, end); + if (!end) { for (Tree subTree : tree.getSubtrees()) { writePoiBoxes(writer, subTree, zoom + 1, fpToWriteSeeks); } diff --git a/DataExtractionOSM/src/osmand_odb.proto b/DataExtractionOSM/src/osmand_odb.proto index f94394d733..2005a7abc6 100644 --- a/DataExtractionOSM/src/osmand_odb.proto +++ b/DataExtractionOSM/src/osmand_odb.proto @@ -258,10 +258,20 @@ message OsmAndTransportIndex { } +message OsmAndTileBox { + // everything is encoded as 31 tile zoom + required uint32 left = 1; + required uint32 right = 2; + required uint32 top = 3; + required uint32 bottom = 4; + +} message OsmAndPoiIndex { required string name = 1; + required OsmAndTileBox boundaries = 2; + repeated OsmAndCategoryTable categoriesTable = 3; // leave space for other indexes diff --git a/OsmAnd/src/net/osmand/plus/AmenityIndexRepositoryBinary.java b/OsmAnd/src/net/osmand/plus/AmenityIndexRepositoryBinary.java index 6406b22f83..a96642a987 100644 --- a/OsmAnd/src/net/osmand/plus/AmenityIndexRepositoryBinary.java +++ b/OsmAnd/src/net/osmand/plus/AmenityIndexRepositoryBinary.java @@ -8,11 +8,8 @@ import java.util.List; import net.osmand.Algoritms; import net.osmand.LogUtil; -import net.osmand.binary.BinaryIndexPart; -import net.osmand.binary.BinaryMapDataObject; import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader.MapIndex; -import net.osmand.binary.BinaryMapIndexReader.MapRoot; import net.osmand.binary.BinaryMapIndexReader.SearchFilter; import net.osmand.binary.BinaryMapIndexReader.SearchRequest; import net.osmand.binary.BinaryMapIndexReader.TagValuePair; @@ -21,7 +18,6 @@ import net.osmand.data.AmenityType; import net.osmand.osm.LatLon; import net.osmand.osm.MapRenderingTypes; import net.osmand.osm.MapUtils; -import net.sf.junidecode.Junidecode; import org.apache.commons.logging.Log; @@ -46,45 +42,12 @@ public class AmenityIndexRepositoryBinary implements AmenityIndexRepository { @Override public boolean checkContains(double latitude, double longitude) { - int x = MapUtils.get31TileNumberX(longitude); - int y = MapUtils.get31TileNumberY(latitude); - for(BinaryIndexPart i : index.getIndexes()){ - if(i instanceof MapIndex){ - List rs = ((MapIndex) i).getRoots(); - if(!rs.isEmpty()){ - MapRoot rt = rs.get(0); - if(rt.getLeft() <= x && rt.getRight() >= x && - rt.getTop() <= y && rt.getBottom() >= y){ - return true; - } - } - } - } - return false; + return index.containsPoiData(latitude, longitude); } @Override public boolean checkContains(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude) { - int leftX = MapUtils.get31TileNumberX(leftLongitude); - int rightX = MapUtils.get31TileNumberX(rightLongitude); - int bottomY = MapUtils.get31TileNumberY(bottomLatitude); - int topY = MapUtils.get31TileNumberY(topLatitude); - for(BinaryIndexPart i : index.getIndexes()){ - if(i instanceof MapIndex){ - List rs = ((MapIndex) i).getRoots(); - if(!rs.isEmpty()){ - MapRoot rt = rs.get(0); - if(rightX < rt.getLeft() || leftX > rt.getRight()){ - continue; - } - if(topY > rt.getBottom() || bottomY < rt.getTop()){ - continue; - } - return true; - } - } - } - return false; + return index.containsPoiData(topLatitude, leftLongitude, bottomLatitude, rightLongitude); } @Override @@ -96,7 +59,8 @@ public class AmenityIndexRepositoryBinary implements AmenityIndexRepository { int sbottom = MapUtils.get31TileNumberY(bottomLatitude); int stop = MapUtils.get31TileNumberY(topLatitude); - SearchRequest req = BinaryMapIndexReader.buildSearchRequest(sleft, sright, stop, sbottom, 16); + SearchRequest req = BinaryMapIndexReader.buildSearchPoiRequest(sleft, sright, stop, sbottom, 16); + // TODO types and filter and live results req.setSearchFilter(new SearchFilter(){ @Override @@ -115,46 +79,13 @@ public class AmenityIndexRepositoryBinary implements AmenityIndexRepository { } return false; } - }); try { - index.searchMapIndex(req); - for(BinaryMapDataObject o : req.getSearchResults()){ - if(o.getPointsLength() == 0){ - continue; + List result = index.searchPoi(req); + for(Amenity am : result){ + if(filter.acceptTypeSubtype(am.getType(), am.getSubType())){ + amenities.add(am); } - - int xTile = 0; - int yTile = 0; - for(int i=0; i