Пример #1
0
    def __init__(self, x, y, crs=wgs84, size_x=640, size_y=640, scale=1,
                 maptype='satellite', use_cache=True, **kwargs):
        """Initialize

        Parameters
        ----------
        x : array
          x coordinates of the points to include on the map
        y : array
          y coordinates of the points to include on the map
        crs : proj or Grid
          coordinate reference system of x, y
        size_x : int
          image size
        size_y : int
          image size
        scale : int
          image scaling factor
        maptype : str, default: 'satellite'
          'roadmap', 'satellite', 'hybrid', 'terrain'
        use_cache : bool, default: True
          store the downloaded image in the cache to avoid future downloads
        kwargs : **
          any keyword accepted by motionless.CenterMap (e.g. `key` for the API)
        """

        if 'zoom' in kwargs or 'center_ll' in kwargs:
            raise ValueError('incompatible kwargs.')

        # Transform to lonlat
        crs = gis.check_crs(crs)
        if isinstance(crs, pyproj.Proj):
            lon, lat = gis.transform_proj(crs, wgs84, x, y)
        elif isinstance(crs, Grid):
            lon, lat = crs.ij_to_crs(x, y, crs=wgs84)
        else:
            raise NotImplementedError()

        # surely not the smartest way to do but should be enough for now
        mc = (np.mean(lon), np.mean(lat))
        zoom = 20
        while zoom >= 0:
            grid = gis.googlestatic_mercator_grid(center_ll=mc, nx=size_x,
                                                  ny=size_y, zoom=zoom,
                                                  scale=scale)
            dx, dy = grid.transform(lon, lat, maskout=True)
            if np.any(dx.mask):
                zoom -= 1
            else:
                break

        GoogleCenterMap.__init__(self, center_ll=mc, size_x=size_x,
                                 size_y=size_y, zoom=zoom, scale=scale,
                                 maptype=maptype, use_cache=use_cache, **kwargs)
Пример #2
0
    def __init__(self, x, y, crs=wgs84, size_x=640, size_y=640,
                 maptype='satellite', use_cache=True, **kwargs):
        """Initialize

        Parameters
        ----------
        x : array
          x coordinates of the points to include on the map
        y : array
          y coordinates of the points to include on the map
        crs : proj or Grid
          coordinate reference system of x, y
        size_x : int
          image size
        size_y : int
          image size
        maptype : str, default: 'satellite'
          'roadmap', 'satellite', 'hybrid', 'terrain'
        use_cache : bool, default: True
          store the downloaded image in the cache to avoid future downloads
        kwargs : **
          any keyword accepted by motionless.CenterMap (e.g. `key` for the API)
        """

        if 'zoom' in kwargs or 'center_ll' in kwargs:
            raise ValueError('incompatible kwargs.')

        # Transform to lonlat
        crs = gis.check_crs(crs)
        if isinstance(crs, pyproj.Proj):
            lon, lat = gis.transform_proj(crs, wgs84, x, y)
        elif isinstance(crs, Grid):
            lon, lat = crs.ij_to_crs(x, y, crs=wgs84)
        else:
            raise NotImplementedError()

        # surely not the smartest way to do but should be enough for now
        mc = (np.mean(lon), np.mean(lat))
        zoom = 20
        while zoom >= 0:
            grid = gis.googlestatic_mercator_grid(center_ll=mc, nx=size_x,
                                                  ny=size_y, zoom=zoom)
            dx, dy = grid.transform(lon, lat, maskout=True)
            if np.any(dx.mask):
                zoom -= 1
            else:
                break

        GoogleCenterMap.__init__(self, center_ll=mc, size_x=size_x,
                                 size_y=size_y, zoom=zoom, maptype=maptype,
                                 use_cache=use_cache, **kwargs)
Пример #3
0
    def __init__(self, center_ll=(11.38, 47.26), size_x=640, size_y=640,
                 scale=1, zoom=12, maptype='satellite', use_cache=True, 
                 **kwargs):
        """Initialize

        Parameters
        ----------
        center_ll : tuple
          tuple of lon, lat center of the map
        size_x : int
          image size
        size_y : int
          image size
        scale : int
          image scaling factor. 1, 2. 2 is higher resolution but takes 
          longer to download
        zoom : int
          google zoom level (https://developers.google.com/maps/documentation/
          static-maps/intro#Zoomlevels). 1 (world) - 20 (buildings)
        maptype : str, default: 'satellite'
          'roadmap', 'satellite', 'hybrid', 'terrain'
        use_cache : bool, default: True
          store the downloaded image in the cache to avoid future downloads
        kwargs : **
          any keyword accepted by motionless.CenterMap (e.g. `key` for the API)
        """

        global API_KEY

        # Google grid
        grid = gis.googlestatic_mercator_grid(center_ll=center_ll,
                                              nx=size_x, ny=size_y,
                                              zoom=zoom, scale=scale)

        if 'key' not in kwargs:
            if API_KEY is None:
                with open(utils.get_demo_file('.api_key'), 'r') as f:
                    API_KEY = f.read().replace('\n', '')
            kwargs['key'] = API_KEY

        # Motionless
        import motionless
        googleurl = motionless.CenterMap(lon=center_ll[0], lat=center_ll[1],
                                         size_x=size_x, size_y=size_y,
                                         maptype=maptype, zoom=zoom, scale=scale, 
                                         **kwargs)

        # done
        self.googleurl = googleurl
        self.use_cache = use_cache
        GeoDataset.__init__(self, grid)
Пример #4
0
    def __init__(self,
                 center_ll=(11.38, 47.26),
                 size_x=640,
                 size_y=640,
                 zoom=12,
                 maptype='satellite',
                 use_cache=True,
                 **kwargs):
        """Initialize

        Parameters
        ----------
        center_ll : tuple
          tuple of lon, lat center of the map
        size_x : int
          image size
        size_y : int
          image size
        zoom int
          google zoom level (https://developers.google.com/maps/documentation/
          static-maps/intro#Zoomlevels)
        maptype : str, default: 'satellite'
          'roadmap', 'satellite', 'hybrid', 'terrain'
        use_cache : bool, default: True
          store the downloaded image in the cache to avoid future downloads
        kwargs : **
          any keyword accepted by motionless.CenterMap (e.g. `key` for the API)
        """

        if 'scale' in kwargs:
            raise NotImplementedError('scale not supported')

        # Google grid
        grid = gis.googlestatic_mercator_grid(center_ll=center_ll,
                                              nx=size_x,
                                              ny=size_y,
                                              zoom=zoom)

        # Motionless
        googleurl = motionless.CenterMap(lon=center_ll[0],
                                         lat=center_ll[1],
                                         size_x=size_x,
                                         size_y=size_y,
                                         maptype=maptype,
                                         zoom=zoom,
                                         **kwargs)

        # done
        self.googleurl = googleurl
        self.use_cache = use_cache
        GeoDataset.__init__(self, grid)
Пример #5
0
    def __init__(self, center_ll=(11.38, 47.26), size_x=640, size_y=640,
                 zoom=12, maptype='satellite', use_cache=True, **kwargs):
        """Initialize

        Parameters
        ----------
        center_ll : tuple
          tuple of lon, lat center of the map
        size_x : int
          image size
        size_y : int
          image size
        zoom int
          google zoom level (https://developers.google.com/maps/documentation/
          static-maps/intro#Zoomlevels)
        maptype : str, default: 'satellite'
          'roadmap', 'satellite', 'hybrid', 'terrain'
        use_cache : bool, default: True
          store the downloaded image in the cache to avoid future downloads
        kwargs : **
          any keyword accepted by motionless.CenterMap (e.g. `key` for the API)
        """

        if 'scale' in kwargs:
            raise NotImplementedError('scale not supported')

        # Google grid
        grid = gis.googlestatic_mercator_grid(center_ll=center_ll,
                                                nx=size_x, ny=size_y,
                                                zoom=zoom)

        # Motionless
        googleurl = motionless.CenterMap(lon=center_ll[0], lat=center_ll[1],
                                         size_x=size_x, size_y=size_y,
                                         maptype=maptype, zoom=zoom, **kwargs)

        # done
        self.googleurl = googleurl
        self.use_cache = use_cache
        GeoDataset.__init__(self, grid)
Пример #6
0
    def __init__(self,
                 x,
                 y,
                 crs=wgs84,
                 size_x=640,
                 size_y=640,
                 scale=1,
                 maptype='satellite',
                 use_cache=True,
                 **kwargs):
        """Initialize

        Parameters
        ----------
        x : array
          x coordinates of the points to include on the map
        y : array
          y coordinates of the points to include on the map
        crs : proj or Grid
          coordinate reference system of x, y
        size_x : int
          image size
        size_y : int
          image size
        scale : int
          image scaling factor. 1, 2. 2 is higher resolution but takes
          longer to download
        maptype : str, default: 'satellite'
          'roadmap', 'satellite', 'hybrid', 'terrain'
        use_cache : bool, default: True
          store the downloaded image in the cache to avoid future downloads
        kwargs : **
          any keyword accepted by motionless.CenterMap (e.g. `key` for the API)

        Notes
        -----
        To obtain the exact domain specified in `x` and `y` you may have to
        play with the `size_x` and `size_y` kwargs.
        """

        global API_KEY

        if 'zoom' in kwargs or 'center_ll' in kwargs:
            raise ValueError('incompatible kwargs.')

        # Transform to lonlat
        crs = gis.check_crs(crs)
        if isinstance(crs, pyproj.Proj):
            lon, lat = gis.transform_proj(crs, wgs84, x, y)
        elif isinstance(crs, Grid):
            lon, lat = crs.ij_to_crs(x, y, crs=wgs84)
        else:
            raise NotImplementedError()

        # surely not the smartest way to do but should be enough for now
        mc = (np.mean(lon), np.mean(lat))
        zoom = 20
        while zoom >= 0:
            grid = gis.googlestatic_mercator_grid(center_ll=mc,
                                                  nx=size_x,
                                                  ny=size_y,
                                                  zoom=zoom,
                                                  scale=scale)
            dx, dy = grid.transform(lon, lat, maskout=True)
            if np.any(dx.mask):
                zoom -= 1
            else:
                break

        if 'key' not in kwargs:
            if API_KEY is None:
                with open(utils.get_demo_file('.api_key'), 'r') as f:
                    API_KEY = f.read().replace('\n', '')
            kwargs['key'] = API_KEY

        GoogleCenterMap.__init__(self,
                                 center_ll=mc,
                                 size_x=size_x,
                                 size_y=size_y,
                                 zoom=zoom,
                                 scale=scale,
                                 maptype=maptype,
                                 use_cache=use_cache,
                                 **kwargs)