Exemple #1
0
    def __init__(self,
                 server="dds.cr.usgs.gov",
                 directory="/srtm/version2_1/SRTM3/",
                 cachedir=None,
                 offline=0):

        if cachedir is None:
            try:
                cachedir = os.path.join(os.environ['HOME'], '.tilecache/SRTM')
            except Exception:
                cachedir = os.path.join(tempfile.gettempdir(), 'MAVProxySRTM')

        self.offline = offline
        self.first_failure = False
        self.server = server
        self.directory = directory
        self.cachedir = cachedir
        '''print "SRTMDownloader - server= %s, directory=%s." % \
              (self.server, self.directory)'''
        if not os.path.exists(cachedir):
            mp_util.mkdir_p(cachedir)
        self.filelist = {}
        self.filename_regex = re.compile(
            r"([NS])(\d{2})([EW])(\d{3})\.hgt\.zip")
        self.filelist_file = os.path.join(self.cachedir, "filelist_python")
        self.childFileListDownload = None
        self.childTileDownload = None
Exemple #2
0
    def __init__(self, server="dds.cr.usgs.gov",
                 directory="/srtm/version2_1/SRTM3/",
                 cachedir=None,
                 offline=0):

        if cachedir is None:
            try:
                cachedir = os.path.join(os.environ['HOME'], '.tilecache/SRTM')
            except Exception:
                cachedir = os.path.join(tempfile.gettempdir(), 'MAVProxySRTM')

        self.offline = offline
        self.first_failure = False
        self.server = server
        self.directory = directory
        self.cachedir = cachedir
	'''print "SRTMDownloader - server= %s, directory=%s." % \
              (self.server, self.directory)'''
        if not os.path.exists(cachedir):
            mp_util.mkdir_p(cachedir)
        self.filelist = {}
        self.filename_regex = re.compile(
                r"([NS])(\d{2})([EW])(\d{3})\.hgt\.zip")
        self.filelist_file = os.path.join(self.cachedir, "filelist_python")
        self.childFileListDownload = None
        self.childTileDownload = None
Exemple #3
0
	def __init__(self, cache_path=None, download=True, cache_size=500,
		     service="MicrosoftSat", tile_delay=0.3, debug=False,
		     max_zoom=19):

		if cache_path is None:
			try:
				cache_path = os.path.join(os.environ['HOME'], '.tilecache')
			except Exception:
				cache_path = os.path.join(tempfile.gettempdir(), 'MAVtilecache')

		if not os.path.exists(cache_path):
			mp_util.mkdir_p(cache_path)

		self.cache_path = cache_path
		self.max_zoom = max_zoom
		self.min_zoom = 1
		self.download = download
		self.cache_size = cache_size
		self.tile_delay = tile_delay
		self.service = service
		self.debug = debug

		if service not in TILE_SERVICES:
			raise TileException('unknown tile service %s' % service)

		# _download_pending is a dictionary of TileInfo objects
		self._download_pending = {}
		self._download_thread = None
		self._loading = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'data', 'loading.jpg')
		self._unavailable = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'data', 'unavailable.jpg')
		self._tile_cache = collections.OrderedDict()
Exemple #4
0
    def downloader(self):
        '''the download thread'''
        http = httplib2.Http()
        while self.tiles_pending() > 0:
            time.sleep(self.tile_delay)

            keys = self._download_pending.keys()[:]

            # work out which one to download next, choosing by request_time
            tile_info = self._download_pending[keys[0]]
            for key in keys:
                if self._download_pending[
                        key].request_time > tile_info.request_time:
                    tile_info = self._download_pending[key]

            url = tile_info.url(self.service)
            path = self.tile_to_path(tile_info)
            key = tile_info.key()

            try:
                if self.debug:
                    print("Downloading %s [%u left]" % (url, len(keys)))
                resp, img = http.request(url)
            except httplib2.HttpLib2Error as e:
                #print('Error loading %s' % url)
                self._tile_cache[key] = self._unavailable
                self._download_pending.pop(key)
                if self.debug:
                    print("Failed %s: %s" % (url, str(e)))
                continue
            if 'content-type' not in resp or resp['content-type'].find(
                    'image') == -1:
                self._tile_cache[key] = self._unavailable
                self._download_pending.pop(key)
                if self.debug:
                    print("non-image response %s" % url)
                continue

            # see if its a blank/unavailable tile
            md5 = hashlib.md5(img).hexdigest()
            if md5 in BLANK_TILES:
                if self.debug:
                    print("blank tile %s" % url)
                self._tile_cache[key] = self._unavailable
                self._download_pending.pop(key)
                continue

            mp_util.mkdir_p(os.path.dirname(path))
            h = open(path + '.tmp', 'w')
            h.write(img)
            h.close()
            os.rename(path + '.tmp', path)
            self._download_pending.pop(key)
        self._download_thread = None
