Skip to content

Instantly share code, notes, and snippets.

Last active March 7, 2017 02:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save YKCzoli/7804815c490daf3f3803fa8da0e66a3b to your computer and use it in GitHub Desktop.



This is the scrappy technical overview of processing the Southern Ontario 1954 imagery. I assume you are familiar with gdal, bash scripting, raster imagery. If you are trying to process similar data and something is unclear, feel free to reach out to me with questions.

I first found the data here:

As you can see you'd have to manually download the files one by one. To circumvent this I found an esri endpoint(which I can't find now..was it taken down, i truly don't know..if someone finds it, please lmk) and sent a query to return a list of the tiles.

I piped this tile list into wget(check the '-i' flag in the docs) and switched the tile name in the url available from clicking on a tile on the above map link.

Once I had all the data I started by inspecting the the file types, projections, size, etc in QGIS.

I created a tile index of the raster in QGIS, in order to limit the area of interest and the processing time.

screen shot 2017-02-26 at 5 46 22 pm

After inspecting the imagery, i realized that i had two different file types. One was jpg(Byte - Eight bit unsigned integer), the other JPEG2000(UInt16 - Sixteen bit unsigned integer).

I usually work with tiff files, so i first decided to convert the files to tiff. I beleive the jpeg 2000 files are a relic of older aerial imagery methods. The different types of images also follow a stark line going north-south just west of Toronto, which I assume represents two different flight missions.

I used gdal_translate to convert the jpg to tiff.

For the jpeg2000 files, i had to do some digging. There were two options, either compile gdal with an open jpeg driver, or find another tool. I used geojasper, with the following script:

cat "~/GTATileList.csv" | while IFS=, read col1 col2 col3

  ~/geojasper --input $col1 --output ~/converted_$col3.tif
  echo $count left

Now, another minor problem i noticed when inspecting the files in qgis was that there was a border area covering the edges of the files:

screen shot 2017-02-26 at 6 02 10 pm

As you can see the overlap of the white areas would be problematic when merging. I used the identify tool to get an understanding of the range that the white areas hold, which i turn to noData:


At this point i still had the discrepancy of having half my files in 8 bit, and half in 16 bit. I processed these batches separately:

cat "~/list.csv" | while IFS=, read col1 col2, col3
do -A $col1 --outfile=$col2 --calc="A*(A<31213)" --NoDataValue=0
for f in ~/*.tif;
  if $f == -A $f --A_band=1 --outfile=$output_location${f:(-11)} --calc="A*(A<243)" --NoDataValue=0

I then scaled the 16 bit images to 8 bit:

for f in $(find ~/folder -name '???????.jpg');
  minMax=$(gdalinfo -mm $f | grep Min/Max)
  gdal_translate -of GTiff -co "COMPRESS-LZW" -scale $min $max 0 255 -ot Byte $f $output_location${f:(-11)}

I merged all the files into one tiff (not sure if there is a more effecient way to do this, most likely using VRT's. Then tiled the files using

Lastly, I uploaded the tiles to S3, and set the tiles into a map with a mapbox satellite overlay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment