Search in sources :

Example 26 with Street

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

the class BinaryMapAddressReaderAdapter method readIntersectedStreet.

protected Street readIntersectedStreet(City c, int street24X, int street24Y, List<String> additionalTagsTable) throws IOException {
    int x = 0;
    int y = 0;
    Street s = new Street(c);
    LinkedList<String> additionalTags = null;
    while (true) {
        int t = codedIS.readTag();
        int tag = WireFormat.getTagFieldNumber(t);
        switch(tag) {
            case 0:
                s.setLocation(MapUtils.getLatitudeFromTile(24, y), MapUtils.getLongitudeFromTile(24, x));
                return s;
            case OsmandOdb.BuildingIndex.ID_FIELD_NUMBER:
                s.setId(codedIS.readUInt64());
                break;
            case OsmandOdb.StreetIntersection.NAME_EN_FIELD_NUMBER:
                s.setEnName(codedIS.readString());
                break;
            case OsmandOdb.StreetIntersection.NAME_FIELD_NUMBER:
                s.setName(codedIS.readString());
                break;
            case OsmandOdb.StreetIntersection.ATTRIBUTETAGIDS_FIELD_NUMBER:
                int tgid = codedIS.readUInt32();
                if (additionalTags == null) {
                    additionalTags = new LinkedList<String>();
                }
                if (additionalTagsTable != null && tgid < additionalTagsTable.size()) {
                    additionalTags.add(additionalTagsTable.get(tgid));
                }
                break;
            case OsmandOdb.StreetIntersection.ATTRIBUTEVALUES_FIELD_NUMBER:
                String nm = codedIS.readString();
                if (additionalTags != null && additionalTags.size() > 0) {
                    String tg = additionalTags.pollFirst();
                    if (tg.startsWith("name:")) {
                        s.setName(tg.substring("name:".length()), nm);
                    }
                }
                break;
            case OsmandOdb.StreetIntersection.INTERSECTEDX_FIELD_NUMBER:
                x = codedIS.readSInt32() + street24X;
                break;
            case OsmandOdb.StreetIntersection.INTERSECTEDY_FIELD_NUMBER:
                y = codedIS.readSInt32() + street24Y;
                break;
            default:
                skipUnknownField(t);
                break;
        }
    }
}
Also used : Street(net.osmand.data.Street)

Example 27 with Street

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

the class BinaryMapIndexReader method testAddressSearch.

private static void testAddressSearch(BinaryMapIndexReader reader) throws IOException {
    // test address index search
    final Map<String, Integer> streetFreq = new HashMap<String, Integer>();
    List<City> cs = reader.getCities(null, BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE);
    for (City c : cs) {
        int buildings = 0;
        reader.preloadStreets(c, null);
        for (Street s : c.getStreets()) {
            updateFrequence(streetFreq, s.getName());
            reader.preloadBuildings(s, buildAddressRequest((ResultMatcher<Building>) null));
            buildings += s.getBuildings().size();
            println(s.getName() + " " + s.getName("ru"));
        }
        println(c.getName() + " " + c.getLocation() + " " + c.getStreets().size() + " " + buildings + " " + c.getEnName(true) + " " + c.getName("ru"));
    }
    // int[] count = new int[1];
    List<City> villages = reader.getCities(buildAddressRequest((ResultMatcher<City>) null), BinaryMapAddressReaderAdapter.VILLAGES_TYPE);
    for (City v : villages) {
        reader.preloadStreets(v, null);
        for (Street s : v.getStreets()) {
            updateFrequence(streetFreq, s.getName());
        }
    }
    System.out.println("Villages " + villages.size());
    List<String> sorted = new ArrayList<String>(streetFreq.keySet());
    Collections.sort(sorted, new Comparator<String>() {

        @Override
        public int compare(String o1, String o2) {
            return -streetFreq.get(o1) + streetFreq.get(o2);
        }
    });
    System.out.println(streetFreq.size());
    for (String s : sorted) {
        System.out.println(s + "   " + streetFreq.get(s));
        if (streetFreq.get(s) < 10) {
            break;
        }
    }
}
Also used : TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) HashMap(java.util.HashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) City(net.osmand.data.City) ResultMatcher(net.osmand.ResultMatcher) Street(net.osmand.data.Street)

Example 28 with Street

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

the class SearchStreetByNameActivity method filter.

private void filter(String query, Collection<Street> list) {
    boolean emptyQuery = query == null || query.length() == 0;
    List<Street> streetsToSend = new ArrayList<>();
    for (Street obj : list) {
        if (namesFilter.isCancelled) {
            break;
        }
        if (emptyQuery || CollatorStringMatcher.cmatches(collator, obj.getNameWithoutCityPart(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get()), query, StringMatcherMode.CHECK_ONLY_STARTS_WITH)) {
            streetsToSend.add(obj);
        }
        if (!emptyQuery && CollatorStringMatcher.cmatches(collator, obj.getNameWithoutCityPart(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get()), query, StringMatcherMode.CHECK_STARTS_FROM_SPACE_NOT_BEGINNING)) {
            streetsToSend.add(obj);
        }
    }
    final int loopSize = 100;
    for (int i = 0; i < streetsToSend.size(); i += loopSize) {
        int endIndex = i + loopSize;
        if (endIndex > streetsToSend.size()) {
            endIndex = streetsToSend.size();
        }
        List<Street> listToSend = streetsToSend.subList(i, endIndex);
        Message msg = uiHandler.obtainMessage(MESSAGE_ADD_ENTITIES, listToSend);
        msg.sendToTarget();
    }
}
Also used : Message(android.os.Message) ArrayList(java.util.ArrayList) Street(net.osmand.data.Street)

