use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.
the class IndexCreator method generateRegionsFile.
public static void generateRegionsFile() throws IOException, SQLException, InterruptedException, XmlPullParserException {
MapRenderingTypesEncoder rt = new MapRenderingTypesEncoder("regions");
String file = "/home/victor/projects/osmand/repo/resources/osmand_regions.osm";
String folder = "/home/victor/projects/osmand/repo/resources/countries-info/";
// $NON-NLS-1$
IndexCreator creator = new IndexCreator(new File(folder));
creator.setMapFileName("regions.ocbf");
creator.setIndexMap(true);
creator.setIndexAddress(false);
creator.setIndexPOI(false);
creator.setIndexTransport(false);
creator.setIndexRouting(false);
MapZooms zooms = MapZooms.parseZooms("5-6");
creator.zoomWaySmoothness = 1;
int st = file.lastIndexOf('/');
int e = file.indexOf('.', st);
creator.setNodesDBFile(new File(folder + file.substring(st, e) + ".tmp.odb"));
creator.generateIndexes(new File(file), new ConsoleProgressImplementation(1), null, zooms, rt, log);
}
use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.
the class FixBasemapRoads method parseOsmFile.
private OsmBaseStorage parseOsmFile(File read) throws FileNotFoundException, IOException, XmlPullParserException {
OsmBaseStorage storage = new OsmBaseStorage();
InputStream stream = new BufferedInputStream(new FileInputStream(read), 8192 * 4);
InputStream streamFile = stream;
if (read.getName().endsWith(".bz2")) {
// $NON-NLS-1$
if (stream.read() != 'B' || stream.read() != 'Z') {
// throw new RuntimeException("The source stream must start with the characters BZ if it is to be read as a BZip2 stream."); //$NON-NLS-1$
} else {
stream = new CBZip2InputStream(stream);
}
} else if (read.getName().endsWith(".gz")) {
// $NON-NLS-1$
stream = new GZIPInputStream(stream);
}
storage.parseOSM(stream, new ConsoleProgressImplementation(), streamFile, true);
return storage;
}
use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.
the class FixLinkedCoastline method process.
private static void process(File read, File write) throws IOException, XMLStreamException, XmlPullParserException {
OsmBaseStorage storage = new OsmBaseStorage();
storage.parseOSM(new FileInputStream(read), new ConsoleProgressImplementation());
Map<EntityId, Entity> entities = new HashMap<EntityId, Entity>(storage.getRegisteredEntities());
List<EntityId> toWrite = new ArrayList<EntityId>();
for (EntityId e : entities.keySet()) {
if (e.getType() == EntityType.WAY) {
Entity oldWay = storage.getRegisteredEntities().remove(e);
List<Way> result = processWay((Way) oldWay);
alignAndAddtoStorage(storage, toWrite, result);
}
}
System.out.println("ERROR Ways : ");
int errors = 0;
for (List<Way> w : endWays.values()) {
Way way = w.get(0);
Way lway = w.get(w.size() - 1);
LatLon first = way.getNodes().get(0).getLatLon();
LatLon last = lway.getNodes().get(lway.getNodes().size() - 1).getLatLon();
double dist = MapUtils.getDistance(first, last);
if (dist < 500000) {
alignAndAddtoStorage(storage, toWrite, w);
} else {
errors++;
String val = "First " + first + "Last " + last + " id " + way.getId() + " dist " + MapUtils.getDistance(first, last) + " m";
System.out.println("Ways in chain - " + w.size() + " - " + val);
}
}
System.out.println("Fixed errors : " + ERRORS + ", errors not fixed : " + errors);
OsmStorageWriter writer = new OsmStorageWriter();
/*Set<Long> ls = new HashSet<Long>();
for(EntityId e : toWrite) {
if(!ls.add(e.getId())) {
System.out.println("!!" + e.getId());
}
}*/
writer.saveStorage(new FileOutputStream(write), storage, toWrite, true);
}
use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.
the class AHSupermarketResolver method updateOSMFile.
// this file could be retrieved using xapi
// 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, XMLStreamException, JSONException, XmlPullParserException {
OsmBaseStorage storage = new OsmBaseStorage();
final Map<String, EntityId> winkelNumbers = new LinkedHashMap<String, EntityId>();
storage.getFilters().add(new IOsmStorageFilter() {
@Override
public boolean acceptEntityToLoad(OsmBaseStorage storage, EntityId entityId, Entity entity) {
if (entity.getTag("winkelnummer") != null && entity.getTag("name").contains("eijn")) {
winkelNumbers.put(entity.getTag("winkelnummer"), entityId);
return true;
}
// 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) {
EntityId id = winkelNumbers.get(s);
Entity e = storage.getRegisteredEntities().get(id);
EntityInfo info = storage.getRegisteredEntityInfo().get(id);
Map<String, String> newTags = new LinkedHashMap<String, String>();
String p = String.valueOf(props.get("format"));
// IMPORTANT : comment what information should be updated or check
String name = "Albert Heijn";
if (!p.equals("AH")) {
name += " " + p;
}
newTags.put("name", name);
newTags.put("phone", String.valueOf(props.get("phone")));
newTags.put("addr:city", String.valueOf(props.get("city")));
newTags.put("addr:street", String.valueOf(props.get("street")));
newTags.put("addr:housenumber", String.valueOf(props.get("housenr")));
newTags.put("addr:postcode", String.valueOf(props.get("zip")));
JSONArray o = (JSONArray) props.get("hours");
OpeningHoursParser.OpeningHours rules = new OpeningHoursParser.OpeningHours();
BasicOpeningHourRule prev = null;
for (int i = 0; i < 7; i++) {
JSONObject obj = o.getJSONObject(i);
if (!obj.isNull("C") && obj.getBoolean("C")) {
} else {
String opened = String.valueOf(obj.get("F"));
String closed = String.valueOf(obj.get("U"));
int start = Integer.parseInt(opened.substring(0, 2)) * 60 + Integer.parseInt(opened.substring(2));
int end = Integer.parseInt(closed.substring(0, 2)) * 60 + Integer.parseInt(closed.substring(2));
if (prev != null && prev.getStartTime() == start && prev.getEndTime() == end) {
prev.getDays()[i] = true;
} else {
BasicOpeningHourRule rule = new OpeningHoursParser.BasicOpeningHourRule();
rule.getDays()[i] = true;
rule.addTimeRange(start, end);
prev = rule;
rules.addRule(rule);
}
}
}
newTags.put("opening_hours", rules.toString());
// Check distance to info
LatLon real = new LatLon((Double) props.get("lat"), (Double) props.get("lng"));
double dist = MapUtils.getDistance(e.getLatLon(), real);
if (dist > 150) {
// TODO move shop ?
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()) {
String val = newTags.get(k);
if (!Algorithms.objectEquals(val, e.getTag(k))) {
e.putTag(k, val);
changed = true;
}
}
if (changed) {
info.setAction("modify");
}
} else {
// 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);
}
}
use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.
the class CombineSRTMIntoFile method process.
private static void process(BinaryMapDataObject country, List<BinaryMapDataObject> boundaries, String downloadName, File directoryWithSRTMFiles, File directoryWithTargetFiles, boolean dryRun) throws IOException, SQLException, InterruptedException, IllegalArgumentException, XmlPullParserException {
final String suffix = "_" + IndexConstants.BINARY_MAP_VERSION + IndexConstants.BINARY_SRTM_MAP_INDEX_EXT;
String name = country.getName();
final File targetFile = new File(directoryWithTargetFiles, Algorithms.capitalizeFirstLetterAndLowercase(downloadName + suffix));
if (targetFile.exists()) {
System.out.println("Already processed " + name);
return;
}
Set<String> srtmFileNames = new TreeSet<String>();
QuadRect qr = new QuadRect(180, -90, -180, 90);
MultipolygonBuilder bld = new MultipolygonBuilder();
bld.addOuterWay(convertToWay(country));
updateBbox(country, qr);
if (boundaries != null) {
for (BinaryMapDataObject o : boundaries) {
bld.addOuterWay(convertToWay(o));
updateBbox(o, qr);
}
}
Multipolygon polygon = bld.build();
System.out.println("RINGS OF MULTIPOLYGON ARE " + polygon.areRingsComplete());
int rightLon = (int) Math.floor(qr.right);
int leftLon = (int) Math.floor(qr.left);
int bottomLat = (int) Math.floor(qr.bottom);
int topLat = (int) Math.floor(qr.top);
boolean onetile = leftLon == rightLon && bottomLat == topLat;
for (int lon = leftLon; lon <= rightLon; lon++) {
for (int lat = bottomLat; lat <= topLat; lat++) {
boolean isOut = !polygon.containsPoint(lat + 0.5, lon + 0.5) && !onetile;
if (isOut) {
LatLon bl = new LatLon(lat, lon);
LatLon br = new LatLon(lat, lon + 1);
LatLon tr = new LatLon(lat + 1, lon + 1);
LatLon tl = new LatLon(lat + 1, lon);
for (Ring r : polygon.getOuterRings()) {
List<Node> border = r.getBorder();
Node prev = border.get(border.size() - 1);
for (int i = 0; i < border.size() && isOut; i++) {
Node n = border.get(i);
if (MapAlgorithms.linesIntersect(prev.getLatLon(), n.getLatLon(), tr, tl)) {
isOut = false;
} else if (MapAlgorithms.linesIntersect(prev.getLatLon(), n.getLatLon(), tr, br)) {
isOut = false;
} else if (MapAlgorithms.linesIntersect(prev.getLatLon(), n.getLatLon(), bl, tl)) {
isOut = false;
} else if (MapAlgorithms.linesIntersect(prev.getLatLon(), n.getLatLon(), br, bl)) {
isOut = false;
}
prev = n;
}
if (!isOut) {
break;
}
}
}
if (!isOut) {
final String filename = getFileName(lon, lat);
srtmFileNames.add(filename);
}
}
}
System.out.println();
System.out.println("PROCESSING " + name + " lon [" + leftLon + " - " + rightLon + "] lat [" + bottomLat + " - " + topLat + "] TOTAL " + srtmFileNames.size() + " files " + srtmFileNames);
System.out.println("-----------------------------");
if (dryRun) {
return;
}
// final File work = new File(directoryWithTargetFiles, "work");
// Map<File, String> mp = new HashMap<File, String>();
// long length = 0;
List<File> files = new ArrayList<File>();
for (String file : srtmFileNames) {
final File fl = new File(directoryWithSRTMFiles, file + ".osm.bz2");
if (!fl.exists()) {
System.err.println("!! Missing " + name + " because " + file + " doesn't exist");
} else {
files.add(fl);
// File ttf = new File(fl.getParentFile(), Algorithms.capitalizeFirstLetterAndLowercase(file) + "_"+ name + ".obf");
// mp.put(ttf, null);
}
}
// be independent of previous results
new File(targetFile.getParentFile(), IndexCreator.TEMP_NODES_DB).delete();
RTree.clearCache();
IndexCreator ic = new IndexCreator(targetFile.getParentFile());
if (srtmFileNames.size() > 100) {
ic.setDialects(DBDialect.SQLITE, DBDialect.SQLITE);
} else {
ic.setDialects(DBDialect.SQLITE_IN_MEMORY, DBDialect.SQLITE_IN_MEMORY);
}
ic.setIndexMap(true);
ic.setRegionName(name + " contour lines");
ic.setMapFileName(targetFile.getName());
ic.setBoundary(polygon);
ic.setZoomWaySmoothness(2);
ic.generateIndexes(files.toArray(new File[files.size()]), new ConsoleProgressImplementation(1), null, MapZooms.parseZooms("11-12;13-"), new MapRenderingTypesEncoder(targetFile.getName()), log, true, false);
// if(length > Integer.MAX_VALUE) {
// System.err.println("!! Can't process " + name + " because too big");
// } else {
// BinaryInspector.combineParts(targetFile, mp);
// }
// for(String file : srtmFileNames) {
// final File fl = new File(work, file);
// fl.delete();
// }
}
Aggregations