3

I'm writing some software that allows users to draw polygons over the raster from a geotiff file.

I can calculate the area of the polygon in pixels; in fact, this calculation is a byproduct of finding the polygon's centroid (which I also report).

However, I would like to convert area in pixels to acres.

Presumably geotiffs have some metadata linking the raster to real world units. I'm vaguely familiar with the concept that internally geotiffs use a "Model (M)" and "Raster (R)" and that there is metadata relating them.

I'm trying to find exactly what metadata there is, and how to query it (using libgeotiff).

For example, if I had a value correlating pixels to square metres, it should be straight forward math to go from pixels -> metres -> acres.

If it is not possible to get an exact correspondence between pixels and real-world units, a method to calculate a reasonable approximation would suffice.

  • Do you have QGIS, GDAL etc.? – jbchurchill Jan 12 '16 at 22:06
  • Yes, but I'm doing this in code so I need to pull the information I need straight from the geotiff via libgeotiff – mio iwakura Jan 12 '16 at 22:13
  • I do not really understand what you are doing. It seems a little confusing and maybe a backwards way of doing it (cart in front of horse thing). Can you clarify? The geotiff is not built as you describe and the relationship between pixels and real world units is not actually as you describe. – If you do not know- just GIS Jan 12 '16 at 22:30
  • @Ifyoudonotknow-justGIS I'm finding the acres within polygons that are drawn over the raster of a geotiff. I am in the process of reading the geotiff spec and am definitely not an expert in this area! – mio iwakura Jan 12 '16 at 22:39
  • What language are you developing in? It seems easier to get the coordinates of the newly drawn polygon, triangulate the polygon, and sum the triangle areas. Here is a link (mathopenref.com/polygonirregulararea.html) and a Python example (github.com/linuxlewis/tripy). – GBG May 14 '19 at 20:52
1

I don't use libgeotiff directly, but use GDAL which uses libgeotiff under the hood, but you should be able to find the pixel dimensions using the ModelPixelScaleTag OR extract them from the ModelTransformationTag. See the documentation for more info.

You'll need to determine whether the raster is projected and what the horizontal units are (i.e metres, feet, degrees). If the raster is not projected and the units are degrees then you'll either need to project the raster to a projected coordinate system or approximate the degrees to metres conversion based on latitude (that's a question that I'm pretty sure has been answered a few times on this site).

I also recommend you have a look at Understanding GeoTIFF tags? and its answers.

And it may be useful to check out the source code of the listgeo tool distributed with libgeotiff.

2

How big are the pixels on a side? This seems like a simple calculation if you know the number of pixels and their size i.e. A single 30m pixel (on each side) = 900 Square Meters = 0.2223945 acres (1 square meter = 0.000247105 acres). Am I misunderstanding something?

Try using the gdalinfo command to determine cell size and projection information.

  • Yes, the calculation should be straight forward with a correspondence between pixels and real-world-units. The size of the pixels is what I am trying to figure out based on the information in the geotiff. – mio iwakura Jan 12 '16 at 22:00
  • Assuming the raster is projected... – user2856 Jan 12 '16 at 22:02
  • I am in the process of reading the geotiff spec, but I know that all the geotiff files that will be used with this software are properly geocoded. It is possible for me to convert a pixel coord to PCS with GTIFImageToPCS, and I can get lat,long with GTIFProj4ToLatLong for example. – mio iwakura Jan 12 '16 at 22:16

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.