how to write a Python script to pick up pictures taken in Hong Kong from ‘imageResults.csv’. We assume that Hong Kong is the area bounded by 22.1° to 22.4° N (latitude) and, 113.8° to 114.3° E (longitude). And print results on screen.
The 10 first lines for the imageresults.csv file:
Image FPN,Time Stamp,Maker,Model,Software,Latitue,Longitude
Pic\A1.jpg,2010:06:21 16:00:57,Apple,iPhone 3G,Picasa 3.0,-12.6465,-29.564333333333334
Pic\A2.jpg,2010:06:21 16:00:57,Apple,iPhone 3G,Picasa 3.0,-61.506,146.97516666666667
Pic\A3.jpg,2010:06:21 16:00:57,Apple,iPhone 3G,Picasa 3.0,-87.77333333333333,-87.331
Pic\A4.jpg,2010:06:21 16:00:57,Apple,iPhone 3G,Picasa 3.0,48.09,-59.55683333333333
Pic\A5.jpg,2010:06:21 16:00:57,Apple,iPhone 3G,Picasa 3.0,74.46433333333333,-174.99833333333333
Pic\A6.jpg,2010:06:21 16:00:57,Apple,iPhone 3G,Picasa 3.0,50.51716666666667,-10.676833333333333
Pic\A7.jpg,2010:06:21 16:00:57,Apple,iPhone 3G,Picasa 3.0,-17.506333333333334,11.686833333333333
Pic\A8.jpg,2010:06:21 16:00:57,Apple,iPhone 3G,Picasa 3.0,82.1015,-103.86116666666666
Pic\A9.jpg,2010:06:21 16:00:57,Apple,iPhone 3G,Picasa 3.0,36.69316666666667,-29.242
CodePudding user response:
No pandas needed.
import csv
with open("imageResults.csv") as f:
for line in csv.DictReader(f):
lat = float(line["Latitue"])
lon = float(line["Longitude"])
if 22.1 < lat < 22.4 and 113.8 < lon < 114.3:
print(line)
In the supplied file, there's one matching photo:
{'Image FPN': 'Pic\\hill & river_R.jpg', 'Time Stamp': '2006:05:17 20:32:04', 'Maker': 'NIKON CORPORATION', 'Model': 'NIKON D200', 'Software': 'Nikon Browser 6.2.7 W', 'Latitue': '22.33166666663889', 'Longitude': '114.02833333333334'}
