use of net.osmand.binary.BinaryMapIndexReader.SearchFilter in project Osmand by osmandapp.
the class BinaryInspector method printMapDetailInfo.
private void printMapDetailInfo(BinaryMapIndexReader index, MapIndex mapIndex) throws IOException {
final StringBuilder b = new StringBuilder();
final DamnCounter mapObjectsCounter = new DamnCounter();
final MapStats mapObjectStats = new MapStats();
if (vInfo.osm) {
printToFile("<?xml version='1.0' encoding='UTF-8'?>\n" + "<osm version='0.6'>\n");
}
if (vInfo.isVStats()) {
BinaryMapIndexReader.READ_STATS = true;
}
final SearchRequest<BinaryMapDataObject> req = BinaryMapIndexReader.buildSearchRequest(MapUtils.get31TileNumberX(vInfo.lonleft), MapUtils.get31TileNumberX(vInfo.lonright), MapUtils.get31TileNumberY(vInfo.lattop), MapUtils.get31TileNumberY(vInfo.latbottom), vInfo.getZoom(), new SearchFilter() {
@Override
public boolean accept(TIntArrayList types, MapIndex index) {
return true;
}
}, new ResultMatcher<BinaryMapDataObject>() {
@Override
public boolean publish(BinaryMapDataObject obj) {
mapObjectsCounter.value++;
if (vInfo.isVStats()) {
mapObjectStats.process(obj);
} else if (vInfo.vmapObjects) {
b.setLength(0);
if (vInfo.osm) {
printOsmMapDetails(obj, b);
try {
printToFile(b.toString());
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
printMapDetails(obj, b, vInfo.vmapCoordinates);
println(b.toString());
}
}
return false;
}
@Override
public boolean isCancelled() {
return false;
}
});
if (vInfo.vstats) {
mapObjectStats.setReq(req);
}
index.searchMapIndex(req, mapIndex);
if (vInfo.osm) {
printToFile("</osm >\n");
}
if (vInfo.vstats) {
mapObjectStats.print();
}
println("\tTotal map objects: " + mapObjectsCounter.value);
}
use of net.osmand.binary.BinaryMapIndexReader.SearchFilter in project OsmAnd-tools by osmandapp.
the class ObfFileInMemory method readBinaryMapData.
private TLongObjectHashMap<BinaryMapDataObject> readBinaryMapData(BinaryMapIndexReader index, MapIndex mi, int zoom) throws IOException {
final TLongObjectHashMap<BinaryMapDataObject> result = new TLongObjectHashMap<>();
final SearchRequest<BinaryMapDataObject> req = BinaryMapIndexReader.buildSearchRequest(MapUtils.get31TileNumberX(lonleft), MapUtils.get31TileNumberX(lonright), MapUtils.get31TileNumberY(lattop), MapUtils.get31TileNumberY(latbottom), zoom, new SearchFilter() {
@Override
public boolean accept(TIntArrayList types, MapIndex index) {
return true;
}
}, new ResultMatcher<BinaryMapDataObject>() {
@Override
public boolean publish(BinaryMapDataObject obj) {
result.put(obj.getId(), obj);
return false;
}
@Override
public boolean isCancelled() {
return false;
}
});
index.searchMapIndex(req, mi);
return result;
}
use of net.osmand.binary.BinaryMapIndexReader.SearchFilter in project Osmand by osmandapp.
the class BinaryMapIndexFilter method process.
private Stat process(final int zoom) throws IOException {
final Stat stat = new Stat();
final Map<TagValuePair, Integer> map = new HashMap<TagValuePair, Integer>();
SearchFilter sf = new SearchFilter() {
@Override
public boolean accept(TIntArrayList types, MapIndex index) {
boolean polygon = false;
boolean polyline = false;
for (int j = 0; j < types.size(); j++) {
int wholeType = types.get(j);
TagValuePair pair = index.decodeType(wholeType);
if (pair != null) {
int t = wholeType & 3;
if (t == RenderingRulesStorage.POINT_RULES) {
stat.pointCount++;
} else if (t == RenderingRulesStorage.LINE_RULES) {
stat.wayCount++;
polyline = true;
} else {
polygon = true;
stat.polygonCount++;
if (!map.containsKey(pair)) {
map.put(pair, 0);
}
map.put(pair, map.get(pair) + 1);
}
}
}
stat.totalCount++;
return polyline;
}
};
ResultMatcher<BinaryMapDataObject> matcher = new ResultMatcher<BinaryMapDataObject>() {
TIntHashSet set = new TIntHashSet();
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean publish(BinaryMapDataObject object) {
// double area = calculateArea(object, zoom);
double len = calculateLength(object, zoom);
if (/*tilesCovers(object, zoom, set) >= 2 && */
len > 100) {
stat.polygonBigSize++;
if (stat.polygonBigSize % 10000 == 0) {
return true;
}
}
return false;
}
};
SearchRequest<BinaryMapDataObject> req = BinaryMapIndexReader.buildSearchRequest(0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, zoom, sf, matcher);
List<BinaryMapDataObject> result = reader.searchMapIndex(req);
ArrayList<TagValuePair> list = new ArrayList<TagValuePair>(map.keySet());
Collections.sort(list, new Comparator<TagValuePair>() {
@Override
public int compare(TagValuePair o1, TagValuePair o2) {
return -map.get(o1) + map.get(o2);
}
});
for (TagValuePair tp : list) {
Integer i = map.get(tp);
if (i > 10) {
// System.out.println(tp.toString() + " " + i);
}
}
for (BinaryMapDataObject obj : result) {
System.out.println("id " + (obj.getId() >> 3) + " " + calculateArea(obj, zoom));
}
return stat;
}
Aggregations