GithubHelp home page GithubHelp logo

mapbox / geo-googledocs Goto Github PK

View Code? Open in Web Editor NEW
277.0 136.0 77.0 40 KB

Tools to integrate Mapbox with Google Docs

Home Page: http://mapbox.com/blog/mapping-google-doc-spreadsheet/

License: MIT License

JavaScript 100.00%
banished

geo-googledocs's Introduction

Geo for Google Docs

Geo for Google Docs is a set of tools that make it easy to use data from Google Docs Spreadsheets in TileMill, an open source map design studio.

Uses

  • Export spreadsheet data to GeoJSON Any spreadsheet with geocodes (longitude and latitude coordinates) can be exported to a TileMill-ready file. After exporting, just copy the GeoJSON file to your TileMill/files/data directory.
  • Geocode arbitrary addresses If your spreadsheet does not have geocodes, you can add them using a geocoding service like those provided by Yahoo PlaceFinder or MapQuest Nominatim or Cicero API. Consult these services for their terms of use.

Installation

  • Copy the source of mapbox.js
  • Open your spreadsheet and goto tools > script editor
  • Replace the content in the text box with the copied source from mapbox.js
  • Set the name of this script to geo
  • Go to file > save and close the popup window
  • Refresh your spreadsheet and you will see a new menu called Geo added after Help on the menu bar

Authors


Usage walkthrough

Geo for Google Docs is an add-on script for Google Docs Spreadsheets that lets you geocode arbitrary addresses and export spreadsheets as GeoJSON.

Getting set up

First copy the source code for the Geo for Google Docs script.

Next, open your spreadsheet in Google Docs and select Tools > Script Editor. Erase the default function myFunction() {} in the code window, and paste in the source code you copied. Name the project 'Geo', File > Save, and close the window. Refresh your spreadsheet and you will see a new Geo menu next to Help.

Now you're ready to use the Geo add-on. It has two simple features: geocode addresses and export as GeoJSON.

Geocoding arbitrary addresses

Say you've got a spreadsheet with a column for addresses. It could be a street address, a ZIP Code, a county or a state name - even a country code. To map this you need to find the geocodes, or longitude and latitude coordinates for these addresses. For locations that are more general, like "Canada", geocoding APIs usually return the coordinates of the centroid - the area's center point - or capital.

After you've installed the Geo script in your spreadsheet, you can use the MapQuest Nominatim or Yahoo PlaceFinder services to get geocodes for your addresses. First select the cells with your address data. This could be one column or several. If you select multiple columns (such as 'Address', 'City', 'State') the columns with be joined together from left to right and sent to the geocoding service. You can also select just a few cells to geocode instead of a whole column. This is useful when you add new rows or update existing addresses and only want to geocode the new data.

Once you've selected your address data, go to Geo > Geocode Addresses. If this is the first time you're using the script, you'll need to authorize it to access your spreadsheet and then go to Geocode Addresses again. Now all you need to do is set your preferred API, enter an API key if the service requires it, and click Geocode.

Geo menu with data in it

You should now see three new columns added to your spreadsheet and coordinate data being entered into those. The third column is a response back from the geocoding service about the resolution of the geocode - something like 'residential' for street address, 'administrative' for state level match if your using MapQuest, or a numeric score if you're using Yahoo. This is particularly useful for checking the accuracy of your geocodes. For instance if you submit a country name and get back a 'residential' response, its likely that the geocoder could not figure out what to do with that address and that you should try to make it more specific, perhaps by using a three-digit code like 'USA' instead of 'United States'. If you find your geocodes are still inaccurate or slightly off, you can manually enter coordinates. Try using a service like Get Lat Lon. Also, we do not recommend you use this script for more than 1,000 geocodes at a time. For large datasets, try Google Refine, which we have successfully used for up to 30,000 addresses.

