Skip to content

unify the geometries of COBs in Muller2016 #226

@michaelchin

Description

@michaelchin

Currently, the geometries of COBs in Muller2016 are a mixture of polygons and polylines. The mixture is causing problem when being plotted in GPlately. We need to modify the COBs and make the geometries all polygons(or polylines?).

Thanks to @nickywright for providing us with a code snippet to convert polylines to polygons.

import os.path
import pygplates


input_filenames = [
    'Global_EarthByte_GPlates_PresentDay_StaticPlatePolygons_2019_v1.shp'
]

output_filename_append = '_polygon'

for input_filename in input_filenames:
    # Convert polylines to polygons in the features.
    feature_collection = pygplates.FeatureCollection(input_filename)
    for feature in feature_collection:
        # polygons = [pygplates.PolygonOnSphere(geometry) for geometry in feature.get_geometries()]
        # changed feature get statement to 'all_geometries' - since feature has issues getting different
        # types of geometries
        for geometry in feature.get_all_geometries():
            polygons = pygplates.PolygonOnSphere(geometry)
            feature.set_geometry(polygons)
    
    # Get the output (polygon) filename from the input (polyline) filename.
    input_filename_root, input_filename_ext = os.path.splitext(input_filename)
    output_filename = ''.join((input_filename_root, output_filename_append, input_filename_ext))
    
    # Write the modified feature collection to output file.
    pygplates.FeatureCollection(feature_collection).write(output_filename)

Thanks to @jcannon-gplates for providing valuable suggestion.

basically a pygplates.PolygonOnSphere can take a polyline as a single argument and it’ll convert it (see the second init() listed here). And similarly for converting a polygon (exterior) to a polyline. So if you can get the polyline/polygon into pygplates format then converting is straightforward.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions