Search in sources :

Example 1 with Building

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

the class IndexAddressCreator method writeCityBlockIndex.

private void writeCityBlockIndex(BinaryMapIndexWriter writer, int type, PreparedStatement streetstat, PreparedStatement waynodesStat, List<City> suburbs, List<City> cities, Map<String, City> postcodes, Map<String, List<MapObject>> namesIndex, Map<String, Integer> tagRules, IProgress progress) throws IOException, SQLException {
    List<BinaryFileReference> refs = new ArrayList<BinaryFileReference>();
    // 1. write cities
    writer.startCityBlockIndex(type);
    for (City c : cities) {
        refs.add(writer.writeCityHeader(c, c.getType().ordinal(), tagRules));
    }
    for (int i = 0; i < cities.size(); i++) {
        City city = cities.get(i);
        BinaryFileReference ref = refs.get(i);
        putNamedMapObject(namesIndex, city, ref.getStartPointer());
        if (type == CITIES_TYPE) {
            progress.progress(1);
        } else {
            if ((cities.size() - i) % 100 == 0) {
                progress.progress(1);
            }
        }
        Map<Street, List<Node>> streetNodes = new LinkedHashMap<Street, List<Node>>();
        List<City> listSuburbs = null;
        if (suburbs != null) {
            for (City suburb : suburbs) {
                if (suburb.getIsInValue().toLowerCase().contains(city.getName().toLowerCase())) {
                    if (listSuburbs == null) {
                        listSuburbs = new ArrayList<City>();
                    }
                    listSuburbs.add(suburb);
                }
            }
        }
        long time = System.currentTimeMillis();
        List<Street> streets = readStreetsBuildings(streetstat, city, waynodesStat, streetNodes, listSuburbs);
        long f = System.currentTimeMillis() - time;
        writer.writeCityIndex(city, streets, streetNodes, ref, tagRules);
        int bCount = 0;
        // register postcodes and name index
        for (Street s : streets) {
            putNamedMapObject(namesIndex, s, s.getFileOffset());
            for (Building b : s.getBuildings()) {
                bCount++;
                if (city.getPostcode() != null && b.getPostcode() == null) {
                    b.setPostcode(city.getPostcode());
                }
                if (b.getPostcode() != null) {
                    if (!postcodes.containsKey(b.getPostcode())) {
                        City p = City.createPostcode(b.getPostcode());
                        p.setLocation(b.getLocation().getLatitude(), b.getLocation().getLongitude());
                        postcodes.put(b.getPostcode(), p);
                    }
                    City post = postcodes.get(b.getPostcode());
                    Street newS = post.getStreetByName(s.getName());
                    if (newS == null) {
                        newS = new Street(post);
                        newS.copyNames(s);
                        newS.setLocation(s.getLocation().getLatitude(), s.getLocation().getLongitude());
                        // newS.getWayNodes().addAll(s.getWayNodes());
                        newS.setId(s.getId());
                        post.registerStreet(newS);
                    }
                    newS.addBuildingCheckById(b);
                }
            }
        }
        if (f > 500) {
            if (logMapDataWarn != null) {
                logMapDataWarn.info("! " + city.getName() + " ! " + f + " ms " + streets.size() + " streets " + bCount + " buildings");
            } else {
                log.info("! " + city.getName() + " ! " + f + " ms " + streets.size() + " streets " + bCount + " buildings");
            }
        }
    }
    writer.endCityBlockIndex();
}
Also used : Building(net.osmand.data.Building) Node(net.osmand.osm.edit.Node) ArrayList(java.util.ArrayList) City(net.osmand.data.City) BinaryFileReference(net.osmand.data.preparation.BinaryFileReference) LinkedHashMap(java.util.LinkedHashMap) SimpleStreet(net.osmand.data.preparation.address.DBStreetDAO.SimpleStreet) Street(net.osmand.data.Street) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with Building

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

the class IndexAddressCreator method indexAddressRelation.

public void indexAddressRelation(Relation i, OsmDbAccessorContext ctx) throws SQLException {
    if ("street".equals(i.getTag(OSMTagKey.TYPE)) || "associatedStreet".equals(i.getTag(OSMTagKey.TYPE))) {
        // $NON-NLS-1$
        LatLon l = null;
        String streetName = null;
        Set<String> isInNames = null;
        ctx.loadEntityRelation(i);
        streetName = i.getTag(OSMTagKey.NAME);
        Iterator<Entity> it = i.getMemberEntities(null).iterator();
        while (l == null && it.hasNext()) {
            // get coordinates from any relation member
            l = it.next().getLatLon();
        }
        isInNames = i.getIsInNames();
        String postcode = i.getTag(OSMTagKey.ADDR_POSTCODE);
        if (streetName == null) {
            // use relation name as a street name
            Collection<Entity> members = i.getMemberEntities("street");
            for (Entity street : members) {
                // find the first street member with name and use it as a street name
                String name = street.getTag(OSMTagKey.NAME);
                if (name != null) {
                    streetName = name;
                    l = street.getLatLon();
                    isInNames = street.getIsInNames();
                    break;
                }
            }
        }
        if (streetName != null) {
            Set<Long> idsOfStreet = getStreetInCity(isInNames, streetName, null, l);
            if (!idsOfStreet.isEmpty()) {
                // both house and address roles can have address
                Collection<Entity> houses = i.getMemberEntities("house");
                houses.addAll(i.getMemberEntities("address"));
                for (Entity house : houses) {
                    String hname = null;
                    String second = null;
                    if (DataExtractionSettings.getSettings().isHousenumberPrefered()) {
                        hname = house.getTag(OSMTagKey.ADDR_HOUSE_NUMBER);
                        second = house.getTag(OSMTagKey.ADDR_HOUSE_NAME);
                    } else {
                        hname = house.getTag(OSMTagKey.ADDR_HOUSE_NAME);
                        second = house.getTag(OSMTagKey.ADDR_HOUSE_NUMBER);
                    }
                    if (hname == null) {
                        hname = second;
                        second = null;
                    }
                    if (hname == null)
                        continue;
                    if (DataExtractionSettings.getSettings().isAdditionalInfo() && second != null)
                        hname += " - [" + second + "]";
                    if (!streetDAO.findBuilding(house)) {
                        // process multipolygon (relation) houses - preload members to create building with correct latlon
                        if (house instanceof Relation)
                            ctx.loadEntityRelation((Relation) house);
                        Building building = EntityParser.parseBuilding(house);
                        if (building.getLocation() == null) {
                            log.warn("building with empty location! id: " + house.getId());
                        } else {
                            building.setName(hname);
                            if (Algorithms.isEmpty(building.getPostcode())) {
                                building.setPostcode(postcode);
                            }
                            streetDAO.writeBuilding(idsOfStreet, building);
                        }
                    }
                }
            }
        }
    }
}
Also used : Building(net.osmand.data.Building) LatLon(net.osmand.data.LatLon) Entity(net.osmand.osm.edit.Entity) Relation(net.osmand.osm.edit.Relation)

Example 3 with Building

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

the class RegionAddressRepositoryBinary method getBuildingByName.

@Override
public Building getBuildingByName(Street street, String name) {
    preloadBuildings(street, null);
    String lang = getLang();
    boolean transliterateNames = isTransliterateNames();
    for (Building b : street.getBuildings()) {
        String bName = b.getName(lang, transliterateNames);
        if (bName.equals(name)) {
            return b;
        }
    }
    return null;
}
Also used : Building(net.osmand.data.Building)

Example 4 with Building

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

the class BinaryInspector method printAddressDetailedInfo.