Many web services exist for geocoding addresses. We use MapQuest's Nominatum search most often, as it is based on Open Street Map data and does not have a defined rate limit. We also use Yahoo PlaceFinder occasionally because it too has a generous rate limit and terms of service. We tend to avoid geocoders with expensive licensing, like the Google Maps API. Before using any geocoder, make sure to review its terms of service. If you'd like to add a new geocoder to this script, please fork it on GitHub and submit a pull request. General issues should be reported on GitHub as well.

Now that your spreadsheet has geospatial data (coordinates), it's ready to be mapped.

Exporting to GeoJSON

To load your spreadsheet data into TileMill or another GIS application like Quantum GIS, save the data as a GeoJSON file. To do this with the Geo script, select all the data you want to export and go to Geo > Export GeoJSON. Select a column with unique content for each row, and specify the columns with your coordinates. Then click export and download the file. You'll need to add .geojson to the end of the filename so that TileMill recognizes it as GeoJSON.

To use this in TileMill, copy the file to your Mapbox data directory. Then open TileMill, add a new layer, and specify this file. Now you're ready to start designing your map. For more on that, see the TileMill Manual and Support Forum.

geo-googledocs's People

Contributors

dhcole avatar ingalls avatar jerheff avatar lbds137 avatar tmcw avatar tylermachado avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

geo-googledocs's Issues

geo-coding script error on international characters

After testing the geo-coding script on Moldova's districts, it looks like the program is stalling out on special international characters, such as ă, ş and î. (Yahoo does not understand these characters either, as this search result shows.) Will need to write an exception for these cases.

Stuck on "Geocoding these addresses..."

I've got the google spreadsheet with addresses.
I've installed mapbox geo-google into the google spreadsheet, and it appears to work.
I've got a mapquest api key and pointed it to the spreadsheet's url.
But when I try to run it, it stays stuck on this screen:
screenshot from 2016-07-27 20 24 48

How to install?

Are there instructions somewhere on how to install this into a spreadsheet? I see the script gallery and the manager, and see I can write/paste some code into the script manager, but, not sure that's the right way. I don't see the script in the gallery.

Geocode Function

  • geocode function
    • define address range (by selection?)
    • select API
    • enter API key
    • define destination fields
    • enter accuracy filter

UI polish

  • handle blank columns
    • max row limit (tested to 4000 rows)
    • add help links (menu and after export)

lat, long, accuracy columns keep getting created

It looks like the function getDestCols() has a bug. This:

var headers = getHeaders(sheet, sheet.getRange(1,1,1,sheet.getLastRow()), 1);

should be this:

var headers = getHeaders(sheet, sheet.getRange(1,1,1,sheet.getLastColumn()), 1);

Otherwise it will only scan as many columns as you have rows.

Geocoding error

I'm trying to geocode some locations in Colombia before creating a map in TileMill. After setting up the script just fine, then trying to geocode, I keep getting a pop-up that says "Oops. We're sorry. The server encountered an error. Please press "OK" to refresh the sheet."

Here's a link to the Google Spreadsheet: https://docs.google.com/spreadsheet/ccc?key=0Atrv3W0m5dcudFVjSW9nd0dCZEFCeXpYVE9PaHBEVnc#gid=0

To give you a little bit of background on the data - it's from sidih.colombiassh.org, a website run by UN OCHA that has a ton of data on Colombia, and contains data on conflict incidents from 2011. Please do not share this data with others, as I do not have permission to distribute it - am simply trying to solve this issue.

The pertinent columns are the last 4, with "Country" (Colombia), "Departamento" (equivalent of state level), "Municipio" (equivalent of county level), and "Lugar" (in this case, refers to a small town or neighborhood in a city). I've tried running it both with and without "Lugar," but it doesn't work either way. I used the Mapquest geocoding since it didn't require an API key.

Any thoughts on what's going on?

Need to replace DocsList with DriveApp

Because Google has discontinued DocsList, "DocsList.createFile" needs to be replaced with "DriveApp.createFile" on line 203 or this script will not work. Took quite a bit of troubleshooting to figure it out.

