How to determine if an image file is georeferenced

4338
2
Jump to solution
09-24-2013 01:43 PM
RickCote
New Contributor
I have a task to scan a folder for georeferenced images. There might be a lot of images, some quite large, and some not georeferenced. The spatial information can also be either embedded or in a world file.

Is there anything available in the runtime that can tell me if "C:\someFolder\file.x" is georeferenced.


Thanks,

Rick Cote
Thalse Systems
0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor
Rick,

If am image has been geo-referenced then it should return an extent. You could have a scenario where an image has a world file but no projection information but it would return an extent. So knowing that, the VBA code below demonstrates how to test for this. I leave it up to you to wrap it up into a loop. The limitation with this example is that it is assumed that the raster is not in a geographical coordinate system.

Public Sub Test()     ' This code expects the first layer in the TOC to be a raster          ' Get map     Dim pMXD As IMxDocument     Set pMXD = ThisDocument     Dim pMap As IMap     Set pMap = pMXD.FocusMap          ' Get raster     Dim pLayer As ILayer     Set pLayer = pMap.Layer(0)     Dim pRasterLayer  As IRasterLayer     Set pRasterLayer = pLayer          ' Get extent     Dim pGeoDataset As IGeoDataset     Set pGeoDataset = pRasterLayer     Dim pEnv As IEnvelope     Set pEnv = pGeoDataset.Extent          ' Test minimum value, assumes rasters are not in decimal degrees     If pEnv.XMin = -0.5 Then         Debug.Print "This raster has no extent so can't be geo-referenced!"     Else         Debug.Print "This raster is geo-referenced!"     End If End Sub

View solution in original post

0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor
Rick,

If am image has been geo-referenced then it should return an extent. You could have a scenario where an image has a world file but no projection information but it would return an extent. So knowing that, the VBA code below demonstrates how to test for this. I leave it up to you to wrap it up into a loop. The limitation with this example is that it is assumed that the raster is not in a geographical coordinate system.

Public Sub Test()     ' This code expects the first layer in the TOC to be a raster          ' Get map     Dim pMXD As IMxDocument     Set pMXD = ThisDocument     Dim pMap As IMap     Set pMap = pMXD.FocusMap          ' Get raster     Dim pLayer As ILayer     Set pLayer = pMap.Layer(0)     Dim pRasterLayer  As IRasterLayer     Set pRasterLayer = pLayer          ' Get extent     Dim pGeoDataset As IGeoDataset     Set pGeoDataset = pRasterLayer     Dim pEnv As IEnvelope     Set pEnv = pGeoDataset.Extent          ' Test minimum value, assumes rasters are not in decimal degrees     If pEnv.XMin = -0.5 Then         Debug.Print "This raster has no extent so can't be geo-referenced!"     Else         Debug.Print "This raster is geo-referenced!"     End If End Sub
0 Kudos
RickCote
New Contributor
It's a performance issue. This is processing I'd have to do if I wanted to load an image, but I don't want to load it just to find out it isn't georeferenced and therefore don't need it anyway. In this application there could be a lot of non-georeferenced images.

The solution I have right now is to scan the image for an indicator string. Working so far but it's bound to fail sometime. After that I may try using the GDAL libraries.

Thanks,
Rick
0 Kudos