Example 29 with Street

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

the class QuickSearchListFragment method showResult.

public void showResult(SearchResult searchResult) {
    if (searchResult.location != null) {
        OsmandApplication app = getMyApplication();
        String lang = searchResult.requiredSearchPhrase.getSettings().getLang();
        boolean transliterate = searchResult.requiredSearchPhrase.getSettings().isTransliterate();
        PointDescription pointDescription = null;
        Object object = searchResult.object;
        switch(searchResult.objectType) {
            case POI:
                Amenity a = (Amenity) object;
                String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType(a, lang, transliterate);
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat);
                pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(app, a));
                break;
            case RECENT_OBJ:
                HistoryEntry entry = (HistoryEntry) object;
                pointDescription = entry.getName();
                if (pointDescription.isPoi()) {
                    Amenity amenity = app.getSearchUICore().findAmenity(entry.getName().getName(), entry.getLat(), entry.getLon(), lang, transliterate);
                    if (amenity != null) {
                        object = amenity;
                        pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI, OsmAndFormatter.getPoiStringWithoutType(amenity, lang, transliterate));
                        pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(app, amenity));
                    }
                } else if (pointDescription.isFavorite()) {
                    LatLon entryLatLon = new LatLon(entry.getLat(), entry.getLon());
                    List<FavouritePoint> favs = app.getFavorites().getFavouritePoints();
                    for (FavouritePoint f : favs) {
                        if (entryLatLon.equals(new LatLon(f.getLatitude(), f.getLongitude())) && pointDescription.getName().equals(f.getName())) {
                            object = f;
                            pointDescription = f.getPointDescription();
                            break;
                        }
                    }
                }
                break;
            case FAVORITE:
                FavouritePoint fav = (FavouritePoint) object;
                pointDescription = fav.getPointDescription();
                break;
            case VILLAGE:
            case CITY:
                String cityName = searchResult.localeName;
                String typeNameCity = QuickSearchListItem.getTypeName(app, searchResult);
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameCity, cityName);
                pointDescription.setIconName("ic_action_building_number");
                break;
            case STREET:
                String streetName = searchResult.localeName;
                String typeNameStreet = QuickSearchListItem.getTypeName(app, searchResult);
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameStreet, streetName);
                pointDescription.setIconName("ic_action_street_name");
                break;
            case HOUSE:
                String typeNameHouse = null;
                String name = searchResult.localeName;
                if (searchResult.relatedObject instanceof City) {
                    name = ((City) searchResult.relatedObject).getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true) + " " + name;
                } else if (searchResult.relatedObject instanceof Street) {
                    String s = ((Street) searchResult.relatedObject).getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
                    typeNameHouse = ((Street) searchResult.relatedObject).getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
                    name = s + " " + name;
                } else if (searchResult.localeRelatedObjectName != null) {
                    name = searchResult.localeRelatedObjectName + " " + name;
                }
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameHouse, name);
                pointDescription.setIconName("ic_action_building");
                break;
            case LOCATION:
                pointDescription = new PointDescription(searchResult.location.getLatitude(), searchResult.location.getLongitude());
                pointDescription.setIconName("ic_action_world_globe");
                break;
            case STREET_INTERSECTION:
                String typeNameIntersection = QuickSearchListItem.getTypeName(app, searchResult);
                if (Algorithms.isEmpty(typeNameIntersection)) {
                    typeNameIntersection = null;
                }
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameIntersection, QuickSearchListItem.getName(app, searchResult));
                pointDescription.setIconName("ic_action_intersection");
                break;
            case WPT:
                GPXUtilities.WptPt wpt = (GPXUtilities.WptPt) object;
                pointDescription = wpt.getPointDescription(getMyApplication());
                break;
        }
        dialogFragment.hideToolbar();
        dialogFragment.hide();
        showOnMap(getMapActivity(), dialogFragment, searchResult.location.getLatitude(), searchResult.location.getLongitude(), searchResult.preferredZoom, pointDescription, object);
    }
}
Also used : Amenity(net.osmand.data.Amenity) OsmandApplication(net.osmand.plus.OsmandApplication) FavouritePoint(net.osmand.data.FavouritePoint) City(net.osmand.data.City) GPXUtilities(net.osmand.plus.GPXUtilities) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) Street(net.osmand.data.Street) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Street (net.osmand.data.Street)29 ArrayList (java.util.ArrayList)16 City (net.osmand.data.City)14 List (java.util.List)11 LatLon (net.osmand.data.LatLon)10 Node (net.osmand.osm.edit.Node)9 Building (net.osmand.data.Building)7 MapObject (net.osmand.data.MapObject)7 LinkedHashMap (java.util.LinkedHashMap)6 TIntArrayList (gnu.trove.list.array.TIntArrayList)5 Amenity (net.osmand.data.Amenity)5 SimpleStreet (net.osmand.data.preparation.address.DBStreetDAO.SimpleStreet)5 TreeMap (java.util.TreeMap)4 ByteString (com.google.protobuf.ByteString)3 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)3 HashMap (java.util.HashMap)3 TreeSet (java.util.TreeSet)3 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)3 BinaryFileReference (net.osmand.data.preparation.BinaryFileReference)3 Message (android.os.Message)2