limit on exporting geoJson

I ran into a problem exporting a big google doc (8 columns * 7956 rows = 63648 cells of data). The export function was stalling and never finished exporting, even after about 10 minutes or so. The export function worked on smaller files (like 8 columns * 2564=20512 cells of data).

So, somewhere between 20k and 60k's worth of cells the script is breaking down. Don't know if that's acceptable or if there's something else we can do to make it accept larger files.

discrepancy b/t script returns and refine returns

After geocoding some zip codes with the script, there are some incorrect lat/lng values that its creating that refines fetching feature doesn't create. Some example zip codes were "10009" and "20003". Not sure where the bug is - might be that you have to call yahoo multiple times - but we need to keep an eye out for catching these errors somehow.

columns re-ordered in tilemill after exporting to geojson

Currently, when you export to geojson and upload the file into tilemill, the columns are re-ordered in a seemingly random fashion. While it does not affect the substance of the data, the order of columns should be maintained during this export to help organization and readability.

Geo code receiving error message

I've been using geo codes for awhile now and love using it but recently i'm getting this error message:

UiApp has been deprecated. Please use HtmlService instead.

Can you specify?

Thanks,

Lorry

blank column header produces empty geojson file

if you're exporting a spreadsheet where one of the columns does not have a header (see below for example) and you select that column as the ID, the export produces an empty file.

example:

benin_data

Description name change?

Currently the description to the project reads this:

Tools to integrate MapBox with Google Docs but its way more generic than this. Perhaps it should read more like, Google docs to .GeoJSON toolset

encodeURIComponent

We should probably use encodeURIComponent instead of encodeURI when encoding the address and key in the query.

Geo no longer responding?

I used the script to geocode a number of addresses (600+) but I just deployed the script on a new sheet. Set it to run as usual, all the steps seem to be in order, but the new columns are not being created and then I get a "geocoding is finished" dialogue box despite nothing having happened. Thoughts?

Google Drive Security concern when authorizing the app's script

I used the script for the spreadsheet in this post and it works great! :) Thanks... but I see the following security concern when authorizing it:

geo has access to: Google Docs View and manage your spreadsheets in Google Drive Google Drive View and manage the files and documents in your Google Drive Additional access Connect to an external service

Doesn't Google allow access to only a specific Spreadsheet? Does the script have to have access to view/manage all spreadsheets in Google Drive?

Rename this project and repository

This is a GeoJSON exporter, currently. Possibly it could expand and deserve a more general name, but we shouldn't spread mapbox thinner right now.

Decoding Inconsistency in API vs Yahoo Sites

Tried using script to get geolocations for SEPI codes (area codes) in Brazil. Using both Yahoo and Mapbox to grab the locations returns the same geolocation for codes in Brazil. However, if I go to the maps.yahoo.com and search the SEPI codes it returns the correct address.

ID full_address
200 11030-161, Brazil
301 04858-480, Brazil
422 05776-410, Brazil
45 04860-160, Brazil
302 04822-230, Brazil
40 05849-230, Brazil
389 05541-030, Brazil
58 09972-060, Brazil
445 04835-080, Brazil
449 04654-000, Brazil
284 04425-000, Brazil
390 04538-000, Brazil
157 09780-190, Brazil
111 03362-020, Brazil
196 04516-001, Brazil

Add zip code column?

Has anyone figured out how to add a zip code column? (Maybe MapQuest doesn't do that? When I tried a sample street, city, state at http://www.mapquestapi.com/geocoding/#optionssample it didn't come back with a zip code.)

Will try the other APIs, too, but meanwhile, thought I'd see if anyone already knows if and how.

Ideally, will want to create a formula that can be applied to a cell, and dragged down... For instance:

=zipcode(a1:c1)

But just getting an originally absent zipcode to be returned in a new column using the current Geo button, would be great.

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.