Sunday 22 February 2015

aerial photography - What is the correct way to merge adjoining raster images?


I am trying to create a raster base layer from NAIP ortho imagery. Unfortunately for me, the area of interest is very near the intersection of four image files. I have tried a few approaches to combining them into a single map layer:



  • Naively grouping them together in a GeoServer Layer group

  • Combining them with GeoServer's ImageMosaic plugin

  • Merging them with gdal_merge.py


In all cases, the result has the same visual problem of ragged black lines where the images meet. See the example image, below. The black lines appear at the edges of each of the individual files, they are not merely an artifact of merging the images, so in a sense this isn't a surprising outcome -- just annoying.


What is the correct procedure to join these orthoimages into a reasonably seamless layer? Is this even a practical thing to do?


Ugly black seams



A few more details:



  • The imagery came from the USDA Geospatial Data Gateway, National Ag. Imagery Program Mosaic listing

  • The files were in MrSID format, but I've also created GeoTIFF copies for the gdal_merge.py approach

  • In addition to the MrSID files, the data set included shape and prj files.

  • The images use projection NAD83 / UTM 16N, so I've been using EPSG 26916

  • I'm a programmer, not a GIS expert, so my knowledge of this area is pretty limited



Answer



Answering my own question: Those black pixels in the images represent a "NoData" value. If I tell the gdal merge code that pixels with a color value of 0 are "NoData," it can correctly stitch the images together. (The "NoData" value isn't necessarily set to 0, it can be any value not otherwise used in the image, but in the case of NAIP ortho images, it was 0.)



The gdal_merge.py program accepts an optional -n argument to set the nodata color value, however I had a problem using that on my system. Apparently, setting the -n option causes the Python code to go through a branch that tries to import a package that I was missing.


Rather than fiddle with the missing package, I chose to merge my four GeoTIFF image files using the gdalwarp tool. I passed the same coordinate system for both source and target, since I just wanted to merge, not warp. I specified the nodata value of 0 by passing the arguments -srcnodata 0 -dstnodata 0.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...