Created
April 20, 2021 14:14
-
-
Save ambientlight/3c75754d86a0217d90e9ceca939aff9d to your computer and use it in GitHub Desktop.
Azure Maps Creator: DWG to Tileset for https://docs.microsoft.com/en-us/azure/azure-maps/tutorial-creator-indoor-maps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ -z $1 ]] ; then | |
echo "Resource path is required" | |
exit 1 | |
fi | |
RESOURCE=$1 | |
# azure maps primary subscription key | |
SUBSCRIPTION_KEY=YOUR_KEY | |
function long_running_invoke_get_target_id() { | |
local SUBPATH=$1 | |
local RESOURCE_SUBPATH=$2 | |
local EXTRA_PARAMS=$3 | |
local LOCATION=$(curl --data '' -X POST "https://atlas.microsoft.com/$SUBPATH?subscription-key=$SUBSCRIPTION_KEY&api-version=1.0$EXTRA_PARAMS" \ | |
-s -o /dev/null -D - | grep location) | |
# removes trailing writespace and carriage return | |
local STATUS_URL=$(echo ${LOCATION#*:} | sed 's/\r$//') | |
local STATE=$(curl -s "$STATUS_URL&subscription-key=$SUBSCRIPTION_KEY") | |
local STATUS=$(echo $STATE | jq .status -r) | |
while [[ $STATUS == "Running" ]] ; do | |
sleep 1 | |
local STATE=$(curl -s "$STATUS_URL&subscription-key=$SUBSCRIPTION_KEY") | |
local STATUS=$(echo $STATE | jq .status -r) | |
done | |
local TARGET_ID=$(echo $STATE | jq .resourceLocation -r | sed "s/^https:\/\/atlas\.microsoft\.com\/$RESOURCE_SUBPATH\/\(.*\)?api-version=1\.0$/\1/") | |
echo $TARGET_ID | |
} | |
LOCATION=$(curl "https://atlas.microsoft.com/mapData/upload?api-version=1.0&dataFormat=zip&subscription-key=$SUBSCRIPTION_KEY" \ | |
--header "Content-Type:application/octet-stream" \ | |
--data-binary @$RESOURCE \ | |
-s -o /dev/null -D - | grep location) | |
# BEFORE=${LOCATION%:*} | |
STATUS_URL=$(echo ${LOCATION#*:} | sed 's/\r$//') | |
STATE=$(curl -s "$STATUS_URL&subscription-key=$SUBSCRIPTION_KEY") | |
STATUS=$(echo $STATE | jq .status -r) | |
while [[ $STATUS == "Running" ]] ; do | |
sleep 1 | |
STATE=$(curl -s "$STATUS_URL&subscription-key=$SUBSCRIPTION_KEY") | |
STATUS=$(echo $STATE | jq .status -r) | |
done | |
META_URL=$(echo $STATE | jq .resourceLocation -r) | |
UDID=$(curl -s "$META_URL&subscription-key=$SUBSCRIPTION_KEY" | jq .udid -r) | |
echo "Upload UDID: $UDID" | |
# conversion | |
CONVERSION_ID=$(long_running_invoke_get_target_id "conversion/convert" "conversion" "&udid=$UDID&inputType=DWG") | |
echo "ConversionID: $CONVERSION_ID" | |
# dataset creation | |
DATASET_ID=$(long_running_invoke_get_target_id "dataset/create" "dataset" "&conversionID=$CONVERSION_ID&type=facility") | |
echo "DatasetID: $DATASET_ID" | |
# tileset creation | |
TILESET_ID=$(long_running_invoke_get_target_id "tileset/create/vector" "tileset" "&datasetID=$DATASET_ID") | |
echo "TilesetID: $TILESET_ID" | |
if [[ -n $TILESET_ID ]] ; then | |
echo "Tileset creation completed succesfully" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment