この例では、再構成された特徴セットを反復処理し、幾何学的領域がターゲット領域と重複する特徴を見つけます。
サンプルコード
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)
詳細コード
- 回転ファイルからモーション モデルをロードします。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 に再構築します。再構成されたプレート結果の保存リストを指定します。
同時にパラメータ機能付きグループとして設定され真実、保証できます再構築されたフィーチャのジオメトリセクションごとにグループ化します。
reconstructed_features = []
pygplates.reconstruct(features, rotation_model, reconstructed_features, group_with_feature=True)
- 再構築された特集リスト内の各要素は、プレートと関連するすべての再構成ジオメトリを含むタプルです。
for feature, feature_reconstructed_geometries in reconstructed_features:
- 各プレートは複数のジオメトリを持つことができるため、複数の再構成ジオメトリを含めることができます。
for feature_reconstructed_geometry in feature_reconstructed_geometries:
- ==pygplates.GeometryOnSphere. distance() == を使用して、ターゲット領域と再構築されたプレート ジオメトリの間の最短距離を計算します。
ジオメトリ1_is_solid再構築されたジオメトリがターゲット領域内に完全に収まる場合は True に設定し、その場合は 0 が返されます。設定しない場合、最小距離は 2 つの境界線が正確に接していない限り 0 になります。そうでない場合は 0 にはなりません。
ジオメトリ2_is_solidTrue に設定すると、ターゲット領域が再構築されたジオメトリ内に完全に収まらないようになります。重複も考慮されます。
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)