如何使用Python解析GeoJSON [英] How can I parse GeoJSON with Python

查看:2352
本文介绍了如何使用Python解析GeoJSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询的geojson数据,现在我想解析并在屏幕上打印.我当前的代码是:

I have have geojson data from a query which I now want to parse and print on screen. My current code is:

import urllib
import geojson

while True:

    url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&starttime=2012-01-01&endtime=2017-03-01&minmagnitude=4.0&maxmagnitude=9.0&minlongitude=5.95&maxlongitude=10.50&minlatitude=45.81&maxlatitude=47.81'
    uh = urllib.urlopen(url)
    data = uh.read()
    print data
    break

看来data是一个简单的字符串.但是,我认为它可以像json参数一样进行解析.我如何处理geojson数据才能打印单个point,例如仅提取第一个点的坐标?

It seems that data is a simple string. However, I thought it could be parsed like a json parameter. How do I have to handle geojson data in order to print a single point, e.g. to extract the coordinates of the first point only?

推荐答案

您可以像读取任何json一样阅读它:

You can read it like any json:

import json
data = json.loads(datastring)
data['features'][0]['geometry'] #Your first point

这篇关于如何使用Python解析GeoJSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