1

I currently have X amount of binary files that are in grid format.

I have the span of these files in the form of latitude/longitude, plus the geographic projection. How can I turn these into georeferenced geoTIFFs/HDF/netCDFs?

For reference the latitude span is -60 to 60, and the longitude span is 85 to 205.

Data is projected in EPSG:4326.

  • Can you use python? By binary grid do you mean .adf format or .bil/bsq/raw? How do you have the span information? Is it a table or part of the file name etc. – Michael Stimson Jul 27 '17 at 21:13
  • I can use Python (and have been). For reference, it can be processed using numpy.fromfile().reshape(). – Matthew Mage Jul 27 '17 at 21:14
  • As for format, I'm not sure. It's more like .bin. The span is given as outside information. – Matthew Mage Jul 27 '17 at 21:14
  • You can embed a known georeference if you have the origin (upper left) and extent, divide the dX by cols to get X cell size and dY by rows to get Y cell size then use SetGeotransform() (y is usually negative) like on this page pcjericks.github.io/py-gdalogr-cookbook/raster_layers.html (ctrl + f for setgeo). What is the raster? According to GDAL docs it could be ENVI - ENVI .hdr Labelled Raster, (is there a .hdr file?) but was the data geographical or projected when the georeference was lost? – Michael Stimson Jul 27 '17 at 21:20
  • 1
    EPSG:4326 is a geographical spatial reference (units: degree) so is unprojected. Projected data would have units: feet or metre. If the data was projected when it lost its georeference you would need to apply a projected GeoTransform or the data will not be accurate even though you have your extent and origin in degrees, you would need to generate the corners, project and build a GeoTransform from those coords. – Michael Stimson Jul 27 '17 at 21:28
2

This is how I ended up solving it:

cols = array.shape[1]
rows = array.shape[0]
originX = 85 # starting longitude, top left
originY = -60 # starting latitude, top left
driver = gdal.GetDriverByName('GTiff') # load the GTiff driver
outRaster = driver.Create(fileName, cols, rows, 1, gdal.GDT_Int16) # create the raster layer
outRaster.SetGeoTransform((originX, pixelWidth, 0, originY, 0, pixelHeight))
outband = outRaster.GetRasterBand(1)
outband.SetNoDataValue(-1)
outband.WriteArray(array) # write the binary file to the TIFF
outRasterSRS = osr.SpatialReference()
outRasterSRS.ImportFromEPSG(4326) # import the EPSG projection
outRaster.SetProjection(outRasterSRS.ExportToWkt()) # sets the projection for the tiff
outband.FlushCache() # flush the cache
  • +1 Can you include the calcs for pixelWidth and pixelHeight please. – Michael Stimson Jul 27 '17 at 21:51
  • 1
    Values for pixelWidth and pixelHeight were given as 0.01. – Matthew Mage Jul 27 '17 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.