Parse TIFF exifs, add altitude parsing

pull/1530/head
Piero Toffanin 2024-07-29 16:57:24 -04:00
rodzic dffdd03ba4
commit 24b32ce75b
3 zmienionych plików z 50 dodań i 58 usunięć

Wyświetl plik

@ -179,10 +179,11 @@ _('Example:'),
}); });
this.capturePath.addTo(this.map); this.capturePath.addTo(this.map);
} }
this.imagesGroup = L.featureGroup(images).addTo(this.map); if (images.length > 0){
this.imagesGroup = L.featureGroup(images).addTo(this.map);
this.map.fitBounds(this.imagesGroup.getBounds()); this.map.fitBounds(this.imagesGroup.getBounds());
}
this.setState({showLoading: false}); this.setState({showLoading: false});
@ -206,59 +207,56 @@ _('Example:'),
const options = { const options = {
ifd0: false, ifd0: false,
exif: [0x9003], exif: [0x9003],
gps: [0x0001, 0x0002, 0x0003, 0x0004], gps: [0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006],
interop: false, interop: false,
ifd1: false // thumbnail ifd1: false // thumbnail
}; };
const next = (i) => {
if (i < images.length - 1) parseImage(i+1);
else{
// Sort by date/time
if (this.hasTimestamp){
this.exifData.sort((a, b) => {
if (a.timestamp < b.timestamp) return -1;
else if (a.timestamp > b.timestamp) return 1;
else return 0;
});
}
resolve();
}
};
const parseImage = i => { const parseImage = i => {
const img = images[i]; const img = images[i];
exifr.parse(img, options).then(gps => { exifr.parse(img, options).then(exif => {
if (!gps.latitude || !gps.longitude){ if (!exif.latitude || !exif.longitude){
// reject(new Error(interpolate(_("Cannot extract GPS data from %(file)s"), {file: img.name}))); // reject(new Error(interpolate(_("Cannot extract GPS data from %(file)s"), {file: img.name})));
next(i);
return; return;
} }
let dateTime = gps["36867"]; let dateTime = exif.DateTimeOriginal;
let timestamp = null; let timestamp = null;
if (dateTime && dateTime.getTime) timestamp = dateTime.getTime();
// Try to parse the date from EXIF to JS
const parts = dateTime.split(" ");
if (parts.length == 2){
let [ d, t ] = parts;
d = d.replace(/:/g, "-");
const tm = Date.parse(`${d} ${t}`);
if (!isNaN(tm)){
timestamp = new Date(tm).getTime();
}
}
if (!timestamp) this.hasTimestamp = false; if (!timestamp) this.hasTimestamp = false;
this.exifData.push({ this.exifData.push({
image: img, image: img,
gps: { gps: {
latitude: gps.latitude, latitude: exif.latitude,
longitude: gps.longitude longitude: exif.longitude,
altitude: exif.GPSAltitude !== undefined ? exif.GPSAltitude : null,
}, },
timestamp timestamp
}); });
if (i < images.length - 1) parseImage(i+1); next(i);
else{ }).catch((e) => {
// Sort by date/time console.warn(e);
if (this.hasTimestamp){ next(i);
this.exifData.sort((a, b) => { });
if (a.timestamp < b.timestamp) return -1;
else if (a.timestamp > b.timestamp) return 1;
else return 0;
});
}
resolve();
}
}).catch(reject);
}; };
if (images.length > 0) parseImage(0); if (images.length > 0) parseImage(0);
@ -497,7 +495,8 @@ _('Example:'),
type: "Point", type: "Point",
coordinates: [ coordinates: [
ed.gps.longitude, ed.gps.longitude,
ed.gps.latitude ed.gps.latitude,
ed.gps.altitude !== null ? ed.gps.altitude : 0
] ]
} }
} }
@ -507,8 +506,8 @@ _('Example:'),
if (format === 'geojson'){ if (format === 'geojson'){
output = JSON.stringify(feats, null, 4); output = JSON.stringify(feats, null, 4);
}else if (format === 'csv'){ }else if (format === 'csv'){
output = `Filename,Timestamp,Latitude,Longitude\r\n${feats.features.map(feat => { output = `Filename,Timestamp,Latitude,Longitude,Altitude\r\n${feats.features.map(feat => {
return `${feat.properties.Filename},${feat.properties.Timestamp},${feat.geometry.coordinates[1]},${feat.geometry.coordinates[0]}` return `${feat.properties.Filename},${feat.properties.Timestamp},${feat.geometry.coordinates[1]},${feat.geometry.coordinates[0]},${feat.geometry.coordinates[2]}`
}).join("\r\n")}`; }).join("\r\n")}`;
}else{ }else{
console.error("Invalid format"); console.error("Invalid format");

Wyświetl plik

@ -140,7 +140,7 @@ class ProjectListItem extends React.Component {
url : 'TO_BE_CHANGED', url : 'TO_BE_CHANGED',
parallelUploads: 6, parallelUploads: 6,
uploadMultiple: false, uploadMultiple: false,
acceptedFiles: "image/*,text/*,.las,.laz,video/*,.srt", acceptedFiles: "image/*,text/plain,.las,.laz,video/*,.srt",
autoProcessQueue: false, autoProcessQueue: false,
createImageThumbnails: false, createImageThumbnails: false,
clickable: this.uploadButton, clickable: this.uploadButton,
@ -501,34 +501,27 @@ class ProjectListItem extends React.Component {
interop: false, interop: false,
ifd1: false // thumbnail ifd1: false // thumbnail
}; };
exifr.parse(f, options).then(gps => { exifr.parse(f, options).then(exif => {
if (!gps.latitude || !gps.longitude){ if (!exif.latitude || !exif.longitude){
reject(); reject();
return; return;
} }
if (hasGPSCallback !== undefined) hasGPSCallback(); if (hasGPSCallback !== undefined) hasGPSCallback();
let dateTime = gps["36867"]; let dateTime = exif.DateTimeOriginal;
if (dateTime && dateTime.toLocaleDateString) dateTime = dateTime.toLocaleDateString();
// Try to parse the date from EXIF to JS
const parts = dateTime.split(" ");
if (parts.length == 2){
let [ d, t ] = parts;
d = d.replace(/:/g, "-");
const tm = Date.parse(`${d} ${t}`);
if (!isNaN(tm)){
dateTime = new Date(tm).toLocaleDateString();
}
}
// Fallback to file modified date if // Fallback to file modified date if
// no exif info is available // no exif info is available
if (!dateTime) dateTime = f.lastModifiedDate.toLocaleDateString(); if (!dateTime){
if (f.lastModifiedDate) dateTime = f.lastModifiedDate.toLocaleDateString();
else if (f.lastModified) dateTime = new Date(f.lastModified).toLocaleDateString();
}
// Query nominatim OSM // Query nominatim OSM
$.ajax({ $.ajax({
url: `https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=${gps.latitude}&lon=${gps.longitude}`, url: `https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=${exif.latitude}&lon=${exif.longitude}`,
contentType: 'application/json', contentType: 'application/json',
type: 'GET' type: 'GET'
}).done(json => { }).done(json => {

Wyświetl plik

@ -1 +1 @@
module.exports = require('exifr/dist/mini.umd'); module.exports = require('exifr/dist/full.legacy.umd');