1 Star 3 Fork 0

dingsl/geobuf-python-demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
geobuf_demo.py 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
dingsl 提交于 2022-03-20 08:27 . update geobuf_demo.py.
# -*- coding: utf-8 -*-
# @Time : 2022/3/20 15:26
# @Author : dingsl
# @FileName: geobuf_demo.py
# @Software: PyCharm
# @CSDN: https://blog.csdn.net/qq_24655701
import tornado.httpserver
import tornado.ioloop
import tornado.options
from tornado.web import RequestHandler
import json, geobuf
from tornado.options import define,options
define('port', default=30050, help='run port', type=int)
class CommonHandler(RequestHandler):
def set_default_headers(self):
# 解决跨域问题
self.set_header("Access-Control-Allow-Origin", "*")
self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, DELETE, PUT')
self.set_header("Access-Control-Allow-Headers", "token, content-type, user-token")
class TestHandler(CommonHandler):
def get(self):
filepath = self.get_argument("filepath")
geojson = json.load(open(filepath, encoding="utf-8"))
buf = geobuf.encode(geojson)
# 返回byte字符
self.write(buf)
application = tornado.web.Application(
handlers = [
(r'/geobuf', TestHandler),
],
# 是否开启debug模式,开启后保存修改内容会重新启动服务
debug = False
)
if __name__ == '__main__':
tornado.options.parse_command_line()
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(options.port)
print('http://127.0.0.1:{0}'.format(options.port))
tornado.ioloop.IOLoop.instance().start()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/AnywalkerGiser/geobuf-python-demo.git
git@gitee.com:AnywalkerGiser/geobuf-python-demo.git
AnywalkerGiser
geobuf-python-demo
geobuf-python-demo
master

搜索帮助