Exemple #1
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)
Exemple #2
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)
Exemple #3
0
def get_loc_gmapsat_images(point, options):
    size = int(options.image_size)
    gmap = motionless.CenterMap(lat=point['lat'], lon=point['lng'], 
                                        zoom=int(options.zoom), size_x=size, size_y=size, 
                                        maptype="hybrid", scale=1, key=options.key)
    url = gmap.generate_url()
    buffer = BytesIO()

    try:
        curl = pycurl.Curl()
        curl.setopt(curl.URL, url)
        curl.setopt(curl.WRITEDATA, buffer)
        curl.perform()
        curl.close()
    except:
        raise  

    return buffer
Exemple #4
0
def get_gmap_static_image(point, options):
    
    size = int(options.image_size)
    gmap = motionless.CenterMap(lat=point['lat'], lon=point['lng'], 
                                        zoom=int(options.zoom), size_x=size, size_y=size, 
                                        maptype=options.maptype, scale=1, key=options.key)
    # url = gmap.generate_url() + "&style=feature:all|element:all|color:0xFFFFFF&style=feature:water|element:all|color:0x2a5a7c|weight:4&style=feature:all|element:labels|visibility:off" # "&style=feature:road.highway|element:geometry.fill|color:0xFED930"
    url = gmap.generate_url() + "&style=feature:water|element:all|color:0x2a5a7c|weight:4" # "&style=feature:road.highway|element:geometry.fill|color:0xFED930"
    buffer = BytesIO()

    try:
        curl = pycurl.Curl()
        curl.setopt(curl.URL, url)
        curl.setopt(curl.WRITEDATA, buffer)
        curl.perform()
        curl.close()
    except:
        raise  

    return buffer