Open GeoJSON data on geojson.io

Overview

geojsonio.py

Open GeoJSON data on geojson.io from Python. geojsonio.py also contains a command line utility that is a Python port of geojsonio-cli.

https://travis-ci.org/jwass/geojsonio.py.svg?branch=master

Usage

Send data to geojson.io and open a browser within python

from geojsonio import display

with open('map.geojson') as f:
    contents = f.read()
    display(contents)

Data

There are two methods by which geojsonio.py gets geojson.io to render the data:

  • Embedding the GeoJSON contents in the geojson.io URL directly
  • Creating an anonymous Github gist and embedding the gist id in the geojson.io URL.

geojsonio.py automatically determines which method is used based on the length of the GeoJSON contents. If the contents are small enough, they will be embedded in the URL. Otherwise geojsonio.py creates an anonymous Gist on Github with the GeoJSON contents. Note: when an anonymous gist is created, the data is uploaded to Github and a unique gist ID is created. If anyone else is able to obtain the gist ID, they will be able to see your data.

Goes Great With GeoPandas

geojsonio.py integrates nicely with GeoPandas to display data in a GeoDataFrame.

Say you have a file containing the borders of all states called states.geojson. Each GeoJSON record has a property called 'Name'. Quickly display all the states whose names start with 'M'

import geopandas as gpd
import geojsonio

states = gpd.read_file('states.geojson')
m_states = states[states['Name'].str.startswith('M')]
geojsonio.display(m_states.to_json())

This will open a browser to the geojson.io window with the polygons drawn on the slippy map.

IPython Notebook Integration

To easily embed geojson.io in an iframe in a Jupyter/IPython notebook, use the embed() method

embed(contents)

Command Line Interface

It can also be used on the command line. Read or pipe a file

$ geojsonio map.geojson
$ geojsonio < run.geojson

Options:

--print prints the url rather than opening it
--domain="http://custominstancedomain.com/"

Installation

Install with pip

