Skip to content
Snippets Groups Projects
Commit dff19050 authored by Riccardo Boero's avatar Riccardo Boero :innocent:
Browse files

Draft of service with python package.

parent 0e44cbe6
No related branches found
No related tags found
No related merge requests found
geodata/data
FROM python:3.9.16-slim-bullseye
# update system and install required software
RUN apt update && /usr/local/bin/python -m pip install --upgrade pip && pip install poetry
# copy zipped data
COPY data /root/data
# unzip geotiff
RUN $HOME/install_data.sh
# setup the python environment
RUN $HOME/load_server_package.sh
# start server & expose port
CMD ["sh", "/root/run.sh"]
EXPOSE 5000
......@@ -2,16 +2,40 @@
---
## Use
The docker container can be started with the following code:
>podman run -t -i --name fact_road_elevation -p 5003:5000 -d registry.git.nilu.no/fact/data/fact\_elevation:0.3
The service could be queried passing the JSON polygon object as in:
```
curl -X POST http://localhost:5000/band_statistics \
-H "Content-Type: application/json" \
-d '{
"polygon_wkt": "POLYGON (())"
}'
```
The polygon definition is made of several points coordinates, as in the case of polygon objects from shapefiles stored in databases. Polygon and COG rasters must share the same coordinate system, which in this case is lat and lon.
---
## Specifications
The API is based on the Flask based web service provided by the FACT Utils [polygonqueryonraster](https://git.nilu.no/fact/utils/PolygonQueryOnRaster/-/packages) package from the the [FACT Polygon Query on Raster](https://git.nilu.no/fact/utils/PolygonQueryOnRaster) project.
The data is from the Terra Advanced Spaceborne Thermal Emission and Reflection Radiometer (ASTER) Global Digital Elevation Model (GDEM) Version 3 (ASTGTM - https://lpdaac.usgs.gov/products/astgtmv003/), that provides a global digital elevation model (DEM) of land areas on Earth at a spatial resolution of 1 arc second (approximately 30 meter horizontal posting at the equator). Coverage is provided from from -83 to 83 degrees latitude.
---
## Notes
Since this service is based on a continuous raster, results for polygon elevation will include:
- 'count' of pixels in the polygon,
- 'min' elevation,
- 'max' elevation,
- 'mean' elevation,
- 'std' standard deviation of elevation,
- 'median' elevation,
- 'entropy', which is the Shannon entropy measure of elevation data.
---
### Authors
Riccardo Boero - ribo@nilu.no
### License
FROM nginx:latest
# copy script
COPY inputs/install_data.sh /root/inputs/install_data.sh
# copy nginx configuration file
COPY inputs/nginx.conf /etc/nginx/nginx.conf
# copy zipped data
COPY data /root/data
# make shell scripts executables
RUN chmod a+x /root/inputs/*.sh
# unzip geotiff
RUN $HOME/inputs/install_data.sh
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
autoindex on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
# This file is machine-generated - editing it directly is not advised
julia_version = "1.9.3"
manifest_format = "2.0"
project_hash = "0ec462e31810c0086edaef2141d40750b1c7c014"
[[deps.Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
[[deps.Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
[[deps.BitFlags]]
git-tree-sha1 = "2dc09997850d68179b69dafb58ae806167a32b1b"
uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
version = "0.1.8"
[[deps.CodecZlib]]
deps = ["TranscodingStreams", "Zlib_jll"]
git-tree-sha1 = "cd67fc487743b2f0fd4380d4cbd3a24660d0eec8"
uuid = "944b1d66-785c-5afd-91f1-9de20f533193"
version = "0.7.3"
[[deps.ConcurrentUtilities]]
deps = ["Serialization", "Sockets"]
git-tree-sha1 = "8cfa272e8bdedfa88b6aefbbca7c19f1befac519"
uuid = "f0e56b4a-5159-44fe-b623-3e5288b988bb"
version = "2.3.0"
[[deps.Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
[[deps.ExceptionUnwrapping]]
deps = ["Test"]
git-tree-sha1 = "e90caa41f5a86296e014e148ee061bd6c3edec96"
uuid = "460bff9d-24e4-43bc-9d9f-a8973cb893f4"
version = "0.1.9"
[[deps.HTTP]]
deps = ["Base64", "CodecZlib", "ConcurrentUtilities", "Dates", "ExceptionUnwrapping", "Logging", "LoggingExtras", "MbedTLS", "NetworkOptions", "OpenSSL", "Random", "SimpleBufferStream", "Sockets", "URIs", "UUIDs"]
git-tree-sha1 = "5eab648309e2e060198b45820af1a37182de3cce"
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3"
version = "1.10.0"
[[deps.InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
[[deps.JLLWrappers]]
deps = ["Artifacts", "Preferences"]
git-tree-sha1 = "7e5d6779a1e09a36db2a7b6cff50942a0a7d0fca"
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
version = "1.5.0"
[[deps.JSON3]]
deps = ["Dates", "Mmap", "Parsers", "PrecompileTools", "StructTypes", "UUIDs"]
git-tree-sha1 = "95220473901735a0f4df9d1ca5b171b568b2daa3"
uuid = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
version = "1.13.2"
[[deps.Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
[[deps.Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
[[deps.LoggingExtras]]
deps = ["Dates", "Logging"]
git-tree-sha1 = "c1dd6d7978c12545b4179fb6153b9250c96b0075"
uuid = "e6f89c97-d47a-5376-807f-9c37f3926c36"
version = "1.0.3"
[[deps.Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
[[deps.MbedTLS]]
deps = ["Dates", "MbedTLS_jll", "MozillaCACerts_jll", "NetworkOptions", "Random", "Sockets"]
git-tree-sha1 = "f512dc13e64e96f703fd92ce617755ee6b5adf0f"
uuid = "739be429-bea8-5141-9913-cc70e7f3736d"
version = "1.1.8"
[[deps.MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
version = "2.28.2+0"
[[deps.Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
[[deps.MozillaCACerts_jll]]
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"
version = "2022.10.11"
[[deps.NetworkOptions]]
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
version = "1.2.0"
[[deps.OpenSSL]]
deps = ["BitFlags", "Dates", "MozillaCACerts_jll", "OpenSSL_jll", "Sockets"]
git-tree-sha1 = "51901a49222b09e3743c65b8847687ae5fc78eb2"
uuid = "4d8831e6-92b7-49fb-bdf8-b643e874388c"
version = "1.4.1"
[[deps.OpenSSL_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
git-tree-sha1 = "cc6e1927ac521b659af340e0ca45828a3ffc748f"
uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95"
version = "3.0.12+0"
[[deps.Parsers]]
deps = ["Dates", "PrecompileTools", "UUIDs"]
git-tree-sha1 = "a935806434c9d4c506ba941871b327b96d41f2bf"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "2.8.0"
[[deps.PrecompileTools]]
deps = ["Preferences"]
git-tree-sha1 = "03b4c25b43cb84cee5c90aa9b5ea0a78fd848d2f"
uuid = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
version = "1.2.0"
[[deps.Preferences]]
deps = ["TOML"]
git-tree-sha1 = "00805cd429dcb4870060ff49ef443486c262e38e"
uuid = "21216c6a-2e73-6563-6e65-726566657250"
version = "1.4.1"
[[deps.Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
[[deps.Random]]
deps = ["SHA", "Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
[[deps.SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
version = "0.7.0"
[[deps.Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
[[deps.SimpleBufferStream]]
git-tree-sha1 = "874e8867b33a00e784c8a7e4b60afe9e037b74e1"
uuid = "777ac1f9-54b0-4bf8-805c-2214025038e7"
version = "1.1.0"
[[deps.Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
[[deps.StructTypes]]
deps = ["Dates", "UUIDs"]
git-tree-sha1 = "ca4bccb03acf9faaf4137a9abc1881ed1841aa70"
uuid = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
version = "1.10.0"
[[deps.TOML]]
deps = ["Dates"]
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
version = "1.0.3"
[[deps.Test]]
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[[deps.TranscodingStreams]]
git-tree-sha1 = "1fbeaaca45801b4ba17c251dd8603ef24801dd84"
uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
version = "0.10.2"
weakdeps = ["Random", "Test"]
[deps.TranscodingStreams.extensions]
TestExt = ["Test", "Random"]
[[deps.URIs]]
git-tree-sha1 = "67db6cc7b3821e19ebe75791a9dd19c9b1188f2b"
uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
version = "1.5.1"
[[deps.UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
[[deps.Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
[[deps.Zlib_jll]]
deps = ["Libdl"]
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
version = "1.2.13+0"
name = "LandComputer"
uuid = "f5af15f0-71d5-4d14-8c92-c6815c71e465"
authors = ["Riccardo Boero <ribo@nilu.no>"]
version = "0.1.0"
[deps]
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
module LandComputer
using HTTP, JSON3
const SERVER = Ref{HTTP.Servers.Server}()
const SERVER_ROUTER = HTTP.Router()
find_square(n) = n*n
function find_square_req(req)
data = JSON3.read(req.body, Dict)
n = data["number"]
return HTTP.Response(200, JSON3.write(Dict("number" => n, "square" => find_square(n))))
end
HTTP.register!(SERVER_ROUTER, "POST", "/api/find_square_req", find_square_req)
function get_land_req(req)
data = JSON3.read(req.body, Dict)
n = data["polygon"]
r = rasterized_polygon(n)
return HTTP.Response(200, JSON3.write(Dict("mean" => find_mean(r), "std" => find_std(r), "min" => find_min(r), "max" => find_max(r))))
end
HTTP.register!(SERVER_ROUTER, "POST", "/api/FACT_lulc", get_land_req)
function live(req)
return HTTP.Response(200, JSON3.write("OK"))
end
HTTP.register!(SERVER_ROUTER, "GET", "/api/live", live)
function run()
SERVER[] = HTTP.serve(SERVER_ROUTER, "0.0.0.0", 3000)
end
end # module LandComputer
#!/bin/bash
# it requires zipped geotiff in "data"
#mkdir data
#sudo mount /dev/sdd2 data -o allow_other
apt update
apt install zip -y
......@@ -12,6 +9,7 @@ echo "*** Unzipping files." # expected number of records in DB:
#for y in {2017..2021}
for y in {2017..2021}
do
unzip -d /usr/share/nginx/html /root/data/lulc${y}.zip
mkdir -p /root/data/${y}
unzip -d /root/data/${y} /root/data/lulc${y}.zip
rm /root/data/lulc${y}.zip
done
#!/usr/bin/env bash
# initialize project
poetry init
# confif repo
poetry config repositories.gitlab https://git.nilu.no/api/v4/projects/1217/packages/pypi
poetry config http-basic.gitlab FACT_token glpat-1zG-TQx___xLsPjj2vsG
# add package
poetry add polygonqueryonraster --source gitlab
#!/usr/bin/env bash
python /app/other/start.py
from polygonqueryonraster.app import GeoTIFFService
if __name__ == "__main__":
"""
Main execution point for running the GeoTIFFService as a standalone application.
This script initializes and starts the GeoTIFFService with a predefined data directory and port number.
It's designed to be run directly from the command line and is useful for quick setups or testing.
The GeoTIFFService is configured to analyze the GeoTIFF files located in the specified directory.
It sets up a Flask-based web server to listen for incoming requests for geospatial analysis.
Configuration:
- Data Directory: The directory where GeoTIFF files are stored. This should be an absolute path.
- Port Number: The port number on which the Flask web server will run.
- Categorical Analysis: Indicates whether the analysis should be categorical. It's set to 'false' by default.
Example:
When this script is run, it starts the GeoTIFFService on the specified port and ready to process
requests on GeoTIFF files located in the specified data directory.
Usage:
python scriptname.py
Note:
To use this script, ensure that the 'polygonqueryonraster' package is installed and accessible in your
Python environment. Modify the 'data_directory' and 'port_number' variables as needed for your setup.
"""
data_directory = '/app/data/aster30m' # Specify your local data directory
port_number = 5000 # Specify the custom port number
categorical = False # Specify whether the analysis is categorical
service = GeoTIFFService(directory=data_directory, port=port_number, categorical=categorical)
service.run()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment