Search in sources :

Example 36 with BinaryMapIndexReader

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);
}
Also used : LatLon(net.osmand.data.LatLon) RoutingContext(net.osmand.router.RoutingContext) RandomAccessFile(java.io.RandomAccessFile) RoutingConfiguration(net.osmand.router.RoutingConfiguration) Builder(net.osmand.router.RoutingConfiguration.Builder) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) FileInputStream(java.io.FileInputStream) RouteSegmentResult(net.osmand.router.RouteSegmentResult)

Example 37 with BinaryMapIndexReader

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();
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) FileOutputStream(java.io.FileOutputStream) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) ArrayList(java.util.ArrayList) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) HashSet(java.util.HashSet)

Example 38 with BinaryMapIndexReader

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();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(net.osmand.osm.edit.Node) ArrayList(java.util.ArrayList) BinaryFileReference(net.osmand.data.preparation.BinaryFileReference) TreeSet(java.util.TreeSet) Street(net.osmand.data.Street) List(java.util.List) ArrayList(java.util.ArrayList) AddressRegion(net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion) MapObject(net.osmand.data.MapObject) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) City(net.osmand.data.City) TreeMap(java.util.TreeMap) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Example 39 with BinaryMapIndexReader

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);
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) ArrayList(java.util.ArrayList) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Before(org.junit.Before)

Example 40 with BinaryMapIndexReader

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;
}
Also used : BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) ResultMatcher(net.osmand.ResultMatcher) LinkedHashMap(java.util.LinkedHashMap) RandomAccessFile(java.io.RandomAccessFile) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) TagValuePair(net.osmand.binary.BinaryMapIndexReader.TagValuePair) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)48 File (java.io.File)26 RandomAccessFile (java.io.RandomAccessFile)25 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)16 List (java.util.List)7 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)7 RoutingConfiguration (net.osmand.router.RoutingConfiguration)7 LinkedHashMap (java.util.LinkedHashMap)6 LatLon (net.osmand.data.LatLon)6 HashMap (java.util.HashMap)5 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)5 MapIndex (net.osmand.binary.BinaryMapIndexReader.MapIndex)5 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)5 City (net.osmand.data.City)5 RoutingContext (net.osmand.router.RoutingContext)5 Point (java.awt.Point)4 FileOutputStream (java.io.FileOutputStream)4 GeocodingResult (net.osmand.binary.GeocodingUtilities.GeocodingResult)4 TLongHashSet (gnu.trove.set.hash.TLongHashSet)3