2010-04-26 18:24:27 +02:00
|
|
|
package com.osmand.data;
|
2010-04-26 17:20:50 +02:00
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.TreeMap;
|
|
|
|
|
2010-05-16 23:49:11 +02:00
|
|
|
import com.osmand.Algoritms;
|
2010-04-27 14:37:49 +02:00
|
|
|
import com.osmand.osm.Entity;
|
|
|
|
import com.osmand.osm.Node;
|
2010-04-27 23:42:19 +02:00
|
|
|
import com.osmand.osm.OSMSettings.OSMTagKey;
|
2010-04-26 17:20:50 +02:00
|
|
|
|
2010-05-27 13:02:02 +02:00
|
|
|
public class City extends MapObject {
|
2010-04-26 17:20:50 +02:00
|
|
|
|
|
|
|
public enum CityType {
|
2010-05-18 15:36:42 +02:00
|
|
|
// that's tricky way to play with that numbers (to avoid including suburbs in city & vice verse)
|
|
|
|
CITY(10000), TOWN(5000), VILLAGE(1300), HAMLET(1000), SUBURB(300);
|
2010-05-16 23:49:11 +02:00
|
|
|
|
|
|
|
private double radius;
|
|
|
|
|
|
|
|
private CityType(double radius) {
|
|
|
|
this.radius = radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getRadius() {
|
2010-04-26 17:20:50 +02:00
|
|
|
return radius;
|
|
|
|
}
|
2010-05-16 23:49:11 +02:00
|
|
|
|
|
|
|
public static String valueToString(CityType t) {
|
|
|
|
return t.toString().toLowerCase();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static CityType valueFromString(String place) {
|
|
|
|
if (place == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
for (CityType t : CityType.values()) {
|
|
|
|
if (t.name().equalsIgnoreCase(place)) {
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2010-04-26 17:20:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private CityType type = null;
|
2010-05-18 15:36:42 +02:00
|
|
|
// Be attentive ! Working with street names ignoring case
|
2010-04-26 17:20:50 +02:00
|
|
|
private Map<String, Street> streets = new TreeMap<String, Street>();
|
|
|
|
|
|
|
|
public City(Node el){
|
2010-05-17 14:03:16 +02:00
|
|
|
super(el);
|
2010-05-16 23:49:11 +02:00
|
|
|
type = CityType.valueFromString(el.getTag(OSMTagKey.PLACE));
|
|
|
|
}
|
|
|
|
|
|
|
|
public City(CityType type){
|
|
|
|
this.type = type;
|
2010-04-26 17:20:50 +02:00
|
|
|
}
|
|
|
|
|
2010-05-18 15:36:42 +02:00
|
|
|
|
2010-05-14 13:44:35 +02:00
|
|
|
public Street registerStreet(String street){
|
2010-05-18 15:36:42 +02:00
|
|
|
if(!streets.containsKey(street.toLowerCase())){
|
|
|
|
streets.put(street.toLowerCase(), new Street(this, street));
|
2010-05-14 13:44:35 +02:00
|
|
|
}
|
2010-05-18 15:36:42 +02:00
|
|
|
return streets.get(street.toLowerCase());
|
|
|
|
}
|
|
|
|
|
|
|
|
public Street unregisterStreet(String name){
|
|
|
|
return streets.remove(name.toLowerCase());
|
2010-05-14 13:44:35 +02:00
|
|
|
}
|
|
|
|
|
2010-05-27 13:02:02 +02:00
|
|
|
public void removeAllStreets(){
|
|
|
|
streets.clear();
|
|
|
|
}
|
|
|
|
|
2010-05-16 23:49:11 +02:00
|
|
|
public Street registerStreet(Street street){
|
2010-05-18 15:36:42 +02:00
|
|
|
String name = street.getName().toLowerCase();
|
|
|
|
if(!Algoritms.isEmpty(name)){
|
|
|
|
if(!streets.containsKey(name)){
|
|
|
|
return streets.put(name, street);
|
|
|
|
} else {
|
|
|
|
// try to merge streets
|
|
|
|
Street prev = streets.get(name);
|
|
|
|
prev.getWayNodes().addAll(street.getWayNodes());
|
|
|
|
prev.getBuildings().addAll(street.getBuildings());
|
|
|
|
return prev;
|
|
|
|
}
|
2010-05-16 23:49:11 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2010-05-14 23:05:18 +02:00
|
|
|
public Street registerBuilding(Entity e){
|
2010-04-27 23:42:19 +02:00
|
|
|
String number = e.getTag(OSMTagKey.ADDR_HOUSE_NUMBER);
|
|
|
|
String street = e.getTag(OSMTagKey.ADDR_STREET);
|
2010-04-26 17:20:50 +02:00
|
|
|
if( street != null && number != null){
|
2010-05-14 23:05:18 +02:00
|
|
|
registerStreet(street).registerBuilding(e);
|
2010-05-18 15:36:42 +02:00
|
|
|
return streets.get(street.toLowerCase());
|
2010-04-26 17:20:50 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public CityType getType(){
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Collection<Street> getStreets(){
|
|
|
|
return streets.values();
|
|
|
|
}
|
|
|
|
|
2010-05-18 15:36:42 +02:00
|
|
|
public Street getStreet(String name){
|
|
|
|
return streets.get(name.toLowerCase());
|
|
|
|
}
|
|
|
|
|
2010-04-26 17:20:50 +02:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "City [" +type+"] " + getName();
|
|
|
|
}
|
2010-05-14 23:05:18 +02:00
|
|
|
|
|
|
|
public void doDataPreparation(){
|
|
|
|
for(Street s : getStreets()){
|
|
|
|
s.doDataPreparation();
|
|
|
|
}
|
|
|
|
}
|
2010-04-26 17:20:50 +02:00
|
|
|
|
|
|
|
}
|