Last active
August 24, 2025 21:32
-
-
Save mikeymckay/9bd6a28c0b5bc21898a95bd2efaa4587 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Define a rectangle that fully contains Kenya (with a small buffer). | |
| const KENYA_BBOX = { | |
| minLat: -5.0, // south | |
| maxLat: 5.5, // north | |
| minLon: 33.5, // west | |
| maxLon: 42.5 // east | |
| }; | |
| const newAlbumName = 'Kenya'; | |
| const filteredItems = []; | |
| function extractLatLon(coords) { | |
| if (!coords) return null; | |
| // Common patterns: | |
| // 1) [lon, lat] | |
| if (Array.isArray(coords) && coords.length >= 2) { | |
| const [lon, lat] = coords; | |
| if (Number.isFinite(lat) && Number.isFinite(lon)) return { lat, lon }; | |
| } | |
| // 2) { latitude, longitude } or { lat, lon } or { lat, lng } | |
| const lat = | |
| coords.latitude ?? | |
| coords.lat; | |
| const lon = | |
| coords.longitude ?? | |
| coords.lon ?? | |
| coords.lng; | |
| if (Number.isFinite(lat) && Number.isFinite(lon)) return { lat, lon }; | |
| return null; | |
| } | |
| function isInBBox({ lat, lon }, bbox) { | |
| return ( | |
| lat >= bbox.minLat && | |
| lat <= bbox.maxLat && | |
| lon >= bbox.minLon && | |
| lon <= bbox.maxLon | |
| ); | |
| } | |
| let nextPageId = null; | |
| gptkCore.isProcessRunning = true; | |
| try { | |
| do { | |
| const page = await gptkApi.getItemsByTakenDate( | |
| /* timestamp = */ null, | |
| /* source = */ null, | |
| /* pageId = */ nextPageId | |
| ); | |
| console.log("\n"); | |
| for (const item of page.items) { | |
| console.log("."); | |
| const coords = extractLatLon(item?.geoLocation?.coordinates); | |
| if (!coords) continue; // skip if no coordinates | |
| if (!isInBBox(coords, KENYA_BBOX)) continue; // skip if outside Kenya bbox | |
| filteredItems.push(item); | |
| console.log(filteredItems.length); | |
| } | |
| nextPageId = page.nextPageId; | |
| } while (nextPageId && filteredItems.length < 20000); | |
| if (filteredItems.length > 0) { | |
| await gptkApiUtils.addToNewAlbum(filteredItems, /* albumName = */ newAlbumName); | |
| } else { | |
| console.warn('No items found within the Kenya bounding box.'); | |
| } | |
| } finally { | |
| gptkCore.isProcessRunning = false; | |
| } | |
| console.log('DONE'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment