use of net.osmand.data.Building in project Osmand by osmandapp.
the class EntityParser method parseBuilding.
public static Building parseBuilding(Entity e) {
Building b = new Building();
parseMapObject(b, e, e.getTags());
// try to extract postcode
String p = e.getTag(OSMTagKey.ADDR_POSTCODE.getValue());
if (p == null) {
p = e.getTag(OSMTagKey.POSTAL_CODE.getValue());
}
b.setPostcode(p);
if (e instanceof Way) {
List<Node> nodes = ((Way) e).getNodes();
for (int i = 0; i < nodes.size(); i++) {
Node node = nodes.get(i);
if (node != null && "yes".equals(node.getTag(OSMTagKey.ENTRANCE)) && !Algorithms.isEmpty(node.getTag(OSMTagKey.REF))) {
b.addEntrance(node.getTag(OSMTagKey.REF), node.getLatLon());
}
}
}
return b;
}
use of net.osmand.data.Building in project OsmAnd-tools by osmandapp.
the class BinaryMapIndexWriter method createStreetAndBuildings.
protected StreetIndex createStreetAndBuildings(Street street, int cx, int cy, String postcodeFilter, Map<Long, Set<Street>> mapNodeToStreet, Map<Street, List<Node>> wayNodes, Map<String, Integer> tagRules) throws IOException {
checkPeekState(CITY_INDEX_INIT);
StreetIndex.Builder streetBuilder = OsmandOdb.StreetIndex.newBuilder();
streetBuilder.setName(street.getName());
if (checkEnNameToWrite(street)) {
streetBuilder.setNameEn(street.getEnName(false));
}
Iterator<Entry<String, String>> it = street.getNamesMap(false).entrySet().iterator();
while (it.hasNext()) {
Entry<String, String> next = it.next();
Integer intg = tagRules.get("name:" + next.getKey());
if (intg != null) {
streetBuilder.addAttributeTagIds(intg);
streetBuilder.addAttributeValues(next.getValue());
}
}
streetBuilder.setId(street.getId());
int sx = MapUtils.get31TileNumberX(street.getLocation().getLongitude());
int sy = MapUtils.get31TileNumberY(street.getLocation().getLatitude());
streetBuilder.setX((sx - cx) >> 7);
streetBuilder.setY((sy - cy) >> 7);
street.sortBuildings();
for (Building b : street.getBuildings()) {
if (postcodeFilter != null && !postcodeFilter.equalsIgnoreCase(b.getPostcode())) {
continue;
}
OsmandOdb.BuildingIndex.Builder bbuilder = OsmandOdb.BuildingIndex.newBuilder();
int bx = MapUtils.get31TileNumberX(b.getLocation().getLongitude());
int by = MapUtils.get31TileNumberY(b.getLocation().getLatitude());
bbuilder.setX((bx - sx) >> 7);
bbuilder.setY((by - sy) >> 7);
String number2 = b.getName2();
if (!Algorithms.isEmpty(number2)) {
LatLon loc = b.getLatLon2();
if (loc == null) {
bbuilder.setX((bx - sx) >> 7);
bbuilder.setY((by - sy) >> 7);
} else {
int bcx = MapUtils.get31TileNumberX(loc.getLongitude());
int bcy = MapUtils.get31TileNumberY(loc.getLatitude());
bbuilder.setX2((bcx - sx) >> 7);
bbuilder.setY2((bcy - sy) >> 7);
}
bbuilder.setName2(number2);
if (b.getInterpolationType() != null) {
bbuilder.setInterpolation(b.getInterpolationType().getValue());
} else if (b.getInterpolationInterval() > 0) {
bbuilder.setInterpolation(b.getInterpolationInterval());
} else {
bbuilder.setInterpolation(1);
}
}
// bbuilder.setId(b.getId());
bbuilder.setName(b.getName());
if (b.getPostcode() != null) {
bbuilder.setPostcode(b.getPostcode());
}
it = b.getNamesMap(false).entrySet().iterator();
while (it.hasNext()) {
Entry<String, String> next = it.next();
Integer intg = tagRules.get("name:" + next.getKey());
if (intg != null) {
bbuilder.addAttributeTagIds(intg);
bbuilder.addAttributeValues(next.getValue());
}
}
if (checkEnNameToWrite(b)) {
bbuilder.setNameEn(b.getEnName(false));
}
if (postcodeFilter == null && b.getPostcode() != null) {
bbuilder.setPostcode(b.getPostcode());
}
streetBuilder.addBuildings(bbuilder.build());
}
if (wayNodes != null) {
Set<Street> checkedStreets = new TreeSet<Street>();
for (Node intersection : wayNodes.get(street)) {
for (Street streetJ : mapNodeToStreet.get(intersection.getId())) {
if (checkedStreets.contains(streetJ) || streetJ.getId().longValue() == street.getId().longValue()) {
continue;
}
checkedStreets.add(streetJ);
StreetIntersection.Builder builder = OsmandOdb.StreetIntersection.newBuilder();
int ix = MapUtils.get31TileNumberX(intersection.getLongitude());
int iy = MapUtils.get31TileNumberY(intersection.getLatitude());
builder.setIntersectedX((ix - sx) >> 7);
builder.setIntersectedY((iy - sy) >> 7);
builder.setName(streetJ.getName());
if (checkEnNameToWrite(streetJ)) {
builder.setNameEn(streetJ.getEnName(false));
}
it = streetJ.getNamesMap(false).entrySet().iterator();
while (it.hasNext()) {
Entry<String, String> next = it.next();
Integer intg = tagRules.get("name:" + next.getKey());
if (intg != null) {
builder.addAttributeTagIds(intg);
builder.addAttributeValues(next.getValue());
}
}
streetBuilder.addIntersections(builder.build());
}
}
}
return streetBuilder.build();
}
use of net.osmand.data.Building in project OsmAnd-tools by osmandapp.
the class IndexAddressCreator method readStreetsAndBuildingsForCity.
private void readStreetsAndBuildingsForCity(PreparedStatement streetBuildingsStat, City city, PreparedStatement waynodesStat, Map<Street, List<Node>> streetNodes, TLongObjectHashMap<Street> visitedStreets, Map<String, List<Street>> uniqueNames) throws SQLException {
streetBuildingsStat.setLong(1, city.getId());
ResultSet set = streetBuildingsStat.executeQuery();
while (set.next()) {
long streetId = set.getLong(1);
if (!visitedStreets.containsKey(streetId)) {
String streetName = set.getString(2);
Map<String, String> names = Algorithms.decodeMap(set.getString(3));
double lat = set.getDouble(4);
double lon = set.getDouble(5);
// load the street nodes
List<Node> thisWayNodes = loadStreetNodes(streetId, waynodesStat);
if (!uniqueNames.containsKey(streetName)) {
uniqueNames.put(streetName, new ArrayList<Street>());
}
Street street = new Street(city);
uniqueNames.get(streetName).add(street);
street.setLocation(lat, lon);
street.setId(streetId);
// If there are more streets with same name in different districts.
// Add district name to all other names. If sorting is right, the first street was the one in the city
String district = set.getString(12);
String cityPart = district == null || district.equals(city.getName()) ? "" : " (" + district + ")";
street.setName(streetName + cityPart);
for (String lang : names.keySet()) {
street.setName(lang, names.get(lang) + cityPart);
}
streetNodes.put(street, thisWayNodes);
city.registerStreet(street);
// mark the street as visited
visitedStreets.put(streetId, street);
}
if (set.getObject(6) != null) {
Street s = visitedStreets.get(streetId);
Building b = new Building();
b.setId(set.getLong(6));
b.copyNames(set.getString(7), null, Algorithms.decodeMap(set.getString(8)));
b.setLocation(set.getDouble(9), set.getDouble(10));
b.setPostcode(set.getString(11));
b.setName2(set.getString(13));
// no en name2 for now
b.setName2(set.getString(14));
double lat2 = set.getDouble(15);
double lon2 = set.getDouble(16);
if (lat2 != 0 || lon2 != 0) {
b.setLatLon2(new LatLon(lat2, lon2));
}
b.setInterpolationInterval(set.getInt(17));
String type = set.getString(18);
if (type != null) {
b.setInterpolationType(BuildingInterpolation.valueOf(type));
}
s.addBuildingCheckById(b);
}
}
set.close();
}
use of net.osmand.data.Building in project OsmAnd-tools by osmandapp.
the class IndexAddressCreator method iterateMainEntity.
public void iterateMainEntity(Entity e, OsmDbAccessorContext ctx) throws SQLException {
Map<String, String> tags = e.getTags();
// index not only buildings but also nodes that belongs to addr:interpolation ways
// currently not supported because nodes are indexed first with buildings
String interpolation = e.getTag(OSMTagKey.ADDR_INTERPOLATION);
if (e instanceof Way && interpolation != null) {
BuildingInterpolation type = null;
int interpolationInterval = 0;
try {
type = BuildingInterpolation.valueOf(interpolation.toUpperCase());
} catch (RuntimeException ex) {
try {
interpolationInterval = Integer.parseInt(interpolation);
} catch (NumberFormatException ex2) {
}
}
if (type != null || interpolationInterval > 0) {
List<Node> nodesWithHno = new ArrayList<Node>();
for (Node n : ((Way) e).getNodes()) {
if (n.getTag(OSMTagKey.ADDR_HOUSE_NUMBER) != null) {
String strt = n.getTag(OSMTagKey.ADDR_STREET);
if (strt == null) {
strt = n.getTag(OSMTagKey.ADDR_PLACE);
}
if (strt != null) {
nodesWithHno.add(n);
}
}
}
if (nodesWithHno.size() > 1) {
for (int i = 1; i < nodesWithHno.size(); i++) {
Node first = nodesWithHno.get(i - 1);
Node second = nodesWithHno.get(i);
boolean exist = streetDAO.findBuilding(first);
if (exist) {
streetDAO.removeBuilding(first);
}
LatLon l = e.getLatLon();
String strt = first.getTag(OSMTagKey.ADDR_STREET);
if (strt == null) {
strt = first.getTag(OSMTagKey.ADDR_PLACE);
}
Set<Long> idsOfStreet = getStreetInCity(first.getIsInNames(), strt, null, l);
if (!idsOfStreet.isEmpty()) {
Building building = EntityParser.parseBuilding(first);
building.setInterpolationInterval(interpolationInterval);
building.setInterpolationType(type);
building.setName(first.getTag(OSMTagKey.ADDR_HOUSE_NUMBER));
building.setName2(second.getTag(OSMTagKey.ADDR_HOUSE_NUMBER));
building.setLatLon2(second.getLatLon());
streetDAO.writeBuilding(idsOfStreet, building);
}
}
}
}
}
String houseName = e.getTag(OSMTagKey.ADDR_HOUSE_NAME);
String houseNumber = e.getTag(OSMTagKey.ADDR_HOUSE_NUMBER);
String street = null;
if (houseNumber != null) {
street = e.getTag(OSMTagKey.ADDR_STREET);
if (street == null) {
street = e.getTag(OSMTagKey.ADDR_PLACE);
}
}
String street2 = e.getTag(OSMTagKey.ADDR_STREET2);
if ((houseName != null || houseNumber != null)) {
if (e instanceof Relation) {
ctx.loadEntityRelation((Relation) e);
Collection<Entity> outs = ((Relation) e).getMemberEntities("outer");
if (!outs.isEmpty()) {
e = outs.iterator().next();
}
}
// skip relations
boolean exist = e instanceof Relation || streetDAO.findBuilding(e);
if (!exist) {
LatLon l = e.getLatLon();
Set<Long> idsOfStreet = getStreetInCity(e.getIsInNames(), street, null, l);
if (!idsOfStreet.isEmpty()) {
Building building = EntityParser.parseBuilding(e);
String hname = null;
String second = null;
if (DataExtractionSettings.getSettings().isHousenumberPrefered()) {
hname = houseNumber;
second = houseName;
} else {
hname = houseName;
second = houseNumber;
}
if (hname == null) {
hname = second;
second = null;
}
String additionalHname = "";
if (DataExtractionSettings.getSettings().isAdditionalInfo() && second != null)
additionalHname = " - [" + second + "]";
int i = hname.indexOf('-');
if (i != -1 && interpolation != null) {
building.setInterpolationInterval(1);
try {
building.setInterpolationType(BuildingInterpolation.valueOf(interpolation.toUpperCase()));
} catch (RuntimeException ex) {
try {
building.setInterpolationInterval(Integer.parseInt(interpolation));
} catch (NumberFormatException ex2) {
}
}
building.setName(hname.substring(0, i));
building.setName2(hname.substring(i + 1));
} else if ((street2 != null) && !street2.isEmpty()) {
int secondNumber = hname.indexOf('/');
if (secondNumber == -1 || !(secondNumber < hname.length() - 1)) {
building.setName(hname + additionalHname);
} else {
building.setName(hname.substring(0, secondNumber) + additionalHname);
Building building2 = EntityParser.parseBuilding(e);
building2.setName(hname.substring(secondNumber + 1) + additionalHname);
Set<Long> ids2OfStreet = getStreetInCity(e.getIsInNames(), street2, null, l);
// remove duplicated entries!
ids2OfStreet.removeAll(idsOfStreet);
if (!ids2OfStreet.isEmpty()) {
streetDAO.writeBuilding(ids2OfStreet, building2);
} else {
building.setName2(building2.getName() + additionalHname);
}
}
} else {
building.setName(hname + additionalHname);
}
streetDAO.writeBuilding(idsOfStreet, building);
}
}
} else if (e instanceof Way && /* && OSMSettings.wayForCar(e.getTag(OSMTagKey.HIGHWAY)) */
e.getTag(OSMTagKey.HIGHWAY) != null && e.getTag(OSMTagKey.NAME) != null && isStreetTag(e.getTag(OSMTagKey.HIGHWAY))) {
// suppose that streets with names are ways for car
// Ignore all ways that have house numbers and highway type
// if we saved address ways we could checked that we registered before
boolean exist = streetDAO.findStreetNode(e);
// check that street way is not registered already
if (!exist) {
LatLon l = e.getLatLon();
Set<Long> idsOfStreet = getStreetInCity(e.getIsInNames(), e.getTag(OSMTagKey.NAME), getOtherNames(e), l);
if (!idsOfStreet.isEmpty()) {
streetDAO.writeStreetWayNodes(idsOfStreet, (Way) e);
}
}
}
if (e.getTag(OSMTagKey.POSTAL_CODE) != null) {
if ("postal_code".equals(e.getTag(OSMTagKey.BOUNDARY))) {
Boundary boundary = extractBoundary(e, ctx);
if (boundary != null) {
postcodeBoundaries.put(e, boundary);
}
} else if (e instanceof Relation) {
ctx.loadEntityRelation((Relation) e);
postalCodeRelations.add((Relation) e);
}
}
}
use of net.osmand.data.Building in project OsmAnd-tools by osmandapp.
the class BinaryComparator method compareAddress.
private void compareAddress(BinaryMapIndexReader i0, BinaryMapIndexReader i1) throws IOException {
for (int cityType : BinaryMapAddressReaderAdapter.CITY_TYPES) {
List<City> ct0 = i0.getCities(null, cityType);
List<City> ct1 = i1.getCities(null, cityType);
Comparator<City> c = comparator();
Collections.sort(ct0, c);
Collections.sort(ct1, c);
int i = 0;
int j = 0;
printComment("CITY TYPE: " + cityType);
while (i < ct0.size() || j < ct1.size()) {
City c0 = get(ct0, i);
City c1 = get(ct1, j);
int cmp = c.compare(c0, c1);
if (cmp < 0) {
while (c.compare(c0, c1) < 0) {
if (COMPARE_SET.contains(CITY_COMPARE) && COMPARE_SET.contains(COMPARE_UNIQUE_1)) {
City ps = searchSimilarCities(c0, ct1, j);
if (ps != null) {
int distance = (int) MapUtils.getDistance(c0.getLocation(), ps.getLocation());
printMapObject(CITY_COMPARE, c0, "(1). Extra city in 1st file: " + c0 + "( " + distance + " m ) possible duplicate " + ps);
} else {
printMapObject(CITY_COMPARE, c0, "(1)! Extra city in 1st file: " + c0);
}
}
i++;
c0 = get(ct0, i);
}
} else if (cmp > 0) {
while (c.compare(c0, c1) > 0) {
if (COMPARE_SET.contains(CITY_COMPARE) && COMPARE_SET.contains(COMPARE_UNIQUE_2)) {
City ps = searchSimilarCities(c1, ct0, i);
if (ps != null) {
int distance = (int) MapUtils.getDistance(c1.getLocation(), ps.getLocation());
printMapObject(CITY_COMPARE, c1, "(1). Extra city in 2nd file: " + c1 + "( " + distance + " m ) possible duplicate " + ps);
} else {
printMapObject(CITY_COMPARE, c1, "(1)! Extra city in 2nd file: " + c0);
}
}
j++;
c1 = get(ct1, j);
}
} else {
// if(cityType == BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE) {
// System.out.println("Same city " + c1.getName() + " == " + c0.getName());
// }
i++;
j++;
i0.preloadStreets(c0, null);
i1.preloadStreets(c1, null);
if (COMPARE_SET.contains(CITY_NAME_COMPARE) && !c0.getNamesMap(true).equals(c1.getNamesMap(true))) {
printComment("(1). City all names are not same : " + c1 + " " + (new JSONObject(c0.getNamesMap(true)) + " != " + (new JSONObject(c1.getNamesMap(true)))));
}
if (c0.getStreets().size() != c1.getStreets().size()) {
if (COMPARE_SET.contains(STREET_COMPARE)) {
if (!isOsmOutput()) {
printComment("(2). City streets " + c1 + ": " + c0.getStreets().size() + " <> " + c1.getStreets().size());
}
List<String> s0 = new ArrayList<String>();
List<String> s1 = new ArrayList<String>();
for (Street s : c0.getStreets()) {
if (c1.getStreetByName(s.getName()) == null) {
s0.add(s.getName());
if (isOsmOutput()) {
printMapObject(STREET_COMPARE, s, "(2) Street " + s + "is not present in 2nd file");
}
}
}
for (Street s : c1.getStreets()) {
if (c0.getStreetByName(s.getName()) == null) {
if (isOsmOutput()) {
printMapObject(STREET_COMPARE, s, "(2) Street " + s + " is not present in 1st file");
}
s1.add(s.getName());
}
}
if (s0.isEmpty() && s1.isEmpty()) {
// locations of streets are not equal
printMapObject(STREET_COMPARE, c0, "(2) Number of streets with same name is not equal" + c0.getStreets());
} else {
printComment("(2).. " + s0 + "<>" + s1);
}
}
} else {
// compare streets
for (int ij = 0; ij < c1.getStreets().size(); ij++) {
Street s0 = c0.getStreets().get(ij);
Street s1 = c1.getStreets().get(ij);
if (!s0.getNamesMap(true).equals(s1.getNamesMap(true)) && COMPARE_SET.contains(STREET_NAME_COMPARE)) {
printMapObject(STREET_NAME_COMPARE, s0, "(2)- Street all names are not same : " + c1 + " " + s0.getNamesMap(true) + " <> " + s1.getNamesMap(true));
}
if (s0.getName().equals(s1.getName())) {
i0.preloadBuildings(s0, null);
i1.preloadBuildings(s1, null);
if (COMPARE_SET.contains(BUILDINGS_COMPARE)) {
if (s0.getBuildings().size() != s1.getBuildings().size()) {
printMapObject(BUILDINGS_COMPARE, s0, "(3). Buildings size: " + s0.getBuildings().size() + "<>" + s1.getBuildings().size() + " " + c0 + ", " + s0);
} else {
for (int it = 0; it < s0.getBuildings().size(); it++) {
Building b0 = s0.getBuildings().get(it);
Building b1 = s1.getBuildings().get(it);
if (!b0.getName().equals(b1.getName())) {
printMapObject(BUILDINGS_COMPARE, b0, "(4). Buildings name: " + b0.getName() + "<>" + b1.getName() + " " + c0 + ", " + s0);
}
if (!Algorithms.objectEquals(b0.getPostcode(), b1.getPostcode())) {
printMapObject(BUILDINGS_COMPARE, b0, "(4). Buildings postcode: " + b0.getPostcode() + "<>" + b1.getPostcode() + " " + c0 + ", " + s0);
}
}
}
}
if (COMPARE_SET.contains(INTERSECTIONS_COMPARE)) {
if (s0.getIntersectedStreets().size() != s1.getIntersectedStreets().size()) {
printMapObject(INTERSECTIONS_COMPARE, s0, "(5). Intersections size: " + s0.getIntersectedStreets().size() + "<>" + s1.getIntersectedStreets().size() + " " + c0 + ", " + s0);
} else {
Collections.sort(s0.getIntersectedStreets(), MapObject.BY_NAME_COMPARATOR);
Collections.sort(s1.getIntersectedStreets(), MapObject.BY_NAME_COMPARATOR);
for (int it = 0; it < s0.getIntersectedStreets().size(); it++) {
Street st0 = s0.getIntersectedStreets().get(it);
Street st1 = s1.getIntersectedStreets().get(it);
if (!st0.getName().equals(st1.getName())) // || !st0.getNamesMap(true).equals(st1.getNamesMap(true))
{
printMapObject(INTERSECTIONS_COMPARE, st0, "(5). Intersections names <> : " + st0 + "<>" + st1 + " " + c0 + ", " + s0 + " ");
}
if (MapUtils.getDistance(st0.getLocation(), st1.getLocation()) > 1500) {
printMapObject(INTERSECTIONS_COMPARE, st0, "(5). Intersections location <> : " + st0 + "<>" + st1 + " " + c0 + ", " + s0 + " ");
}
}
}
}
} else {
if (COMPARE_SET.contains(STREET_NAME_COMPARE)) {
printMapObject(STREET_NAME_COMPARE, s0, "(3)? Street name order: " + s0 + "!=" + s1 + " " + c0);
}
}
}
}
}
}
}
}
Aggregations