respect the admin_center of boundary relation

This commit is contained in:
Pavol Zibrita 2012-06-21 21:26:41 +02:00
parent faf00a6c5e
commit e622992acf
3 changed files with 51 additions and 26 deletions

View file

@ -20,6 +20,7 @@ public class Boundary {
private List<Way> outerWays = new ArrayList<Way>(1);
private List<Way> innerWays = new ArrayList<Way>(0);
private boolean closedWay;
private long adminCenterId;
public Boundary(boolean closedWay){
this.closedWay = closedWay;
@ -166,4 +167,12 @@ public class Boundary {
return getName() + " alevel:" + getAdminLevel() + " type: relation closed:" + isClosedWay();
}
public void setAdminCenterId(long l) {
this.adminCenterId = l;
}
public long getAdminCenterId() {
return adminCenterId;
}
}

View file

@ -17,6 +17,7 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -142,7 +143,10 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
City cityFound = null;
String boundaryName = boundary.getName().toLowerCase();
for (City c : citiesToSearch) {
if (boundary.containsPoint(c.getLocation())) {
if (c.getId() == boundary.getAdminCenterId()) {
cityFound = c;
break;
} else if (boundary.containsPoint(c.getLocation())) {
if (boundaryName.equalsIgnoreCase(c.getName())) {
cityFound = c;
break;
@ -239,42 +243,52 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
private Boundary putCityBoundary(Boundary boundary, City cityFound) {
final Boundary oldBoundary = cityBoundaries.get(cityFound);
if (oldBoundary != null) {
if (boundary.getAdminCenterId() == cityFound.getId()
&& badBoundary(cityFound, oldBoundary)) {
cityBoundaries.put(cityFound, boundary);
logBoundaryChanged(boundary, cityFound);
} else
// try to found the biggest area (not small center district)
if (oldBoundary.getAdminLevel() > boundary.getAdminLevel() && !oldBoundary.getName().equalsIgnoreCase(cityFound.getName())) {
if (oldBoundary.getAdminLevel() > boundary.getAdminLevel()
&& badBoundary(cityFound, oldBoundary)) {
cityBoundaries.put(cityFound, boundary);
String s = "City: " + cityFound.getName() + " boundary: " + boundary.getName();
if(logMapDataWarn != null) {
logMapDataWarn.info(s);
} else {
log.info(s);
}
} else if(boundary.getName().equalsIgnoreCase(cityFound.getName()) &&
!oldBoundary.getName().equalsIgnoreCase(cityFound.getName())){
logBoundaryChanged(boundary, cityFound);
} else if (boundary.getName().equalsIgnoreCase(cityFound.getName())
&& badBoundary(cityFound, oldBoundary)) {
cityBoundaries.put(cityFound, boundary);
String s = "City: " + cityFound.getName() + " boundary: " + boundary.getName();
if(logMapDataWarn != null) {
logMapDataWarn.info(s);
} else {
log.info(s);
}
} else if(oldBoundary.getAdminLevel() == boundary.getAdminLevel() &&
oldBoundary != boundary && boundary.getName().equalsIgnoreCase(oldBoundary.getName())){
if(!oldBoundary.isClosedWay() && !boundary.isClosedWay()){
logBoundaryChanged(boundary, cityFound);
} else if (oldBoundary.getAdminLevel() == boundary.getAdminLevel()
&& oldBoundary != boundary
&& boundary.getName().equalsIgnoreCase(
oldBoundary.getName())) {
if (!oldBoundary.isClosedWay() && !boundary.isClosedWay()) {
oldBoundary.getInnerWays().addAll(boundary.getInnerWays());
oldBoundary.getOuterWays().addAll(boundary.getOuterWays());
}
}
} else {
cityBoundaries.put(cityFound, boundary);
if(logMapDataWarn != null) {
logMapDataWarn.info("City: " + cityFound.getName() + " boundary: " + boundary.getName());
} else {
log.info("City: " + cityFound.getName() + " boundary: " + boundary.getName());
}
logBoundaryChanged(boundary, cityFound);
}
return oldBoundary;
}
private boolean badBoundary(City cityFound, final Boundary oldBoundary) {
return oldBoundary.getAdminCenterId() != cityFound.getId() ||
!oldBoundary.getName().equalsIgnoreCase(cityFound.getName());
}
private void logBoundaryChanged(Boundary boundary, City cityFound) {
String s = "City: " + cityFound.getName() + " boundary: " + boundary.getName();
if(logMapDataWarn != null) {
logMapDataWarn.info(s);
} else {
log.info(s);
}
}
private boolean isBoundary(Entity e) {
return "administrative".equals(e.getTag(OSMTagKey.BOUNDARY)) && (e instanceof Relation || e instanceof Way);
}
@ -303,6 +317,8 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
}
boundary.getOuterWays().add((Way) es);
}
} else if (es instanceof Node && ("admin_centre".equals(entities.get(es)) || "admin_center".equals(entities.get(es)))) {
boundary.setAdminCenterId(es.getId());
}
}
boundary.computeIsClosedWay();
@ -521,7 +537,7 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
}
name = normalizeStreetName(name);
Set<City> result = new HashSet<City>();
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()));

View file

@ -58,7 +58,7 @@ public class OSMSettings {
URL("url"), //$NON-NLS-1$
WIKIPEDIA("wikipedia"), //$NON-NLS-1$
ADMIN_LEVEL("admin_level"), //$NON-NLS-1$
ADMIN_LEVEL("admin_level") //$NON-NLS-1$
;
private final String value;