Pro.TIFF
— API for parsing TIFF images¶
Extracting GPS Data¶
The following code example demonstrates how to extract GPS information from a TIFF image:
from Pro.Core import *
from Pro.TIFF import *
def parseTIFF(fname):
c = createContainerFromFile(fname)
if c.isNull():
return
obj = TIFFObject()
if not obj.Load(c):
return
gps = TIFFGPSCoordinates()
dirs = obj.RetrieveDirectoryEntries()
index = -1
while (index := obj.GetGPSData(dirs, gps, index + 1)) != -1:
print(obj.GPSDataToGString(gps))
Module API¶
Pro.TIFF module API.
Classes:
This class represents an entry in a TIFF directory.
List of
TIFFDirectoryEntry
elements.Iterator class for
TIFFDirectoryEntryList
.Represents GPS coordinate information extracted from a TIFF image.
This class represents a TIFF image object.
Represents a TIFF tag element, which contains the name, type, and value of a tag.
- class TIFFDirectoryEntry¶
This class represents an entry in a TIFF directory.
A TIFF directory entry contains information about a tag, including the tag identifier, type, count of values, and the value or value offset.
Attributes:
The number of values associated with the tag.
The file offset of the directory entry.
The tag identifier.
The data type of the tag’s value.
The value or the file offset to the value.
- count¶
The number of values associated with the tag.
- entry_offset¶
The file offset of the directory entry.
- tag¶
The tag identifier.
- type¶
The data type of the tag’s value.
- value_offset¶
The value or the file offset to the value.
- class TIFFDirectoryEntryList¶
List of
TIFFDirectoryEntry
elements.Methods:
append
(value)Inserts
value
at the end of the list.
at
(i)Returns the item at index position
i
in the list.
clear
()Removes all items from the list.
contains
(value)Checks the presence of an element in the list.
count
(value)Returns the number of occurrences of
value
in the list.
indexOf
(value[, start])Searches for an element in the list.
insert
(i, value)Inserts
value
at index positioni
in the list.
isEmpty
()Checks whether the list is empty.
iterator
()Creates an iterator for the list.
removeAll
(value)Removes all occurrences of
value
in the list and returns the number of entries removed.
removeAt
(i)Removes the item at index position
i
.
reserve
(alloc)Reserve space for
alloc
elements.
size
()Returns the number of items in the list.
takeAt
(i)Removes the item at index position
i
and returns it.
- append(value: Pro.TIFF.TIFFDirectoryEntry) → None¶
Inserts
value
at the end of the list.
- Parameters
value (TIFFDirectoryEntry) – The value to add to the list.
See also
insert()
.
- at(i: int) → Pro.TIFF.TIFFDirectoryEntry¶
Returns the item at index position
i
in the list.i
must be a valid index position in the list (i.e.,0 <= i < size()
).
- Parameters
i (int) – The index of the element to return.
- Returns
Returns the requested element.
- Return type
- clear() → None¶
Removes all items from the list.
- contains(value: Pro.TIFF.TIFFDirectoryEntry) → bool¶
Checks the presence of an element in the list.
- Parameters
value (TIFFDirectoryEntry) – The value to check for.
- Returns
Returns
True
if the list contains an occurrence ofvalue
; otherwise returnsFalse
.- Return type
bool
- count(value: Pro.TIFF.TIFFDirectoryEntry) → int¶
Returns the number of occurrences of
value
in the list.
- Parameters
value (TIFFDirectoryEntry) – The value to count.
- Returns
Returns the number of occurrences.
- Return type
int
See also
indexOf()
andcontains()
.
- indexOf(value: Pro.TIFF.TIFFDirectoryEntry, start: int = 0) → int¶
Searches for an element in the list.
- Parameters
value (TIFFDirectoryEntry) – The value to search for.
start (int) – The start index.
- Returns
Returns the index position of the first occurrence of
value
in the list. Returns-1
if no item was found.- Return type
int
See also
contains()
.
- insert(i: int, value: Pro.TIFF.TIFFDirectoryEntry) → None¶
Inserts
value
at index positioni
in the list. Ifi
is0
, the value is prepended to the list. Ifi
issize()
, the value is appended to the list.
- Parameters
i (int) – The position at which to add the value.
value (TIFFDirectoryEntry) – The value to add.
See also
append()
andremoveAt()
.
- isEmpty() → bool¶
Checks whether the list is empty.
- Returns
Returns
True
if the list contains no items; otherwise returnsFalse
.- Return type
bool
See also
size()
.
- iterator() → Pro.TIFF.TIFFDirectoryEntryListIt¶
Creates an iterator for the list.
- Returns
Returns the iterator.
- Return type
- removeAll(value: Pro.TIFF.TIFFDirectoryEntry) → int¶
Removes all occurrences of
value
in the list and returns the number of entries removed.
- Parameters
value (TIFFDirectoryEntry) – The value to remove from the list.
- Returns
Returns the number of entries removed.
- Return type
int
See also
removeAt()
.
- removeAt(i: int) → None¶
Removes the item at index position
i
.i
must be a valid index position in the list (i.e.,0 <= i < size()
).
- Parameters
i (int) – The index of the item to remove.
See also
removeAll()
.
- reserve(alloc: int) → None¶
Reserve space for
alloc
elements. Calling this method doesn’t change the size of the list.
- Parameters
alloc (int) – The amount of elements to reserve space for.
- takeAt(i: int) → Pro.TIFF.TIFFDirectoryEntry¶
Removes the item at index position
i
and returns it.i
must be a valid index position in the list (i.e.,0 <= i < size()
).
- Parameters
i (int) – The index of the element to remove from the list.
- Returns
Returns the removed element. If you don’t use the return value,
removeAt()
is more efficient.- Return type
See also
removeAt()
.
- class TIFFDirectoryEntryListIt(obj: Pro.TIFF.TIFFDirectoryEntryList)¶
Iterator class for
TIFFDirectoryEntryList
.
- Parameters
obj (TIFFDirectoryEntryList) – The object to iterate over.
Methods:
hasNext
()Returns
True
if there is at least one item ahead of the iterator, i.e. the iterator is not at the back of the container; otherwise returnsFalse
.Returns
True
if there is at least one item behind the iterator, i.e. the iterator is not at the front of the container; otherwise returnsFalse
.
next
()Returns the next item and advances the iterator by one position.
previous
()Returns the previous item and moves the iterator back by one position.
toBack
()Moves the iterator to the back of the container (after the last item).
toFront
()Moves the iterator to the front of the container (before the first item).
- hasNext() → bool¶
- Returns
Returns
True
if there is at least one item ahead of the iterator, i.e. the iterator is not at the back of the container; otherwise returnsFalse
.- Return type
bool
See also
hasPrevious()
andnext()
.
- hasPrevious() → bool¶
- Returns
Returns
True
if there is at least one item behind the iterator, i.e. the iterator is not at the front of the container; otherwise returnsFalse
.- Return type
bool
See also
hasNext()
andprevious()
.
- next() → Pro.TIFF.TIFFDirectoryEntry¶
- Returns
Returns the next item and advances the iterator by one position.
- Return type
See also
hasNext()
andprevious()
.
- previous() → Pro.TIFF.TIFFDirectoryEntry¶
- Returns
Returns the previous item and moves the iterator back by one position.
- Return type
See also
hasPrevious()
andnext()
.
- toBack() → None¶
Moves the iterator to the back of the container (after the last item).
See also
toFront()
andprevious()
.
- class TIFFGPSCoordinates¶
Represents GPS coordinate information extracted from a TIFF image.
This class contains the latitude and longitude coordinates and their references (North/South, East/West).
Attributes:
The latitude coordinate value.
The latitude reference, either ord(‘N’) for north or ord(‘S’) for south.
The longitude coordinate value.
The longitude reference, either ord(‘E’) for east or ord(‘W’) for west.
- latitude¶
The latitude coordinate value.
- latitude_ref¶
The latitude reference, either ord(‘N’) for north or ord(‘S’) for south.
- longitude¶
The longitude coordinate value.
- longitude_ref¶
The longitude reference, either ord(‘E’) for east or ord(‘W’) for west.
- class TIFFObject¶
Bases:
Pro.Core.CFFObject
This class represents a TIFF image object.
It provides methods to access and manipulate TIFF image data, directories, and tags.
Methods:
ContainGPSData
(entries)Checks if the given directory entries contain GPS data.
GPSDataToGString
(coord)Converts GPS coordinate data to a string representation.
GetGPSData
(entries, coord[, start])Retrieves GPS data from the TIFF directory entries.
Retrieves the stored directory entries of the TIFF image.
Retrieves the indexes of stored pages in the TIFF image.
PageNumberOfEntries
(dirs, pidxs, i)Retrieves the page number for the given directory entry.
Retrieves the base offset used for printing directory entries.
PrintDirectories
(entries, out_or_start[, …])Prints the TIFF directory entries.
PrintDirectoriesMinimal
(entries, out_or_start)Prints minimal information of the TIFF directory entries.
PrintDirectory
(dir, out)Prints detailed information about a TIFF directory entry to the output stream.
PrintDirectoryMinimal
(dir, out)Prints minimal information about a TIFF directory entry to the output stream.
RetrieveDirectoryEntries
([pidxs])Retrieves the TIFF directory entries from the image.
SetPrintBaseOffset
(offset)Sets the base offset used for printing directory entries.
SetStoredDirectoryEntries
(dirs[, pidxs])Stores the provided directory entries.
TagToElement
(tag)Converts a tag identifier to a
TIFFTagElement
object.
- ContainGPSData(entries: Pro.TIFF.TIFFDirectoryEntryList) → bool¶
Checks if the given directory entries contain GPS data.
- Parameters
entries (TIFFDirectoryEntryList) – The list of TIFF directory entries to check.
- Returns
Returns
True
if GPS data is present; otherwise returnsFalse
.- Return type
bool
See also
GetGPSData()
.
- GPSDataToGString(coord: Pro.TIFF.TIFFGPSCoordinates) → str¶
Converts GPS coordinate data to a string representation.
- Parameters
coord (TIFFGPSCoordinates) – The GPS coordinates to convert.
- Returns
Returns a string representation of the GPS coordinates.
- Return type
str
See also
GetGPSData()
.
- GetGPSData(entries: Pro.TIFF.TIFFDirectoryEntryList, coord: Pro.TIFF.TIFFGPSCoordinates, start: int = 0) → int¶
Retrieves GPS data from the TIFF directory entries.
- Parameters
entries (TIFFDirectoryEntryList) – The list of TIFF directory entries.
coord (TIFFGPSCoordinates) – The object to store the retrieved GPS coordinates.
start (int) – The starting index in the directory entries to search from.
- Returns
Returns the index of the directory entry where GPS data was found, or
-1
if not found.- Return type
int
See also
ContainGPSData()
.
- GetStoredDirectoryEntries() → Pro.TIFF.TIFFDirectoryEntryList¶
Retrieves the stored directory entries of the TIFF image.
- Returns
Returns a list of stored TIFF directory entries.
- Return type
See also
SetStoredDirectoryEntries()
andRetrieveDirectoryEntries()
.
- GetStoredPageIndexes() → Pro.Core.NTUIntList¶
Retrieves the indexes of stored pages in the TIFF image.
- Returns
Returns a list of page indexes.
- Return type
- PageNumberOfEntries(dirs: Pro.TIFF.TIFFDirectoryEntryList, pidxs: Pro.Core.NTUIntList, i: int) → int¶
Retrieves the page number for the given directory entry.
- Parameters
dirs (TIFFDirectoryEntryList) – The list of TIFF directory entries.
pidxs (NTUIntList) – The list of page indexes.
i (int) – The index of the directory entry.
- Returns
Returns the page number corresponding to the directory entry at index
i
.- Return type
int
- PrintBaseOffset() → int¶
Retrieves the base offset used for printing directory entries.
- Returns
Returns the base offset.
- Return type
int
See also
SetPrintBaseOffset()
.
- PrintDirectories(entries: Pro.TIFF.TIFFDirectoryEntryList, out_or_start: Union[Pro.Core.NTTextStream, int], size: Optional[int] = None, out: Optional[Pro.Core.NTTextStream] = None) → None¶
Prints the TIFF directory entries.
If
out_or_start
is anNTTextStream
, the entries are printed to the stream.If
out_or_start
is anint
, it represents the starting index,size
is the number of entries to print, andout
is the stream to print to.
- Parameters
entries (TIFFDirectoryEntryList) – The list of TIFF directory entries to print.
out_or_start (Union[NTTextStream, int]) – The output stream or the starting index.
size (Optional[int]) – The number of entries to print (if
out_or_start
is an index).out (Optional[NTTextStream]) – The output stream to print to (if
out_or_start
is an index).See also
PrintDirectory()
andPrintDirectoriesMinimal()
.
- PrintDirectoriesMinimal(entries: Pro.TIFF.TIFFDirectoryEntryList, out_or_start: Union[Pro.Core.NTTextStream, int], size: Optional[int] = None, out: Optional[Pro.Core.NTTextStream] = None) → None¶
Prints minimal information of the TIFF directory entries.
If
out_or_start
is anNTTextStream
, the entries are printed to the stream.If
out_or_start
is anint
, it represents the starting index,size
is the number of entries to print, andout
is the stream to print to.
- Parameters
entries (TIFFDirectoryEntryList) – The list of TIFF directory entries to print.
out_or_start (Union[NTTextStream, int]) – The output stream or the starting index.
size (Optional[int]) – The number of entries to print (if
out_or_start
is an index).out (Optional[NTTextStream]) – The output stream to print to (if
out_or_start
is an index).See also
PrintDirectoryMinimal()
andPrintDirectories()
.
- PrintDirectory(dir: Pro.TIFF.TIFFDirectoryEntry, out: Pro.Core.NTTextStream) → None¶
Prints detailed information about a TIFF directory entry to the output stream.
- Parameters
dir (TIFFDirectoryEntry) – The TIFF directory entry to print.
out (NTTextStream) – The output stream.
See also
PrintDirectories()
.
- PrintDirectoryMinimal(dir: Pro.TIFF.TIFFDirectoryEntry, out: Pro.Core.NTTextStream) → None¶
Prints minimal information about a TIFF directory entry to the output stream.
- Parameters
dir (TIFFDirectoryEntry) – The TIFF directory entry to print.
out (NTTextStream) – The output stream.
See also
PrintDirectoriesMinimal()
.
- RetrieveDirectoryEntries(pidxs: Optional[Pro.Core.NTUIntList] = None) → Pro.TIFF.TIFFDirectoryEntryList¶
Retrieves the TIFF directory entries from the image.
- Parameters
pidxs (Optional[NTUIntList]) – An optional list of page indexes to retrieve entries from. If not provided, entries from all pages are retrieved.
- Returns
Returns a list of TIFF directory entries.
- Return type
See also
GetStoredDirectoryEntries()
andSetStoredDirectoryEntries()
.
- SetPrintBaseOffset(offset: int) → None¶
Sets the base offset used for printing directory entries.
- Parameters
offset (int) – The base offset to set.
See also
PrintBaseOffset()
.
- SetStoredDirectoryEntries(dirs: Pro.TIFF.TIFFDirectoryEntryList, pidxs: Pro.Core.NTUIntList = NTUIntList()) → None¶
Stores the provided directory entries.
- Parameters
dirs (TIFFDirectoryEntryList) – The list of TIFF directory entries to store.
pidxs (NTUIntList) – The list of page indexes corresponding to the directory entries. If not provided, an empty list is used.
See also
GetStoredDirectoryEntries()
andRetrieveDirectoryEntries()
.
- static TagToElement(tag: int) → Pro.TIFF.TIFFTagElement¶
Converts a tag identifier to a
TIFFTagElement
object.
- Parameters
tag (int) – The tag identifier.
- Returns
Returns the corresponding
TIFFTagElement
object.- Return type
- class TIFFTagElement¶
Represents a TIFF tag element, which contains the name, type, and value of a tag.
Attributes:
The name of the TIFF tag.
The data type of the TIFF tag’s value.
The value of the TIFF tag.
- name¶
The name of the TIFF tag.
- type¶
The data type of the TIFF tag’s value.
- value¶
The value of the TIFF tag.