Search in sources :

Example 21 with QuadRect

use of net.osmand.data.QuadRect in project Osmand by osmandapp.

the class PrecalculatedRouteDirection method getIndex.

public int getIndex(int x31, int y31) {
    int ind = -1;
    cachedS.clear();
    // indexedPoints.getObjects(x31 - SHIFT, y31 - SHIFT, x31 + SHIFT, y31 + SHIFT, cachedS);
    quadTree.queryInBox(new QuadRect(x31 - SHIFT, y31 - SHIFT, x31 + SHIFT, y31 + SHIFT), cachedS);
    if (cachedS.size() == 0) {
        for (int k = 0; k < SHIFTS.length; k++) {
            quadTree.queryInBox(new QuadRect(x31 - SHIFTS[k], y31 - SHIFTS[k], x31 + SHIFTS[k], y31 + SHIFTS[k]), cachedS);
            // indexedPoints.getObjects(x31 - SHIFTS[k], y31 - SHIFTS[k], x31 + SHIFTS[k], y31 + SHIFTS[k],cachedS);
            if (cachedS.size() != 0) {
                break;
            }
        }
        if (cachedS.size() == 0) {
            return -1;
        }
    }
    double minDist = 0;
    for (int i = 0; i < cachedS.size(); i++) {
        Integer n = cachedS.get(i);
        double ds = BinaryRoutePlanner.squareRootDist(x31, y31, pointsX[n], pointsY[n]);
        if (ds < minDist || i == 0) {
            ind = n;
            minDist = ds;
        }
    }
    return ind;
}
Also used : QuadRect(net.osmand.data.QuadRect) QuadPoint(net.osmand.data.QuadPoint)

Example 22 with QuadRect

use of net.osmand.data.QuadRect in project Osmand by osmandapp.

the class SearchPhrase method getRadiusBBoxToSearch.

public QuadRect getRadiusBBoxToSearch(int radius) {
    int radiusInMeters = getRadiusSearch(radius);
    QuadRect cache1kmRect = get1km31Rect();
    if (cache1kmRect == null) {
        return null;
    }
    int max = (1 << 31) - 1;
    double dx = (cache1kmRect.width() / 2) * radiusInMeters / 1000;
    double dy = (cache1kmRect.height() / 2) * radiusInMeters / 1000;
    double topLeftX = Math.max(0, cache1kmRect.left - dx);
    double topLeftY = Math.max(0, cache1kmRect.top - dy);
    double bottomRightX = Math.min(max, cache1kmRect.right + dx);
    double bottomRightY = Math.min(max, cache1kmRect.bottom + dy);
    return new QuadRect(topLeftX, topLeftY, bottomRightX, bottomRightY);
}
Also used : QuadRect(net.osmand.data.QuadRect)

Example 23 with QuadRect

use of net.osmand.data.QuadRect in project Osmand by osmandapp.

the class OsmandRegions method getCountries.

private List<BinaryMapDataObject> getCountries(int tile31x, int tile31y) {
    HashSet<String> set = new HashSet<String>(quadTree.queryInBox(new QuadRect(tile31x, tile31y, tile31x, tile31y), new ArrayList<String>()));
    List<BinaryMapDataObject> result = new ArrayList<BinaryMapDataObject>();
    Iterator<String> it = set.iterator();
    while (it.hasNext()) {
        String cname = it.next();
        BinaryMapDataObject container = null;
        int count = 0;
        for (BinaryMapDataObject bo : countriesByDownloadName.get(cname)) {
            if (contain(bo, tile31x, tile31y)) {
                count++;
                container = bo;
                break;
            }
        }
        if (count % 2 == 1) {
            result.add(container);
        }
    }
    return result;
}
Also used : BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) QuadRect(net.osmand.data.QuadRect) HashSet(java.util.HashSet)

Example 24 with QuadRect

use of net.osmand.data.QuadRect in project Osmand by osmandapp.

