Search in sources :

Example 1 with City

use of net.osmand.data.City in project OsmAnd-tools by osmandapp.

the class BinaryMapIndexWriter method writeAddressNameIndex.

public void writeAddressNameIndex(Map<String, List<MapObject>> namesIndex) throws IOException {
    checkPeekState(ADDRESS_INDEX_INIT);
    codedOutStream.writeTag(OsmAndAddressIndex.NAMEINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
    preserveInt32Size();
    Map<String, BinaryFileReference> res = writeIndexedTable(OsmAndAddressNameIndexData.TABLE_FIELD_NUMBER, namesIndex.keySet());
    for (Entry<String, List<MapObject>> entry : namesIndex.entrySet()) {
        BinaryFileReference ref = res.get(entry.getKey());
        codedOutStream.writeTag(OsmAndAddressNameIndexData.ATOM_FIELD_NUMBER, FieldType.MESSAGE.getWireType());
        codedOutStream.flush();
        long pointer = getFilePointer();
        if (ref != null) {
            ref.writeReference(raf, getFilePointer());
        }
        AddressNameIndexData.Builder builder = AddressNameIndexData.newBuilder();
        // collapse same name ?
        for (MapObject o : entry.getValue()) {
            AddressNameIndexDataAtom.Builder atom = AddressNameIndexDataAtom.newBuilder();
            // this is optional
            // atom.setName(o.getName());
            // if(checkEnNameToWrite(o)){
            // atom.setNameEn(o.getEnName());
            // }
            int type = 1;
            if (o instanceof City) {
                if (((City) o).isPostcode()) {
                    type = 2;
                } else {
                    CityType ct = ((City) o).getType();
                    if (ct != CityType.CITY && ct != CityType.TOWN) {
                        type = 3;
                    }
                }
            } else if (o instanceof Street) {
                type = 4;
            }
            atom.setType(type);
            LatLon ll = o.getLocation();
            int x = (int) MapUtils.getTileNumberX(16, ll.getLongitude());
            int y = (int) MapUtils.getTileNumberY(16, ll.getLatitude());
            atom.addXy16((x << 16) + y);
            atom.addShiftToIndex((int) (pointer - o.getFileOffset()));
            if (o instanceof Street) {
                atom.addShiftToCityIndex((int) (pointer - ((Street) o).getCity().getFileOffset()));
            }
            builder.addAtom(atom.build());
        }
        codedOutStream.writeMessageNoTag(builder.build());
    }
    int len = writeInt32Size();
    log.info("ADDRESS NAME INDEX SIZE : " + len);
}
Also used : CityType(net.osmand.data.City.CityType) AddressNameIndexDataAtom(net.osmand.binary.OsmandOdb.AddressNameIndexDataAtom) ByteString(com.google.protobuf.ByteString) City(net.osmand.data.City) LatLon(net.osmand.data.LatLon) Street(net.osmand.data.Street) TIntArrayList(gnu.trove.list.array.TIntArrayList) List(java.util.List) ArrayList(java.util.ArrayList) TByteArrayList(gnu.trove.list.array.TByteArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) MapObject(net.osmand.data.MapObject) OsmAndAddressNameIndexData(net.osmand.binary.OsmandOdb.OsmAndAddressNameIndexData) AddressNameIndexData(net.osmand.binary.OsmandOdb.OsmAndAddressNameIndexData.AddressNameIndexData)

Example 2 with City

use of net.osmand.data.City in project OsmAnd-tools by osmandapp.

the class IndexAddressCreator method createMissingCity.

private City createMissingCity(Entity e, CityType t) throws SQLException {
    City c = EntityParser.parseCity(e, t);
    if (c.getLocation() == null) {
        return null;
    }
    // long centerId = e.getId();
    regCity(c, e);
    writeCity(c);
    commitWriteCity();
    return c;
}
Also used : City(net.osmand.data.City)

Example 3 with City

use of net.osmand.data.City in project OsmAnd-tools by osmandapp.

the class IndexAddressCreator method getStreetInCity.

public Set<Long> getStreetInCity(Set<String> isInNames, String name, Map<String, String> names, final LatLon location) throws SQLException {
    if (location == null) {
        return Collections.emptySet();
    }
    name = normalizeStreetName(name);
    Set<City> result = new LinkedHashSet<City>();
    List<City> nearestObjects = new ArrayList<City>();
    nearestObjects.addAll(cityManager.getClosestObjects(location.getLatitude(), location.getLongitude()));
    nearestObjects.addAll(cityVillageManager.getClosestObjects(location.getLatitude(), location.getLongitude()));
    // either we found a city boundary the street is in
    for (City c : nearestObjects) {
        Boundary boundary = cityBoundaries.get(c);
        if (isInNames.contains(c.getName()) || (boundary != null && boundary.containsPoint(location))) {
            result.add(c);
        }
    }
    // or we need to find closest city
    Collections.sort(nearestObjects, new Comparator<City>() {

        @Override
        public int compare(City c1, City c2) {
            double r1 = relativeDistance(location, c1);
            double r2 = relativeDistance(location, c2);
            return Double.compare(r1, r2);
        }
    });
    for (City c : nearestObjects) {
        if (relativeDistance(location, c) > 0.2) {
            if (result.isEmpty()) {
                result.add(c);
            }
            break;
        } else if (!result.contains(c)) {
            // city doesn't have boundary or there is a mistake in boundaries and we found nothing before
            if (!cityBoundaries.containsKey(c) || result.isEmpty()) {
                result.add(c);
            }
        }
    }
    return registerStreetInCities(name, names, location, result);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) City(net.osmand.data.City) Boundary(net.osmand.data.Boundary)

Example 4 with City

use of net.osmand.data.City in project OsmAnd-tools by osmandapp.

the class IndexAddressCreator method readStreetsBuildings.

private List<Street> readStreetsBuildings(PreparedStatement streetBuildingsStat, City city, PreparedStatement waynodesStat, Map<Street, List<Node>> streetNodes, List<City> citySuburbs) throws SQLException {
    TLongObjectHashMap<Street> visitedStreets = new TLongObjectHashMap<Street>();
    Map<String, List<Street>> uniqueNames = new TreeMap<String, List<Street>>(OsmAndCollator.primaryCollator());
    // read streets for city
    readStreetsAndBuildingsForCity(streetBuildingsStat, city, waynodesStat, streetNodes, visitedStreets, uniqueNames);
    // read streets for suburbs of the city
    if (citySuburbs != null) {
        for (City suburb : citySuburbs) {
            readStreetsAndBuildingsForCity(streetBuildingsStat, suburb, waynodesStat, streetNodes, visitedStreets, uniqueNames);
        }
    }
    mergeStreetsWithSameNames(streetNodes, uniqueNames);
    return new ArrayList<Street>(streetNodes.keySet());
}
Also used : ArrayList(java.util.ArrayList) SimpleStreet(net.osmand.data.preparation.address.DBStreetDAO.SimpleStreet) Street(net.osmand.data.Street) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) List(java.util.List) ArrayList(java.util.ArrayList) City(net.osmand.data.City) TreeMap(java.util.TreeMap)