Exemple #5
0
	def downloader(self):
		'''the download thread'''
		http = httplib2.Http()
		while self.tiles_pending() > 0:
			time.sleep(self.tile_delay)

			keys = self._download_pending.keys()[:]

			# work out which one to download next, choosing by request_time
			tile_info = self._download_pending[keys[0]]
			for key in keys:
				if self._download_pending[key].request_time > tile_info.request_time:
					tile_info = self._download_pending[key]
			
			url = tile_info.url(self.service)
			path = self.tile_to_path(tile_info)
			key = tile_info.key()
			
			try:
				if self.debug:
					print("Downloading %s [%u left]" % (url, len(keys)))
				resp,img = http.request(url)
			except httplib2.HttpLib2Error as e:
				#print('Error loading %s' % url)
				self._tile_cache[key] = self._unavailable
				self._download_pending.pop(key)
				if self.debug:
					print("Failed %s: %s" % (url, str(e)))
				continue
			if 'content-type' not in resp or resp['content-type'].find('image') == -1:
				self._tile_cache[key] = self._unavailable
				self._download_pending.pop(key)
				if self.debug:
					print("non-image response %s" % url)
				continue
				

			# see if its a blank/unavailable tile
			md5 = hashlib.md5(img).hexdigest()
			if md5 in BLANK_TILES:
				if self.debug:
					print("blank tile %s" % url)
				self._tile_cache[key] = self._unavailable
				self._download_pending.pop(key)
				continue

			mp_util.mkdir_p(os.path.dirname(path))
			h = open(path+'.tmp','w')
			h.write(img)
			h.close()
			os.rename(path+'.tmp', path)
			self._download_pending.pop(key)
		self._download_thread = None
Exemple #6
0
    def __init__(self, server="dds.cr.usgs.gov",
                 directory="/srtm/version2_1/SRTM3/",
                 cachedir=os.path.join(os.environ['HOME'], '.tilecache/SRTM'),
                 offline=0):

        self.offline = offline
        self.server = server
        self.directory = directory
        self.cachedir = cachedir
	'''print "SRTMDownloader - server= %s, directory=%s." % \
              (self.server, self.directory)'''
        if not os.path.exists(cachedir):
            mp_util.mkdir_p(cachedir)
        self.filelist = {}
        self.filename_regex = re.compile(
                r"([NS])(\d{2})([EW])(\d{3})\.hgt\.zip")
        self.filelist_file = self.cachedir + "/filelist_python"
        self.childFileListDownload = None
        self.childTileDownload = None
Exemple #7
0
    def __init__(self,
                 cache_path=None,
                 download=True,
                 cache_size=500,
                 service="MicrosoftSat",
                 tile_delay=0.3,
                 debug=False,
                 max_zoom=19):

        if cache_path is None:
            try:
                cache_path = os.path.join(os.environ['HOME'], '.tilecache')
            except Exception:
                cache_path = os.path.join(tempfile.gettempdir(),
                                          'MAVtilecache')

        if not os.path.exists(cache_path):
            mp_util.mkdir_p(cache_path)

        self.cache_path = cache_path
        self.max_zoom = max_zoom
        self.min_zoom = 1
        self.download = download
        self.cache_size = cache_size
        self.tile_delay = tile_delay
        self.service = service
        self.debug = debug

        if service not in TILE_SERVICES:
            raise TileException('unknown tile service %s' % service)

        # _download_pending is a dictionary of TileInfo objects
        self._download_pending = {}
        self._download_thread = None
        self._loading = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), '..', 'data',
            'loading.jpg')
        self._unavailable = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), '..', 'data',
            'unavailable.jpg')
        self._tile_cache = collections.OrderedDict()