コード例 #1
0
ファイル: retile.py プロジェクト: TimSC/osm-to-gps-map
def MergeArea(x, y, zoom, mapIds, tileGroups):
	lat, lon = tiles.num2deg(x, y, zoom)
	x2, y2 = tiles.deg2num(lat, lon, dataTileZoom)

	lat2, lon2 = tiles.num2deg(x+1, y+1, zoom)
	x3, y3 = tiles.deg2num(lat2, lon2, dataTileZoom)

	fiList = []
	for cx in range(x2, x3):
		for cy in range(y2, y3):
			fina = "../12/{0}/{1}.osm.bz2".format(cx, cy)
			if not os.path.isfile(fina):
				continue
			fiList.append(fina)

	if len(fiList) == 0:
		return
	#out = bz2.BZ2File("merge.osm.bz2","w")
	#print "Found {0} data tiles".format(len(fiList))

	tileGroups.append(fiList)
	mapId = 63240000+len(mapIds)
	mapIds.append(mapId)

	if 0:
		countNodes, countWays, countRelations = mergeTiles.MergeFiles(fiList, out, 0)

		if countNodes + countWays + countRelations == 0:
			#Everything is empty
			return

		cmd = "java -jar ../splitter-r412/splitter.jar --mapid={0} merge.osm.bz2".format(mapId)
		
		os.system(cmd)
コード例 #2
0
ファイル: retile.py プロジェクト: TimSC/osm-to-gps-map
def CalcFileSize(x, y, zoom, dataTileZoom):
	lat, lon = tiles.num2deg(x, y, zoom)
	x2, y2 = tiles.deg2num(lat, lon, dataTileZoom)

	lat2, lon2 = tiles.num2deg(x+1, y+1, zoom)
	x3, y3 = tiles.deg2num(lat2, lon2, dataTileZoom)

	#print (x2, x3), (y2, y3)
	totalSize = 0
	for cx in range(x2, x3):
		for cy in range(y2, y3):
			fina = "../12/{0}/{1}.osm.bz2".format(cx, cy)
			if not os.path.isfile(fina):
				continue
			s = os.path.getsize(fina)
			totalSize += s
	return totalSize
コード例 #3
0
ファイル: download.py プロジェクト: TimSC/osm-to-gps-map
def GetTile(x, y, zoom, outFina):
	
	topLeft = tiles.num2deg(x, y, zoom)
	bottomRight = tiles.num2deg(x+1, y+1, zoom)

	#url = "http://fosm.org/api/0.6/map?bbox={0},{1},{2},{3}".format(topLeft[1],bottomRight[0],bottomRight[1],topLeft[0])
	url = "http://sodium:8010/api/0.6/map?bbox={0},{1},{2},{3}".format(topLeft[1],bottomRight[0],bottomRight[1],topLeft[0])
	print (url)
	timeout = 1
	waiting = 1
	
	while waiting:
		try:
			body, header = urlutil.Get(url)
			responseCode = urlutil.HeaderResponseCode(header)
			print (responseCode)
			if responseCode == "HTTP/1.1 200 OK":
				waiting = 0
			else:
				time.sleep(timeout)
				timeout *= 2

		except pycurl.error:
			time.sleep(timeout)
			timeout *= 2

	extSp = os.path.splitext(outFina)
	extSp2 = os.path.splitext(extSp[0])

	if extSp[1] == ".bz2" and extSp2[1] == ".osm":
		outFi = bz2.BZ2File(outFina,"w")
		outFi.write(body)

	if extSp[1] == ".gz" and extSp2[1] == ".o5m":
		osmData = OsmData.OsmData()
		osmData.LoadFromOsmXml(BytesIO(body))
		osmData.SaveToO5m(gzip.open(outFina, "wb"))

	return 1
コード例 #4
0
ファイル: retile.py プロジェクト: TimSC/osm-to-gps-map
def ProcessAreaNextZoom(x, y, zoom, dataTileZoom, mapIds, tileGroups):

	lat, lon = tiles.num2deg(x, y, zoom)
	x2, y2 = tiles.deg2num(lat, lon, zoom+1)

	lat2, lon2 = tiles.num2deg(x+1, y+1, zoom)
	x3, y3 = tiles.deg2num(lat2, lon2, zoom+1)

	for cx in range(x2, x3):
		for cy in range(y2, y3):
			totalFileSize = CalcFileSize(cx, cy, zoom+1, dataTileZoom)
			if totalFileSize <= maxAllowedFileSize or zoom >= dataTileZoom:

				if zoom >= dataTileZoom:
					ProcessSingleDataTile(cx, cy, zoom+1, mapIds, tileGroups)
				else:
					#Merge at this zoom
					#print "Merge tiles", cx, cy, zoom+1, totalFileSize
					MergeArea(cx, cy, zoom+1, mapIds, tileGroups)
			else:
				#Recusively consder higher zoom level
				ProcessAreaNextZoom(cx, cy, zoom+1, dataTileZoom, mapIds, tileGroups)
コード例 #5
0
ファイル: retile.py プロジェクト: TimSC/osm-to-gps-map
def MergeArea(x, y, zoom, mapIds, tileGroups):
    lat, lon = tiles.num2deg(x, y, zoom)
    x2, y2 = tiles.deg2num(lat, lon, dataTileZoom)

    lat2, lon2 = tiles.num2deg(x + 1, y + 1, zoom)
    x3, y3 = tiles.deg2num(lat2, lon2, dataTileZoom)

    fiList = []
    for cx in range(x2, x3):
        for cy in range(y2, y3):
            fina = "../12/{0}/{1}.osm.bz2".format(cx, cy)
            if not os.path.isfile(fina):
                continue
            fiList.append(fina)

    if len(fiList) == 0:
        return
    #out = bz2.BZ2File("merge.osm.bz2","w")
    #print "Found {0} data tiles".format(len(fiList))

    tileGroups.append(fiList)
    mapId = 63240000 + len(mapIds)
    mapIds.append(mapId)

    if 0:
        countNodes, countWays, countRelations = mergeTiles.MergeFiles(
            fiList, out, 0)

        if countNodes + countWays + countRelations == 0:
            #Everything is empty
            return

        cmd = "java -jar ../splitter-r412/splitter.jar --mapid={0} merge.osm.bz2".format(
            mapId)

        os.system(cmd)