pgplates column - Load/Save - load and save feature sets
Create a new file containing a subset of features from other files
In this example, we will create a new GPML file that only contains coastlines with plate ID 801
sample code
import pygplates
# 加载全球海岸线特征
input_feature_collection = pygplates.FeatureCollection("Global_EarthByte_GPlates_PresentDay_Coastlines.gpmlz")
# 新建用于储存板块801特征的列表
features_in_plate_801 = []
# 白能力所有海岸线特征,将那些在板块801的特征到“features_in_plate_801”
for feature in input_feature_collection:
if feature.get_reconstruction_plate_id() == 801:
features_in_plate_801.append(feature)
# 储存为一个新的文件
output_feature_collection = pygplates.FeatureCollection(features_in_plate_801)
output_feature_collection.write("3-output_coastlines_801.gpml")
Detailed explanation
Features can be loaded and saved using the pygplates.FeatureCollection object
First, we get the GPlates coastline features from the "coastlines.gpml" file and store them in the pygplates.FeatureCollection object
features = pygplates.FeatureCollection('coastlines.gpml')
Or you can use the pygplates.FeatureCollection.read() function
features = pygplates.FeatureCollection.read('coastlines.gpml')
Then create an empty list to store the subset of plate 801
features_in_plate_801 = []
The pygplates.FeatureCollection object can be processed like a sequence, which can traverse all coastline features and pick out the plate 801
for feature in features:
if feature.get_reconstruction_plate_id() == 801:
features_in_plate_801.append(feature)
We need to create a new pygplates.FeatureCollection object to save the plate 801
output_feature_collection = pygplates.FeatureCollection(features_in_plate_801)
Now we can save this object as a gpml file
output_feature_collection.write('coastlines_801.gpml')
Create a file from features taken from multiple files
In this example we create a new GPML file that contains ridges from one file and isochrones from another.
sample code
import pygplates
# 多个目标文件
filenames = ["Muller_etal_2019_GeeK07_Ridges.gpmlz", "Seton_etal_2020_Isochrons.gpmlz"]
# 所有文件中所有特征的储存列表
merged_features = []
# 读取特征到列表
for filename in filenames:
features = pygplates.FeatureCollection(filename)
merged_features.extend(features)
# 将所有特征整合到一个文件
merged_feature_collection = pygplates.FeatureCollection(merged_features)
merged_feature_collection.write("3-output_ridges_and_isochrons.gpml")