A python micro service template for transforming a JSON entity stream. This service is designed to be used as a microservice system with the HTTP transform in a Sesam service instance.
It converts UTM33 (EUREF89 aka GAB) coordinates to LatLong (GPS coordinates aka WGS84).
cd utmtolatlong-microservice/service virtualenv --python=python3 venv . venv/bin/activate pip install -r requirements.txt python transform-service.py * Running on http://0.0.0.0:5001/ (Press CTRL+C to quit) * Restarting with stat * Debugger is active! * Debugger pin code: 260-787-156
The service listens on port 5001 on localhost.
cd utmtolatlong-microservice docker build -t utmtolatlong-microservice . docker run -it --rm --name utmtolatlong-microservice -p 5001:5001 utmtolatlong-microservice
Get the IP from docker:
docker inspect -f '{{.Name}} - {{.NetworkSettings.IPAddress }}' utmtolatlong-microservice
JSON entities can be posted to 'http://localhost:5001/transform'. The result is streamed back to the client. Exchange "localhost" with the Docker IP if running in Docker.
$ curl -s -XPOST 'http://localhost:5001/transform' -H "Content-type: application/json" -d '[{ "_id": "jane", "northing": "12344", "easting": "6543", "zone": "32"}]' | jq -S .
[
{
"_id": "jane",
"message": "Hello world!",
"name": "Jane Doe",
"northing": "12344",
"easting": "6543",
"zone": "32",
"lat": 0.11134243423572525,
"lon": 4.569868852874141
}
]
Note the example uses curl to send the request and jq prettify the response.
You can configure the service with the following environment variables:
| Variable | Description | Default |
EASTING_PROPERTY |
The name of the property holding the "easting" value. The value itself can be either a string, float, int or decimal. If a string, it must be castable to a float. | "easting" |
NORTHING_PROPERTY |
The name of the property holding the "northing" value. The value itself can be either a string, float, int or decimal. If a string, it must be castable to a float. | "northing" |
ZONE_PROPERTY |
The name of the property holding the "zone" value. The value itself can be either a string, float, int or decimal. It must be castable to an int. | "zone" |
ZONE_DEFAULT |
The default "zone" value if none are found in the entity. The value itself can be either a string, float, int or decimal. It must be castable to an int. | "32" |
HEMI_PROPERTY |
The name of the property holding the "hemisphere" value. The value itself can be either a string, float, int or decimal. It must be castable to an int. A 0 value means northern hemisphere, any other value means southern hemisphere. | "hemi" |
HEMI_DEFAULT |
The default "hemisphere" value. The value itself can be either a string, float, int or decimal. It must be castable to an int. A 0 value means northern hemisphere, any other value means southern hemisphere. | "0" |
LAT_PROPERTY |
The name of the property that will hold the converted "latitude" value. | "lat" |
LONG_PROPERTY |
The name of the property that will hold the converted "longitude" value. | "long" |
INCLUDE_LAT_LONG |
A flag to indicate wheter to include a lat_long value in the returned entity. A value of "true" means yes. Any other value means no. | "false" |
LAT_LONG_PROPERTY |
The name of the property that will hold the converted "lat_long" value
("lat, long"). It is only inserted in the returned entity if INCLUDE_LAT_LONG
evaluates to yes. |
"lat_long" |
When running in Docker you can either specify this in a file (see https://docs.docker.com/compose/env-file/) or on the command line with "docker run .. -e VAR1=VAL1 -e VAR2=VAL2 .."