small refactoring
git-svn-id: https://osmand.googlecode.com/svn/trunk@15 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
ad43c7785d
commit
7a408ac70d
14 changed files with 198 additions and 144 deletions
21
DataExtractionOSM/src/com/osmand/Algoritms.java
Normal file
21
DataExtractionOSM/src/com/osmand/Algoritms.java
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
package com.osmand;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic algorithms that are not in jdk
|
||||||
|
*/
|
||||||
|
public class Algoritms {
|
||||||
|
|
||||||
|
public static boolean isEmpty(String s){
|
||||||
|
return s == null || s.length() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean objectEquals(Object a, Object b){
|
||||||
|
if(a == null){
|
||||||
|
return b == null;
|
||||||
|
} else {
|
||||||
|
return a.equals(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,10 +0,0 @@
|
||||||
package com.osmand;
|
|
||||||
|
|
||||||
public interface Constants {
|
|
||||||
|
|
||||||
// TODO externalize proper way
|
|
||||||
public String pathToTestDataDir = "E:\\Information\\OSM maps\\";
|
|
||||||
|
|
||||||
public String ADDR_HOUSE_NUMBER = "addr:housenumber";
|
|
||||||
public String ADDR_STREET = "addr:street";
|
|
||||||
}
|
|
|
@ -52,9 +52,12 @@ import com.osmand.data.Street;
|
||||||
import com.osmand.data.City.CityType;
|
import com.osmand.data.City.CityType;
|
||||||
import com.osmand.osm.Entity;
|
import com.osmand.osm.Entity;
|
||||||
import com.osmand.osm.LatLon;
|
import com.osmand.osm.LatLon;
|
||||||
|
import com.osmand.osm.MapUtils;
|
||||||
import com.osmand.osm.Node;
|
import com.osmand.osm.Node;
|
||||||
|
import com.osmand.osm.OSMSettings;
|
||||||
import com.osmand.osm.Relation;
|
import com.osmand.osm.Relation;
|
||||||
import com.osmand.osm.Way;
|
import com.osmand.osm.Way;
|
||||||
|
import com.osmand.osm.OSMSettings.OSMTagKey;
|
||||||
import com.osmand.osm.io.OsmBaseStorage;
|
import com.osmand.osm.io.OsmBaseStorage;
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,7 +102,7 @@ public class DataExtraction implements IMapLocationListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static boolean parseMinsk = false;
|
private static boolean parseSmallFile = true;
|
||||||
private static boolean parseOSM = true;
|
private static boolean parseOSM = true;
|
||||||
|
|
||||||
///////////////////////////////////////////
|
///////////////////////////////////////////
|
||||||
|
@ -107,11 +110,10 @@ public class DataExtraction implements IMapLocationListener {
|
||||||
public void testReadingOsmFile() throws ParserConfigurationException, SAXException, IOException, XMLStreamException {
|
public void testReadingOsmFile() throws ParserConfigurationException, SAXException, IOException, XMLStreamException {
|
||||||
|
|
||||||
InputStream stream ;
|
InputStream stream ;
|
||||||
if(parseMinsk){
|
if(parseSmallFile){
|
||||||
stream = new FileInputStream(Constants.pathToTestDataDir+"minsk.osm");
|
stream = new FileInputStream(DefaultLauncherConstants.pathToOsmFile);
|
||||||
} else {
|
} else {
|
||||||
stream = new FileInputStream(Constants.pathToTestDataDir+"belarus_2010_04_01.osm.bz2");
|
stream = new FileInputStream(DefaultLauncherConstants.pathToOsmBz2File);
|
||||||
// stream = new FileInputStream(Constants.pathToTestDataDir+"minsk_2010_04_26.osm.bz2");
|
|
||||||
if (stream.read() != 66 || stream.read() != 90)
|
if (stream.read() != 66 || stream.read() != 90)
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"The source stream must start with the characters BZ if it is to be read as a BZip2 stream.");
|
"The source stream must start with the characters BZ if it is to be read as a BZip2 stream.");
|
||||||
|
@ -134,8 +136,8 @@ public class DataExtraction implements IMapLocationListener {
|
||||||
OsmBaseStorage storage = new OsmBaseStorage(){
|
OsmBaseStorage storage = new OsmBaseStorage(){
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptEntityToLoad(Entity e) {
|
public boolean acceptEntityToLoad(Entity e) {
|
||||||
if ("yes".equals(e.getTag("building"))) {
|
if ("yes".equals(e.getTag(OSMTagKey.BUILDING))) {
|
||||||
if (e.getTag(Constants.ADDR_HOUSE_NUMBER) != null && e.getTag(Constants.ADDR_STREET) != null) {
|
if (e.getTag(OSMTagKey.ADDR_HOUSE_NUMBER) != null && e.getTag(OSMTagKey.ADDR_STREET) != null) {
|
||||||
buildings.add(e);
|
buildings.add(e);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -145,14 +147,18 @@ public class DataExtraction implements IMapLocationListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptNodeToLoad(Node n) {
|
public boolean acceptNodeToLoad(Node n) {
|
||||||
if (n.getTag("amenity") != null) {
|
if (n.getTag(OSMTagKey.AMENITY) != null) {
|
||||||
amenities.add(n);
|
amenities.add(n);
|
||||||
} else if (n.getTag("shop") != null) {
|
} else if (n.getTag(OSMTagKey.SHOP) != null) {
|
||||||
n.putTag("amenity", "shop");
|
// TODO temp solution
|
||||||
|
n.putTag(OSMTagKey.AMENITY.getValue(), OSMTagKey.SHOP.getValue());
|
||||||
|
amenities.add(n);
|
||||||
|
} else if (n.getTag(OSMTagKey.LEISURE) != null) {
|
||||||
|
// TODO temp solution
|
||||||
|
n.putTag(OSMTagKey.AMENITY.getValue(), OSMTagKey.LEISURE.getValue());
|
||||||
amenities.add(n);
|
amenities.add(n);
|
||||||
}
|
}
|
||||||
// TODO leisure
|
if (n.getTag(OSMTagKey.PLACE) != null) {
|
||||||
if (n.getTag("place") != null) {
|
|
||||||
places.add(n);
|
places.add(n);
|
||||||
if (places.size() % 500 == 0) System.out.println();
|
if (places.size() % 500 == 0) System.out.println();
|
||||||
System.out.print("-");
|
System.out.print("-");
|
||||||
|
@ -167,7 +173,7 @@ public class DataExtraction implements IMapLocationListener {
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptWayToLoad(Way w) {
|
public boolean acceptWayToLoad(Way w) {
|
||||||
if (WayUtil.wayForCar(w.getTag("highway"))) {
|
if (OSMSettings.wayForCar(w.getTag(OSMTagKey.HIGHWAY))) {
|
||||||
mapWays.add(w);
|
mapWays.add(w);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -186,7 +192,7 @@ public class DataExtraction implements IMapLocationListener {
|
||||||
// 1. found towns !
|
// 1. found towns !
|
||||||
Region country = new Region(null);
|
Region country = new Region(null);
|
||||||
for (Node s : places) {
|
for (Node s : places) {
|
||||||
String place = s.getTag("place");
|
String place = s.getTag(OSMTagKey.PLACE);
|
||||||
if(place == null){
|
if(place == null){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -195,7 +201,7 @@ public class DataExtraction implements IMapLocationListener {
|
||||||
} else {
|
} else {
|
||||||
City registerCity = country.registerCity(s);
|
City registerCity = country.registerCity(s);
|
||||||
if(registerCity == null){
|
if(registerCity == null){
|
||||||
System.out.println(place + " - " + s.getTag("name"));
|
System.out.println(place + " - " + s.getTag(OSMTagKey.NAME));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,12 +239,13 @@ public class DataExtraction implements IMapLocationListener {
|
||||||
|
|
||||||
runUI(country);
|
runUI(country);
|
||||||
List<Long> interestedObjects = new ArrayList<Long>();
|
List<Long> interestedObjects = new ArrayList<Long>();
|
||||||
NodeUtil.fillList(places, interestedObjects);
|
MapUtils.addIdsToList(places, interestedObjects);
|
||||||
NodeUtil.fillList(amenities, interestedObjects);
|
MapUtils.addIdsToList(amenities, interestedObjects);
|
||||||
NodeUtil.fillList(mapWays, interestedObjects);
|
MapUtils.addIdsToList(mapWays, interestedObjects);
|
||||||
// NodeUtil.fillList(buildings, interestedObjects);
|
// MapUtils.addIdsToList(buildings, interestedObjects);
|
||||||
|
if (DefaultLauncherConstants.writeTestOsmFile != null) {
|
||||||
storage.saveStorage(new FileOutputStream("C:/1_tmp.osm"), interestedObjects, true);
|
storage.saveStorage(new FileOutputStream(DefaultLauncherConstants.writeTestOsmFile), interestedObjects, true);
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("USED Memory " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1e6);
|
System.out.println("USED Memory " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1e6);
|
||||||
|
@ -251,7 +258,7 @@ public class DataExtraction implements IMapLocationListener {
|
||||||
|
|
||||||
protected City selectedCity;
|
protected City selectedCity;
|
||||||
|
|
||||||
private MapPanel mapPanel = new MapPanel(new File(Constants.pathToTestDataDir+"MinskTiles"));
|
private MapPanel mapPanel = new MapPanel(new File(DefaultLauncherConstants.pathToDirWithTiles));
|
||||||
|
|
||||||
private DefaultMutableTreeNode amenitiesTree;
|
private DefaultMutableTreeNode amenitiesTree;
|
||||||
private JTree treePlaces;
|
private JTree treePlaces;
|
||||||
|
@ -278,7 +285,7 @@ public class DataExtraction implements IMapLocationListener {
|
||||||
DefaultMutableTreeNode strTree = new DataExtractionTreeNode(str.getName(), str);
|
DefaultMutableTreeNode strTree = new DataExtractionTreeNode(str.getName(), str);
|
||||||
cityNodeTree.add(strTree);
|
cityNodeTree.add(strTree);
|
||||||
for(Entity e : str.getBuildings()){
|
for(Entity e : str.getBuildings()){
|
||||||
DefaultMutableTreeNode building = new DataExtractionTreeNode(e.getTag(Constants.ADDR_HOUSE_NUMBER), e);
|
DefaultMutableTreeNode building = new DataExtractionTreeNode(e.getTag(OSMTagKey.ADDR_HOUSE_NUMBER), e);
|
||||||
strTree.add(building);
|
strTree.add(building);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -357,7 +364,7 @@ public class DataExtraction implements IMapLocationListener {
|
||||||
Node node = ((City)jList.getSelectedValue()).getNode();
|
Node node = ((City)jList.getSelectedValue()).getNode();
|
||||||
String text = "Lat : " + node.getLatitude() + " Lon " + node.getLongitude();
|
String text = "Lat : " + node.getLatitude() + " Lon " + node.getLongitude();
|
||||||
if(selectedCity != null){
|
if(selectedCity != null){
|
||||||
text += " distance " + NodeUtil.getDistance(selectedCity.getNode(), node);
|
text += " distance " + MapUtils.getDistance(selectedCity.getNode(), node);
|
||||||
}
|
}
|
||||||
label.setText(text);
|
label.setText(text);
|
||||||
mapPanel.setLatLon(node.getLatitude(), node.getLongitude());
|
mapPanel.setLatLon(node.getLatitude(), node.getLongitude());
|
||||||
|
@ -417,15 +424,15 @@ public class DataExtraction implements IMapLocationListener {
|
||||||
Collections.sort(closestAmenities, new Comparator<Node>(){
|
Collections.sort(closestAmenities, new Comparator<Node>(){
|
||||||
@Override
|
@Override
|
||||||
public int compare(Node o1, Node o2) {
|
public int compare(Node o1, Node o2) {
|
||||||
return Double.compare(NodeUtil.getDistance(o1, newLatitude, newLongitude),
|
return Double.compare(MapUtils.getDistance(o1, newLatitude, newLongitude),
|
||||||
NodeUtil.getDistance(o2, newLatitude, newLongitude));
|
MapUtils.getDistance(o2, newLatitude, newLongitude));
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Map<String, List<Node>> filter = new TreeMap<String, List<Node>>();
|
Map<String, List<Node>> filter = new TreeMap<String, List<Node>>();
|
||||||
for(Node n : closestAmenities){
|
for(Node n : closestAmenities){
|
||||||
String type = n.getTag("amenity");
|
String type = n.getTag(OSMTagKey.AMENITY);
|
||||||
if(!filter.containsKey(type)){
|
if(!filter.containsKey(type)){
|
||||||
filter.put(type, new ArrayList<Node>());
|
filter.put(type, new ArrayList<Node>());
|
||||||
}
|
}
|
||||||
|
@ -444,9 +451,9 @@ public class DataExtraction implements IMapLocationListener {
|
||||||
|
|
||||||
for(int i=0; i<15 && i < closestAmenities.size(); i++){
|
for(int i=0; i<15 && i < closestAmenities.size(); i++){
|
||||||
Node n = closestAmenities.get(i);
|
Node n = closestAmenities.get(i);
|
||||||
String type = n.getTag("amenity");
|
String type = n.getTag(OSMTagKey.AMENITY);
|
||||||
String name = n.getTag("name");
|
String name = n.getTag(OSMTagKey.NAME);
|
||||||
int dist = (int) (NodeUtil.getDistance(n, newLatitude, newLongitude));
|
int dist = (int) (MapUtils.getDistance(n, newLatitude, newLongitude));
|
||||||
String str = type +" "+(name == null ? n.getId() : name) +" [" +dist+" m ]";
|
String str = type +" "+(name == null ? n.getId() : name) +" [" +dist+" m ]";
|
||||||
((DefaultMutableTreeNode)amenitiesTree.getChildAt(0)).add(
|
((DefaultMutableTreeNode)amenitiesTree.getChildAt(0)).add(
|
||||||
new DataExtractionTreeNode(str, n));
|
new DataExtractionTreeNode(str, n));
|
||||||
|
@ -466,8 +473,8 @@ public class DataExtraction implements IMapLocationListener {
|
||||||
|
|
||||||
p.removeAllChildren();
|
p.removeAllChildren();
|
||||||
for (Node n : filter.get(s)) {
|
for (Node n : filter.get(s)) {
|
||||||
String name = n.getTag("name");
|
String name = n.getTag(OSMTagKey.NAME);
|
||||||
int dist = (int) (NodeUtil.getDistance(n, newLatitude, newLongitude));
|
int dist = (int) (MapUtils.getDistance(n, newLatitude, newLongitude));
|
||||||
String str = (name == null ? n.getId() : name) + " [" + dist + " m ]";
|
String str = (name == null ? n.getId() : name) + " [" + dist + " m ]";
|
||||||
DataExtractionTreeNode node = new DataExtractionTreeNode(str, n);
|
DataExtractionTreeNode node = new DataExtractionTreeNode(str, n);
|
||||||
p.add(node);
|
p.add(node);
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.osmand;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is temp class where all path & machine specific properties are written
|
||||||
|
*/
|
||||||
|
public abstract class DefaultLauncherConstants {
|
||||||
|
|
||||||
|
public static String pathToTestDataDir = "E:\\Information\\OSM maps\\";
|
||||||
|
|
||||||
|
public static String pathToOsmFile = pathToTestDataDir + "minsk.osm";
|
||||||
|
public static String pathToOsmBz2File = pathToTestDataDir + "belarus_2010_04_01.osm.bz2";
|
||||||
|
|
||||||
|
public static String pathToDirWithTiles = pathToTestDataDir +"MinskTiles";
|
||||||
|
|
||||||
|
public static String writeTestOsmFile = "C:\\1_tmp.osm"; // could be null - wo writing
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ import javax.swing.UIManager;
|
||||||
import com.osmand.DataExtraction.ExitListener;
|
import com.osmand.DataExtraction.ExitListener;
|
||||||
import com.osmand.data.DataTileManager;
|
import com.osmand.data.DataTileManager;
|
||||||
import com.osmand.osm.LatLon;
|
import com.osmand.osm.LatLon;
|
||||||
|
import com.osmand.osm.MapUtils;
|
||||||
|
|
||||||
public class MapPanel extends JPanel {
|
public class MapPanel extends JPanel {
|
||||||
|
|
||||||
|
@ -47,8 +48,7 @@ public class MapPanel extends JPanel {
|
||||||
frame.addWindowListener(new ExitListener());
|
frame.addWindowListener(new ExitListener());
|
||||||
Container content = frame.getContentPane();
|
Container content = frame.getContentPane();
|
||||||
|
|
||||||
// MapPanel panel = new MapPanel(new ZipFile(Constants.pathToTestDataDir + "MinskTiles.zipp"));
|
MapPanel panel = new MapPanel(new File(DefaultLauncherConstants.pathToDirWithTiles));
|
||||||
MapPanel panel = new MapPanel(new File(Constants.pathToTestDataDir + "MinskTiles"));
|
|
||||||
|
|
||||||
content.add(panel, BorderLayout.CENTER);
|
content.add(panel, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
@ -98,11 +98,11 @@ public class MapPanel extends JPanel {
|
||||||
|
|
||||||
|
|
||||||
public double getXTile(){
|
public double getXTile(){
|
||||||
return NodeUtil.getTileNumberX(zoom, longitude);
|
return MapUtils.getTileNumberX(zoom, longitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getYTile(){
|
public double getYTile(){
|
||||||
return NodeUtil.getTileNumberY(zoom, latitude);
|
return MapUtils.getTileNumberY(zoom, latitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -208,16 +208,16 @@ public class MapPanel extends JPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(points != null){
|
if(points != null){
|
||||||
double latDown = NodeUtil.getLatitudeFromTile(zoom, yTileDown);
|
double latDown = MapUtils.getLatitudeFromTile(zoom, yTileDown);
|
||||||
double longDown = NodeUtil.getLongitudeFromTile(zoom, xTileRight);
|
double longDown = MapUtils.getLongitudeFromTile(zoom, xTileRight);
|
||||||
double latUp = NodeUtil.getLatitudeFromTile(zoom, yTileUp);
|
double latUp = MapUtils.getLatitudeFromTile(zoom, yTileUp);
|
||||||
double longUp = NodeUtil.getLongitudeFromTile(zoom, xTileLeft);
|
double longUp = MapUtils.getLongitudeFromTile(zoom, xTileLeft);
|
||||||
List<LatLon> objects = points.getObjects(latUp, longUp, latDown, longDown);
|
List<LatLon> objects = points.getObjects(latUp, longUp, latDown, longDown);
|
||||||
pointsToDraw.clear();
|
pointsToDraw.clear();
|
||||||
for(LatLon n : objects){
|
for(LatLon n : objects){
|
||||||
int pixX = NodeUtil.getPixelShiftX(zoom, n.getLongitude(), this.longitude, tileSize) +
|
int pixX = MapUtils.getPixelShiftX(zoom, n.getLongitude(), this.longitude, tileSize) +
|
||||||
getWidth() / 2;
|
getWidth() / 2;
|
||||||
int pixY = NodeUtil.getPixelShiftY(zoom, n.getLatitude(), this.latitude, tileSize) +
|
int pixY = MapUtils.getPixelShiftY(zoom, n.getLatitude(), this.latitude, tileSize) +
|
||||||
getHeight() / 2;
|
getHeight() / 2;
|
||||||
if(pixX >= 0 && pixY >= 0){
|
if(pixX >= 0 && pixY >= 0){
|
||||||
pointsToDraw.add(new Point(pixX, pixY));
|
pointsToDraw.add(new Point(pixX, pixY));
|
||||||
|
@ -302,19 +302,19 @@ public class MapPanel extends JPanel {
|
||||||
if (e.getID() == KeyEvent.KEY_RELEASED) {
|
if (e.getID() == KeyEvent.KEY_RELEASED) {
|
||||||
if (e.getKeyCode() == 37) {
|
if (e.getKeyCode() == 37) {
|
||||||
// LEFT button
|
// LEFT button
|
||||||
longitude = NodeUtil.getLongitudeFromTile(zoom, getXTile()-0.5);
|
longitude = MapUtils.getLongitudeFromTile(zoom, getXTile()-0.5);
|
||||||
processed = true;
|
processed = true;
|
||||||
} else if (e.getKeyCode() == 39) {
|
} else if (e.getKeyCode() == 39) {
|
||||||
// RIGHT button
|
// RIGHT button
|
||||||
longitude = NodeUtil.getLongitudeFromTile(zoom, getXTile()+0.5);
|
longitude = MapUtils.getLongitudeFromTile(zoom, getXTile()+0.5);
|
||||||
processed = true;
|
processed = true;
|
||||||
} else if (e.getKeyCode() == 38) {
|
} else if (e.getKeyCode() == 38) {
|
||||||
// UP button
|
// UP button
|
||||||
latitude = NodeUtil.getLatitudeFromTile(zoom, getYTile()-0.5);
|
latitude = MapUtils.getLatitudeFromTile(zoom, getYTile()-0.5);
|
||||||
processed = true;
|
processed = true;
|
||||||
} else if (e.getKeyCode() == 40) {
|
} else if (e.getKeyCode() == 40) {
|
||||||
// DOWN button
|
// DOWN button
|
||||||
latitude = NodeUtil.getLatitudeFromTile(zoom, getYTile()+0.5);
|
latitude = MapUtils.getLatitudeFromTile(zoom, getYTile()+0.5);
|
||||||
processed = true;
|
processed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -357,8 +357,8 @@ public class MapPanel extends JPanel {
|
||||||
public void dragTo(Point p){
|
public void dragTo(Point p){
|
||||||
double dx = (startDragging.x - (double)p.x)/tileSize;
|
double dx = (startDragging.x - (double)p.x)/tileSize;
|
||||||
double dy = (startDragging.y - (double)p.y)/tileSize;
|
double dy = (startDragging.y - (double)p.y)/tileSize;
|
||||||
double lat = NodeUtil.getLatitudeFromTile(zoom, getYTile() + dy);
|
double lat = MapUtils.getLatitudeFromTile(zoom, getYTile() + dy);
|
||||||
double lon = NodeUtil.getLongitudeFromTile(zoom, getXTile() + dx);
|
double lon = MapUtils.getLongitudeFromTile(zoom, getXTile() + dx);
|
||||||
setLatLon(lat, lon);
|
setLatLon(lat, lon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
package com.osmand;
|
|
||||||
|
|
||||||
public class WayUtil {
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean wayForCar(String tagHighway){
|
|
||||||
if(tagHighway != null){
|
|
||||||
String[] cars = new String[]{"trunk", "motorway", "primary", "secondary", "tertiary", "service", "residential",
|
|
||||||
"trunk_link", "motorway_link", "primary_link", "secondary_link", "residential_link",
|
|
||||||
"tertiary_link", "track" };
|
|
||||||
for(String c : cars){
|
|
||||||
if(c.equals(tagHighway)){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,10 +4,10 @@ import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import com.osmand.NodeUtil;
|
|
||||||
import com.osmand.osm.Entity;
|
import com.osmand.osm.Entity;
|
||||||
import com.osmand.osm.LatLon;
|
import com.osmand.osm.LatLon;
|
||||||
import com.osmand.osm.Node;
|
import com.osmand.osm.Node;
|
||||||
|
import com.osmand.osm.OSMSettings.OSMTagKey;
|
||||||
|
|
||||||
public class City {
|
public class City {
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ public class City {
|
||||||
|
|
||||||
public City(Node el){
|
public City(Node el){
|
||||||
this.el = el;
|
this.el = el;
|
||||||
String place = el.getTag("place");
|
String place = el.getTag(OSMTagKey.PLACE);
|
||||||
for(CityType t : CityType.values()){
|
for(CityType t : CityType.values()){
|
||||||
if(t.name().equalsIgnoreCase(place)){
|
if(t.name().equalsIgnoreCase(place)){
|
||||||
type = t;
|
type = t;
|
||||||
|
@ -40,8 +40,8 @@ public class City {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Street registerBuilding(LatLon point, Entity e){
|
public Street registerBuilding(LatLon point, Entity e){
|
||||||
String number = e.getTag("addr:housenumber");
|
String number = e.getTag(OSMTagKey.ADDR_HOUSE_NUMBER);
|
||||||
String street = e.getTag("addr:street");
|
String street = e.getTag(OSMTagKey.ADDR_STREET);
|
||||||
if( street != null && number != null){
|
if( street != null && number != null){
|
||||||
if(!streets.containsKey(street)){
|
if(!streets.containsKey(street)){
|
||||||
streets.put(street, new Street(street));
|
streets.put(street, new Street(street));
|
||||||
|
@ -54,7 +54,7 @@ public class City {
|
||||||
|
|
||||||
|
|
||||||
public String getName(){
|
public String getName(){
|
||||||
return el.getTag("name");
|
return el.getTag(OSMTagKey.NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CityType getType(){
|
public CityType getType(){
|
||||||
|
|
|
@ -5,7 +5,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.osmand.NodeUtil;
|
import com.osmand.osm.MapUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -39,10 +39,10 @@ public class DataTileManager<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<T> getObjects(double latitudeUp, double longitudeUp, double latitudeDown, double longitudeDown) {
|
public List<T> getObjects(double latitudeUp, double longitudeUp, double latitudeDown, double longitudeDown) {
|
||||||
int tileXUp = (int) NodeUtil.getTileNumberX(zoom, longitudeUp);
|
int tileXUp = (int) MapUtils.getTileNumberX(zoom, longitudeUp);
|
||||||
int tileYUp = (int) NodeUtil.getTileNumberY(zoom, latitudeUp);
|
int tileYUp = (int) MapUtils.getTileNumberY(zoom, latitudeUp);
|
||||||
int tileXDown = (int) NodeUtil.getTileNumberX(zoom, longitudeDown);
|
int tileXDown = (int) MapUtils.getTileNumberX(zoom, longitudeDown);
|
||||||
int tileYDown = (int) NodeUtil.getTileNumberY(zoom, latitudeDown);
|
int tileYDown = (int) MapUtils.getTileNumberY(zoom, latitudeDown);
|
||||||
List<T> result = new ArrayList<T>();
|
List<T> result = new ArrayList<T>();
|
||||||
for (int i = tileXUp; i <= tileXDown; i++) {
|
for (int i = tileXUp; i <= tileXDown; i++) {
|
||||||
for (int j = tileYUp; j <= tileYDown; j++) {
|
for (int j = tileYUp; j <= tileYDown; j++) {
|
||||||
|
@ -58,8 +58,8 @@ public class DataTileManager<T> {
|
||||||
* however the first objects are from closer tile than last
|
* however the first objects are from closer tile than last
|
||||||
*/
|
*/
|
||||||
public List<T> getClosestObjects(double latitude, double longitude, int depth){
|
public List<T> getClosestObjects(double latitude, double longitude, int depth){
|
||||||
int tileX = (int) NodeUtil.getTileNumberX(zoom, longitude);
|
int tileX = (int) MapUtils.getTileNumberX(zoom, longitude);
|
||||||
int tileY = (int) NodeUtil.getTileNumberY(zoom, latitude);
|
int tileY = (int) MapUtils.getTileNumberY(zoom, latitude);
|
||||||
List<T> result = new ArrayList<T>();
|
List<T> result = new ArrayList<T>();
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,8 +97,8 @@ public class DataTileManager<T> {
|
||||||
|
|
||||||
|
|
||||||
public String evaluateTile(double latitude, double longitude){
|
public String evaluateTile(double latitude, double longitude){
|
||||||
int tileX = (int) NodeUtil.getTileNumberX(zoom, longitude);
|
int tileX = (int) MapUtils.getTileNumberX(zoom, longitude);
|
||||||
int tileY = (int) NodeUtil.getTileNumberY(zoom, latitude);
|
int tileY = (int) MapUtils.getTileNumberY(zoom, latitude);
|
||||||
return evTile(tileX, tileY);
|
return evTile(tileX, tileY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,13 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.osmand.NodeUtil;
|
import com.osmand.Algoritms;
|
||||||
import com.osmand.data.City.CityType;
|
import com.osmand.data.City.CityType;
|
||||||
import com.osmand.osm.Entity;
|
import com.osmand.osm.Entity;
|
||||||
import com.osmand.osm.LatLon;
|
import com.osmand.osm.LatLon;
|
||||||
|
import com.osmand.osm.MapUtils;
|
||||||
import com.osmand.osm.Node;
|
import com.osmand.osm.Node;
|
||||||
|
import com.osmand.osm.OSMSettings.OSMTagKey;
|
||||||
|
|
||||||
public class Region {
|
public class Region {
|
||||||
private Entity entity;
|
private Entity entity;
|
||||||
|
@ -35,7 +37,7 @@ public class Region {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName(){
|
public String getName(){
|
||||||
return entity == null ? "" : entity.getTag("name");
|
return entity == null ? "" : entity.getTag(OSMTagKey.NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<City> getCitiesByType(CityType type){
|
public Collection<City> getCitiesByType(CityType type){
|
||||||
|
@ -72,7 +74,7 @@ public class Region {
|
||||||
double relDist = Double.POSITIVE_INFINITY;
|
double relDist = Double.POSITIVE_INFINITY;
|
||||||
for(CityType t : CityType.values()){
|
for(CityType t : CityType.values()){
|
||||||
for(City c : cities.get(t)){
|
for(City c : cities.get(t)){
|
||||||
double rel = NodeUtil.getDistance(c.getNode(), point) / t.getRadius();
|
double rel = MapUtils.getDistance(c.getNode(), point) / t.getRadius();
|
||||||
if(rel < 1) {
|
if(rel < 1) {
|
||||||
return c; // we are in that city
|
return c; // we are in that city
|
||||||
}
|
}
|
||||||
|
@ -95,7 +97,7 @@ public class Region {
|
||||||
|
|
||||||
public City registerCity(Node c){
|
public City registerCity(Node c){
|
||||||
City city = new City(c);
|
City city = new City(c);
|
||||||
if(city.getType() != null && !NodeUtil.isEmpty(city.getName())){
|
if(city.getType() != null && !Algoritms.isEmpty(city.getName())){
|
||||||
cities.get(city.getType()).add(city);
|
cities.get(city.getType()).add(city);
|
||||||
return city;
|
return city;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import java.util.Collections;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.osmand.osm.OSMSettings.OSMTagKey;
|
||||||
|
|
||||||
public abstract class Entity {
|
public abstract class Entity {
|
||||||
// lazy initializing
|
// lazy initializing
|
||||||
private Map<String, String> tags = null;
|
private Map<String, String> tags = null;
|
||||||
|
@ -25,6 +27,10 @@ public abstract class Entity {
|
||||||
return tags.put(key, value);
|
return tags.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTag(OSMTagKey key){
|
||||||
|
return getTag(key.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
public String getTag(String key){
|
public String getTag(String key){
|
||||||
if(tags == null){
|
if(tags == null){
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
package com.osmand;
|
package com.osmand.osm;
|
||||||
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.osmand.osm.Entity;
|
/**
|
||||||
import com.osmand.osm.LatLon;
|
* This utility class includes :
|
||||||
import com.osmand.osm.Node;
|
* 1. distance algorithms
|
||||||
|
* 2. finding center for array of nodes
|
||||||
public class NodeUtil {
|
* 3. tile evaluation algorithms
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MapUtils {
|
||||||
public static double getDistance(Node e1, Node e2){
|
public static double getDistance(Node e1, Node e2){
|
||||||
return getDistance(e1.getLatitude(), e1.getLongitude(), e2.getLatitude(), e2.getLongitude());
|
return getDistance(e1.getLatitude(), e1.getLongitude(), e2.getLatitude(), e2.getLongitude());
|
||||||
}
|
}
|
||||||
|
@ -23,11 +24,6 @@ public class NodeUtil {
|
||||||
return getDistance(e1.getLatitude(), e1.getLongitude(), point.getLatitude(), point.getLongitude());
|
return getDistance(e1.getLatitude(), e1.getLongitude(), point.getLatitude(), point.getLongitude());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void fillList(Collection<? extends Entity> source, List<Long> ids){
|
|
||||||
for(Entity e : source){
|
|
||||||
ids.add(e.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets distance in meters
|
* Gets distance in meters
|
||||||
|
@ -42,6 +38,15 @@ public class NodeUtil {
|
||||||
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
||||||
return R * c * 1000;
|
return R * c * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets distance in meters
|
||||||
|
*/
|
||||||
|
public static double getDistance(LatLon l1, LatLon l2){
|
||||||
|
return getDistance(l1, l2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static LatLon getWeightCenter(Collection<LatLon> nodes){
|
public static LatLon getWeightCenter(Collection<LatLon> nodes){
|
||||||
if(nodes.isEmpty()){
|
if(nodes.isEmpty()){
|
||||||
|
@ -69,18 +74,6 @@ public class NodeUtil {
|
||||||
return new LatLon(latitude/nodes.size(), longitude/nodes.size());
|
return new LatLon(latitude/nodes.size(), longitude/nodes.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LatLon getLatLon(Node n){
|
|
||||||
return new LatLon(n.getLatitude(), n.getLongitude());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets distance in meters
|
|
||||||
*/
|
|
||||||
public static double getDistance(LatLon l1, LatLon l2){
|
|
||||||
return getDistance(l1, l2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,31 +105,18 @@ public class NodeUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getPixelShiftX(int zoom, double long1, double long2, int tileSize){
|
public static int getPixelShiftX(int zoom, double long1, double long2, int tileSize){
|
||||||
return (int) ((NodeUtil.getTileNumberX(zoom, long1) - NodeUtil.getTileNumberX(zoom, long2)) * tileSize);
|
return (int) ((getTileNumberX(zoom, long1) - getTileNumberX(zoom, long2)) * tileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getPixelShiftY(int zoom, double lat1, double lat2, int tileSize){
|
public static int getPixelShiftY(int zoom, double lat1, double lat2, int tileSize){
|
||||||
return (int) ((NodeUtil.getTileNumberY(zoom, lat1) - NodeUtil.getTileNumberY(zoom, lat2)) * tileSize);
|
return (int) ((getTileNumberY(zoom, lat1) - getTileNumberY(zoom, lat2)) * tileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void addIdsToList(Collection<? extends Entity> source, List<Long> ids){
|
||||||
|
for(Entity e : source){
|
||||||
|
ids.add(e.getId());
|
||||||
public static boolean isEmpty(String s){
|
|
||||||
return s == null || s.length() == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean objectEquals(Object a, Object b){
|
|
||||||
if(a == null){
|
|
||||||
return b == null;
|
|
||||||
} else {
|
|
||||||
return a.equals(b);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean tag(Entity e, String name, String value){
|
|
||||||
String tag = e.getTag(name);
|
|
||||||
return value.equals(tag);
|
|
||||||
}
|
|
||||||
}
|
}
|
54
DataExtractionOSM/src/com/osmand/osm/OSMSettings.java
Normal file
54
DataExtractionOSM/src/com/osmand/osm/OSMSettings.java
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
package com.osmand.osm;
|
||||||
|
|
||||||
|
public class OSMSettings {
|
||||||
|
|
||||||
|
public enum OSMTagKey {
|
||||||
|
NAME("name"),
|
||||||
|
// ways
|
||||||
|
HIGHWAY("highway"),
|
||||||
|
BUILDING("building"),
|
||||||
|
|
||||||
|
// address
|
||||||
|
PLACE("place"),
|
||||||
|
ADDR_HOUSE_NUMBER("addr:housenumber"),
|
||||||
|
ADDR_STREET("addr:street"),
|
||||||
|
|
||||||
|
// POI
|
||||||
|
AMENITY("amenity"),
|
||||||
|
SHOP("shop"),
|
||||||
|
LEISURE("leisure"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String value;
|
||||||
|
private OSMTagKey(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum OSMHighwayTypes {
|
||||||
|
TRUNK, MOTORWAY, PRIMARY, SECONDARY, RESIDENTIAL, TERTIARY, SERVICE, TRACK,
|
||||||
|
|
||||||
|
// TODO is link needed?
|
||||||
|
TRUNK_LINK, MOTORWAY_LINK, PRIMARY_LINK, SECONDARY_LINK, RESIDENTIAL_LINK, TERTIARY_LINK, SERVICE_LINK, TRACK_LINK,
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean wayForCar(String tagHighway){
|
||||||
|
if(tagHighway != null){
|
||||||
|
String[] cars = new String[]{"trunk", "motorway", "primary", "secondary", "tertiary", "service", "residential",
|
||||||
|
"trunk_link", "motorway_link", "primary_link", "secondary_link", "residential_link",
|
||||||
|
"tertiary_link", "track" };
|
||||||
|
for(String c : cars){
|
||||||
|
if(c.equals(tagHighway)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,8 +5,6 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.osmand.NodeUtil;
|
|
||||||
|
|
||||||
public class Way extends Entity {
|
public class Way extends Entity {
|
||||||
|
|
||||||
// lazy loading
|
// lazy loading
|
||||||
|
@ -75,7 +73,7 @@ public class Way extends Entity {
|
||||||
list.add(n.getLatLon());
|
list.add(n.getLatLon());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NodeUtil.getWeightCenter(list);
|
return MapUtils.getWeightCenter(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ import javax.xml.parsers.SAXParser;
|
||||||
import javax.xml.parsers.SAXParserFactory;
|
import javax.xml.parsers.SAXParserFactory;
|
||||||
import javax.xml.stream.XMLStreamException;
|
import javax.xml.stream.XMLStreamException;
|
||||||
import javax.xml.stream.XMLStreamWriter;
|
import javax.xml.stream.XMLStreamWriter;
|
||||||
import javax.xml.transform.OutputKeys;
|
|
||||||
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
Loading…
Reference in a new issue