Class XYGrid

  • All Implemented Interfaces:
    Serializable

    public class XYGrid
    extends Object
    implements Serializable
    XYGrid spans an equal degree grid over the world.

    Example IDs for zoom = 2:

    How XYGrid sees the world.
    +90 lat
    45|67
    -180--0--+180longitude
    01|23
    -90 lat

    Longitude +180 will be wrapped around to -180. Coordinates lying on grid-borders will be assigned to the north-eastern cell.

    See Also:
    Serialized Form
    • Constructor Detail

      • XYGrid

        public XYGrid​(int zoom)
        XYGrid.
        Parameters:
        zoom - The zoom to be used. The number of tiles in a row equals 2^zoom. The maximum zoom is 30 due to the maximum accuracy and values of used numeric formats.
    • Method Detail

      • getBoundingBox

        public static OSHDBBoundingBox getBoundingBox​(CellId cellId)
        Calculate the OSHDBBoundingBox of a specific GridCell.
        Parameters:
        cellId - CellId for which to get the OSHDBBoundingBox
        Returns:
        OSHDBBoundingBox for cellId
      • getBoundingBox

        public static OSHDBBoundingBox getBoundingBox​(CellId cellId,
                                                      boolean enlarge)
        Calculate the OSHDBBoundingBox of a specific GridCell.
        Parameters:
        cellId - CellId for which to get the OSHDBBoundingBox
        enlarge - true if the bbox should be enlarged
        Returns:
        OSHDBBoundingBox for cellId
      • getId

        public long getId​(double longitude,
                          double latitude)
        Returns the covering tile of a coordinate. Coordinates lying on borders will be placed in the northern and/or eastern tile except for coordinates on the North Pole which are placed in the northernmost tile.
        Parameters:
        longitude - Longitude of the point
        latitude - Latitude of the point
        Returns:
        Returns the ID of the tile as shown above
      • getId

        public long getId​(long longitude,
                          long latitude)
        Returns the covering tile of a coordinate. Coordinates lying on borders will be placed in the northern and/or eastern tile except for coordinates on the North Pole which are placed in the northernmost tile.
        Parameters:
        longitude - Longitude in osm-coordinate system (long integer)
        latitude - Latitude in osm-coordinate system (long integer)
      • getId

        public long getId​(OSHDBBoundingBox bbox)
        Returns the smallest Id of the given Bounding Box.
        Parameters:
        bbox - OSHDBBoundingBox for which the id is calculated
        Returns:
        south-western cellId of given BBOX
      • getCellWidth

        public double getCellWidth()
        Returns width (and height) of cells in given Grid.
        Returns:
        length in degree of borders of cells
      • getCellDimensions

        public OSHDBBoundingBox getCellDimensions​(long cellId)
        Calculates BBOX of given Cell.
        Parameters:
        cellId - ID of a cell calculated by getID
        Returns:
        a BBOX for that cell
      • getEstimatedIdCount

        public long getEstimatedIdCount​(OSHDBBoundingBox data)
        Returns number of Cells within given BBOX.
        Parameters:
        data - BBOX to estimate number of cells for
        Returns:
        the long
      • getLevel

        public int getLevel()
        getter for zoomlevel.
        Returns:
        zoomlevel
      • bbox2CellIdRanges

        public Set<XYGrid.IdRange> bbox2CellIdRanges​(OSHDBBoundingBox bbox,
                                                     boolean enlarge)
        Calculates all tiles, that lie within a bounding-box.

        TODO but priority 999: Add possibility to snap the BBX to the tile-grid. TODO: is an exception needed?

        Parameters:
        bbox - The bounding box. First dimension is longitude, second is latitude.
        enlarge - if true, the BBOX is enlarged by one tile to the south-west (bottom-left) direction, if false only holds tiles that intersect with the given BBOX.
        Returns:
        Returns a set of Tile-IDs that lie within the given BBOX.
      • getNeighbours

        public Set<XYGrid.IdRange> getNeighbours​(CellId center)
        Get 2D neighbours of given cellId.
        Parameters:
        center - Center CellId
        Returns:
        a set of ID-ranges containing the neighbours of the given cell and the cell itself. -1L,-1L will be added, if this cell lies on the edge of the XYGrid