the class Way method getLatLonBBox.

public QuadRect getLatLonBBox() {
    QuadRect qr = null;
    if (nodes != null) {
        for (Node n : nodes) {
            if (qr == null) {
                qr = new QuadRect();
                qr.left = (float) n.getLongitude();
                qr.right = (float) n.getLongitude();
                qr.top = (float) n.getLatitude();
                qr.bottom = (float) n.getLatitude();
            }
            if (n.getLongitude() < qr.left) {
                qr.left = (float) n.getLongitude();
            } else if (n.getLongitude() > qr.right) {
                qr.right = (float) n.getLongitude();
            }
            if (n.getLatitude() > qr.top) {
                qr.top = (float) n.getLatitude();
            } else if (n.getLatitude() < qr.bottom) {
                qr.bottom = (float) n.getLatitude();
            }
        }
    }
    return qr;
}
Also used : QuadRect(net.osmand.data.QuadRect)

Example 25 with QuadRect

use of net.osmand.data.QuadRect in project Osmand by osmandapp.

the class MapillaryVectorLayer method drawPoints.

protected void drawPoints(Canvas canvas, RotatedTileBox tileBox, int tileX, int tileY, GeometryTile tile, Map<QuadPointDouble, Map> visiblePoints) {
    int dzoom = tileBox.getZoom() - TILE_ZOOM;
    int mult = (int) Math.pow(2.0, dzoom);
    QuadRect tileBounds = tileBox.getTileBounds();
    double px, py, tx, ty;
    float x, y;
    float pw = point.getWidth();
    float ph = point.getHeight();
    float pwd = pw / 2;
    float phd = ph / 2;
    for (Geometry g : tile.getData()) {
        if (g instanceof Point && !g.isEmpty() && g.getUserData() != null && g.getUserData() instanceof HashMap) {
            Point p = (Point) g;
            px = p.getCoordinate().x / EXTENT;
            py = p.getCoordinate().y / EXTENT;
            tx = (tileX + px) * mult;
            ty = (tileY + py) * mult;
            if (tileBounds.contains(tx, ty, tx, ty)) {
                if (settings.USE_MAPILLARY_FILTER.get()) {
                    if (filtered(p.getUserData()))
                        continue;
                }
                x = tileBox.getPixXFromTile(tileX + px, tileY + py, TILE_ZOOM);
                y = tileBox.getPixYFromTile(tileX + px, tileY + py, TILE_ZOOM);
                canvas.drawBitmap(point, x - pwd, y - phd, paintPoint);
                visiblePoints.put(new QuadPointDouble(tileX + px, tileY + py), (Map) p.getUserData());
            }
        }
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) HashMap(java.util.HashMap) Point(com.vividsolutions.jts.geom.Point) QuadRect(net.osmand.data.QuadRect) Point(com.vividsolutions.jts.geom.Point) Paint(android.graphics.Paint) QuadPointDouble(net.osmand.data.QuadPointDouble)

Aggregations

QuadRect (net.osmand.data.QuadRect)60 Paint (android.graphics.Paint)19 ArrayList (java.util.ArrayList)19 LatLon (net.osmand.data.LatLon)13 Bitmap (android.graphics.Bitmap)8 RotatedTileBox (net.osmand.data.RotatedTileBox)8 WptPt (net.osmand.plus.GPXUtilities.WptPt)8 TIntArrayList (gnu.trove.list.array.TIntArrayList)7 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)6 Amenity (net.osmand.data.Amenity)5 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)4 Point (com.vividsolutions.jts.geom.Point)4 List (java.util.List)4 QuadPointDouble (net.osmand.data.QuadPointDouble)4 TransportStop (net.osmand.data.TransportStop)4 PoiCategory (net.osmand.osm.PoiCategory)4 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)4 Rect (android.graphics.Rect)3 RectF (android.graphics.RectF)3 File (java.io.File)3