pygplates专栏——Introduction——查找某个几何区域的重构特征
本例子将迭代重建的特征集合,然后找到那些几何区域与目标区域重叠的特征。
示例代码
import pygplates
rotations_model = pygplates.RotationsModel("rotations.rot")
features = pygplates.FeatureCollection("features.gpml")
reconstruction_time = 10
polygon = pygplates.PolygonOnSphere([(0,0), (90,0), (0,90)])
reconstructed_features = []
pygplates.reconstruct(features, rotation_model, reconstructed_features, reconstruction_time, group_with_feature=True)
overlapping_features = []
for feature, feature_reconstructed_geometries in reconstructed_features:
for feature_reconstructed_geometry in feature_reconstructed_geometries:
min_distance_to_feature = pygplates.GeometryOnSphere.distance(
polygon,
feature_reconstructed_geometry.get_reconstructed_geometry(),
geometry1_is_solid=True,
geometry2_is_solid=True)
if min_distance_to_feature == 0:
overlapping_feature.append(feature)
break
if overlapping_features:
overlapping_feature_collection = pygplates.FeatureCollection(overlapping_features)
overlapping_features_filename = "features_overlapping_at_{0}Ma.gpml".format(reconstruction_time)
overlapping_feature_collection.write(overlapping_features_filename)
代码详解
- 从运动文件(rotation file)加载运动模型到pygplates.RotationModel类中。
rotation_model = pygplates.RotationModel("rotations.rot")
- 加载可重建的板块到pygplates.FeatureCollection类中。
features = pygplates.FeatureCollection("features.gpml")
reconstruction_time = 10
polygon = pygplates.PolygonOnSphere([(0,0), (90,0), (0,90)])
- 使用pygplates.reconstruct()重建所有板块至10Ma。为重建的板块结果指定一个储存列表。
同时将参数group_with_feature设置为True,可以保证reconstructed feature geometries根据板块分组。
reconstructed_features = []
pygplates.reconstruct(features, rotation_model, reconstructed_features, group_with_feature=True)
- reconstructed_featured列表里的每个元素都是一个元组,包含了一个板块和所有与之相关的重建几何形状。
for feature, feature_reconstructed_geometries in reconstructed_features:
- 每个板块可以有多个几何图形,因而可以含有多个重建几何图形。
for feature_reconstructed_geometry in feature_reconstructed_geometries:
- 使用 == pygplates.GeometryOnSphere.distance() == 计算目标区域和重建板块几何图形的最短距离。
geometry1_is_solid设置为True,以防重建的几何形状完全落入目标区域内,这种情况会返回0。如果不如此设置,除非两者边界正好相接,最小距离才会为0,否则永不为0。
geometry2_is_solid设置为True,以防目标区域完全落入重建的几何形状内。同样也会视为重叠。
min_distance_to_feature = pygplates.GeometryOnSphere.distance(
polygon,
feature_reconstructed_geometry.get_reconstrued_geometry(),
geometry1_is_solid=True,
geometry2_is_solid=True)
- 最小距离为0表示当前重建的几何形状与目标区域相接或重叠。
if min_distance_to_feature == 0:
overlapping_features.append(feature)
break
overlapping_feature_collection = pygplates.FeatureCollection(overlapping_features)
overlapping_feature_filename = "features_overlapping_{0}Ma.gpml".format(reconstruction_time)
overlapping_feature_collection.write(overlapping_features_filename)