use of net.osmand.binary.BinaryMapIndexReader in project OsmAnd-tools by osmandapp.
the class DijkstraAlgorithm method main.
public static void main(String[] args) throws IOException, InterruptedException, XmlPullParserException {
File fl = new File("/Users/victorshcherb/osmand/maps/Netherlands_europe_2.obf");
// $NON-NLS-1$ //$NON-NLS-2$
RandomAccessFile raf = new RandomAccessFile(fl, "r");
RoutePlannerFrontEnd fe = new RoutePlannerFrontEnd(false);
Builder builder = RoutingConfiguration.parseFromInputStream(new FileInputStream("/Users/victorshcherb/osmand/repos/resources/routing/routing.xml"));
RoutingConfiguration config = builder.build("car", RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 3);
RoutingContext ctx = fe.buildRoutingContext(config, null, new BinaryMapIndexReader[] { new BinaryMapIndexReader(raf, fl) }, RouteCalculationMode.NORMAL);
RouteResultPreparation.PRINT_TO_CONSOLE_ROUTE_INFORMATION_TO_TEST = true;
List<RouteSegmentResult> route = fe.searchRoute(ctx, new LatLon(52.28283, 4.8622713), new LatLon(52.326496, 4.8753176), null);
}
use of net.osmand.binary.BinaryMapIndexReader in project OsmAnd-tools by osmandapp.
the class BinaryComparator method compare.
private void compare(String[] argArr) throws IOException {
if (argArr == null || argArr.length < 2) {
System.out.println(helpMessage);
System.exit(1);
}
List<BinaryMapIndexReader> indexes = new ArrayList<BinaryMapIndexReader>();
List<RandomAccessFile> rafs = new ArrayList<RandomAccessFile>();
for (int i = 0; i < argArr.length; i++) {
String arg = argArr[i];
if (arg.startsWith("--osm=")) {
fosm = new FileOutputStream(arg.substring("--osm=".length()));
} else if (arg.startsWith("--")) {
if (COMPARE_ARGS.containsKey(arg)) {
COMPARE_SET.add(COMPARE_ARGS.get(arg));
} else {
System.out.print("Error: unknown argument");
System.out.println(helpMessage);
System.exit(1);
}
} else {
RandomAccessFile raf = new RandomAccessFile(arg, "r");
BinaryMapIndexReader reader = new BinaryMapIndexReader(raf, new File(arg));
indexes.add(reader);
rafs.add(raf);
}
}
if (COMPARE_SET.isEmpty()) {
COMPARE_SET.addAll(COMPARE_ARGS.values());
}
if (isOsmOutput()) {
fosm.write("<?xml version='1.0' encoding='utf-8'?>\n".getBytes());
fosm.write("<osm version='0.6'>\n".getBytes());
}
Set<Integer> addressCompareSet = new HashSet<Integer>(COMPARE_SET);
addressCompareSet.retainAll(Arrays.asList(ADDRESS_COMPARE));
if (!addressCompareSet.isEmpty()) {
compareAddress(indexes.get(0), indexes.get(1));
}
if (COMPARE_SET.contains(POI_COMPARE) || COMPARE_SET.contains(POI_DETAILS)) {
comparePoi(indexes.get(0), indexes.get(1));
}
if (isOsmOutput()) {
fosm.write("</osm>".getBytes());
fosm.close();
}
}
use of net.osmand.binary.BinaryMapIndexReader in project OsmAnd-tools by osmandapp.
the class BinaryMerger method combineAddressIndex.
private void combineAddressIndex(String name, BinaryMapIndexWriter writer, AddressRegion[] addressRegions, BinaryMapIndexReader[] indexes) throws IOException {
Set<String> attributeTagsTableSet = new TreeSet<String>();
for (int i = 0; i != addressRegions.length; i++) {
AddressRegion region = addressRegions[i];
attributeTagsTableSet.addAll(region.getAttributeTagsTable());
}
writer.startWriteAddressIndex(name, attributeTagsTableSet);
List<String> attributeTagsTable = new ArrayList<String>();
attributeTagsTable.addAll(attributeTagsTableSet);
Map<String, Integer> tagRules = new HashMap<String, Integer>();
Map<String, List<MapObject>> namesIndex = new TreeMap<String, List<MapObject>>(Collator.getInstance());
ListIterator<String> it = attributeTagsTable.listIterator();
while (it.hasNext()) {
tagRules.put(it.next(), it.previousIndex());
}
for (int type : BinaryMapAddressReaderAdapter.CITY_TYPES) {
Map<City, BinaryMapIndexReader> cityMap = new HashMap<City, BinaryMapIndexReader>();
for (int i = 0; i < addressRegions.length; i++) {
AddressRegion region = addressRegions[i];
final BinaryMapIndexReader index = indexes[i];
for (City city : index.getCities(region, null, type)) {
normalizePostcode(city, extractCountryName(index));
if (cityMap.containsKey(city)) {
cityMap.remove(city);
}
cityMap.put(city, index);
}
}
List<City> cities = new ArrayList<City>(cityMap.keySet());
Map<City, List<City>> mergeCityGroup = new HashMap<City, List<City>>();
Collections.sort(cities, MapObject.BY_NAME_COMPARATOR);
mergeCitiesByNameDistance(cities, mergeCityGroup, cityMap, type == BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE);
List<BinaryFileReference> refs = new ArrayList<BinaryFileReference>();
// 1. write cities
writer.startCityBlockIndex(type);
Map<City, Map<Street, List<Node>>> namesakesStreetNodes = new HashMap<City, Map<Street, List<Node>>>();
for (int i = 0; i < cities.size(); i++) {
City city = cities.get(i);
BinaryMapIndexReader rindex = cityMap.get(city);
preloadStreetsAndBuildings(rindex, city, namesakesStreetNodes);
List<City> namesakes = mergeCityGroup.get(city);
if (namesakes != null) {
for (City namesake : namesakes) {
preloadStreetsAndBuildings(cityMap.get(namesake), namesake, namesakesStreetNodes);
city = mergeCities(city, namesake, namesakesStreetNodes);
}
}
int cityType = city.isPostcode() ? -1 : city.getType().ordinal();
BinaryFileReference ref = writer.writeCityHeader(city, cityType, tagRules);
refs.add(ref);
writer.writeCityIndex(city, city.getStreets(), namesakesStreetNodes.get(city), ref, tagRules);
IndexAddressCreator.putNamedMapObject(namesIndex, city, ref.getStartPointer());
if (!city.isPostcode()) {
for (Street s : city.getStreets()) {
IndexAddressCreator.putNamedMapObject(namesIndex, s, s.getFileOffset());
}
}
city.getStreets().clear();
namesakesStreetNodes.clear();
}
writer.endCityBlockIndex();
}
writer.writeAddressNameIndex(namesIndex);
writer.endWriteAddressIndex();
}
use of net.osmand.binary.BinaryMapIndexReader in project OsmAnd-tools by osmandapp.
the class JUnitRouteTest method setupFiles.
@Before
public void setupFiles() throws IOException {
if (rs != null) {
return;
}
// test without native because it is not present on the server
// lib = NativeSwingRendering.getDefaultFromSettings();
RouteResultPreparation.PRINT_TO_CONSOLE_ROUTE_INFORMATION_TO_TEST = true;
String obfdir = System.getenv("OBF_DIR");
if (Algorithms.isEmpty(obfdir)) {
obfdir = DataExtractionSettings.getSettings().getBinaryFilesDir();
}
List<File> files = new ArrayList<File>();
for (File f : new File(obfdir).listFiles()) {
if (f.getName().endsWith(".obf")) {
files.add(f);
}
}
rs = new BinaryMapIndexReader[files.size()];
int it = 0;
for (File f : files) {
// $NON-NLS-1$ //$NON-NLS-2$
RandomAccessFile raf = new RandomAccessFile(f, "r");
rs[it++] = new BinaryMapIndexReader(raf, f);
}
}
use of net.osmand.binary.BinaryMapIndexReader 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;
}
Aggregations