Example 5 with City

use of net.osmand.data.City in project OsmAnd-tools by osmandapp.

the class IndexAddressCreator method findCityPart.

private String findCityPart(LatLon location, City city) {
    String cityPart = city.getName();
    boolean found = false;
    Boundary cityBoundary = cityBoundaries.get(city);
    if (cityBoundary != null) {
        List<City> subcities = boundaryToContainingCities.get(cityBoundary);
        if (subcities != null) {
            for (City subpart : subcities) {
                if (subpart != city) {
                    Boundary subBoundary = cityBoundaries.get(subpart);
                    if (cityBoundary != null && subBoundary != null && subBoundary.getAdminLevel() > cityBoundary.getAdminLevel()) {
                        // old code
                        // subpart.getName();
                        cityPart = findNearestCityOrSuburb(subBoundary, location);
                        // ?FIXME
                        if (subBoundary.containsPoint(location)) {
                            cityPart = subpart.getName();
                            found = true;
                            break;
                        }
                    }
                }
            }
        }
    }
    if (!found) {
        Boundary b = cityBoundaries.get(city);
        cityPart = findNearestCityOrSuburb(b, location);
    }
    return cityPart;
}
Also used : City(net.osmand.data.City) Boundary(net.osmand.data.Boundary)

Aggregations

City (net.osmand.data.City)37 ArrayList (java.util.ArrayList)19 Street (net.osmand.data.Street)14 List (java.util.List)11 LatLon (net.osmand.data.LatLon)10 TIntArrayList (gnu.trove.list.array.TIntArrayList)6 LinkedHashMap (java.util.LinkedHashMap)6 Boundary (net.osmand.data.Boundary)6 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)5 MapObject (net.osmand.data.MapObject)5 Amenity (net.osmand.data.Amenity)4 CityType (net.osmand.data.City.CityType)4 Node (net.osmand.osm.edit.Node)4 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)3 HashMap (java.util.HashMap)3 ResultMatcher (net.osmand.ResultMatcher)3 AddressRegion (net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion)3 Building (net.osmand.data.Building)3 SimpleStreet (net.osmand.data.preparation.address.DBStreetDAO.SimpleStreet)3 AbstractPoiType (net.osmand.osm.AbstractPoiType)3