Hi Thomas,
Actually by feature it means a pygplates.Feature. So feature2.gpml
is a filename (which is a string), and hence not strictly a feature, or even a sequence of features. And [“features.shp”, “features2.gpml”]
is a sequence of filenames (ie, a sequence of strings).
The reason the following worked…
collection = pygmt.FeatureCollection("features.shp")
…is because features.shp
is a filename which satisfies an optional filename, or sequence of features, or a single feature
.
Whereas…
collection = pygmt.FeatureCollection(["features.shp", "features2.gpml"])
…does not work because ["features.shp", "features2.gpml"]
is a sequence of filenames which does not satisfy an optional filename, or sequence of features, or a single feature
.
A pygplates.FeatureCollection is a little more restrictive in this way than functions like pygplates.reconstruct.
This is mainly to keep the idea of a feature collection as a sequence of features that are either added manually or loaded from a single file. In other words, ["features.shp", "features2.shp"]
is really two different files which ideally should correspond to two different feature collections. For example, those two files could have different sets of shapefile attributes, so when you combine them things can get a little messy.
Although that wouldn’t stop you from combining two feature collections into one if you really wanted. For example:
feature_collection1 = pygplates.FeatureCollection('features1.gpml')
feature_collection2 = pygplates.FeatureCollection('features2.gpml')
combined_feature_collection = pygplates.FeatureCollection(feature_collection1)
combined_feature_collection.add(feature_collection2)
…this works because a pygplates.FeatureCollection
object can be treated as a sequence of features
.
Note that functions like pygplates.reconstruct are more flexible because they can accept any arbitrary combination of features. That function accepts (as its first argument reconstructable_features):
a feature collection, or filename, or feature, or sequence of features, or a sequence (eg, list or tuple) of any combination of those four types
…so you can have something quite arbitrary like:
reconstructable_features = [
'features1.gpml', # a filename
'features2.gpml', # a filename
[a_feature, another_feature], # a sequence of features
yet_another_feature, # a feature
a_feature_collection] # a feature collection
pygplates.reconstruct(reconstructable_features, ...)
In this way, a lot of pyGPlates functions like this are essentially using pygplates.FeaturesFunctionArgument to parse their arguments.
It’s most likely your pyGPlates version is less than 0.30
. The latest public release is 0.36
.
New additions are usually noted in the docs (eg, for TopologicalModel it says New in version 0.30).
To see your version you can type:
print(pygplates.__version__)
…in your script.
Or type…
python -c "import pygplates; print(pygplates.__version__)"
…on the command line.