Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I parse GeoJSON with Python

Tags:

People also ask

What is GeoJSON in Python?

GeoJSON is a format for representing geographic objects. It's different from regular JSON because it supports geometry types, such as: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection.

How do I visualize a GeoJSON file?

You can open GeoJSON files from your computer, Google Drive. GeoJSON Map Viewer is a tool that views the GeoJSON file in your browser. This app allows you to validate your GeoJSON and display it on a Google map.

Is GeoJSON an API?

In general, the (beta) geojson-api was developed for a project that assesses OpenStreetMap (OSM) city-level building data.


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

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?