Merge feature collections

Hi everyone

I’m looking for a quick way to merge several feature collections into one file (preferably using python or pygplates, but maybe also by loading them to GPlates and saving them together). With the rotation files, this can be done by simply adding the rotation data from one file to the end of another one. With the .gpml file format, it’s a bit less intuitive because of the .xml tree structure.

Thank you!
Lior

Hi Lior,

With pyGPlates you can do something like:

all_files = [ 'file1.gpml', 'file2.gpml']

all_features = []
for file in all_files:
    # Read the current file.
    features_in_file = pygplates.FeatureCollection(file)
    # Add all features in 'features_in_file' to our list.
    all_features.extend(features_in_file)

# Put all features in one collection and write it out.
pygplates.FeatureCollection(all_features).write('all.gpml')

Without pyGPlates you can use a text editor and manually copy’n’paste the <gml:featureMember> ... </gml:featureMember> parts from one GPML file into an existing GPML file (inserting them inside the main <gpml:FeatureCollection> ... </gpml:FeatureCollection> part).

That worked well, Thanks!