判断json是否为Geojson
Determine whether json is Geojson
我在 json 文件中有几个字段,我需要确定哪些 json 字段是 GeoJSON。例如,这是我拥有的数据示例:
{
"name": "bob",
"age": 20,
"info": {"height": 189, "weight": 101}
"location": { "type": "Feature","geometry": {"type": "Point","coordinates": [125.6, 10.1]},"properties": {"name": "Dinagat Islands"}}
}
我想从这里获取以下列信息:
- 名称(字符串)
- 年龄(整数)
- 信息 (json)
- 位置(地理位置json)
确定 json 对象是否真的是 GeoJSON 对象的最佳方法是什么?我查看了 GeoJSON 的各种示例,例如 http://geojsonlint.com/,它似乎在如何指定方面非常灵活。
是否有确定 json 对象是否为 GeoJSON 的可靠方法?
您可以使用 pandas 将 json/geojson 对象转换为数据框。 Link .
使用以下方法获取位置点:
安装geopy.
pip install geopy
获取位置:
location = df['location']['geometry']['coordinates']
然后,
try:
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="specify_your_app_name_here")
location = geolocator.reverse(str(location))
print(location.address)
except:
print('not GEOjson') #there will be exception if the coordinates don't represent a location
这是基于coordinates
是一个pair
,会给出位置地址。
其他:
您可以检查它们是否具有 coordinates
或 geometry
等功能,然后检查其 geojson
。
由于整个事物都在数据框中,因此更容易可视化并根据需要使用任何值!!
你也可以用同样的方式获得name
、location
或其他任何东西。
我在 json 文件中有几个字段,我需要确定哪些 json 字段是 GeoJSON。例如,这是我拥有的数据示例:
{
"name": "bob",
"age": 20,
"info": {"height": 189, "weight": 101}
"location": { "type": "Feature","geometry": {"type": "Point","coordinates": [125.6, 10.1]},"properties": {"name": "Dinagat Islands"}}
}
我想从这里获取以下列信息:
- 名称(字符串)
- 年龄(整数)
- 信息 (json)
- 位置(地理位置json)
确定 json 对象是否真的是 GeoJSON 对象的最佳方法是什么?我查看了 GeoJSON 的各种示例,例如 http://geojsonlint.com/,它似乎在如何指定方面非常灵活。
是否有确定 json 对象是否为 GeoJSON 的可靠方法?
您可以使用 pandas 将 json/geojson 对象转换为数据框。 Link
使用以下方法获取位置点:
安装geopy.
pip install geopy
获取位置:
location = df['location']['geometry']['coordinates']
然后,
try:
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="specify_your_app_name_here")
location = geolocator.reverse(str(location))
print(location.address)
except:
print('not GEOjson') #there will be exception if the coordinates don't represent a location
这是基于coordinates
是一个pair
,会给出位置地址。
其他:
您可以检查它们是否具有 coordinates
或 geometry
等功能,然后检查其 geojson
。
由于整个事物都在数据框中,因此更容易可视化并根据需要使用任何值!!
你也可以用同样的方式获得name
、location
或其他任何东西。