从 GEOJSON 文件中检索数据值并输入到 .py 文件中的公式
Retrieve data values from a GEOJSON file and input into formula in .py file
我有一个 GEOJSON 文件,其中包含特定地震的震级和深度等地震信息:
{"type": "FeatureCollection","name": "event_CATAC2020vvem","crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },"features": [{ "type": "Feature", "properties": { "id": "CATAC2020vvem", "date": "2020-11-06 10:22:48", "latitude": "6.887407303", "longitude": "-73.20696259", "magnitude": "4.315760204", "depth": "151.9202271" },"geometry": { "type": "Point", "coordinates": [ -73.20696259, 6.887407303 ] } }]}
我还有一个 .py 文件,其中包含用于计算和打印强度值距离 d 的结果的公式。
ml = float(input("Enter Magnitude Value: "))
h = float(input("Enter Depth Value: "))
#Iso = float(input("Enter Intensity MMI Value: "))
import math
Io = 1.5 * (ml - math.log(h) + 1.4)
for Iso in [i/10 for i in range(5,125,5)]:
a = (Io - Iso) / (1.8)
d = (10 / 8) * (a)
d = d - 1
if d <= 0:
print("Distance is zero")
else:
d = math.sqrt(h * h + d * d)
print("Radius (km) for " + str(Iso) + " MMI:", d)
目前,我必须手动输入这些震级和深度值,并且想从 GEOJSON 文件中检索震级和深度值并将它们输入到方程中。是否有我可以编写的脚本来检索这些数据并将其输入到公式中?谢谢
使用 bult-in 包 json
您可以在 Python 中加载 JSON 对象。
import math
import json
# Open JSON file
f = open('data.geojson',)
# returns JSON object as a dictionary
data = json.load(f)
for feature in data['features']:
ml = float(feature['properties']['magnitude'])
h = float(feature['properties']['depth'])
Io = 1.5 * (ml - math.log(h) + 1.4)
for Iso in [i/10 for i in range(5,125,5)]:
a = (Io - Iso) / (1.8)
d = (10 / 8) * (a)
d = d - 1
if d <= 0:
print("Distance is zero")
else:
d = math.sqrt(h * h + d * d)
print("Radius (km) for " + str(Iso) + " MMI:", d)
我有一个 GEOJSON 文件,其中包含特定地震的震级和深度等地震信息:
{"type": "FeatureCollection","name": "event_CATAC2020vvem","crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },"features": [{ "type": "Feature", "properties": { "id": "CATAC2020vvem", "date": "2020-11-06 10:22:48", "latitude": "6.887407303", "longitude": "-73.20696259", "magnitude": "4.315760204", "depth": "151.9202271" },"geometry": { "type": "Point", "coordinates": [ -73.20696259, 6.887407303 ] } }]}
我还有一个 .py 文件,其中包含用于计算和打印强度值距离 d 的结果的公式。
ml = float(input("Enter Magnitude Value: "))
h = float(input("Enter Depth Value: "))
#Iso = float(input("Enter Intensity MMI Value: "))
import math
Io = 1.5 * (ml - math.log(h) + 1.4)
for Iso in [i/10 for i in range(5,125,5)]:
a = (Io - Iso) / (1.8)
d = (10 / 8) * (a)
d = d - 1
if d <= 0:
print("Distance is zero")
else:
d = math.sqrt(h * h + d * d)
print("Radius (km) for " + str(Iso) + " MMI:", d)
目前,我必须手动输入这些震级和深度值,并且想从 GEOJSON 文件中检索震级和深度值并将它们输入到方程中。是否有我可以编写的脚本来检索这些数据并将其输入到公式中?谢谢
使用 bult-in 包 json
您可以在 Python 中加载 JSON 对象。
import math
import json
# Open JSON file
f = open('data.geojson',)
# returns JSON object as a dictionary
data = json.load(f)
for feature in data['features']:
ml = float(feature['properties']['magnitude'])
h = float(feature['properties']['depth'])
Io = 1.5 * (ml - math.log(h) + 1.4)
for Iso in [i/10 for i in range(5,125,5)]:
a = (Io - Iso) / (1.8)
d = (10 / 8) * (a)
d = d - 1
if d <= 0:
print("Distance is zero")
else:
d = math.sqrt(h * h + d * d)
print("Radius (km) for " + str(Iso) + " MMI:", d)