pygplates.FeatureCollectionFileFormatRegistry

class pygplates.FeatureCollectionFileFormatRegistry

Bases: Boost.Python.instance

Reads and writes feature collections from/to various feature collection file formats.

The following default file formats are currently supported by GPlates:

File Format Filename Extension Supports Read Supports Write
GPlates Markup Language ‘.gpml’ Yes Yes
Compressed GPML ‘.gpmlz’ or ‘.gpml.gz’ Yes Yes
PLATES4 line ‘.dat’ or ‘.pla’ Yes Yes
PLATES4 rotation ‘.rot’ Yes Yes
GPlates rotation ‘.grot’ Yes Yes
ESRI Shapefile ‘.shp’ Yes Yes
OGR GMT ‘.gmt’ Yes Yes
GMT xy ‘.xy’ No Yes
GMAP Virtual Geomagnetic Poles ‘.vgp’ Yes No

In the future, support will be added to enable users to implement and register readers/writers for other file formats (or their own non-standard file formats).

__init__()

Create a new registry of feature collection readers/writers and registers the default file formats supported by GPlates.

feature_collection_file_format_registry = pygplates.FeatureCollectionFileFormatRegistry()

Methods

__init__() Create a new registry of feature collection readers/writers and registers the default file formats supported by GPlates.
read(filename) Reads one or more feature collections (from one or more files).
write(feature_collection, filename) Writes a feature collection to the file with name filename.
read(filename)

Reads one or more feature collections (from one or more files).

Parameters:filename (string, or sequence of strings) – the name of the file (or files) to read
Return type:FeatureCollection, list of FeatureCollection
Raises:OpenFileForReadingError if any file is not readable
Raises:FileFormatNotSupportedError if any file format (identified by a filename extension) does not support reading

For example:

try:
    feature_collection = feature_collection_file_format_registry.read(filename)
except pygplates.OpenFileForReadingError:
    # Handle inability to read from file.
    ...
except pygplates.FileFormatNotSupportedError:
    # Handle unsupported file format (for reading).
    ...

Note

The returned feature collection may contain fewer features than are stored in the file if there were read errors. TODO: return read errors.

write(feature_collection, filename)

Writes a feature collection to the file with name filename.

Parameters:
  • feature_collection (FeatureCollection) – the feature collection to write
  • filename (string) – the name of the file to write
Raises:

OpenFileForWritingError if the file is not writable

Raises:

FileFormatNotSupportedError if the file format (identified by the filename extension) does not support writing

For example:

try:
    feature_collection_file_format_registry.write(feature_collection, filename)
except pygplates.OpenFileForWritingError:
    # Handle inability to write to file.
    ...
except pygplates.FileFormatNotSupportedError:
    # Handle unsupported file format (for writing).
    ...