Search in sources :

Example 11 with Building

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

the class BinaryMapAddressReaderAdapter method readStreet.

protected Street readStreet(Street s, SearchRequest<Building> buildingsMatcher, boolean loadBuildingsAndIntersected, int city24X, int city24Y, String postcodeFilter, List<String> additionalTagsTable) throws IOException {
    int x = 0;
    int y = 0;
    LinkedList<String> additionalTags = null;
    boolean loadLocation = city24X != 0 || city24Y != 0;
    while (true) {
        int t = codedIS.readTag();
        int tag = WireFormat.getTagFieldNumber(t);
        switch(tag) {
            case 0:
                if (loadLocation) {
                    s.setLocation(MapUtils.getLatitudeFromTile(24, y), MapUtils.getLongitudeFromTile(24, x));
                }
                return s;
            case OsmandOdb.StreetIndex.ID_FIELD_NUMBER:
                s.setId(codedIS.readUInt64());
                break;
            case OsmandOdb.StreetIndex.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.StreetIndex.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.StreetIndex.NAME_EN_FIELD_NUMBER:
                s.setEnName(codedIS.readString());
                break;
            case OsmandOdb.StreetIndex.NAME_FIELD_NUMBER:
                s.setName(codedIS.readString());
                break;
            case OsmandOdb.StreetIndex.X_FIELD_NUMBER:
                int sx = codedIS.readSInt32();
                if (loadLocation) {
                    x = sx + city24X;
                } else {
                    x = (int) MapUtils.getTileNumberX(24, s.getLocation().getLongitude());
                }
                break;
            case OsmandOdb.StreetIndex.Y_FIELD_NUMBER:
                int sy = codedIS.readSInt32();
                if (loadLocation) {
                    y = sy + city24Y;
                } else {
                    y = (int) MapUtils.getTileNumberY(24, s.getLocation().getLatitude());
                }
                break;
            case OsmandOdb.StreetIndex.INTERSECTIONS_FIELD_NUMBER:
                int length = codedIS.readRawVarint32();
                if (loadBuildingsAndIntersected) {
                    int oldLimit = codedIS.pushLimit(length);
                    Street si = readIntersectedStreet(s.getCity(), x, y, additionalTagsTable);
                    s.addIntersectedStreet(si);
                    codedIS.popLimit(oldLimit);
                } else {
                    codedIS.skipRawBytes(length);
                }
                break;
            case OsmandOdb.StreetIndex.BUILDINGS_FIELD_NUMBER:
                int offset = codedIS.getTotalBytesRead();
                length = codedIS.readRawVarint32();
                if (loadBuildingsAndIntersected) {
                    int oldLimit = codedIS.pushLimit(length);
                    Building b = readBuilding(offset, x, y, additionalTagsTable);
                    if (postcodeFilter == null || postcodeFilter.equalsIgnoreCase(b.getPostcode())) {
                        if (buildingsMatcher == null || buildingsMatcher.publish(b)) {
                            s.addBuilding(b);
                        }
                    }
                    codedIS.popLimit(oldLimit);
                } else {
                    codedIS.skipRawBytes(length);
                }
                break;
            default:
                skipUnknownField(t);
                break;
        }
    }
}
Also used : Building(net.osmand.data.Building) Street(net.osmand.data.Street)

Example 12 with Building

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

the class BinaryMapAddressReaderAdapter method readBuilding.

protected Building readBuilding(int fileOffset, int street24X, int street24Y, List<String> additionalTagsTable) throws IOException {
    int x = 0;
    int y = 0;
    int x2 = 0;
    int y2 = 0;
    LinkedList<String> additionalTags = null;
    Building b = new Building();
    b.setFileOffset(fileOffset);
    while (true) {
        int t = codedIS.readTag();
        int tag = WireFormat.getTagFieldNumber(t);
        switch(tag) {
            case 0:
                b.setLocation(MapUtils.getLatitudeFromTile(24, y), MapUtils.getLongitudeFromTile(24, x));
                if (x2 != 0 && y2 != 0) {
                    b.setLatLon2(new LatLon(MapUtils.getLatitudeFromTile(24, y2), MapUtils.getLongitudeFromTile(24, x2)));
                }
                return b;
            case OsmandOdb.BuildingIndex.ID_FIELD_NUMBER:
                b.setId(codedIS.readUInt64());
                break;
            case OsmandOdb.BuildingIndex.NAME_EN_FIELD_NUMBER:
                b.setEnName(codedIS.readString());
                break;
            case OsmandOdb.BuildingIndex.NAME_FIELD_NUMBER:
                b.setName(codedIS.readString());
                break;
            case OsmandOdb.BuildingIndex.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.BuildingIndex.ATTRIBUTEVALUES_FIELD_NUMBER:
                String nm = codedIS.readString();
                if (additionalTags != null && additionalTags.size() > 0) {
                    String tg = additionalTags.pollFirst();
                    if (tg.startsWith("name:")) {
                        b.setName(tg.substring("name:".length()), nm);
                    }
                }
                break;
            case OsmandOdb.BuildingIndex.NAME_EN2_FIELD_NUMBER:
                // no where to set now
                codedIS.readString();
                break;
            case OsmandOdb.BuildingIndex.NAME2_FIELD_NUMBER:
                b.setName2(codedIS.readString());
                break;
            case OsmandOdb.BuildingIndex.INTERPOLATION_FIELD_NUMBER:
                int sint = codedIS.readSInt32();
                if (sint > 0) {
                    b.setInterpolationInterval(sint);
                } else {
                    b.setInterpolationType(BuildingInterpolation.fromValue(sint));
                }
                break;
            case OsmandOdb.BuildingIndex.X_FIELD_NUMBER:
                x = codedIS.readSInt32() + street24X;
                break;
            case OsmandOdb.BuildingIndex.X2_FIELD_NUMBER:
                x2 = codedIS.readSInt32() + street24X;
                break;
            case OsmandOdb.BuildingIndex.Y_FIELD_NUMBER:
                y = codedIS.readSInt32() + street24Y;
                break;
            case OsmandOdb.BuildingIndex.Y2_FIELD_NUMBER:
                y2 = codedIS.readSInt32() + street24Y;
                break;
            case OsmandOdb.BuildingIndex.POSTCODE_FIELD_NUMBER:
                b.setPostcode(codedIS.readString());
                break;
            default:
                skipUnknownField(t);
                break;
        }
    }
}
Also used : Building(net.osmand.data.Building) LatLon(net.osmand.data.LatLon)

Example 13 with Building

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

the class GeocodingUtilities method loadStreetBuildings.

private List<GeocodingResult> loadStreetBuildings(final GeocodingResult road, BinaryMapIndexReader reader, GeocodingResult street) throws IOException {
    final List<GeocodingResult> streetBuildings = new ArrayList<GeocodingResult>();
    reader.preloadBuildings(street.street, null);
    log.info("Preload buildings " + street.street.getName() + " " + street.city.getName() + " " + street.street.getId());
    for (Building b : street.street.getBuildings()) {
        if (b.getLatLon2() != null) {
            double slat = b.getLocation().getLatitude();
            double slon = b.getLocation().getLongitude();
            double tolat = b.getLatLon2().getLatitude();
            double tolon = b.getLatLon2().getLongitude();
            double coeff = MapUtils.getProjectionCoeff(road.searchPoint.getLatitude(), road.searchPoint.getLongitude(), slat, slon, tolat, tolon);
            double plat = slat + (tolat - slat) * coeff;
            double plon = slon + (tolon - slon) * coeff;
            if (MapUtils.getDistance(road.searchPoint, plat, plon) < DISTANCE_BUILDING_PROXIMITY) {
                GeocodingResult bld = new GeocodingResult(street);
                bld.building = b;
                // bld.connectionPoint = b.getLocation();
                bld.connectionPoint = new LatLon(plat, plon);
                streetBuildings.add(bld);
                String nm = b.getInterpolationName(coeff);
                if (!Algorithms.isEmpty(nm)) {
                    bld.buildingInterpolation = nm;
                }
            }
        } else if (MapUtils.getDistance(b.getLocation(), road.searchPoint) < DISTANCE_BUILDING_PROXIMITY) {
            GeocodingResult bld = new GeocodingResult(street);
            bld.building = b;
            bld.connectionPoint = b.getLocation();
            streetBuildings.add(bld);
        }
    }
    return streetBuildings;
}
Also used : Building(net.osmand.data.Building) LatLon(net.osmand.data.LatLon) ArrayList(java.util.ArrayList)

Aggregations

Building (net.osmand.data.Building)13 LatLon (net.osmand.data.LatLon)7 Street (net.osmand.data.Street)7 ArrayList (java.util.ArrayList)6 Node (net.osmand.osm.edit.Node)4 City (net.osmand.data.City)3 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 ResultSet (java.sql.ResultSet)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 MapObject (net.osmand.data.MapObject)2 SimpleStreet (net.osmand.data.preparation.address.DBStreetDAO.SimpleStreet)2 Entity (net.osmand.osm.edit.Entity)2 Relation (net.osmand.osm.edit.Relation)2 ByteString (com.google.protobuf.ByteString)1 TLongArrayList (gnu.trove.list.array.TLongArrayList)1 TLongHashSet (gnu.trove.set.hash.TLongHashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Entry (java.util.Map.Entry)1