Skip to content

Instantly share code, notes, and snippets.

@mlc
Last active January 26, 2025 04:35
Show Gist options
  • Save mlc/017aa2145f14a21fb90a740d7ac15d42 to your computer and use it in GitHub Desktop.
Save mlc/017aa2145f14a21fb90a740d7ac15d42 to your computer and use it in GitHub Desktop.
tpg distance-to-best-photo map

make a map of your TPG photo scores

in just a few easy far too many far too complex steps

compute the distances

  1. Make a Postgres database with PostGIS
  2. Add a photos table:
    CREATE TABLE photos(id SERIAL PRIMARY KEY, title VARCHAR(255), location geography(POINT, 4326) NOT NULL);
    CREATE INDEX photos_location ON photos USING GIST(location);
  3. Load your photo locations into the photos table
  4. Make a graticule table:
    create table graticule(geom geography(point,4326) not null);
    insert into graticule(select st_point(lng,lat)::geography from generate_series(-90,90,0.1) as lat, generate_series(-180,180,0.1) as lng);
  5. Compute the best photo for every point on the graticule:
    create table raster as select graticule.geom, b.dist,b.id from graticule cross join lateral (select location <-> graticule.geom dist, id from photos order by dist limit 1) as b ;
  6. Download the data to your local working directory:
    \copy (select st_x(geom::geometry),st_y(geom::geometry),dist from raster) to 'raster2.csv' csv;

plot the results

  1. Rename raster2.csv to raster2.xyz
  2. Convert to a TIFF, using gdal_translate from GDAL:
    gdal_translate -a_srs EPSG:4326 raster2.xyz raster2.tiff
  3. Using QGIS or another tool of your choice, add the resulting TIFF as a raster layer to a new project.
  4. Make it pretty, I guess
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment