implement ah shop resolver

git-svn-id: https://osmand.googlecode.com/svn/trunk@454 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-08-16 15:29:45 +00:00
parent b06b43ca9c
commit d1866f90ed
4 changed files with 152 additions and 47 deletions

View file

@ -79,12 +79,14 @@ public class IndexBatchCreator {
protected static final String[] usStates = new String[] {
// "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut",
// "Delaware", "District_of_Columbia", "Florida", "Georgia", "Guantanamo_Bay", "Hawaii",
"Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine",
"Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri",
"Montana", "Nebraska", "Nevada", "New_Hampshire", "New_Jersey", "New_Mexico",
"New_York", "North_Carolina", "North_Dakota", "Ohio", "Oklahoma", "Oregon",
"Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee",
"Texas", "Utah", "Vermont", "Virginia", "Washington", "West_Virginia", "Wisconsin", "Wyoming",
// "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine",
// "Maryland", "Massachusetts", "Michigan",
// TODO
// "Minnesota", "Mississippi", "Missouri",
// "Montana", "Nebraska", "Nevada", "New_Hampshire", "New_Jersey", "New_Mexico",
// "New_York", "North_Carolina", "North_Dakota", "Ohio", "Oklahoma", "Oregon",
// "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee",
// "Texas", "Utah", "Vermont", "Virginia", "Washington", "West_Virginia", "Wisconsin", "Wyoming",
};
protected static final String[] canadaStates = new String[] {
@ -100,10 +102,8 @@ public class IndexBatchCreator {
};
// TODO only australia, new zealand created
// TODO australia out of memory address
protected static final String[] oceania = new String[] {
"Australia",
// "New_Zealand",
// "Australia", "New_Zealand",
// "American_Samoa","Baker_Island","Cocos_Keeling_Islands","Cook_Islands",
// "Federated_States_of_Micronesia","Fiji", "French_Polynesia","Guam","Howland_Island",
// "Independent_State_of_Samoa","Jarvis_Island","Johnston_Atoll","Kiribati",

View file

@ -69,6 +69,12 @@ import com.osmand.swing.DataExtractionSettings;
*/
public class IndexCreator {
private static final Log log = LogFactory.getLog(DataExtraction.class);
// TODO check
// 1. check postal_code if the building was registered by relation!
// TODO normalizing (!!!), lowercase, converting en street names after all!
// TODO find proper location for streets ! centralize them
public static final int BATCH_SIZE = 5000;
public static final String TEMP_NODES_DB = "nodes"+IndexConstants.MAP_INDEX_EXT;
@ -1303,35 +1309,24 @@ public class IndexCreator {
}
// TODO check
// 1. check that not added twice from relations
// 2. check postal_code if the building was registered by relation!
// TODO normalizing (!!!), lowercase, converting en street names after all!
// TODO find proper location for streets ! centralize them
public static void main(String[] args) throws IOException, SAXException, SQLException {
File workDir = new File("e:/Information/OSM maps/osmand/");
File workDir = new File("C:/");
IndexCreator extr = new IndexCreator(workDir);
// extr.setIndexPOI(true);
extr.setIndexPOI(true);
// extr.setIndexTransport(true);
extr.setIndexAddress(true);
extr.setNormalizeStreets(true);
extr.setSaveAddressWays(true);
File file = new File(workDir, "netherlands.odb");
extr.setNodesDBFile(file);
extr.generateIndexes(file, new ConsoleProgressImplementation(2), null);
// extr.generateIndexes(new File("e:/Information/OSM maps/osm_map/netherlands.osm.bz2"), new ConsoleProgressImplementation(2), null);
// extr.generateIndexes(new File("e:/Information/OSM maps/belarus osm/minsk.osm"), new ConsoleProgressImplementation(4), null);
// extr.generateIndexes(new File("e:/Information/OSM maps/belarus osm/belarus_2010_06_02.osm.bz2"), new ConsoleProgressImplementation(4), null);
// extr.setIndexAddress(true);
// extr.setNormalizeStreets(true);
// extr.setSaveAddressWays(true);
// 1. generates using nodes db
// File file = new File(workDir, "nodes.map.odb");
// extr.setNodesDBFile(file);
// extr.generateIndexes(file, new ConsoleProgressImplementation(2), null);
// 2. generates using osm bz2
// extr.generateIndexes(new File("e:/Information/OSM maps/belarus osm/belarus_2010_06_02.osm.bz2"), new ConsoleProgressImplementation(4), null);
}
}

View file

@ -1,5 +1,10 @@
package com.osmand.osm.util;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@ -14,6 +19,9 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.UIManager;
import javax.xml.stream.XMLStreamException;
import org.apache.commons.logging.Log;
@ -25,11 +33,13 @@ import org.json.JSONTokener;
import org.xml.sax.SAXException;
import com.osmand.Algoritms;
import com.osmand.data.DataTileManager;
import com.osmand.impl.ConsoleProgressImplementation;
import com.osmand.osm.Entity;
import com.osmand.osm.EntityInfo;
import com.osmand.osm.LatLon;
import com.osmand.osm.MapUtils;
import com.osmand.osm.Node;
import com.osmand.osm.OpeningHoursParser;
import com.osmand.osm.Entity.EntityId;
import com.osmand.osm.OpeningHoursParser.BasicDayOpeningHourRule;
@ -37,6 +47,9 @@ import com.osmand.osm.OpeningHoursParser.OpeningHoursRule;
import com.osmand.osm.io.IOsmStorageFilter;
import com.osmand.osm.io.OsmBaseStorage;
import com.osmand.osm.io.OsmStorageWriter;
import com.osmand.swing.DataExtractionSettings;
import com.osmand.swing.MapPanel;
import com.osmand.swing.MapPointsLayer;
/**
* Downloads list of Albert Heijn supermarkets and converts them to a map.
@ -119,8 +132,8 @@ public class AHSupermarketResolver {
// this file could be retrieved using xapi
// http://xapi.openstreetmap.org/api/0.6/node[shop=supermarket][bbox=2.5,50,7.8,53.5]
public void updateOSMFile(String pathToOsmFile, String pathToModifiedFile) throws IOException, SAXException, XMLStreamException, JSONException{
// http://xapi.openstreetmap.org/api/0.6/*[shop=supermarket][bbox=2.5,50,7.8,53.5]
public void updateOSMFile(String pathToOsmFile, String pathToModifiedFile, boolean show) throws IOException, SAXException, XMLStreamException, JSONException{
OsmBaseStorage storage = new OsmBaseStorage();
final Map<String, EntityId> winkelNumbers = new LinkedHashMap<String, EntityId>();
@ -128,17 +141,33 @@ public class AHSupermarketResolver {
@Override
public boolean acceptEntityToLoad(OsmBaseStorage storage, EntityId entityId, Entity entity) {
if(entity.getTag("winkelnummer") !=null){
if(entity.getTag("winkelnummer") !=null && entity.getTag("name").contains("eijn")){
winkelNumbers.put(entity.getTag("winkelnummer"), entityId);
return true;
}
return false;
// register all nodes in order to operate with ways
return true;
}
});
storage.parseOSM(new FileInputStream(pathToOsmFile), new ConsoleProgressImplementation(2), null, true);
Map<String, Map<String, Object>> supermarkets = getSupermarkets();
DataTileManager<Entity> deleted = new DataTileManager<Entity>();
for(String s : winkelNumbers.keySet()){
if(!supermarkets.containsKey(s)){
System.err.println("Shop " + s + " id=" +winkelNumbers.get(s) + " doesn't present on the site.");
EntityId e = winkelNumbers.get(s);
Entity en = storage.getRegisteredEntities().get(e);
deleted.registerObject(en.getLatLon().getLatitude(), en.getLatLon().getLongitude(),
en);
}
}
DataTileManager<Entity> notCorrelated = new DataTileManager<Entity>();
DataTileManager<Entity> notShown = new DataTileManager<Entity>();
for(String s : supermarkets.keySet()){
Map<String, Object> props = supermarkets.get(s);
if(winkelNumbers.get(s) != null){
@ -191,7 +220,10 @@ public class AHSupermarketResolver {
double dist = MapUtils.getDistance(e.getLatLon(), real);
if(dist > 150){
// TODO move shop ?
System.err.println("Winkel number = " + s + " is to far from site info - " + dist + " m !!! " + real);
System.err.println("Winkel number = " + s + " is too far from site info - " + dist + " m !!! " + real);
if(dist > 300){
notCorrelated.registerObject(real.getLatitude(), real.getLongitude(), e);
}
}
boolean changed = false;
for(String k : newTags.keySet()){
@ -205,19 +237,73 @@ public class AHSupermarketResolver {
info.setAction("modify");
}
} else {
// TODO add new shop ????
// TODO?
LatLon real = new LatLon((Double)props.get("lat"), (Double) props.get("lng"));
System.err.println("Winkel number = " + s + " is not found in database !!! " + real);
Node n = new Node(real.getLatitude(), real.getLongitude(), -1);
n.putTag("winkelnummer", "REG : " + s);
notShown.registerObject(real.getLatitude(), real.getLongitude(), n);
}
}
OsmStorageWriter writer = new OsmStorageWriter();
writer.saveStorage(new FileOutputStream(pathToModifiedFile), storage, null, true);
if(show){
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
final MapPanel panel = new MapPanel(DataExtractionSettings.getSettings().getTilesDirectory());
panel.setFocusable(true);
MapPointsLayer toAdd = panel.getLayer(MapPointsLayer.class);
toAdd.setPoints(notShown);
toAdd.setPointSize(5);
toAdd.setTagToShow("winkelnummer");
MapPointsLayer red = new MapPointsLayer();
red.setPoints(deleted);
red.setColor(Color.red);
red.setPointSize(5);
panel.addLayer(red);
MapPointsLayer blue = new MapPointsLayer();
blue.setPoints(notCorrelated);
blue.setColor(Color.blue);
blue.setPointSize(4);
panel.addLayer(blue);
JFrame frame = new JFrame("Map view");
frame.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e) {
DataExtractionSettings settings = DataExtractionSettings.getSettings();
settings.saveDefaultLocation(panel.getLatitude(), panel.getLongitude());
settings.saveDefaultZoom(panel.getZoom());
System.exit(0);
}
});
Container content = frame.getContentPane();
content.add(panel, BorderLayout.CENTER);
JMenuBar bar = new JMenuBar();
bar.add(MapPanel.getMenuToChooseSource(panel));
frame.setJMenuBar(bar);
frame.setSize(512, 512);
frame.setVisible(true);
}
}
public static void main(String[] args) throws IOException, SAXException, XMLStreamException, JSONException {
AHSupermarketResolver resolver = new AHSupermarketResolver();
resolver.updateOSMFile("C:/ams_poi.osm", "C:/ams_poi_mod.osm");
resolver.updateOSMFile("e:/Information/OSM maps/osm_map/holl_supermarket.osm", "e:/Information/OSM maps/osm_map/ams_poi_mod.osm",
true);
}
}

View file

@ -7,7 +7,9 @@ import java.awt.geom.AffineTransform;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.osmand.data.DataTileManager;
import com.osmand.osm.Entity;
@ -18,10 +20,16 @@ import com.osmand.osm.Way;
public class MapPointsLayer implements MapPanelLayer {
private MapPanel map;
// special points to draw
private DataTileManager<? extends Entity> points;
private List<Point> pointsToDraw = new ArrayList<Point>();
private Color color = Color.black;
private int size = 3;
private String tagToShow = null;
private Map<Point, String> pointsToDraw = new LinkedHashMap<Point, String>();
private List<Line2D> linesToDraw = new ArrayList<Line2D>();
@Override
@ -31,19 +39,35 @@ public class MapPointsLayer implements MapPanelLayer {
@Override
public void initLayer(MapPanel map) {
this.map = map;
}
public void setColor(Color color){
this.color = color;
}
public void setPointSize(int size){
this.size = size;
}
public void setTagToShow(String tag) {
this.tagToShow = tag;
}
@Override
public void paintLayer(Graphics g) {
g.setColor(Color.black);
g.setColor(color);
// draw user points
for (Point p : pointsToDraw) {
g.drawOval(p.x, p.y, 3, 3);
g.fillOval(p.x, p.y, 3, 3);
for (Point p : pointsToDraw.keySet()) {
g.drawOval(p.x, p.y, size, size);
g.fillOval(p.x, p.y, size, size);
if(tagToShow != null && pointsToDraw.get(p) != null){
g.drawString(pointsToDraw.get(p), p.x, p.y);
}
}
g.setColor(Color.black);
g.setColor(color);
// draw user points
int[] xPoints = new int[4];
int[] yPoints = new int[4];
@ -104,7 +128,7 @@ public class MapPointsLayer implements MapPanelLayer {
int pixX = (int) (MapUtils.getPixelShiftX(map.getZoom(), n.getLongitude(), map.getLongitude(), map.getTileSize()) + map.getCenterPointX());
int pixY = (int) (MapUtils.getPixelShiftY(map.getZoom(), n.getLatitude(), map.getLatitude(), map.getTileSize()) + map.getCenterPointY());
if (pixX >= 0 && pixY >= 0) {
pointsToDraw.add(new Point(pixX, pixY));
pointsToDraw.put(new Point(pixX, pixY), n.getTag(tagToShow));
}
} else {
}