Search in sources :

Example 31 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class BinaryInspector method printPOIDetailInfo.

private void printPOIDetailInfo(VerboseInfo verbose, BinaryMapIndexReader index, PoiRegion p) throws IOException {
    SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(MapUtils.get31TileNumberX(verbose.lonleft), MapUtils.get31TileNumberX(verbose.lonright), MapUtils.get31TileNumberY(verbose.lattop), MapUtils.get31TileNumberY(verbose.latbottom), verbose.getZoom(), BinaryMapIndexReader.ACCEPT_ALL_POI_TYPE_FILTER, new ResultMatcher<Amenity>() {

        @Override
        public boolean publish(Amenity object) {
            Iterator<Entry<String, String>> it = object.getAdditionalInfo().entrySet().iterator();
            String s = "";
            while (it.hasNext()) {
                Entry<String, String> e = it.next();
                if (e.getValue().startsWith(" gz ")) {
                    s += " " + e.getKey() + "=...";
                } else {
                    s += " " + e.getKey() + "=" + e.getValue();
                }
            }
            println(object.getType().getKeyName() + ": " + object.getSubType() + " " + object.getName() + " " + object.getLocation() + " osmid=" + (object.getId() >> 1) + " " + s);
            return false;
        }

        @Override
        public boolean isCancelled() {
            return false;
        }
    });
    index.initCategories(p);
    println("\tRegion: " + p.name);
    println("\t\tBounds " + formatLatBounds(MapUtils.get31LongitudeX(p.left31), MapUtils.get31LongitudeX(p.right31), MapUtils.get31LatitudeY(p.top31), MapUtils.get31LatitudeY(p.bottom31)));
    println("\t\tCategories:");
    for (int i = 0; i < p.categories.size(); i++) {
        println("\t\t\t" + p.categories.get(i));
        for (int j = 0; j < p.subcategories.get(i).size(); j++) println("\t\t\t\t" + p.subcategories.get(i).get(j));
    }
    println("\t\tSubtypes:");
    for (int i = 0; i < p.subTypes.size(); i++) {
        PoiSubType st = p.subTypes.get(i);
        println("\t\t\t" + st.name + " " + (st.text ? "text" : (" encoded " + st.possibleValues.size())));
    }
    // req.poiTypeFilter = null;//for test only
    index.searchPoi(p, req);
}
Also used : Amenity(net.osmand.data.Amenity) Entry(java.util.Map.Entry) PoiSubType(net.osmand.binary.BinaryMapPoiReaderAdapter.PoiSubType) TLongIterator(gnu.trove.iterator.TLongIterator) Iterator(java.util.Iterator) TIntObjectIterator(gnu.trove.iterator.TIntObjectIterator)

Example 32 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class BinaryMapIndexReader method buildSearchPoiRequest.

