use of net.osmand.data.QuadRect in project OsmAnd-tools by osmandapp.
the class FixBasemapRoads method addRegionTag.
private void addRegionTag(OsmandRegions or, Way firstWay) throws IOException {
QuadRect qr = firstWay.getLatLonBBox();
int lx = MapUtils.get31TileNumberX(qr.left);
int rx = MapUtils.get31TileNumberX(qr.right);
int by = MapUtils.get31TileNumberY(qr.bottom);
int ty = MapUtils.get31TileNumberY(qr.top);
List<BinaryMapDataObject> bbox = or.queryBbox(lx, rx, ty, by);
TreeSet<String> lst = new TreeSet<String>();
for (BinaryMapDataObject bo : bbox) {
// }
if (or.contain(bo, lx / 2 + rx / 2, by / 2 + ty / 2)) {
String dw = or.getDownloadName(bo);
if (!Algorithms.isEmpty(dw) && or.isDownloadOfType(bo, OsmandRegions.MAP_TYPE)) {
lst.add(dw);
}
}
}
firstWay.putTag(MapRenderingTypesEncoder.OSMAND_REGION_NAME_TAG, serialize(lst));
}
use of net.osmand.data.QuadRect in project OsmAnd-tools by osmandapp.
the class NativeSwingRendering method updateBoundaries.
private void updateBoundaries(File f, String nm) {
try {
BinaryMapIndexReader r = new BinaryMapIndexReader(new RandomAccessFile(f, "r"), f);
try {
if (r.getMapIndexes().isEmpty() || r.getMapIndexes().get(0).getRoots().isEmpty()) {
return;
}
MapRoot rt = r.getMapIndexes().get(0).getRoots().get(0);
if (!diffs.containsKey(nm)) {
MapDiff mm = new MapDiff();
mm.baseName = nm;
diffs.put(nm, mm);
}
MapDiff dd = diffs.get(nm);
dd.baseFile = f;
dd.timestamp = r.getDateCreated();
dd.bounds = new QuadRect(MapUtils.get31LongitudeX(rt.getLeft()), MapUtils.get31LatitudeY(rt.getTop()), MapUtils.get31LongitudeX(rt.getRight()), MapUtils.get31LatitudeY(rt.getBottom()));
Iterator<String> iterator = dd.diffs.keySet().iterator();
while (iterator.hasNext()) {
dd.selected = iterator.next();
}
} finally {
r.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
use of net.osmand.data.QuadRect in project OsmAnd-tools by osmandapp.
the class IndexAddressCreator method updatePostcodeBoundaries.
private void updatePostcodeBoundaries(IProgress progress, Map<String, City> postcodes) throws SQLException {
progress.startTask("Process postcode boundaries", postcodeBoundaries.size());
Iterator<Entry<Entity, Boundary>> it = postcodeBoundaries.entrySet().iterator();
PreparedStatement ps = mapConnection.prepareStatement("SELECT postcode, latitude, longitude, id" + " FROM building where latitude <= ? and latitude >= ? and longitude >= ? and longitude <= ? ");
TLongObjectHashMap<String> assignPostcodes = new TLongObjectHashMap<>();
while (it.hasNext()) {
Entry<Entity, Boundary> e = it.next();
String postcode = e.getKey().getTag(OSMTagKey.POSTAL_CODE);
Multipolygon mp = e.getValue().getMultipolygon();
QuadRect bbox = mp.getLatLonBbox();
if (bbox.width() > 0) {
ps.setDouble(1, bbox.top);
ps.setDouble(2, bbox.bottom);
ps.setDouble(3, bbox.left);
ps.setDouble(4, bbox.right);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
String pst = rs.getString(1);
if (Algorithms.isEmpty(pst)) {
if (mp.containsPoint(rs.getDouble(2), rs.getDouble(3))) {
assignPostcodes.put(rs.getLong(4), postcode);
}
}
}
}
progress.progress(1);
}
ps.close();
ps = mapConnection.prepareStatement("UPDATE " + " building set postcode = ? where id = ? ");
TLongObjectIterator<String> its = assignPostcodes.iterator();
int cnt = 0;
while (its.hasNext()) {
its.advance();
ps.setString(1, its.value());
ps.setLong(2, its.key());
ps.addBatch();
if (cnt > BATCH_SIZE) {
ps.executeBatch();
cnt = 0;
}
}
ps.executeBatch();
ps.close();
}
use of net.osmand.data.QuadRect 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();
// }
}
use of net.osmand.data.QuadRect in project Osmand by osmandapp.
the class OsmandRegions method cacheAllCountries.
public Map<String, LinkedList<BinaryMapDataObject>> cacheAllCountries() throws IOException {
quadTree = new QuadTree<String>(new QuadRect(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE), 8, 0.55f);
final ResultMatcher<BinaryMapDataObject> resultMatcher = new ResultMatcher<BinaryMapDataObject>() {
// int c = 0;
@Override
public boolean publish(BinaryMapDataObject object) {
if (object.getPointsLength() < 1) {
return false;
}
initTypes(object);
String nm = mapIndexFields.get(mapIndexFields.downloadNameType, object);
if (!countriesByDownloadName.containsKey(nm)) {
LinkedList<BinaryMapDataObject> ls = new LinkedList<BinaryMapDataObject>();
countriesByDownloadName.put(nm, ls);
ls.add(object);
} else {
countriesByDownloadName.get(nm).add(object);
}
int maxx = object.getPoint31XTile(0);
int maxy = object.getPoint31YTile(0);
int minx = maxx;
int miny = maxy;
for (int i = 1; i < object.getPointsLength(); i++) {
int x = object.getPoint31XTile(i);
int y = object.getPoint31YTile(i);
if (y < miny) {
miny = y;
} else if (y > maxy) {
maxy = y;
}
if (x < minx) {
minx = x;
} else if (x > maxx) {
maxx = x;
}
}
quadTree.insert(nm, new QuadRect(minx, miny, maxx, maxy));
return false;
}
@Override
public boolean isCancelled() {
return false;
}
};
iterateOverAllObjects(resultMatcher);
return countriesByDownloadName;
}
Aggregations