add: file upload

rrr-marble 2 years ago
parent 7e39964fed
commit 6b3cc13d4c

@ -17,7 +17,7 @@ def geojson2vt(uploaded_geojson) -> str:
uploaded_geojson_path = "land.geojson" # replace value with the path to the saved geojson uploaded_geojson_path = "land.geojson" # replace value with the path to the saved geojson
vector_tiles_id = uploaded_geojson_path + uuid.uuid4().hex vector_tiles_id = uploaded_geojson_path + uuid.uuid4().hex
tippecanoe_command = f"tippecanoe --maximum-zoom=g --output-to-directory={vector_tiles_id} --drop-densest-as-needed --no-tile-compression {uploaded_geojson_path}" tippecanoe_command = f"tippecanoe --maximum-zoom=g --output-to-directory={vector_tiles_id} --drop-densest-as-needed --no-tile-compression {uploaded_geojson_path}"
subprocess.run(tippecanoe_command, shell=True) # https://stackoverflow.com/a/51950538/14742462 #subprocess.run(tippecanoe_command, shell=True) # https://stackoverflow.com/a/51950538/14742462
metadata_path = Path(vector_tiles_id, "metadata.json") metadata_path = Path(vector_tiles_id, "metadata.json")
with open(metadata_path, "r") as metadata_file: with open(metadata_path, "r") as metadata_file:
metadata = json.load(metadata_file) metadata = json.load(metadata_file)
@ -30,7 +30,8 @@ def geojson2vt(uploaded_geojson) -> str:
json.dump(catalog, catalog_file, ensure_ascii=False) json.dump(catalog, catalog_file, ensure_ascii=False)
return vector_tiles_id return vector_tiles_id
geojson2vt("ert") if __name__ == "__main__":
geojson2vt("ert")

@ -1,7 +1,14 @@
from fastapi import FastAPI from fastapi import FastAPI, UploadFile
from .geojson2vt import geojson2vt
app = FastAPI() app = FastAPI()
@app.get("/") @app.get("/")
async def root(): async def root():
return {"message": "Hello World!"} return {"message": "Hello World!"}
@app.post("/upload/")
async def create_upload_file(file: UploadFile):
geojson2vt(file)
return {"filename": file.filename}

16
poetry.lock generated

@ -207,6 +207,20 @@ files = [
[package.dependencies] [package.dependencies]
typing-extensions = ">=4.6.0,<4.7.0 || >4.7.0" typing-extensions = ">=4.6.0,<4.7.0 || >4.7.0"
[[package]]
name = "python-multipart"
version = "0.0.7"
description = "A streaming multipart parser for Python"
optional = false
python-versions = ">=3.7"
files = [
{file = "python_multipart-0.0.7-py3-none-any.whl", hash = "sha256:b1fef9a53b74c795e2347daac8c54b252d9e0df9c619712691c1cc8021bd3c49"},
{file = "python_multipart-0.0.7.tar.gz", hash = "sha256:288a6c39b06596c1b988bb6794c6fbc80e6c369e35e5062637df256bee0c9af9"},
]
[package.extras]
dev = ["atomicwrites (==1.2.1)", "attrs (==19.2.0)", "coverage (==6.5.0)", "hatch", "invoke (==2.2.0)", "more-itertools (==4.3.0)", "pbr (==4.3.0)", "pluggy (==1.0.0)", "py (==1.11.0)", "pytest (==7.2.0)", "pytest-cov (==4.0.0)", "pytest-timeout (==2.1.0)", "pyyaml (==5.1)"]
[[package]] [[package]]
name = "sniffio" name = "sniffio"
version = "1.3.0" version = "1.3.0"
@ -267,4 +281,4 @@ standard = ["colorama (>=0.4)", "httptools (>=0.5.0)", "python-dotenv (>=0.13)",
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.11" python-versions = "^3.11"
content-hash = "f3bcc47b9274ec536168a19385d173378d272e74220e966aef2a34eca1e7c5ee" content-hash = "ea9a5187e026efd84d1eaf25926de037c113f142e23f98d44c342a5aea7ff900"

@ -10,6 +10,7 @@ readme = "README.md"
python = "^3.11" python = "^3.11"
fastapi = "^0.109.2" fastapi = "^0.109.2"
uvicorn = "^0.27.0.post1" uvicorn = "^0.27.0.post1"
python-multipart = "^0.0.7"
[build-system] [build-system]

Loading…
Cancel
Save