use of net.osmand.obf.preparation.IndexPoiCreator in project OsmAnd-tools by osmandapp.
the class BinaryMerger method combinePoiIndex.
private void combinePoiIndex(String name, BinaryMapIndexWriter writer, long dateCreated, PoiRegion[] poiRegions, BinaryMapIndexReader[] indexes) throws IOException, SQLException {
final int[] writtenPoiCount = { 0 };
MapRenderingTypesEncoder renderingTypes = new MapRenderingTypesEncoder(null, name);
boolean overwriteIds = false;
IndexCreatorSettings settings = new IndexCreatorSettings();
settings.indexPOI = true;
final IndexPoiCreator indexPoiCreator = new IndexPoiCreator(settings, renderingTypes, overwriteIds);
indexPoiCreator.createDatabaseStructure(new File(new File(System.getProperty("user.dir")), IndexCreator.getPoiFileName(name)));
final Map<Long, List<Amenity>> amenityRelations = new HashMap<Long, List<Amenity>>();
final TLongHashSet set = new TLongHashSet();
final long[] generatedRelationId = { -1 };
for (int i = 0; i < poiRegions.length; i++) {
BinaryMapIndexReader index = indexes[i];
final TLongHashSet file = new TLongHashSet();
log.info("Region: " + extractRegionName(index));
index.searchPoi(BinaryMapIndexReader.buildSearchPoiRequest(0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, -1, BinaryMapIndexReader.ACCEPT_ALL_POI_TYPE_FILTER, new ResultMatcher<Amenity>() {
@Override
public boolean publish(Amenity amenity) {
try {
boolean isRelation = amenity.getId() < 0;
if (isRelation) {
long j = latlon(amenity);
List<Amenity> list;
if (!amenityRelations.containsKey(j)) {
list = new ArrayList<Amenity>(1);
amenityRelations.put(j, list);
} else {
list = amenityRelations.get(j);
}
boolean unique = true;
for (Amenity a : list) {
if (a.getType() == amenity.getType() && Algorithms.objectEquals(a.getSubType(), amenity.getSubType())) {
unique = false;
break;
}
}
if (unique) {
amenity.setId(generatedRelationId[0]--);
amenityRelations.get(j).add(amenity);
indexPoiCreator.insertAmenityIntoPoi(amenity);
writtenPoiCount[0]++;
}
} else {
if (!set.contains(amenity.getId())) {
file.add(amenity.getId());
indexPoiCreator.insertAmenityIntoPoi(amenity);
writtenPoiCount[0]++;
}
}
return false;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
public boolean isCancelled() {
return false;
}
}));
set.addAll(file);
}
indexPoiCreator.writeBinaryPoiIndex(writer, name, null);
indexPoiCreator.commitAndClosePoiFile(dateCreated);
// REMOVE_POI_DB = false;
if (REMOVE_POI_DB) {
indexPoiCreator.removePoiFile();
}
log.info("Written " + writtenPoiCount[0] + " POI.");
}
Aggregations