Geotagging my coordinates with images

Hi,there . The code that i want to write is :(i have a file of images and each images has a gps coordination in my csv excel file , well i need a code that gets a coordinates from my excel and tags it to it’s own picture… and at the end when i get the properties of my pictures i can see the coordinates in details) … i wrote to many codes but I wasn’t successful …plz help me to solve it ..thank you . And i took an example of my code .
Picfile=(address);coordsfile=(address.csv);
for i = 1:height(coords)
filename = coords.Filename{i};
lat = coords.Latitude(i);
lon = coords.Longitude(i);
command = sprintf( lat, lon, filename);
system(['exiftool ' command]);
end

댓글 수: 4

Walter Roberson
Walter Roberson 2025년 1월 16일

height(coords) tends to imply that coords is a non-scalar struct. However, coords.Filename{i} is invalid indexing if coords is a non-scalar struct. I suggest using numel(coords.Filename) instead of height(coords)

Moa
Moa 2025년 1월 16일
편집: Walter Roberson 2025년 1월 17일
Thanks can you help me more plz.i have problem in creating exiftool command to set gps location ….can you please explain what should i put or not in there !?
This part of my code is :
Cmd=sprintf(exiftool -gpslatitude=lat -gpslongitude=lon filename);
Status = system(cmd)
And i get this error
Warning:error converting value for gps:gpslatitude(valueconvinv
)
And my full code is :
Clc
Clear all
Coord(path of coords.csv)
Photo=(path of my image file)
Coords=readtable(coord)
For i=1:numel(coords.filename)
Filename= coords.filename(i)
Lat= coords.latitude(i)
Lon= coords.longitude(i)
Cmd=sprintf(exiftool -gpslatitude=lat -gpslongitude=lon filename);
Addpath(genpath(path of my run_exiftool file that I downloaded from here)
Status = system(cmd)
Thanks for your help in advance
Walter Roberson
Walter Roberson 2025년 1월 17일
편집: Walter Roberson 2025년 1월 17일
MATLAB is case sensitive, so For will not be recognized as being a for loop.
Also, the quotes ‘ and “ are unicode U+2018 and U+201C which are not recognized by MATLAB. You need to use U+0027 and U+0022 instead.
Cmd=sprintf('exiftool -gpslatitude=%g -gpslongitude=%g filename', Lat, Lon);

댓글을 달려면 로그인하십시오.

답변 (1개)

Sandeep Mishra
Sandeep Mishra 2025년 1월 16일

0 개 추천

Hi Moa,
You can use the ‘Exiftool’ open-source software to modify the EXIF Data of an image.
Refer to the following example code snippet to modify the GPS property:
imagePath = 'image_file_name.png';
latitude = 38.7041;
longitude = 77.1025;
% Creating exiftool command to set GPS location
cmd = sprintf('exiftool -GPSLatitude=%f -GPSLatitudeRef=%s -GPSLongitude=%f -GPSLongitudeRef=%s "%s"', ...
latitude, latRef, longitude, lonRef, imagePath);
% Executing the exiftool command
status = system(cmd);
I hope this helps you!

댓글 수: 1

Moa
Moa 2025년 1월 16일

I have problem in creating exiftool command to set gps location ….can you please explain what should i put or not in there !? This part of my code is : Cmd=sprintf(‘exiftool -gpslatitude=lat -gpslongitude=lon filename’); Status = system(cmd) And i get this error Warning:error converting value for gps:gpslatitude(valueconvinv)

And my full code is : Clc Clear all Coord(“path of coords.csv”) Photo=(“path of my image file”) Coords=readtable(coord) For i=1:numel(coords.filename) Filename= coords.filename(i) Lat= coords.latitude(i) Lon= coords.longitude(i) Cmd=sprintf(‘exiftool -gpslatitude=lat -gpslongitude=lon filename’); Addpath(genpath(“path of my run_exiftool file that I downloaded from here”) Status = system(cmd) Thanks for your help in advance

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

태그

질문:

Moa
2025년 1월 16일

편집:

2025년 1월 17일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by