Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

547
Views
How can I parse GeoJSON with Python

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?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

import geojson
with open(path_to_file) as f:
    gj = geojson.load(f)
features = gj['features'][0]
over 4 years ago · Santiago Trujillo Report

0

You can read it like any json:

import json
data = json.loads(datastring)
data['features'][0]['geometry'] #Your first point
over 4 years ago · Santiago Trujillo Report

0

You can also use geopandas:

import geopandas as gpd
earthquake = gpd.read_file('earthquake.geojson')
print(earthquake.head())
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!