Class GeoUtil



  • public final class GeoUtil
    extends java.lang.Object
    These are math utilities for converting between pixels, tiles, and geographic coordinates. Implements a Google Maps style mercator projection.
    • Constructor Detail

      • GeoUtil

        public GeoUtil​()
    • Method Detail

      • getMapSize

        public static java.awt.Dimension getMapSize​(int zoom,
                                                    TileFactoryInfo info)
        Parameters:
        zoom - Zoom
        info - Tile factory info
        Returns:
        the size of the map at the given zoom, in tiles (num tiles tall by num tiles wide)
      • isValidTile

        public static boolean isValidTile​(int x,
                                          int y,
                                          int zoomLevel,
                                          TileFactoryInfo info)
        Parameters:
        x - X
        y - Y
        zoomLevel - Zoom level
        info - Tile factory info
        Returns:
        true if this point in tiles is valid at this zoom level. For example, if the zoom level is 0 (zoomed all the way out, where there is only one tile), then x,y must be 0,0
      • getBitmapCoordinate

        public static java.awt.geom.Point2D getBitmapCoordinate​(GeoPosition c,
                                                                int zoomLevel,
                                                                TileFactoryInfo info)
        Given a position (latitude/longitude pair) and a zoom level, return the appropriate point in pixels. The zoom level is necessary because pixel coordinates are in terms of the zoom level
        Parameters:
        c - A lat/lon pair
        zoomLevel - the zoom level to extract the pixel coordinate for
        info - Tile factory info
        Returns:
        Bitmap coordinate point
      • getBitmapCoordinate

        public static java.awt.geom.Point2D getBitmapCoordinate​(double latitude,
                                                                double longitude,
                                                                int zoomLevel,
                                                                TileFactoryInfo info)
        Given a position (latitude/longitude pair) and a zoom level, return the appropriate point in pixels. The zoom level is necessary because pixel coordinates are in terms of the zoom level
        Parameters:
        latitude - Latitude
        longitude - Longitude
        zoomLevel - the zoom level to extract the pixel coordinate for
        info - Tile factory info
        Returns:
        Position point
      • getPosition

        public static GeoPosition getPosition​(java.awt.geom.Point2D pixelCoordinate,
                                              int zoom,
                                              TileFactoryInfo info)
      • getPositionForAddress

        public static GeoPosition getPositionForAddress​(java.lang.String[] fields)
                                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • getPositionForAddress

        public static GeoPosition getPositionForAddress​(java.lang.String street,
                                                        java.lang.String city,
                                                        java.lang.String state)
                                                 throws java.io.IOException
        Convert a street address into a position. Uses the Yahoo GeoCoder. You must supply your own yahoo id.
        Parameters:
        street - Street
        city - City
        state - State (must be a US state)
        Returns:
        the position of this street address
        Throws:
        java.io.IOException - if the request fails.
      • getResolution

        public static double getResolution​(int zoomLevel,
                                           double lat)
        Get resolution
        Parameters:
        zoomLevel - The zoom level
        lat - The latitude
        Returns:
        Resolution
      • getScale

        public static double getScale​(int zoomLevel,
                                      double lat)
        Get scale
        Parameters:
        zoomLevel - The zoom level
        lat - The latitude
        Returns:
        Scale