Changeset 2f5d3e6
- Timestamp:
- 03/25/12 12:38:19 (15 months ago)
- Branches:
- master
- Children:
- 2d03273
- Parents:
- 25f2707
- git-author:
- xkolman2 <xkolman2@…> (03/25/12 12:38:19)
- git-committer:
- xkolman2 <xkolman2@…> (03/25/12 12:38:19)
- File:
-
- 1 edited
-
modules/mod_mapData.py (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
-
modules/mod_mapData.py
r7d1b4b7 r2f5d3e6 93 93 def checkTiles(self, tilesToDownload): 94 94 """ 95 Get tiles that need to be downloaded and look if we don t already have some of these tiles,96 then generate a set of ('url','filename') t ouples and send them to the threaded downloader95 Get tiles that need to be downloaded and look if we don't already have some of these tiles, 96 then generate a set of ('url','filename') tuples and send them to the threaded downloader 97 97 """ 98 98 print "Checking if there are duplicated tiles" … … 103 103 return [] 104 104 layer = self.get('layer', None) # TODO: manual layer setting 105 maplayers = self.modrana.getMapLayers() # a dictionary describing supported map layers105 maplayers = self.modrana.getMapLayers() # a dictionary describing supported map layers 106 106 extension = maplayers[layer]['type'] # what is the extension for the current layer ? 107 107 folderPrefix = maplayers[layer]['folderPrefix'] # what is the extension for the current layer ? … … 114 114 (z,x,y) = (tile[2],tile[0],tile[1]) 115 115 filePath = tileFolder + mapTiles.getImagePath(x, y, z, folderPrefix, extension) 116 if not os.path.exists(filePath): # we don t have this file116 if not os.path.exists(filePath): # we don't have this file 117 117 neededTiles.append(tile) 118 118 … … 125 125 mapTiles = self.m.get('mapTiles', None) 126 126 tileFolder = self._getTileFolderPath() # where should we store the downloaded tiles 127 maplayers = self.modrana.getMapLayers() # a di stionary describing supported maplayers127 maplayers = self.modrana.getMapLayers() # a dictionary describing supported map layers 128 128 extension = maplayers[layer]['type'] # what is the extension for the current layer ? 129 129 folderPrefix = maplayers[layer]['folderPrefix'] # what is the extension for the current layer ? … … 135 135 def addToQueue(self, neededTiles): 136 136 """load urls and filenames to download queue, 137 optional y check for duplicates137 optionally check for duplicates 138 138 """ 139 139 … … 144 144 if check: 145 145 neededTiles = self.checkTiles(neededTiles) 146 with self.dlListLock: # make sure the set of needed tiles is ac essed in an atomic way146 with self.dlListLock: # make sure the set of needed tiles is accessed in an atomic way 147 147 self.currentDownloadList = neededTiles # load the files to the download queue variable 148 148 149 149 def getTileUrl(self,x,y,z,layer): 150 """Return url for given tile coor indates and layer"""150 """Return url for given tile coordinates and layer""" 151 151 mapTiles = self.m.get('mapTiles', None) 152 152 if mapTiles: … … 176 176 location = self.get("downloadArea", "here") # here or route 177 177 178 z = self.get('z', 15) # this is the curre wnt zoomlevel as show on the map screen178 z = self.get('z', 15) # this is the current zoomlevel as show on the map screen 179 179 minZ = z - int(self.get('zoomUpSize', 0)) # how many zoomlevels up (from current zoomelevel) should we download ? 180 180 if minZ < 0: … … 201 201 are of 40km*40km, instead of the requested 10km 202 202 therefore, zoom level 15 is used as the minimum number for splitting tiles down 203 when the maximum zoomlevel from the range requested is less than 15, we don t split at all"""203 when the maximum zoomlevel from the range requested is less than 15, we don't split at all""" 204 204 if midZ < 15 and maxZ < 15: 205 205 midZ = maxZ … … 225 225 loadTl = self.m.get('loadTracklogs', None) # get the tracklog module 226 226 GPXTracklog = loadTl.getActiveTracklog() 227 """because we don t need all the information in the original list and227 """because we don't need all the information in the original list and 228 228 also might need to add interpolated points, we make a local copy of 229 229 the original list""" … … 286 286 """ 287 287 2.Oct.2010 2:41 :D 288 after a lot of effort spent, I still can't get threaded download to re aliably289 work with sqlite s otrage without getting stuck288 after a lot of effort spent, I still can't get threaded download to reliably 289 work with sqlite storage without getting stuck 290 290 this currently happens only on the N900, not on PC (or I was simply not able to to reproduce it) 291 therefore, when on N900 with sqlite tile storage, use only simple single threaded download291 therefore, when on N900 with sqlite tile storage, use only simple single-threaded download 292 292 """ 293 293 # if self.device=='n900': … … 304 304 well, looks like the culprit was just the urlib3 socket pool with blocking turned on 305 305 so all the threads (even when doing it with a single thread) hanged on the block 306 it seems to be wo trking alright + its pretty fast too306 it seems to be working alright + its pretty fast too 307 307 """ 308 308 getFilesThread = self.GetFiles(self, neededTiles, layer, maxThreads) … … 331 331 def addOtherZoomlevels(self, tiles, tilesZ, maxZ, minZ): 332 332 """expand the tile coverage to other zoomlevels 333 maxZ = maximum NUMERICAL zoom, 17 for e axmple333 maxZ = maximum NUMERICAL zoom, 17 for example 334 334 minZ = minimum NUMERICAL zoom, 0 for example 335 335 we use two different methods to get the needed tiles: 336 * split ing the tiles from one zoomlevel down to the other337 * rounding the tiles coor idnates to get tiles from one zoomlevel up336 * splitting the tiles from one zoomlevel down to the other 337 * rounding the tiles coordinates to get tiles from one zoomlevel up 338 338 we choose a zoomlevel (tilesZ) and then split down and round down from it 339 339 * tilesZ is determined in the handle message method, … … 343 343 be downloading much more tiles than needed 344 344 => for now, if we get tilesZ (called midZ in handle message) that is lower than 15, 345 we set it to the lowest zoomlevel, so we get don t get too much unneeded tiles when splitting345 we set it to the lowest zoomlevel, so we get don't get too much unneeded tiles when splitting 346 346 """ 347 347 start = clock() … … 351 351 352 352 """start of the tile splitting code""" 353 previousZoomlevelTiles = None # we will split tthe tiles from the previous zoomlevel353 previousZoomlevelTiles = None # we will split the tiles from the previous zoomlevel 354 354 print "splitting down" 355 355 for z in range(tilesZ, maxZ): # to max zoom (fo each z we split one zoomlevel down) … … 363 363 now we split each tile to 4 tiles on a higher zoomlevel nr 364 364 see: http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Subtiles 365 for a tile with coor idnates x,y:365 for a tile with coordinates x,y: 366 366 2x,2y |2x+1,2y 367 367 2x,2y+1|2x+1,2y+1 … … 379 379 previousZoomlevelTiles = newTilesFromSplit # set the new tiles s as prev. tiles for next iteration 380 380 381 """start of the tile coor idnates rounding code"""382 previousZoomlevelTiles = None # we will the tile coor idnates to get tiles for the upper level381 """start of the tile coordinates rounding code""" 382 previousZoomlevelTiles = None # we will the tile coordinates to get tiles for the upper level 383 383 print "rounding up" 384 r = range(minZ, tilesZ) # we go from the tile-z up, e.g. a seq ence of progresivly smaller integers384 r = range(minZ, tilesZ) # we go from the tile-z up, e.g. a sequence progressively smaller integers 385 385 r.reverse() 386 386 for z in r: … … 392 392 y = tile[1] 393 393 """as per: http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Subtiles 394 we divide each coor idnate with 2 to get the upper tile394 we divide each coordinate with 2 to get the upper tile 395 395 some upper tiles can be found up to four times, so this could be most probably 396 396 optimized if need be (for charting the Jupiter, Sun or a Dyson sphere ? :)""" … … 501 501 with self.callback.dlListLock: 502 502 self.callbackSet.discard(item) 503 size = 0 # tiles we don t have dont need to be downloaded, therefore 0503 size = 0 # tiles we don't have don't need to be downloaded, therefore 0 504 504 with incrementLock: 505 505 self.processed+=1 … … 518 518 (url, filename, folder, folderPrefix, layerType) = self.callback.getTileUrlAndPath(x, y, z, self.layer) 519 519 m = self.callback.m.get('storeTiles', None) # get the tile storage module 520 # get the s otre tiles module520 # get the store tiles module 521 521 if m: 522 522 # does the tile exist ? … … 670 670 with self.callback.dlListLock: 671 671 item = self.neededTiles.pop() 672 except: # start the loop from beg gining, so that shutdown can be checked and the thread can exit672 except: # start the loop from beginning, so that shutdown can be checked and the thread can exit 673 673 print "waiting for more work" 674 674 time.sleep(2) … … 773 773 """get tilenamames for tiles around the route for given radius and zoom""" 774 774 """ now we look whats the distance between each two trackpoints, 775 if it is larger than the tracklog radius, we add ad itioanl interpolated points,775 if it is larger than the tracklog radius, we add additional interpolated points, 776 776 so we get continuous coverage for the tracklog """ 777 777 first = True … … 802 802 # the spiral gives us tiles around coordinates for a given radius 803 803 currentPointTiles = self.spiral(x,y,z,radius) 804 """now we take the resulting list and process it in su ach a way,804 """now we take the resulting list and process it in such a way, 805 805 that the tiles coordinates can be stored in a set, 806 806 so we will save only unique tiles""" … … 812 812 813 813 def addPointsToLine(self, lat1, lon1, lat2, lon2, maxDistance): 814 """experimental (recursive) function for adding ad itional points between two coordinates,814 """experimental (recursive) function for adding additional points between two coordinates, 815 815 until their distance is less or or equal to maxDistance 816 816 (this is actually a wrapper for a local recursive function)""" … … 818 818 def localAddPointsToLine(lat1, lon1, lat2, lon2, maxDistance): 819 819 distance = geo.distance(lat1, lon1, lat2, lon2) 820 if distance <= maxDistance: # the termination criteri um820 if distance <= maxDistance: # the termination criterion 821 821 return 822 822 else: … … 834 834 # is this menu the correct menu ? 835 835 if menuName == 'batchTileDl': 836 """in order for the thre eds to work normally, it is needed to pause the main loop for a while836 """in order for the threads to work normally, it is needed to pause the main loop for a while 837 837 * this works only for this menu, in other menus (even the edit menu) the threads will be slow to start 838 838 * when looking at map, the threads behave as expected :) … … 963 963 else: 964 964 failedCountString = "%d downloads failed" % failedCount 965 text = "<b>%s</b>: <b>%d</b> of <b>%d</b> tiles done\n\n<b>%1.2f MB</b> transfer ed, %s" % (action, currentTileCount, totalTileCount, MBTotalTransfered, failedCountString)965 text = "<b>%s</b>: <b>%d</b> of <b>%d</b> tiles done\n\n<b>%1.2f MB</b> transferred, %s" % (action, currentTileCount, totalTileCount, MBTotalTransfered, failedCountString) 966 966 elif getFilesThread.isAlive() == False: #TODO: send an alert that download is complete 967 967 if getFilesThread.getDownloadCount(): 968 # some downloads occur ed968 # some downloads occurred 969 969 text = "<b>Download complete.</b>" 970 970 else: 971 # no downloads occur ed971 # no downloads occurred 972 972 if failedCount: 973 973 # no downloads + failed downloads 974 974 text = "<b>Download of all tiles failed.</b>" 975 975 else: 976 # no down alods and no failed downloads976 # no downloads and no failed downloads 977 977 text = "<b>All tiles were locally available.</b>" 978 978 return text
Note: See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/trac/gps_navigace/chrome/site/nlp-logo.png)