pygplates专栏——Reconstruc features——reconstruct regular features

Reconstruct regular features

This example shows several different scenarios that involve reconstructing common features of geological time.

Export refactored features to file

In this example we reconstruct regular features and export the result to Shapefile.

sample code

import pygplates

# 加载板块运动模型
rotation_model = pygplates.RotationModel("Muller2019-Young2019-Cao2020_CombinedRotations.rot")
# 加载一些features
features = pygplates.FeatureCollection("Global_EarthByte_GPlates_PresentDay_Coastlines.gpmlz")
# 重建的地质时间
reconstruction_time = 50
# 输出的文件
export_filename = "6-Exported_reconstructed_features_to_a_file_reconstructed_{0}Ma.shp".format(reconstruction_time)
# 重建
pygplates.reconstruct(features, rotation_model, export_filename, reconstruction_time)

Detailed explanation

First load the plate motion model (pygplates.RotationModel)

rotation_model = pygplates.RotationModel('rotations.rot')

Load features that need to be rebuilt (pygplates.FeatureCollection)

features = pygplates.FeatureCollection('features.gpml')

Set rebuild time

reconstruction_time = 50

Finally complete the reconstruction results and save

pygplates.reconstruct(features, rotation_model, export_filename, reconstruction_time)

Calculate reconstruction distance

sample code

import pygplates

# 返回几何要素(点/多点/折线/多边形)质心的函数。
def get_geometry_centroid(geometry):
    # 检查几何要素是否为多边形
    try:
        return geometry.get_interior_centroid()
    except AttributeError:
        # 不是多边形,继续
        pass
    # 检查几何要素是否为多线条或多点
    try:
        return geometry.get_centroid()
    except AttributeError:
        pass
    # 仅剩点
    return geometry
# 加载板块运动模型
rotation_model = pygplates.RotationModel("Muller2019-Young2019-Cao2020_CombinedRotations.rot")
# 加载一些特征
features = pygplates.FeatureCollection("2-output_points.gpml")
# 重建地质时间
reconstruction_time = 50
# 重建
reconstructed_feature_geometries = []
pygplates.reconstruct(features, rotation_model, reconstructed_feature_geometries, reconstruction_time)
# 遍历所有重建结果
for reconstructed_feature_geometry in reconstructed_feature_geometries:
    # 计算距离:今时今日几何要素的质点和重建后的质点
    distance_reconstructed = pygplates.GeometryOnSphere.distance(
        get_geometry_centroid(reconstructed_feature_geometry.get_present_day_geometry()),
        get_geometry_centroid(reconstructed_feature_geometry.get_reconstructed_geometry())
    )
    # 将弧度转换为公里
    distance_reconstructed_in_kms = distance_reconstructed * pygplates.Earth.mean_radius_in_kms
    # 输出相关特征名称和板块ID,以及重建的距离
    print("Feature: %s" % reconstructed_feature_geometry.get_feature().get_name())
    print("  plate ID: %d" % reconstructed_feature_geometry.get_feature().get_reconstruction_plate_id())
    print("  distance reconstructed: %f Kms" % distance_reconstructed_in_kms)

Detailed explanation

For a certain function, pygplates defines many related functions.
If, we can ignore whether the geometric element is pygplates.PointOnSphere, pygplates.MultiPointOnSphere, pygplates.PolyineOnSphere or pygplates.PolygonOnSphere. Each geometry feature type requires a different method of obtaining particles.
So we first try pygplates.PolygonOnSphere.get_interior_centroid(), then try get_centroid(), and finally the geometric feature point is its own particle.

def get_geometry_centroid(geometry):
    try:
        return geometry.get_interior_centroid()
    except AttributeError:
        pass
    try:
        return geometry.get_centroid()
    except AttributeError:
        pass
    return geometry

Use the pygplates.GeometryOnSphere.distance() method to calculate the shortest distance between two mass points, then use pygplates.Earth to convert it to kilometers.

distance_reconstructed = pygplates.GeometryOnSphere.distance(
    get_geometry_centroid(reconstructed_feature_geometry.get_present_day_geometry()),
    get_geometry_centroid(reconstructed_feature_geometry.get_reconstructed_geometry()))
distance_reconstructed_in_kms = distance_reconstructed * pygplates.Earth.mean_radius_in_kms

Guess you like

Origin blog.csdn.net/whitedrogen/article/details/131718270