use the exif data of a tiff image to check if the points of the image are in polygon

30 views
Skip to first unread message

Lamsking

unread,
Jul 26, 2019, 8:56:20 AM7/26/19
to Geospatial Python
Hello,
I have a problem I wanted to solve:
using the exif data of the tif image, retrieve the four points of the image in question and then check if the coordinates of the image appear on a shapefile file in which there are polygons with python.
I'm really new to the field. Thank you in advance.

Geodesy

unread,
Jul 26, 2019, 7:54:46 PM7/26/19
to Geospatial Python
 >  .... the four points of the image

Are you speaking of the corners or any arbitrary random four points that are from pixels in the image?
Is your 'tif' a GeoTiff, or otherwise have a spatial reference system applied?
Are the images and polygons in the same spatial reference system?

Michael

Mario Miler

unread,
Jul 27, 2019, 5:27:45 AM7/27/19
to Geospatial Python
Hi,
here is a quick example how it could be done. This example assumes that raster image and polygons in a shapefile are in the same coordinate systems.

I hope it helps.
example.zip

Lamsking

unread,
Jul 27, 2019, 11:40:07 AM7/27/19
to Geospatial Python
Hello!
The idea was to use the geographical coordinates of the drone to retrieve the four points of the image and with these four corners locate the corresponding location on the shapefile file that contains the polygons.
thanks

Lamsking

unread,
Jul 27, 2019, 11:47:01 AM7/27/19
to Geospatial Python
Hi Mario thanks for your example.
But when i try with my image tif and the shapefile , i obtened this warning
_init__.py:216: NotGeoreferencedWarning: Dataset has no geotransform set. The identity matrix may be returned.
  s = DatasetReader(path, driver=driver, sharing=sharing, **kwargs)
Traceback (most recent call last):
  File "raster_in_polygon.py", line 15, in <module>
    print ("Raster image intersects with polygon ID: %s" % (poly['properties']['id']))
KeyError: 'id'

Mario Miler

unread,
Jul 27, 2019, 2:09:26 PM7/27/19
to Geospatial Python
That example was not meant to work with every dataset, you need to modify it to fit you data. Your error suggests that your shapefile is different than mine, for example, you dont' have ID column in you shapefile. It is hard to know exact problem without you dataset.
Reply all
Reply to author
Forward
0 new messages