use of net.osmand.binary.BinaryMapDataObject in project Osmand by osmandapp.
the class OsmandRegions method prepareFile.
public BinaryMapIndexReader prepareFile(String fileName) throws IOException {
reader = new BinaryMapIndexReader(new RandomAccessFile(fileName, "r"), new File(fileName));
// final Collator clt = OsmAndCollator.primaryCollator();
final Map<String, String> parentRelations = new LinkedHashMap<String, String>();
final ResultMatcher<BinaryMapDataObject> resultMatcher = new ResultMatcher<BinaryMapDataObject>() {
@Override
public boolean publish(BinaryMapDataObject object) {
initTypes(object);
int[] types = object.getTypes();
for (int i = 0; i < types.length; i++) {
TagValuePair tp = object.getMapIndex().decodeType(types[i]);
if ("boundary".equals(tp.value)) {
return false;
}
}
WorldRegion rd = initRegionData(parentRelations, object);
if (rd == null) {
return false;
}
if (rd.regionDownloadName != null) {
downloadNamesToFullNames.put(rd.regionDownloadName, rd.regionFullName);
}
fullNamesToRegionData.put(rd.regionFullName, rd);
return false;
}
@Override
public boolean isCancelled() {
return false;
}
};
iterateOverAllObjects(resultMatcher);
// post process download names
for (Map.Entry<String, String> e : parentRelations.entrySet()) {
String fullName = e.getKey();
String parentFullName = e.getValue();
// String parentParentFulName = parentRelations.get(parentFullName); // could be used for japan/russia
WorldRegion rd = fullNamesToRegionData.get(fullName);
WorldRegion parent = fullNamesToRegionData.get(parentFullName);
if (parent != null && rd != null) {
parent.addSubregion(rd);
}
}
structureWorldRegions(new ArrayList<WorldRegion>(fullNamesToRegionData.values()));
return reader;
}
use of net.osmand.binary.BinaryMapDataObject in project Osmand by osmandapp.
the class OsmandRegions method cacheAllCountries.
public Map<String, LinkedList<BinaryMapDataObject>> cacheAllCountries() throws IOException {
quadTree = new QuadTree<String>(new QuadRect(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE), 8, 0.55f);
final ResultMatcher<BinaryMapDataObject> resultMatcher = new ResultMatcher<BinaryMapDataObject>() {
// int c = 0;
@Override
public boolean publish(BinaryMapDataObject object) {
if (object.getPointsLength() < 1) {
return false;
}
initTypes(object);
String nm = mapIndexFields.get(mapIndexFields.downloadNameType, object);
if (!countriesByDownloadName.containsKey(nm)) {
LinkedList<BinaryMapDataObject> ls = new LinkedList<BinaryMapDataObject>();
countriesByDownloadName.put(nm, ls);
ls.add(object);
} else {
countriesByDownloadName.get(nm).add(object);
}
int maxx = object.getPoint31XTile(0);
int maxy = object.getPoint31YTile(0);
int minx = maxx;
int miny = maxy;
for (int i = 1; i < object.getPointsLength(); i++) {
int x = object.getPoint31XTile(i);
int y = object.getPoint31YTile(i);
if (y < miny) {
miny = y;
} else if (y > maxy) {
maxy = y;
}
if (x < minx) {
minx = x;
} else if (x > maxx) {
maxx = x;
}
}
quadTree.insert(nm, new QuadRect(minx, miny, maxx, maxy));
return false;
}
@Override
public boolean isCancelled() {
return false;
}
};
iterateOverAllObjects(resultMatcher);
return countriesByDownloadName;
}
use of net.osmand.binary.BinaryMapDataObject in project Osmand by osmandapp.
the class OsmandRegions method findBinaryMapDataObject.
public BinaryMapDataObject findBinaryMapDataObject(LatLon latLon) throws IOException {
int point31x = MapUtils.get31TileNumberX(latLon.getLongitude());
int point31y = MapUtils.get31TileNumberY(latLon.getLatitude());
BinaryMapDataObject res = null;
List<BinaryMapDataObject> mapDataObjects;
try {
mapDataObjects = queryBbox(point31x, point31x, point31y, point31y);
} catch (IOException e) {
throw new IOException("Error while calling queryBbox");
}
if (mapDataObjects != null) {
Iterator<BinaryMapDataObject> it = mapDataObjects.iterator();
while (it.hasNext()) {
BinaryMapDataObject o = it.next();
if (o.getTypes() != null) {
boolean isRegion = true;
for (int i = 0; i < o.getTypes().length; i++) {
TagValuePair tp = o.getMapIndex().decodeType(o.getTypes()[i]);
if ("boundary".equals(tp.value)) {
isRegion = false;
break;
}
}
WorldRegion downloadRegion = getRegionData(getFullName(o));
if (!isRegion || downloadRegion == null || !downloadRegion.isRegionMapDownload() || !contain(o, point31x, point31y)) {
it.remove();
}
}
}
double smallestArea = -1;
for (BinaryMapDataObject o : mapDataObjects) {
double area = OsmandRegions.getArea(o);
if (smallestArea == -1) {
smallestArea = area;
res = o;
} else if (area < smallestArea) {
smallestArea = area;
res = o;
}
}
}
return res;
}
use of net.osmand.binary.BinaryMapDataObject in project Osmand by osmandapp.
the class OsmandRegions method testCountry.
private static void testCountry(OsmandRegions or, double lat, double lon, String... test) throws IOException {
long t = System.currentTimeMillis();
List<BinaryMapDataObject> cs = or.query(MapUtils.get31TileNumberX(lon), MapUtils.get31TileNumberY(lat));
Set<String> expected = new TreeSet<String>(Arrays.asList(test));
Set<String> found = new TreeSet<String>();
for (BinaryMapDataObject b : cs) {
String nm = b.getNameByType(or.mapIndexFields.nameEnType);
if (nm == null) {
nm = b.getName();
}
if (or.isDownloadOfType(b, MAP_TYPE)) {
found.add(nm.toLowerCase());
}
}
if (!found.equals(expected)) {
throw new IllegalStateException(" Expected " + expected + " but was " + found);
}
System.out.println("Found " + expected + " in " + (System.currentTimeMillis() - t) + " ms");
}
use of net.osmand.binary.BinaryMapDataObject in project Osmand by osmandapp.
the class RenderingRuleProperty method createAdditionalStringProperty.
public static RenderingRuleProperty createAdditionalStringProperty(String name) {
return new RenderingRuleProperty(name, STRING_TYPE, true) {
@Override
public boolean accept(int ruleValue, int renderingProperty, RenderingRuleSearchRequest req) {
BinaryMapDataObject obj = req.getObject();
String val = req.getStorage().getStringValue(ruleValue);
if (obj == null) {
int vl = req.getIntPropertyValue(this);
if (vl == -1) {
return false;
}
String val2 = req.getStorage().getStringValue(vl);
return val != null && val.equals(val2);
}
int k = val.indexOf('=');
if (k != -1) {
String ts = val.substring(0, k);
String vs = val.substring(k + 1);
Integer ruleInd = req.getObject().getMapIndex().getRule(ts, vs);
if (ruleInd != null) {
if (req.getObject().containsAdditionalType(ruleInd)) {
return true;
}
}
} else {
String ts = val;
int[] additionalTypes = obj.getAdditionalTypes();
for (int i = 0; i < additionalTypes.length; i++) {
TagValuePair vp = obj.getMapIndex().decodeType(additionalTypes[i]);
if (vp != null && ts.equals(vp.tag)) {
return true;
}
}
}
return false;
}
};
}
Aggregations