Coder Social home page Coder Social logo

gmaps2geojson's Introduction

gmaps2geojson

Super simple python utility for getting GeoJSON from Google Maps routes.

Setup

Written using Python 3.6. Install requirements with pip install -r gmaps2geojson/requirements.txt.

Get an API key for the Google Maps Directions API. Set this as an environment variable.

export GMAPS_KEY='YOUR API KEY HERE'

Usage

>>> import gmaps2geojson
>>> writer = gmaps2geojson.Writer()
>>> directions1 = writer.query("2131 7th Ave, Seattle, WA 98121", "900 Poplar Pl S, Seattle, WA 98144")
>>> directions2 = writer.query("900 Poplar Pl S, Seattle, WA 98144", "219 Broadway E, Seattle, WA 98102")
>>> directions2
*Will output all [long,lat] coordinates of geojson line
>>> writer.save("example.geojson")

or combine all queries into an array and use query_array

>>> import gmaps2geojson
>>> writer = gmaps2geojson.Writer()
>>> directions = writer.query_array([
      ["2131 7th Ave, Seattle, WA 98121", "900 Poplar Pl S, Seattle, WA 98144"],
      ["900 Poplar Pl S, Seattle, WA 98144", "219 Broadway E, Seattle, WA 98102"]
    ])
>>> directions
*Will output all [long,lat] coordinates of geojson line
>>> writer.save("example.geojson")
  • query(src, dest, custom_label=None): Use the query function to get a list of coordinates -- derived from the first result on Google Maps between the provided source and destination. Returns list of (longitude, latitude) coordinates
  • query_array(src_dest_array, custom_label=None): Same as the query function, only this accepts an array of [src, dest] string locations. Returns a list of (longitude, latitude) coordinates connecting each location. Passing an array of [["San Carlos, Antioquia, Colombia", "Villavicencio, Colombia"],["Villavicencio, Colombia","Cali, Colombia"]] will calculate the coordinates connecting San Carlos to Villavicencio to Cali. Write those coordinates to a file using...
  • write(filename): Outputs geojson of all queried routes. All routes have a name property in the format of <src> to <dest> unless a custom_label was specified when querying.

See example.py and example.geojson.

gmaps2geojson's People

Contributors

kexin-zhang avatar sweaverdeloitte avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.