use of net.osmand.data.Building.BuildingInterpolation 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);
}
}
}
Aggregations