Skip to content

Instantly share code, notes, and snippets.

@zedxxx
Last active July 1, 2023 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zedxxx/0f699e84e8b22b15fc84a6300a0228ee to your computer and use it in GitHub Desktop.
Save zedxxx/0f699e84e8b22b15fc84a6300a0228ee to your computer and use it in GitHub Desktop.
SatMap cache tile server + SASPlanet zmp
[PARAMS]
GUID={C137CF51-CBEF-4267-80EA-DF88C157D0C5}
ParentSubMenu=SatMap Cache
name=Google Sat
NameInCache=satmap.sat
DefURLBase=http://localhost:8080/satmap/0/{z}/{x}/{y}
ContentType=image/jpeg
Ext=.jpg
EPSG=3785
CacheType=9
MemCacheTTL=30000000
MemCacheCapacity=2000
MaxConnectToServerCount=1
#!/usr/bin/python
from http.server import BaseHTTPRequestHandler, HTTPServer
import sqlite3
hostName = "localhost"
serverPort = 8080
conn = (sqlite3.connect('b:/cache1'),
sqlite3.connect('b:/cache2'),
)
cursor = list(map(lambda connection: connection.cursor(), conn))
class SatMapServer(BaseHTTPRequestHandler):
protocol_version = 'HTTP/1.1'
content_type = ("image/jpeg", "image/png", "image/png", "image/jpeg")
def do_GET(self):
# http://localhost:port/stamap/{map}/{z}/{x}/{y}
req = self.path.split("/")
if req and len(req) == 6:
_,_,m,z,x,y = req
else:
self.send_response(400) # Bad Request
self.send_header("content-length", "0")
self.end_headers()
return
query = """SELECT f11,f12 FROM tiles WHERE f2=? AND f5=? AND f3=? AND f4=?"""
tile = None
for cur in cursor:
cur.execute(query, (z,m,x,y))
tile = cur.fetchone()
if tile:
break
if tile:
self.send_response(200) # Ok
self.send_header("content-type", self.content_type[int(m)])
self.send_header("content-length", tile[0])
self.end_headers()
self.wfile.write(tile[1])
else:
self.send_response(404) # Not Found
self.send_header("content-length", "0")
self.end_headers()
if __name__ == '__main__':
httpd = HTTPServer((hostName, serverPort), SatMapServer)
print("SatMap server started at %s:%s" % (hostName, serverPort))
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
print("Server stopped.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment