add send to panoramax bash script for mapillary multiple folders

This commit is contained in:
Tykayn 2023-06-13 12:21:27 +02:00 committed by tykayn
parent 9fa87a3e4a
commit 2dc0025735
6 changed files with 2849 additions and 0 deletions

2681
.nx/installation/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
{"name":"nx-installation","devDependencies":{"nx":"16.3.1"}}

View File

@ -0,0 +1,38 @@
const fs = require('fs');
const path = require('path');
const inputDirNameArg = process.argv[2];
console.log('dossier:', inputDirNameArg)
const extensions = [];
function findFileExtensions(directory) {
function traverseDirectory(dirPath) {
fs.readdir(dirPath, (err, files) => {
if (err) throw err;
files.forEach((file) => {
const filePath = path.join(dirPath, file);
const stat = fs.lstatSync(filePath);
if (stat.isFile()) {
const extension = path.extname(filePath).toLowerCase();
if (!extensions.includes(extension)) {
extensions.push(extension);
}
} else if (stat.isDirectory() && !file.startsWith('.')) {
traverseDirectory(filePath);
console.log(extensions.length, extensions);
}
});
});
}
traverseDirectory(directory);
}
findFileExtensions(inputDirNameArg);

View File

@ -0,0 +1,33 @@
#!/bin/bash
# ---------------------------------------------------------------------------------------------
# envoi de plusieurs dossiers de photos (exportés de mapillary) vers panoramax
# fonctionne avec un dossier contenant les dossiers de photos de mapillary
# déplace les dossiers importés dans un autre afin d'effectuer un suivi progresssif
#
# ---------------- usage:
# changez les variables suivantes, puis lancez la commande bash:
#
# bash panoramax_bash_send.sh
#
# ---------------------------- made by tykayn www.cipherbliss.com -----------------------------
containing_mapillary_folders="/home/poule/encrypted/stockage-syncable/photos/imagerie_kartaview_carto_tel/mapillary"
done_mapillary_folders="/home/poule/encrypted/stockage-syncable/photos/imagerie_kartaview_carto_tel/already_sent_to_panoramax_osm_fr"
panoramax_instance="https://panoramax.openstreetmap.fr"
function import_mapillary_folders_and_move_in_imported_folder() {
echo 'change directory to' $containing_mapillary_folders
cd $containing_mapillary_folders
echo "dossiers à envoyer: "
ls -l |wc -l
echo " "
# loop in containing folder
for f in *; do
echo "envoi du dossier" "$containing_mapillary_folders/$f"
geovisio upload --api-url $panoramax_instance "$containing_mapillary_folders/$f"
mv "$containing_mapillary_folders/$f" "$done_mapillary_folders"
done
}
import_mapillary_folders_and_move_in_imported_folder

View File

@ -0,0 +1,67 @@
const fs = require('fs');
const path = require('path');
var exec = require('child_process').exec;
const mapillaryDirectoryContainer = "/home/poule/encrypted/stockage-syncable/photos/imagerie kartaview carto tel/mapillary"; // Replace with path to source directory
const panoramaxCommand = "geovisio upload --api-url https://panoramax.openstreetmap.fr "
const reallyUploadToPanoramax = false;
/**
* envoyer les photos d'un dossier dans panoramax
* @param folderName
* @returns {Promise<{name: string, email: string}>}
*/
async function importToPanoramax(folderName) {
// Exec output contains both stderr and stdout outputs
console.log('exec command listing ', folderName)
const countPhotos = await exec('ls -l ' + folderName + ' |wc -l')
console.log('countPhotos.stdout', countPhotos)
let stdOutData = {
name: countPhotos.stdout,
}
if (reallyUploadToPanoramax) {
const uploadPanoramax = await exec(panoramaxCommand + folderName)
stdOutData['upload'] = uploadPanoramax.stdout
}
return stdOutData;
}
importToPanoramax(mapillaryDirectoryContainer)
let commandOutput = [];
/**
* lister les dossier dans un dossier et faire un upload dans panoramax
* @param dir
*/
function traverseDirectoryTree(dir) {
const contents = fs.readdirSync(dir);
for (let i = 0; i < contents.length; i++) {
let filename = contents[i];
const fullPath = path.join(dir, filename);
try {
const stats = fs.lstatSync(fullPath);
if (stats.isFile()) {
return;
} else if (stats.isDirectory()) {
console.log(`Dossier ${fullPath} à envoyer`);
// commande envoi
// geovisio upload --api-url https://panoramax.openstreetmap.fr le_dossier_de_photos
// traverseDirectoryTree(fullPath);
importToPanoramax(fullPath).then(data => commandOutput.push(data))
}
} catch (err) {
console.error(`Error traversing ${fullPath}: ${err}`);
}
}
}
traverseDirectoryTree(mapillaryDirectoryContainer);
console.log("Exiting directory tree");

View File

@ -0,0 +1,29 @@
import sys
import json
from urllib import request
# Define query parameters for OpenStreetMap Overpass API
query = """
{
__export_roof_area__: "paris";
("building" "roof");
union;
out;
totalways;
};
out geom;
"""
url = f"https://overpass-api.de/interpreter?data=[out:{query}]&lang=json&zipped=true"
# Execute GET request and retrieve JSON data
response = request.urlopen(url)
data = json.loads(response.read().decode('utf-8'))
way = next((x for x in data["elements"] if x["type"] == "way"), None)
total_area = 0.0
if way:
nodes = [node['nodes'] for node in way["geometry"] if node["type"] == "Area"]
for node in nodes:
area = float(node["value"]) * 10**6 # Convert bytes to km^2
total_area += area
print(f"Total roof area of buildings in Paris: {total_area}")