$ pip install geojsonio
Comments
  • GitHub removed support for anonymous gists

    GitHub removed support for anonymous gists

    I kept getting GitHubError: 422 Validation Failed from github3.py when running geojsonio.display(json, force_gist=True). Then I found issue 795 on the github3.py repo. Are there any plans already in the works to pass GitHub account info for pushing geojsons to authorized gists?

    opened by chesterharvey 6
  • github3.exceptions.AuthenticationFailed: 401 Requires authentication

    github3.exceptions.AuthenticationFailed: 401 Requires authentication

    When I try to visualize a bigger geojson, I get:

    Traceback (most recent call last):
      File "/home/math/.local/bin/geojsonio", line 11, in <module>
        sys.exit(main())
      File "/home/math/.local/lib/python3.5/site-packages/geojsonio/geojsonio.py", line 214, in main
        url = make_url(contents, args.domain)
      File "/home/math/.local/lib/python3.5/site-packages/geojsonio/geojsonio.py", line 93, in make_url
        gist = _make_gist(contents)
      File "/home/math/.local/lib/python3.5/site-packages/geojsonio/geojsonio.py", line 172, in _make_gist
        gist = ghapi.create_gist(description, files)
      File "/home/math/.local/lib/python3.5/site-packages/github3/decorators.py", line 37, in auth_wrapper
        raise error_for(r)
    github3.exceptions.AuthenticationFailed: 401 Requires authentication
    

    How can I authenticate?

    opened by MartinThoma 2
  • README.rst: Try adding unindented line at end

    README.rst: Try adding unindented line at end

    Taking a wild guess that maybe PyPI is not liking the RST because it ends in the middle of an indented block.

    I think docutils likes to see an unindented line to finish each block.

    Wild guess...

    opened by msabramo 2
  • add 'force_gist' option

    add 'force_gist' option

    Allows users to use a gist even for smaller geojson content. This might be useful for creating quick geojson.io examples for embedding in HTML and may be slightly faster in some cases. To maintain backwards compatibility, the new option defaults to False. This PR also contains some PEP 8 cleanups.

    opened by carsonfarmer 1
  • Fix _make_gist by providing github token through command line

    Fix _make_gist by providing github token through command line

    Github does not allow anonymous gist creation, so we have to provide an identification token. This is done using command line parameter ("-t", "--github-token") To create a token, go to https://github.com/settings/tokens

    opened by Mappy-team-LBS 0
  • Could not parse JSON error: Empty FeatureCollection

    Could not parse JSON error: Empty FeatureCollection

    Thank you for your contribution, the tool is pretty cool and simple.

    I tried to reproduce an example using geopandas as in the README but I got an error message once the browser opens: "Could not parse JSON" on the top left, and an empty FeatureCollection on the right.

    import geopandas as gpd
    import geojsonio
    
    gdf = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres')) 
    geojsonio.display(gdf.to_json())
    geojsonio.display(gdf.iloc[:2].to_json()) # Worked
    

    After investigation, I found that in fact the problem depends on the size of the URL request, as the geojson loaded is big.

    I manage to get it worked if I take the first 4 rows of the GeoDataFrame, but it can't make it above 7. I bet it is a restriction on geojson.io side, but I wonder if you had a solution to bypass ? Maybe login or run it local somehow, I am not sure.

    opened by mazzma12 0
  • Fixed auth

    Fixed auth

    Created auth(gituser, gitpass) and testauth() methods.

    To solve the issue (https://github.com/jwass/geojsonio.py/issues/11) I had to create an auth method using github3.py.

    opened by medeirosjoaquim 17
  • KeyError: 'owner' / IncompleteResponse: None

    KeyError: 'owner' / IncompleteResponse: None

    Hi,

    Following this tutorial: https://www.twilio.com/blog/2017/08/geospatial-analysis-python-geojson-geopandas.html

    When I get to the geojsonio.display() line, I get the following error:

    ---------------------------------------------------------------------------
    KeyError                                  Traceback (most recent call last)
    ~/temp-venv/lib/python3.6/site-packages/github3/models.py in __init__(self, json, session)
         47         try:
    ---> 48             self._update_attributes(json)
         49         except KeyError as kerr:
    
    ~/temp-venv/lib/python3.6/site-packages/github3/gists/gist.py in _update_attributes(self, gist)
        324     def _update_attributes(self, gist):
    --> 325         super(Gist, self)._update_attributes(gist)
        326         self.commits_url = gist['commits_url']
    
    ~/temp-venv/lib/python3.6/site-packages/github3/gists/gist.py in _update_attributes(self, gist)
         50         self.id = gist['id']
    ---> 51         self.owner = users.ShortUser(gist['owner'], self)
         52         self.public = gist['public']
    
    KeyError: 'owner'
    
    During handling of the above exception, another exception occurred:
    
    IncompleteResponse                        Traceback (most recent call last)
    <ipython-input-12-9a29351e3f24> in <module>()
    ----> 1 geojsonio.display(precincts)
    
    ~/temp-venv/lib/python3.6/site-packages/geojsonio/geojsonio.py in display(contents, domain, force_gist)
         34 
         35     """
    ---> 36     url = make_url(contents, domain, force_gist)
         37     webbrowser.open(url)
         38     return url
    
    ~/temp-venv/lib/python3.6/site-packages/geojsonio/geojsonio.py in make_url(contents, domain, force_gist, size_for_gist)
         91         url = data_url(contents, domain)
         92     else:
    ---> 93         gist = _make_gist(contents)
         94         url = gist_url(gist.id, domain)
         95 
    
    ~/temp-venv/lib/python3.6/site-packages/geojsonio/geojsonio.py in _make_gist(contents, description, filename)
        170     ghapi = github3.GitHub()
        171     files = {filename: {'content': contents}}
    --> 172     gist = ghapi.create_gist(description, files)
        173 
        174     return gist
    
    ~/temp-venv/lib/python3.6/site-packages/github3/github.py in create_gist(self, description, files, public)
        303         url = self._build_url('gists')
        304         json = self._json(self._post(url, data=new_gist), 201)
    --> 305         return self._instance_or_null(gists.Gist, json)
        306 
        307     @requires_auth
    
    ~/temp-venv/lib/python3.6/site-packages/github3/models.py in _instance_or_null(self, instance_class, json)
        144             return None
        145 
    --> 146         return instance_class(json, self)
        147 
        148     def _json(self, response, expected_status_code, include_cache_info=True):
    
    ~/temp-venv/lib/python3.6/site-packages/github3/models.py in __init__(self, json, session)
         48             self._update_attributes(json)
         49         except KeyError as kerr:
    ---> 50             raise exceptions.IncompleteResponse(json, kerr)
         51 
         52     def _update_attributes(self, json):
    
    IncompleteResponse: None The library was expecting more data in the response (KeyError('owner',)). Either GitHub modified it's response body, or your token is not properly scoped to retrieve this information.
    
    opened by m-deck 2
  • ValueError: startfile: filepath too long for Windows

    ValueError: startfile: filepath too long for Windows

    When running:

    from geojsonio import display
    with open('map.geojson') as f:
        contents = f.read()
        display(contents)
    

    with data from Google in the file map.geojson I receive the following error:

    ValueError                                Traceback (most recent call last)
    <ipython-input-6-cd14c4214ce4> in <module>()
          3 with open('map.geojson') as f:
          4     contents = f.read()
    ----> 5     display(contents)
    
    C:\ProgramData\Anaconda3\lib\site-packages\geojsonio\geojsonio.py in display(contents, domain, force_gist)
         35     """
         36     url = make_url(contents, domain, force_gist)
    ---> 37     webbrowser.open(url)
         38     return url
         39 # display() used to be called to_geojsonio. Keep it around for now...
    
    C:\ProgramData\Anaconda3\lib\webbrowser.py in open(url, new, autoraise)
         58     for name in _tryorder:
         59         browser = get(name)
    ---> 60         if browser.open(url, new, autoraise):
         61             return True
         62     return False
    
    C:\ProgramData\Anaconda3\lib\webbrowser.py in open(self, url, new, autoraise)
        511         def open(self, url, new=0, autoraise=True):
        512             try:
    --> 513                 os.startfile(url)
        514             except OSError:
        515                 # [Error 22] No application is associated with the specified
    
    ValueError: startfile: filepath too long for Windows
    
    opened by robmarkcole 8
Owner
Jacob Wasserman
Jacob Wasserman
Python bindings and utilities for GeoJSON

geojson This Python library contains: Functions for encoding and decoding GeoJSON formatted data Classes for all GeoJSON Objects An implementation of

Jazzband 765 Jan 6, 2023
Python bindings and utilities for GeoJSON

geojson This Python library contains: Functions for encoding and decoding GeoJSON formatted data Classes for all GeoJSON Objects An implementation of

Jazzband 763 Dec 26, 2022
gjf: A tool for fixing invalid GeoJSON objects

gjf: A tool for fixing invalid GeoJSON objects The goal of this tool is to make it as easy as possible to fix invalid GeoJSON objects through Python o

Yazeed Almuqwishi 91 Dec 6, 2022
A bot that tweets info and location map for new bicycle parking added to OpenStreetMap within a GeoJSON boundary.

Bike parking tweepy bot app A twitter bot app that searches for bicycle parking added to OpenStreetMap. Relies on AWS Lambda/S3, Python3, Tweepy, Flas

Angelo Trivisonno 1 Dec 19, 2021
Open Data Cube analyses continental scale Earth Observation data through time

Open Data Cube Core Overview The Open Data Cube Core provides an integrated gridded data analysis environment for decades of analysis ready earth obse

Open Data Cube 410 Dec 13, 2022
A package built to support working with spatial data using open source python

EarthPy EarthPy makes it easier to plot and manipulate spatial data in Python. Why EarthPy? Python is a generic programming language designed to suppo

Earth Lab 414 Dec 23, 2022
EOReader is a multi-satellite reader allowing you to open optical and SAR data.

Remote-sensing opensource python library reading optical and SAR sensors, loading and stacking bands, clouds, DEM and index.

ICube-SERTIT 152 Dec 30, 2022
GeoNode is an open source platform that facilitates the creation, sharing, and collaborative use of geospatial data.

Table of Contents What is GeoNode? Try out GeoNode Install Learn GeoNode Development Contributing Roadmap Showcase Most useful links Licensing What is

GeoNode Development Team 1.2k Dec 26, 2022
GebPy is a Python-based, open source tool for the generation of geological data of minerals, rocks and complete lithological sequences.

GebPy is a Python-based, open source tool for the generation of geological data of minerals, rocks and complete lithological sequences. The data can be generated randomly or with respect to user-defined constraints, for example a specific element concentration within minerals and rocks or the order of units within a complete lithological profile.

Maximilian Beeskow 16 Nov 29, 2022
Imports VZD (Latvian State Land Service) open data into postgis enabled database

Python script main.py downloads and imports Latvian addresses into PostgreSQL database. Data contains parishes, counties, cities, towns, and streets.

Kaspars Foigts 7 Oct 26, 2022
A public data repository for datasets created from TransLink GTFS data.

TransLink Spatial Data What: TransLink is the statutory public transit authority for the Metro Vancouver region. This GitHub repository is a collectio

Henry Tang 3 Jan 14, 2022
Using Global fishing watch's data to build a machine learning model that can identify illegal fishing and poaching activities through satellite and geo-location data.

Using Global fishing watch's data to build a machine learning model that can identify illegal fishing and poaching activities through satellite and geo-location data.

Ayush Mishra 3 May 6, 2022
Mmdb-server - An open source fast API server to lookup IP addresses for their geographic location

mmdb-server mmdb-server is an open source fast API server to lookup IP addresses

Alexandre Dulaunoy 67 Nov 25, 2022
Python Data. Leaflet.js Maps.

folium Python Data, Leaflet.js Maps folium builds on the data wrangling strengths of the Python ecosystem and the mapping strengths of the Leaflet.js

null 6k Jan 2, 2023
Python tools for geographic data

GeoPandas Python tools for geographic data Introduction GeoPandas is a project to add support for geographic data to pandas objects. It currently impl

GeoPandas 3.5k Jan 3, 2023
Fiona reads and writes geographic data files

Fiona Fiona reads and writes geographic data files and thereby helps Python programmers integrate geographic information systems with other computer s

null 987 Jan 4, 2023
Python package for earth-observing satellite data processing

Satpy The Satpy package is a python library for reading and manipulating meteorological remote sensing data and writing it to various image and data f

PyTroll 882 Dec 27, 2022
Use Mapbox GL JS to visualize data in a Python Jupyter notebook

Location Data Visualization library for Jupyter Notebooks Library documentation at https://mapbox-mapboxgl-jupyter.readthedocs-hosted.com/en/latest/.

Mapbox 620 Dec 15, 2022
python toolbox for visualizing geographical data and making maps

geoplotlib is a python toolbox for visualizing geographical data and making maps data = read_csv('data/bus.csv') geoplotlib.dot(data) geoplotlib.show(

Andrea Cuttone 976 Dec 11, 2022