Fix search poi by name
This commit is contained in:
parent
aea993a619
commit
03ad5809fa
9 changed files with 170 additions and 149 deletions
|
@ -10,7 +10,7 @@ public class ToDoConstants {
|
|||
|
||||
// Index
|
||||
// Map QuadTree (skip small areas!!!)
|
||||
// new Address test Name index!!!
|
||||
// POI index exclude building hno from categories!!!
|
||||
// slightly changed POI (check it)!
|
||||
// Routing index
|
||||
// Identify coastline areas and pure ocean areas
|
||||
|
@ -23,13 +23,6 @@ public class ToDoConstants {
|
|||
// == Osmand application (TODO 127) ==
|
||||
// TODO prepare C++ version of routing algorithm
|
||||
|
||||
// Map Refactoring
|
||||
// Remove notification from OsmAndMapTileView (?)
|
||||
|
||||
// === Refactoring issues ===
|
||||
// !|| 125 || Introduce service layer rather than singletons and put all related into new package (services). Review architecture. Split some big classes. ||
|
||||
|
||||
|
||||
|
||||
// DONE SWING
|
||||
|
||||
|
|
|
@ -21,9 +21,12 @@ import net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion;
|
|||
import net.osmand.binary.BinaryMapIndexReader.MapIndex;
|
||||
import net.osmand.binary.BinaryMapIndexReader.MapRoot;
|
||||
import net.osmand.binary.BinaryMapIndexReader.SearchFilter;
|
||||
import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter;
|
||||
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
|
||||
import net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion;
|
||||
import net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.AmenityType;
|
||||
import net.osmand.data.Building;
|
||||
import net.osmand.data.City;
|
||||
import net.osmand.data.MapObject;
|
||||
|
@ -46,7 +49,7 @@ public class BinaryInspector {
|
|||
// inspector(new String[]{"-v","C:\\Users\\tpd\\osmand\\Housenumbers.obf"});
|
||||
//inspector(new String[]{"/home/victor/projects/OsmAnd/data/osm-gen/saved/Belarus-newzooms-new-rt.obf"});
|
||||
// inspector(new String[]{"/home/victor/projects/OsmAnd/download/spain/Spain_europe_1_small.obf"});
|
||||
inspector(new String[]{"-vaddress", "/home/victor/projects/OsmAnd/data/osm-gen/Luxembourg.obf"});
|
||||
inspector(new String[]{"-vpoi", "/home/victor/projects/OsmAnd/data/osm-gen/Luxembourg.obf"});
|
||||
|
||||
|
||||
// test case extract parts
|
||||
|
@ -430,83 +433,12 @@ public class BinaryInspector {
|
|||
i, j++));
|
||||
}
|
||||
if((verbose != null && verbose.isVmap())){
|
||||
final StringBuilder b = new StringBuilder();
|
||||
SearchRequest<BinaryMapDataObject> req = BinaryMapIndexReader.buildSearchRequest(MapUtils.get31TileNumberX(verbose.lonleft),
|
||||
MapUtils.get31TileNumberX(verbose.lonright),
|
||||
MapUtils.get31TileNumberY(verbose.lattop),
|
||||
MapUtils.get31TileNumberY(verbose.latbottom), verbose.getZoom(),
|
||||
new SearchFilter() {
|
||||
@Override
|
||||
public boolean accept(TIntArrayList types, MapIndex index) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
new ResultMatcher<BinaryMapDataObject>() {
|
||||
@Override
|
||||
public boolean publish(BinaryMapDataObject object) {
|
||||
boolean way = object.getPointsLength() > 1;
|
||||
b.setLength(0);
|
||||
b.append(way ? "Way " : "Point ");
|
||||
if(object.getName() != null){
|
||||
b.append(object.getName());
|
||||
}
|
||||
b.append(" ").append((object.getId() >> 1)).append(" ");
|
||||
formatTags(object, b);
|
||||
b.append(" ");
|
||||
for (int i = 0; i < object.getPointsLength(); i++) {
|
||||
b.append(" ");
|
||||
formatPoint(object, i, b);
|
||||
}
|
||||
println(b.toString());
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
index.searchMapIndex(req);
|
||||
printMapDetailInfo(verbose, index);
|
||||
}
|
||||
} else if(p instanceof PoiRegion && (verbose != null && verbose.isVpoi())){
|
||||
printPOIDetailInfo(verbose, index);
|
||||
} else if (p instanceof AddressRegion && (verbose != null && verbose.isVaddress())) {
|
||||
for(String region : index.getRegionNames()){
|
||||
println("\tRegion:" + region);
|
||||
int[] cityType = new int[] {BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE,
|
||||
BinaryMapAddressReaderAdapter.POSTCODES_TYPE,
|
||||
BinaryMapAddressReaderAdapter.VILLAGES_TYPE};
|
||||
for (int j = 0; j < cityType.length; j++) {
|
||||
int type = cityType[j];
|
||||
for (City c : index.getCities(region, null, type)) {
|
||||
println("\t\t" + c + getId(c));
|
||||
index.preloadStreets(c, null);
|
||||
for (Street t : c.getStreets()) {
|
||||
if (verbose.contains(t)) {
|
||||
print("\t\t\t" + t.getName() + getId(t));
|
||||
// if (type == BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE) {
|
||||
index.preloadBuildings(t, null);
|
||||
List<Building> buildings = t.getBuildings();
|
||||
if (buildings != null && !buildings.isEmpty()) {
|
||||
print("\t\t (");
|
||||
for (Building b : buildings) {
|
||||
print(b.toString() + ",");
|
||||
}
|
||||
print(")");
|
||||
}
|
||||
List<Street> streets = t.getIntersectedStreets();
|
||||
if (streets != null && !streets.isEmpty()) {
|
||||
print("\n\t\t\t\t\t\t\t x (");
|
||||
for (Street s : streets) {
|
||||
print(s.getName() +", ");
|
||||
}
|
||||
print(")");
|
||||
}
|
||||
// }
|
||||
println("");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
printAddressDetailedInfo(verbose, index);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
@ -518,6 +450,112 @@ public class BinaryInspector {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
private static void printAddressDetailedInfo(VerboseInfo verbose, BinaryMapIndexReader index) throws IOException {
|
||||
for(String region : index.getRegionNames()){
|
||||
println("\tRegion:" + region);
|
||||
int[] cityType = new int[] {BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE,
|
||||
BinaryMapAddressReaderAdapter.POSTCODES_TYPE,
|
||||
BinaryMapAddressReaderAdapter.VILLAGES_TYPE};
|
||||
for (int j = 0; j < cityType.length; j++) {
|
||||
int type = cityType[j];
|
||||
for (City c : index.getCities(region, null, type)) {
|
||||
println("\t\t" + c + getId(c));
|
||||
index.preloadStreets(c, null);
|
||||
for (Street t : c.getStreets()) {
|
||||
if (verbose.contains(t)) {
|
||||
print("\t\t\t" + t.getName() + getId(t));
|
||||
// if (type == BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE) {
|
||||
index.preloadBuildings(t, null);
|
||||
List<Building> buildings = t.getBuildings();
|
||||
if (buildings != null && !buildings.isEmpty()) {
|
||||
print("\t\t (");
|
||||
for (Building b : buildings) {
|
||||
print(b.toString() + ",");
|
||||
}
|
||||
print(")");
|
||||
}
|
||||
List<Street> streets = t.getIntersectedStreets();
|
||||
if (streets != null && !streets.isEmpty()) {
|
||||
print("\n\t\t\t\t\t\t\t x (");
|
||||
for (Street s : streets) {
|
||||
print(s.getName() +", ");
|
||||
}
|
||||
print(")");
|
||||
}
|
||||
// }
|
||||
println("");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void printMapDetailInfo(VerboseInfo verbose, BinaryMapIndexReader index) throws IOException {
|
||||
final StringBuilder b = new StringBuilder();
|
||||
SearchRequest<BinaryMapDataObject> req = BinaryMapIndexReader.buildSearchRequest(MapUtils.get31TileNumberX(verbose.lonleft),
|
||||
MapUtils.get31TileNumberX(verbose.lonright),
|
||||
MapUtils.get31TileNumberY(verbose.lattop),
|
||||
MapUtils.get31TileNumberY(verbose.latbottom), verbose.getZoom(),
|
||||
new SearchFilter() {
|
||||
@Override
|
||||
public boolean accept(TIntArrayList types, MapIndex index) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
new ResultMatcher<BinaryMapDataObject>() {
|
||||
@Override
|
||||
public boolean publish(BinaryMapDataObject object) {
|
||||
boolean way = object.getPointsLength() > 1;
|
||||
b.setLength(0);
|
||||
b.append(way ? "Way " : "Point ");
|
||||
if(object.getName() != null){
|
||||
b.append(object.getName());
|
||||
}
|
||||
b.append(" ").append((object.getId() >> 1)).append(" ");
|
||||
formatTags(object, b);
|
||||
b.append(" ");
|
||||
for (int i = 0; i < object.getPointsLength(); i++) {
|
||||
b.append(" ");
|
||||
formatPoint(object, i, b);
|
||||
}
|
||||
println(b.toString());
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
index.searchMapIndex(req);
|
||||
}
|
||||
|
||||
private static void printPOIDetailInfo(VerboseInfo verbose, BinaryMapIndexReader index) throws IOException {
|
||||
SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(MapUtils.get31TileNumberX(verbose.lonleft),
|
||||
MapUtils.get31TileNumberX(verbose.lonright),
|
||||
MapUtils.get31TileNumberY(verbose.lattop),
|
||||
MapUtils.get31TileNumberY(verbose.latbottom), verbose.getZoom(),
|
||||
new SearchPoiTypeFilter() {
|
||||
@Override
|
||||
public boolean accept(AmenityType type, String subcategory) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
new ResultMatcher<Amenity>() {
|
||||
@Override
|
||||
public boolean publish(Amenity object) {
|
||||
println(object.toString() + " " + object.getLocation());
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
index.searchPoi(req);
|
||||
}
|
||||
|
||||
private static String getId(MapObject o ){
|
||||
if(o.getId() == null) {
|
||||
|
|
|
@ -1336,13 +1336,13 @@ public class BinaryMapIndexReader {
|
|||
|
||||
|
||||
private static boolean testMapSearch = false;
|
||||
private static boolean testAddressSearch = true;
|
||||
private static boolean testAddressSearch = false;
|
||||
private static boolean testPoiSearch = false;
|
||||
private static boolean testTransportSearch = false;
|
||||
private static int sleft = MapUtils.get31TileNumberX(6);
|
||||
private static int sright = MapUtils.get31TileNumberX(14);
|
||||
private static int stop = MapUtils.get31TileNumberY(54);
|
||||
private static int sbottom = MapUtils.get31TileNumberY(45);
|
||||
private static int sleft = MapUtils.get31TileNumberX(6.3);
|
||||
private static int sright = MapUtils.get31TileNumberX(6.5);
|
||||
private static int stop = MapUtils.get31TileNumberY(49.8);
|
||||
private static int sbottom = MapUtils.get31TileNumberY(49.3);
|
||||
|
||||
private static void println(String s){
|
||||
System.out.println(s);
|
||||
|
@ -1360,7 +1360,7 @@ public class BinaryMapIndexReader {
|
|||
}
|
||||
if(testAddressSearch) {
|
||||
testAddressSearchByName(reader);
|
||||
// testAddressSearch(reader);
|
||||
testAddressSearch(reader);
|
||||
}
|
||||
if(testTransportSearch) {
|
||||
testTransportSearch(reader);
|
||||
|
@ -1378,7 +1378,7 @@ public class BinaryMapIndexReader {
|
|||
|
||||
private static void testPoiSearchByName(BinaryMapIndexReader reader) throws IOException {
|
||||
println("Searching by name...");
|
||||
SearchRequest<Amenity> req = buildSearchPoiRequest(sleft, sright, "kolie", null);
|
||||
SearchRequest<Amenity> req = buildSearchPoiRequest(sleft, sright, "kol", null);
|
||||
reader.searchPoiByName(req);
|
||||
for (Amenity a : req.getSearchResults()) {
|
||||
println(a.getType() + " " + a.getSubType() + " " + a.getName() + " " + a.getLocation());
|
||||
|
@ -1409,18 +1409,13 @@ public class BinaryMapIndexReader {
|
|||
private static void testTransportSearch(BinaryMapIndexReader reader) throws IOException {
|
||||
// test transport
|
||||
for (TransportIndex i : reader.transportIndexes) {
|
||||
println(i.left + " " + i.right + " " + i.top + " " + i.bottom);
|
||||
println(i.stringTable.offsets + "");
|
||||
println("Transport bounds : " + i.left + " " + i.right + " " + i.top + " " + i.bottom);
|
||||
}
|
||||
{
|
||||
int sleft = MapUtils.get31TileNumberX(27.573);
|
||||
int sright = MapUtils.get31TileNumberX(27.581);
|
||||
int stop = MapUtils.get31TileNumberY(53.912);
|
||||
int sbottom = MapUtils.get31TileNumberY(53.908);
|
||||
for (TransportStop s : reader.searchTransportIndex(buildSearchTransportRequest(sleft, sright, stop, sbottom, 15, null))) {
|
||||
println(s.getName());
|
||||
TIntObjectHashMap<TransportRoute> routes = reader.getTransportRoutes(s.getReferencesToRoutes());
|
||||
for (net.osmand.data.TransportRoute route : routes.values()) {
|
||||
for (net.osmand.data.TransportRoute route : routes.valueCollection()) {
|
||||
println(" " + route.getRef() + " " + route.getName() + " " + route.getDistance() + " "
|
||||
+ route.getAvgBothDistance());
|
||||
}
|
||||
|
@ -1430,7 +1425,7 @@ public class BinaryMapIndexReader {
|
|||
for (TransportStop s : reader.searchTransportIndex(buildSearchTransportRequest(sleft, sright, stop, sbottom, 16, null))) {
|
||||
println(s.getName());
|
||||
TIntObjectHashMap<TransportRoute> routes = reader.getTransportRoutes(s.getReferencesToRoutes());
|
||||
for (net.osmand.data.TransportRoute route : routes.values()) {
|
||||
for (net.osmand.data.TransportRoute route : routes.valueCollection()) {
|
||||
println(" " + route.getRef() + " " + route.getName() + " " + route.getDistance() + " "
|
||||
+ route.getAvgBothDistance());
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import net.osmand.CollatorStringMatcher;
|
|||
import net.osmand.LogUtil;
|
||||
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
||||
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
|
||||
import net.osmand.binary.OsmandOdb.OsmAndPoiNameIndex.OsmAndPoiNameIndexData;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.AmenityType;
|
||||
import net.osmand.osm.MapUtils;
|
||||
|
@ -242,6 +243,7 @@ public class BinaryMapPoiReaderAdapter {
|
|||
private TIntLongHashMap readPoiNameIndex(Collator instance, String query, SearchRequest<Amenity> req) throws IOException {
|
||||
TIntLongHashMap offsets = new TIntLongHashMap();
|
||||
TIntArrayList dataOffsets = null;
|
||||
int offset = 0;
|
||||
while(true){
|
||||
int t = codedIS.readTag();
|
||||
int tag = WireFormat.getTagFieldNumber(t);
|
||||
|
@ -252,13 +254,13 @@ public class BinaryMapPoiReaderAdapter {
|
|||
int length = readInt();
|
||||
int oldLimit = codedIS.pushLimit(length);
|
||||
dataOffsets = new TIntArrayList();
|
||||
offset = codedIS.getTotalBytesRead();
|
||||
map.readIndexedStringTable(instance, query, "", dataOffsets, 0);
|
||||
codedIS.popLimit(oldLimit);
|
||||
break; }
|
||||
case OsmandOdb.OsmAndPoiNameIndex.DATA_FIELD_NUMBER : {
|
||||
if(dataOffsets != null){
|
||||
dataOffsets.sort();
|
||||
int offset = codedIS.getTotalBytesRead();
|
||||
dataOffsets.sort(); // 1104125
|
||||
for (int i = 0; i < dataOffsets.size(); i++) {
|
||||
codedIS.seek(dataOffsets.get(i) + offset);
|
||||
int len = codedIS.readRawVarint32();
|
||||
|
@ -288,7 +290,7 @@ public class BinaryMapPoiReaderAdapter {
|
|||
switch (tag) {
|
||||
case 0:
|
||||
return;
|
||||
case OsmandOdb.OsmAndPoiNameIndexData.ATOMS_FIELD_NUMBER :
|
||||
case OsmAndPoiNameIndexData.ATOMS_FIELD_NUMBER :
|
||||
int len = codedIS.readRawVarint32();
|
||||
int oldLim = codedIS.pushLimit(len);
|
||||
readPoiNameIndexDataAtom(offsets, req);
|
||||
|
@ -366,10 +368,8 @@ public class BinaryMapPoiReaderAdapter {
|
|||
if(skipTiles != null){
|
||||
skipTiles.clear();
|
||||
}
|
||||
|
||||
LOG.info("Searched poi structure in "+(System.currentTimeMillis() - time) +
|
||||
"ms. Found " + offsets.length +" subtress");
|
||||
|
||||
for (int j = 0; j < offsets.length; j++) {
|
||||
codedIS.seek(offsets[j] + indexOffset);
|
||||
int len = readInt();
|
||||
|
|
|
@ -827,11 +827,12 @@ public class BinaryMapIndexWriter {
|
|||
codedOutStream.writeMessage(OsmAndTransportIndex.STRINGTABLE_FIELD_NUMBER, st.build());
|
||||
}
|
||||
|
||||
public BinaryFileReference startWritePOIIndex(String name, int left31, int right31, int bottom31, int top31) 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
|
||||
BinaryFileReference startPoiIndex = preserveInt32Size();
|
||||
preserveInt32Size();
|
||||
long startPointer = getFilePointer();
|
||||
if (name != null) {
|
||||
codedOutStream.writeString(OsmandOdb.OsmAndPoiIndex.NAME_FIELD_NUMBER, name);
|
||||
}
|
||||
|
@ -841,7 +842,7 @@ public class BinaryMapIndexWriter {
|
|||
builder.setTop(top31);
|
||||
builder.setBottom(bottom31);
|
||||
codedOutStream.writeMessage(OsmandOdb.OsmAndPoiIndex.BOUNDARIES_FIELD_NUMBER, builder.build());
|
||||
return startPoiIndex;
|
||||
return startPointer;
|
||||
}
|
||||
|
||||
public void endWritePOIIndex() throws IOException {
|
||||
|
@ -889,7 +890,7 @@ public class BinaryMapIndexWriter {
|
|||
codedOutStream.writeMessage(OsmandOdb.OsmAndPoiBox.CATEGORIES_FIELD_NUMBER, builder.build());
|
||||
}
|
||||
|
||||
public Map<PoiTileBox, List<BinaryFileReference>> writePoiNameIndex(Map<String, Set<PoiTileBox>> namesIndex, BinaryFileReference startPoiIndex) throws IOException {
|
||||
public Map<PoiTileBox, List<BinaryFileReference>> writePoiNameIndex(Map<String, Set<PoiTileBox>> namesIndex, long startPoiIndex) throws IOException {
|
||||
checkPeekState(POI_INDEX_INIT);
|
||||
codedOutStream.writeTag(OsmandOdb.OsmAndPoiIndex.NAMEINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
||||
preserveInt32Size();
|
||||
|
@ -897,7 +898,7 @@ public class BinaryMapIndexWriter {
|
|||
Map<PoiTileBox, List<BinaryFileReference>> fpToWriteSeeks = new LinkedHashMap<PoiTileBox, List<BinaryFileReference>>();
|
||||
Map<String, BinaryFileReference> indexedTable = writeIndexedTable(OsmandOdb.OsmAndPoiNameIndex.TABLE_FIELD_NUMBER, namesIndex.keySet());
|
||||
for(Map.Entry<String, Set<PoiTileBox>> e : namesIndex.entrySet()) {
|
||||
codedOutStream.writeTag(OsmandOdb.OsmAndPoiNameIndex.DATA_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
||||
codedOutStream.writeTag(OsmandOdb.OsmAndPoiNameIndex.DATA_FIELD_NUMBER, FieldType.MESSAGE.getWireType());
|
||||
BinaryFileReference nameTableRef = indexedTable.get(e.getKey());
|
||||
codedOutStream.flush();
|
||||
nameTableRef.writeReference(raf, getFilePointer());
|
||||
|
@ -915,7 +916,7 @@ public class BinaryMapIndexWriter {
|
|||
}
|
||||
OsmAndPoiNameIndex.OsmAndPoiNameIndexData msg = builder.build();
|
||||
|
||||
codedOutStream.writeMessage(OsmandOdb.OsmAndPoiNameIndex.DATA_FIELD_NUMBER, msg);
|
||||
codedOutStream.writeMessageNoTag(msg);
|
||||
long endPointer = getFilePointer();
|
||||
|
||||
// first message
|
||||
|
@ -925,7 +926,7 @@ public class BinaryMapIndexWriter {
|
|||
if (!fpToWriteSeeks.containsKey(box)) {
|
||||
fpToWriteSeeks.put(box, new ArrayList<BinaryFileReference>());
|
||||
}
|
||||
fpToWriteSeeks.get(box).add(net.osmand.data.preparation.BinaryFileReference.createShiftReference(endPointer - accumulateSize, startPoiIndex.getStartPointer()));
|
||||
fpToWriteSeeks.get(box).add(net.osmand.data.preparation.BinaryFileReference.createShiftReference(endPointer - accumulateSize, startPoiIndex));
|
||||
accumulateSize += CodedOutputStream.computeMessageSize(OsmAndPoiNameIndex.OsmAndPoiNameIndexData.ATOMS_FIELD_NUMBER,
|
||||
msg.getAtoms(i));
|
||||
|
||||
|
@ -993,11 +994,12 @@ public class BinaryMapIndexWriter {
|
|||
public void startWritePoiData(int zoom, int x, int y, List<BinaryFileReference> fpPoiBox) throws IOException {
|
||||
pushState(POI_DATA, POI_INDEX_INIT);
|
||||
codedOutStream.writeTag(OsmandOdb.OsmAndPoiIndex.POIDATA_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
||||
BinaryFileReference startPoiData = preserveInt32Size();
|
||||
long pointer = codedOutStream.getWrittenBytes();
|
||||
preserveInt32Size();
|
||||
codedOutStream.flush();
|
||||
// write shift to that data
|
||||
for (int i = 0; i < fpPoiBox.size(); i++) {
|
||||
fpPoiBox.get(i).writeReference(raf, startPoiData.getStartPointer());
|
||||
fpPoiBox.get(i).writeReference(raf, pointer);
|
||||
}
|
||||
|
||||
codedOutStream.writeUInt32(OsmandOdb.OsmAndPoiBoxData.ZOOM_FIELD_NUMBER, zoom);
|
||||
|
@ -1011,7 +1013,7 @@ public class BinaryMapIndexWriter {
|
|||
writeInt32Size();
|
||||
}
|
||||
|
||||
public BinaryFileReference startWritePoiBox(int zoom, int tileX, int tileY, BinaryFileReference startPoiIndex, boolean end)
|
||||
public BinaryFileReference startWritePoiBox(int zoom, int tileX, int tileY, long startPoiIndex, boolean end)
|
||||
throws IOException {
|
||||
checkPeekState(POI_INDEX_INIT, POI_BOX);
|
||||
if (state.peek() == POI_INDEX_INIT) {
|
||||
|
@ -1036,7 +1038,7 @@ public class BinaryMapIndexWriter {
|
|||
|
||||
if (end) {
|
||||
codedOutStream.writeTag(OsmandOdb.OsmAndPoiBox.SHIFTTODATA_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
||||
BinaryFileReference shift = BinaryFileReference.createShiftReference(getFilePointer(), startPoiIndex.getStartPointer());
|
||||
BinaryFileReference shift = BinaryFileReference.createShiftReference(getFilePointer(), startPoiIndex);
|
||||
codedOutStream.writeFixed32NoTag(0);
|
||||
return shift;
|
||||
}
|
||||
|
|
|
@ -627,8 +627,8 @@ public class IndexCreator {
|
|||
IndexCreator creator = new IndexCreator(new File("/home/victor/projects/OsmAnd/data/osm-gen/")); //$NON-NLS-1$
|
||||
creator.setIndexMap(false);
|
||||
creator.setIndexAddress(true);
|
||||
creator.setIndexPOI(false);
|
||||
creator.setIndexTransport(false);
|
||||
creator.setIndexPOI(true);
|
||||
creator.setIndexTransport(true);
|
||||
|
||||
creator.recreateOnlyBinaryFile = false;
|
||||
creator.deleteDatabaseIndexes = false;
|
||||
|
|
|
@ -292,7 +292,7 @@ public class IndexPoiCreator extends AbstractIndexPartCreator {
|
|||
int left31 = minX;
|
||||
int bottom31 = maxY;
|
||||
int top31 = minY;
|
||||
BinaryFileReference startFpPoiIndex = writer.startWritePOIIndex(regionName, left31, right31, bottom31, top31);
|
||||
long startFpPoiIndex = writer.startWritePOIIndex(regionName, left31, right31, bottom31, top31);
|
||||
|
||||
// 2. write categories table
|
||||
Map<String, Map<String, Integer>> categories = rootZoomsTree.node.categories;
|
||||
|
@ -420,7 +420,7 @@ public class IndexPoiCreator extends AbstractIndexPartCreator {
|
|||
}
|
||||
|
||||
private void writePoiBoxes(BinaryMapIndexWriter writer, Tree<PoiTileBox> tree,
|
||||
BinaryFileReference startFpPoiIndex, Map<PoiTileBox, List<BinaryFileReference>> fpToWriteSeeks,
|
||||
long startFpPoiIndex, Map<PoiTileBox, List<BinaryFileReference>> fpToWriteSeeks,
|
||||
Map<String, Map<String, Integer>> categories, Map<String, Integer> catIndexes) throws IOException, SQLException {
|
||||
int x = tree.getNode().x;
|
||||
int y = tree.getNode().y;
|
||||
|
|
|
@ -8,7 +8,6 @@ import net.osmand.ResultMatcher;
|
|||
import net.osmand.data.Building;
|
||||
import net.osmand.data.City;
|
||||
import net.osmand.data.MapObject;
|
||||
import net.osmand.data.PostCode;
|
||||
import net.osmand.data.Street;
|
||||
import net.osmand.osm.LatLon;
|
||||
import net.osmand.osm.MapUtils;
|
||||
|
@ -32,20 +31,20 @@ public interface RegionAddressRepository {
|
|||
|
||||
|
||||
|
||||
public void preloadCities(ResultMatcher<MapObject> resultMatcher);
|
||||
public void preloadCities(ResultMatcher<City> resultMatcher);
|
||||
|
||||
public void preloadBuildings(Street street, ResultMatcher<Building> resultMatcher);
|
||||
|
||||
public void preloadStreets(MapObject o, ResultMatcher<Street> resultMatcher);
|
||||
public void preloadStreets(City o, ResultMatcher<Street> resultMatcher);
|
||||
|
||||
|
||||
public List<MapObject> getLoadedCities();
|
||||
|
||||
public PostCode getPostcode(String name);
|
||||
public City getPostcode(String name);
|
||||
|
||||
public City getCityById(Long id);
|
||||
|
||||
public Street getStreetByName(MapObject cityOrPostcode, String name);
|
||||
public Street getStreetByName(City cityOrPostcode, String name);
|
||||
|
||||
public Building getBuildingByName(Street street, String name);
|
||||
|
||||
|
@ -56,9 +55,9 @@ public interface RegionAddressRepository {
|
|||
public LatLon findStreetIntersection(Street street, Street street2);
|
||||
|
||||
// TODO remove that method
|
||||
public List<Street> fillWithSuggestedStreets(MapObject o, ResultMatcher<Street> resultMatcher, String... names);
|
||||
public List<Street> fillWithSuggestedStreets(City o, ResultMatcher<Street> resultMatcher, String... names);
|
||||
|
||||
public List<MapObject> fillWithSuggestedCities(String name, ResultMatcher<MapObject> resultMatcher, LatLon currentLocation);
|
||||
public List<City> fillWithSuggestedCities(String name, ResultMatcher<City> resultMatcher, LatLon currentLocation);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -15,11 +15,11 @@ import net.osmand.CollatorStringMatcher;
|
|||
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.binary.BinaryMapAddressReaderAdapter;
|
||||
import net.osmand.binary.BinaryMapIndexReader;
|
||||
import net.osmand.data.Building;
|
||||
import net.osmand.data.City;
|
||||
import net.osmand.data.MapObject;
|
||||
import net.osmand.data.PostCode;
|
||||
import net.osmand.data.Street;
|
||||
import net.osmand.osm.LatLon;
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
|||
|
||||
|
||||
private final LinkedHashMap<Long, City> cities = new LinkedHashMap<Long, City>();
|
||||
private final Map<String, PostCode> postCodes;
|
||||
private final Map<String, City> postCodes;
|
||||
private boolean useEnglishNames = false;
|
||||
private final Collator collator;
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
|||
this.region = name;
|
||||
this.collator = Collator.getInstance();
|
||||
this.collator.setStrength(Collator.PRIMARY); //ignores also case
|
||||
this.postCodes = new TreeMap<String, PostCode>(collator);
|
||||
this.postCodes = new TreeMap<String, City>(collator);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,10 +52,11 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
|||
|
||||
|
||||
@Override
|
||||
public synchronized void preloadCities(ResultMatcher<MapObject> resultMatcher) {
|
||||
public synchronized void preloadCities(ResultMatcher<City> resultMatcher) {
|
||||
if (cities.isEmpty()) {
|
||||
try {
|
||||
List<City> cs = file.getCities(region, BinaryMapIndexReader.buildAddressRequest(resultMatcher));
|
||||
List<City> cs = file.getCities(region, BinaryMapIndexReader.buildAddressRequest(resultMatcher),
|
||||
BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE);
|
||||
for (City c : cs) {
|
||||
cities.put(c.getId(), c);
|
||||
}
|
||||
|
@ -88,18 +89,13 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized void preloadStreets(MapObject o, ResultMatcher<Street> resultMatcher) {
|
||||
assert o instanceof PostCode || o instanceof City;
|
||||
Collection<Street> streets = o instanceof PostCode ? ((PostCode) o).getStreets() : ((City) o).getStreets();
|
||||
public synchronized void preloadStreets(City o, ResultMatcher<Street> resultMatcher) {
|
||||
Collection<Street> streets = o.getStreets();
|
||||
if(!streets.isEmpty()){
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if(o instanceof PostCode){
|
||||
file.preloadStreets((PostCode) o, BinaryMapIndexReader.buildAddressRequest(resultMatcher));
|
||||
} else {
|
||||
file.preloadStreets((City) o, BinaryMapIndexReader.buildAddressRequest(resultMatcher));
|
||||
}
|
||||
file.preloadStreets(o, BinaryMapIndexReader.buildAddressRequest(resultMatcher));
|
||||
} catch (IOException e) {
|
||||
log.error("Disk operation failed" , e); //$NON-NLS-1$
|
||||
}
|
||||
|
@ -113,19 +109,16 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
|||
|
||||
|
||||
@Override
|
||||
public List<Street> fillWithSuggestedStreets(MapObject o, ResultMatcher<Street> resultMatcher, String... names) {
|
||||
assert o instanceof PostCode || o instanceof City;
|
||||
City city = (City) (o instanceof City ? o : null);
|
||||
PostCode post = (PostCode) (o instanceof PostCode ? o : null);
|
||||
public List<Street> fillWithSuggestedStreets(City o, ResultMatcher<Street> resultMatcher, String... names) {
|
||||
List<Street> streetsToFill = new ArrayList<Street>();
|
||||
if(names.length == 0){
|
||||
preloadStreets(o, resultMatcher);
|
||||
streetsToFill.addAll(post == null ? city.getStreets() : post.getStreets());
|
||||
streetsToFill.addAll(o.getStreets());
|
||||
return streetsToFill;
|
||||
}
|
||||
preloadStreets(o, null);
|
||||
|
||||
Collection<Street> streets = post == null ? city.getStreets() : post.getStreets();
|
||||
Collection<Street> streets =o.getStreets();
|
||||
|
||||
// 1st step loading by starts with
|
||||
for (StringMatcherMode mode : streetsCheckMode) {
|
||||
|
@ -148,8 +141,8 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
|||
|
||||
|
||||
@Override
|
||||
public List<MapObject> fillWithSuggestedCities(String name, ResultMatcher<MapObject> resultMatcher, LatLon currentLocation) {
|
||||
List<MapObject> citiesToFill = new ArrayList<MapObject>();
|
||||
public List<City> fillWithSuggestedCities(String name, ResultMatcher<City> resultMatcher, LatLon currentLocation) {
|
||||
List<City> citiesToFill = new ArrayList<City>();
|
||||
if (cities.isEmpty()) {
|
||||
preloadCities(resultMatcher);
|
||||
citiesToFill.addAll(cities.values());
|
||||
|
@ -166,8 +159,9 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
|||
if (name.length() >= 2 && Algoritms.containsDigit(name)) {
|
||||
// also try to identify postcodes
|
||||
String uName = name.toUpperCase();
|
||||
for (PostCode code : file.getPostcodes(region, BinaryMapIndexReader.buildAddressRequest(resultMatcher),
|
||||
new CollatorStringMatcher(collator, uName, StringMatcherMode.CHECK_CONTAINS))) {
|
||||
for (City code : file.getCities(region, BinaryMapIndexReader.buildAddressRequest(resultMatcher),
|
||||
new CollatorStringMatcher(collator, uName, StringMatcherMode.CHECK_CONTAINS),
|
||||
BinaryMapAddressReaderAdapter.POSTCODES_TYPE)) {
|
||||
citiesToFill.add(code);
|
||||
if (resultMatcher.isCancelled()) {
|
||||
return citiesToFill;
|
||||
|
|
Loading…
Reference in a new issue