public static SearchRequest<Amenity> buildSearchPoiRequest(List<Location> route, double radius, SearchPoiTypeFilter poiTypeFilter, ResultMatcher<Amenity> resultMatcher) {
    SearchRequest<Amenity> request = new SearchRequest<Amenity>();
    float coeff = (float) (radius / MapUtils.getTileDistanceWidth(SearchRequest.ZOOM_TO_SEARCH_POI));
    TLongObjectHashMap<List<Location>> zooms = new TLongObjectHashMap<List<Location>>();
    for (int i = 1; i < route.size(); i++) {
        Location cr = route.get(i);
        Location pr = route.get(i - 1);
        double tx = MapUtils.getTileNumberX(SearchRequest.ZOOM_TO_SEARCH_POI, cr.getLongitude());
        double ty = MapUtils.getTileNumberY(SearchRequest.ZOOM_TO_SEARCH_POI, cr.getLatitude());
        double px = MapUtils.getTileNumberX(SearchRequest.ZOOM_TO_SEARCH_POI, pr.getLongitude());
        double py = MapUtils.getTileNumberY(SearchRequest.ZOOM_TO_SEARCH_POI, pr.getLatitude());
        double topLeftX = Math.min(tx, px) - coeff;
        double topLeftY = Math.min(ty, py) - coeff;
        double bottomRightX = Math.max(tx, px) + coeff;
        double bottomRightY = Math.max(ty, py) + coeff;
        for (int x = (int) topLeftX; x <= bottomRightX; x++) {
            for (int y = (int) topLeftY; y <= bottomRightY; y++) {
                long hash = (((long) x) << SearchRequest.ZOOM_TO_SEARCH_POI) + y;
                if (!zooms.containsKey(hash)) {
                    zooms.put(hash, new LinkedList<Location>());
                }
                List<Location> ll = zooms.get(hash);
                ll.add(pr);
                ll.add(cr);
            }
        }
    }
    int sleft = Integer.MAX_VALUE, sright = 0, stop = Integer.MAX_VALUE, sbottom = 0;
    for (long vl : zooms.keys()) {
        long x = (vl >> SearchRequest.ZOOM_TO_SEARCH_POI) << (31 - SearchRequest.ZOOM_TO_SEARCH_POI);
        long y = (vl & ((1 << SearchRequest.ZOOM_TO_SEARCH_POI) - 1)) << (31 - SearchRequest.ZOOM_TO_SEARCH_POI);
        sleft = (int) Math.min(x, sleft);
        stop = (int) Math.min(y, stop);
        sbottom = (int) Math.max(y, sbottom);
        sright = (int) Math.max(x, sright);
    }
    request.radius = radius;
    request.left = sleft;
    request.zoom = -1;
    request.right = sright;
    request.top = stop;
    request.bottom = sbottom;
    request.tiles = zooms;
    request.poiTypeFilter = poiTypeFilter;
    request.resultMatcher = resultMatcher;
    return request;
}
Also used : Amenity(net.osmand.data.Amenity) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) TIntArrayList(gnu.trove.list.array.TIntArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NodeList(org.w3c.dom.NodeList) Location(net.osmand.Location)

Example 33 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class BinaryMapIndexReader method testPoiSearchByName.

private static void testPoiSearchByName(BinaryMapIndexReader reader) throws IOException {
    println("Searching by name...");
    SearchRequest<Amenity> req = buildSearchPoiRequest(0, 0, "Art", 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, null);
    reader.searchPoiByName(req);
    for (Amenity a : req.getSearchResults()) {
        println(a.getType().getTranslation() + " " + a.getSubType() + " " + a.getName() + " " + a.getLocation());
    }
}
Also used : Amenity(net.osmand.data.Amenity)

Example 34 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class BinaryMapPoiReaderAdapter method readPoiData.

private boolean readPoiData(int left31, int right31, int top31, int bottom31, SearchRequest<Amenity> req, PoiRegion region, TLongHashSet toSkip, int zSkip) throws IOException {
    int x = 0;
    int y = 0;
    int zoom = 0;
    boolean read = false;
    while (true) {
        if (req.isCancelled()) {
            return read;
        }
        int t = codedIS.readTag();
        int tag = WireFormat.getTagFieldNumber(t);
        switch(tag) {
            case 0:
                return read;
            case OsmandOdb.OsmAndPoiBoxData.X_FIELD_NUMBER:
                x = codedIS.readUInt32();
                break;
            case OsmandOdb.OsmAndPoiBoxData.ZOOM_FIELD_NUMBER:
                zoom = codedIS.readUInt32();
                break;
            case OsmandOdb.OsmAndPoiBoxData.Y_FIELD_NUMBER:
                y = codedIS.readUInt32();
                break;
            case OsmandOdb.OsmAndPoiBoxData.POIDATA_FIELD_NUMBER:
                int len = codedIS.readRawVarint32();
                int oldLim = codedIS.pushLimit(len);
                Amenity am = readPoiPoint(left31, right31, top31, bottom31, x, y, zoom, req, region, true);
                codedIS.popLimit(oldLim);
                if (am != null) {
                    if (toSkip != null) {
                        int xp = (int) MapUtils.getTileNumberX(zSkip, am.getLocation().getLongitude());
                        int yp = (int) MapUtils.getTileNumberY(zSkip, am.getLocation().getLatitude());
                        long valSkip = (((long) xp) << zSkip) | yp;
                        if (!toSkip.contains(valSkip)) {
                            boolean publish = req.publish(am);
                            if (publish) {
                                read = true;
                                toSkip.add(valSkip);
                            }
                        } else if (zSkip <= zoom) {
                            codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
                            return read;
                        }
                    } else {
                        if (req.publish(am)) {
                            read = true;
                        }
                    }
                }
                break;
            default:
                skipUnknownField(t);
                break;
        }
    }
}
Also used : Amenity(net.osmand.data.Amenity) AmenityRoutePoint(net.osmand.data.Amenity.AmenityRoutePoint)

Example 35 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class BinaryMapPoiReaderAdapter method readPoiData.

private void readPoiData(CollatorStringMatcher matcher, SearchRequest<Amenity> req, PoiRegion region) throws IOException {
    int x = 0;
    int y = 0;
    int zoom = 0;
    while (true) {
        if (req.isCancelled() || req.limitExceeded()) {
            return;
        }
        int t = codedIS.readTag();
        int tag = WireFormat.getTagFieldNumber(t);
        switch(tag) {
            case 0:
                return;
            case OsmandOdb.OsmAndPoiBoxData.X_FIELD_NUMBER:
                x = codedIS.readUInt32();
                break;
            case OsmandOdb.OsmAndPoiBoxData.ZOOM_FIELD_NUMBER:
                zoom = codedIS.readUInt32();
                break;
            case OsmandOdb.OsmAndPoiBoxData.Y_FIELD_NUMBER:
                y = codedIS.readUInt32();
                break;
            case OsmandOdb.OsmAndPoiBoxData.POIDATA_FIELD_NUMBER:
                int len = codedIS.readRawVarint32();
                int oldLim = codedIS.pushLimit(len);
                Amenity am = readPoiPoint(0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, x, y, zoom, req, region, false);
                codedIS.popLimit(oldLim);
                if (am != null) {
                    boolean matches = matcher.matches(am.getName().toLowerCase()) || matcher.matches(am.getEnName(true).toLowerCase());
                    if (!matches) {
                        for (String s : am.getAllNames()) {
                            matches = matcher.matches(s.toLowerCase());
                            if (matches) {
                                break;
                            }
                        }
                        if (!matches) {
                            Map<String, String> lt = am.getAdditionalInfo();
                            for (Entry<String, String> e : lt.entrySet()) {
                                if (!e.getKey().contains("_name")) {
                                    continue;
                                }
                                matches = matcher.matches(e.getValue());
                                if (matches) {
                                    break;
                                }
                            }
                        }
                    }
                    if (matches) {
                        req.publish(am);
                    }
                }
                break;
            default:
                skipUnknownField(t);
                break;
        }
    }
}
Also used : Amenity(net.osmand.data.Amenity) AmenityRoutePoint(net.osmand.data.Amenity.AmenityRoutePoint)

Aggregations

Amenity (net.osmand.data.Amenity)53 LatLon (net.osmand.data.LatLon)17 ArrayList (java.util.ArrayList)11 PoiCategory (net.osmand.osm.PoiCategory)9 AbstractPoiType (net.osmand.osm.AbstractPoiType)8 PoiType (net.osmand.osm.PoiType)8 PointDescription (net.osmand.data.PointDescription)7 Paint (android.graphics.Paint)6 View (android.view.View)6 ImageView (android.widget.ImageView)6 HashMap (java.util.HashMap)6 FavouritePoint (net.osmand.data.FavouritePoint)6 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)5 File (java.io.File)5 Map (java.util.Map)5 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)5 QuadRect (net.osmand.data.QuadRect)5 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 LinearLayout (android.widget.LinearLayout)4