pygplates column——Introduction——Find the reconstruction features of a certain geometric area
This example iterates over the reconstructed feature set, and then finds those features whose geometric region overlaps the target region.
sample code
import pygplates
# 加载rotations模型
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)
# 重建至10Ma时与目标区域重叠的特征
overlapping_features = []
# 遍历所有重建特征
for feature, feature_reconstructed_geometries in reconstructed_features:
# 遍历当前特征的所有重建几何图形
for feature_reconstructed_geometry in feature_reconstructed_geometries:
# 获取当前重建几何图形至目标区域的最短距离
# 将目标区域内部的距离视为0
# 同样将重建几何图形的内部距离视为0
min_distance_to_feature = pygplates.GeometryOnSphere.distance(
polygon,
feature_reconstructed_geometry.get_reconstructed_geometry(),
geometry1_is_solid=True,
geometry2_is_solid=True)
# 当min_distance_to_feature=0表示重建的几何图形要么与目标区域相接,要么重叠(或者皆可)
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)
Detailed code
- Load the motion model from the rotation file intopygplates.RotationModelin class.
rotation_model = pygplates.RotationModel("rotations.rot")
- Load rebuildable plates intopygplates.FeatureCollectionin class.
features = pygplates.FeatureCollection("features.gpml")
- Specifies the rebuild time.
reconstruction_time = 10
- new target area
polygon = pygplates.PolygonOnSphere([(0,0), (90,0), (0,90)])
- usepygplates.reconstruct()Rebuild all plates to 10Ma. Specifies a storage list for reconstructed plate results.
At the same time the parametergroup_with_featureSet asTrue, can guaranteereconstructed feature geometriesGroup by section.
reconstructed_features = []
pygplates.reconstruct(features, rotation_model, reconstructed_features, group_with_feature=True)
- reconstructed_featuredEach element in the list is a tuple containing a plate and all associated reconstruction geometry.
for feature, feature_reconstructed_geometries in reconstructed_features:
- Each plate can have multiple geometries and therefore can contain multiple reconstruction geometries.
for feature_reconstructed_geometry in feature_reconstructed_geometries:
- Use ==pygplates.GeometryOnSphere.distance() == to calculate the shortest distance between the target region and the reconstructed plate geometry.
geometry1_is_solidSet to True in case the reconstructed geometry falls completely within the target area, in which case 0 is returned. If not set, the minimum distance will be 0 unless the borders of the two are exactly touching, otherwise it will never be 0.
geometry2_is_solidSet to True to prevent the target region from falling completely within the reconstructed geometry. Also considered overlapping.
min_distance_to_feature = pygplates.GeometryOnSphere.distance(
polygon,
feature_reconstructed_geometry.get_reconstrued_geometry(),
geometry1_is_solid=True,
geometry2_is_solid=True)
- A minimum distance of 0 means that the current reconstructed geometry touches or overlaps the target area.
if min_distance_to_feature == 0:
overlapping_features.append(feature)
break
- Write overlapping plates to file.
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)