private void printAddressDetailedInfo(VerboseInfo verbose, BinaryMapIndexReader index, AddressRegion region) throws IOException {
    String[] cityType_String = new String[] { "Cities/Towns section", "Postcodes section", "Villages section" };
    for (int j = 0; j < BinaryMapAddressReaderAdapter.CITY_TYPES.length; j++) {
        int type = BinaryMapAddressReaderAdapter.CITY_TYPES[j];
        final List<City> cities = index.getCities(region, null, type);
        print(MessageFormat.format("\t{0}, {1,number,#} group(s)", cityType_String[j], cities.size()));
        if (BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE == type) {
            if (!verbose.vstreetgroups && !verbose.vcities) {
                println("");
                continue;
            }
        } else if (!verbose.vstreetgroups) {
            println("");
            continue;
        }
        println(":");
        for (City c : cities) {
            int size = index.preloadStreets(c, null);
            List<Street> streets = new ArrayList<Street>(c.getStreets());
            String name = c.getName(verbose.lang);
            if (verbose.vcitynames) {
                boolean includeEnName = verbose.lang == null || !verbose.lang.equals("en");
                name += " " + c.getNamesMap(includeEnName).toString();
            }
            String cityDescription = (type == BinaryMapAddressReaderAdapter.POSTCODES_TYPE ? MessageFormat.format("\t\t''{0}'' {1,number,#} street(s) size {2,number,#} bytes", name, streets.size(), size) : MessageFormat.format("\t\t''{0}'' [{1,number,#}], {2,number,#} street(s) size {3,number,#} bytes", name, c.getId(), streets.size(), size));
            print(cityDescription);
            if (!verbose.vstreets) {
                println("");
                continue;
            }
            println(":");
            if (!verbose.contains(c))
                continue;
            for (Street t : streets) {
                if (!verbose.contains(t))
                    continue;
                index.preloadBuildings(t, null);
                final List<Building> buildings = t.getBuildings();
                final List<Street> intersections = t.getIntersectedStreets();
                println(MessageFormat.format("\t\t\t''{0}'' [{1,number,#}], {2,number,#} building(s), {3,number,#} intersections(s)", new Object[] { t.getName(verbose.lang), t.getId(), buildings.size(), intersections.size() }));
                if (buildings != null && !buildings.isEmpty() && verbose.vbuildings) {
                    println("\t\t\t\tBuildings:");
                    for (Building b : buildings) {
                        println(MessageFormat.format("\t\t\t\t{0} [{1,number,#} {2} ]", new Object[] { b.getName(verbose.lang), b.getId(), b.getPostcode() == null ? "" : b.getPostcode() }));
                    }
                }
                if (intersections != null && !intersections.isEmpty() && verbose.vintersections) {
                    print("\t\t\t\tIntersects with:");
                    for (Street s : intersections) {
                        println("\t\t\t\t\t" + s.getName(verbose.lang));
                    }
                }
            }
        }
    }
}
Also used : Building(net.osmand.data.Building) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) Street(net.osmand.data.Street) MapObject(net.osmand.data.MapObject) City(net.osmand.data.City)

Example 5 with Building

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

the class BinaryMapIndexReader method testAddressJustifySearch.

/**
 * @param reader
 * @throws IOException
 */
/**
 * @param reader
 * @throws IOException
 */
private static void testAddressJustifySearch(BinaryMapIndexReader reader) throws IOException {
    final String streetName = "Logger";
    final double lat = 52.28212d;
    final double lon = 4.86269d;
    // test address index search
    final List<Street> streetsList = new ArrayList<Street>();
    SearchRequest<MapObject> req = buildAddressByNameRequest(new ResultMatcher<MapObject>() {

        @Override
        public boolean publish(MapObject object) {
            if (object instanceof Street && object.getName().equalsIgnoreCase(streetName)) {
                if (MapUtils.getDistance(object.getLocation(), lat, lon) < 20000) {
                    streetsList.add((Street) object);
                    return true;
                }
                return false;
            }
            return false;
        }

        @Override
        public boolean isCancelled() {
            return false;
        }
    }, streetName, StringMatcherMode.CHECK_EQUALS_FROM_SPACE);
    reader.searchAddressDataByName(req);
    TreeMap<MapObject, Street> resMap = new TreeMap<MapObject, Street>(new Comparator<MapObject>() {

        @Override
        public int compare(MapObject o1, MapObject o2) {
            LatLon l1 = o1.getLocation();
            LatLon l2 = o2.getLocation();
            if (l1 == null || l2 == null) {
                return l2 == l1 ? 0 : (l1 == null ? -1 : 1);
            }
            return Double.compare(MapUtils.getDistance(l1, lat, lon), MapUtils.getDistance(l2, lat, lon));
        }
    });
    for (Street s : streetsList) {
        resMap.put(s, s);
        reader.preloadBuildings(s, null);
        for (Building b : s.getBuildings()) {
            if (MapUtils.getDistance(b.getLocation(), lat, lon) < 100) {
                resMap.put(b, s);
            }
        }
    }
    for (MapObject e : resMap.keySet()) {
        Street s = resMap.get(e);
        if (e instanceof Building && MapUtils.getDistance(e.getLocation(), lat, lon) < 40) {
            Building b = (Building) e;
            System.out.println(b.getName() + "   " + s);
        } else if (e instanceof Street) {
            System.out.println(s + "   " + ((Street) s).getCity());
        }
    }
}
Also used : Building(net.osmand.data.Building) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) LatLon(net.osmand.data.LatLon) Street(net.osmand.data.Street) MapObject(net.osmand.data.MapObject)

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