My database was only storing the URL to those images, not their widths and heights. In order to generate the correct HTML I needed that extra information.
Niche Museums hosts photos in an S3 bucket behind Imgix, which means I can resize the photos on demand using the ?w= and ?h= query parameters.
It also means I can get back JSON for the EXIF data of the images by appending ?fm=json.
I skipped a step here: how did I load the data into that raw_photos table in the first place?
First I wrote a Python script to retrieve the JSON metadata for every photo. This dumped them into a photos-metadata/ directory, each one with a name like IMG_0859.jpeg.json.
Next, I wrote a sqlite-utils Python script to load all of those JSON files into my SQLite database. That script also creates a photos view that implements the above case SQL logic.
I initially wrote this as a shell script, but it was a LOT slower than doing it in Python:
I haven’t been to most of those countries, so those locations are showing in the wrong place!
I said to GPT-4:
1
{
2
"HPositioningError": 128,
3
"Longitude": 122.449,
4
"Latitude": 37.7422,
5
"Speed": 0,
6
"SpeedRef": "K",
7
"ImgDirectionRef": "T",
8
"ImgDirection": 320.522,
9
"LongitudeRef": "W",
10
"LatitudeRef": "N",
11
"AltitudeRef": 0,
12
"DateStamp": "2018:02:20",
13
"Altitude": 167,
14
"TimeStamp": "22:44:21",
15
"DestBearingRef": "T",
16
"DestBearing": 320.522
17
}
How do I turn that into a latitude/longitude with correct - or +
It replied:
To convert the given JSON data into a proper latitude/longitude format with correct positive or negative signs, you’ll need to account for the LatitudeRef and LongitudeRef values. If the LatitudeRef is “S” (South), the latitude should be negative. If the LongitudeRef is “W” (West), the longitude should be negative.
I pasted in my SQL query and said “Rewrite this SQL query to apply those rules” - and it gave me the following: