MARK MCDONALD: Hi, and welcome to Google Developers Live.
I'm Mark McDonald, and I'm with Josh Livni
here from the Maps Developer Relations team.
Today we're going to start talking about Google Maps
Engine and a couple of new features
we've got on the endpoints.
Over to you, Josh.
JOSH LIVNI: Thanks Mark.
Yeah, so Google Maps Engine, some of you might be familiar,
is a kind of easy way to create, share, publish maps, and put
data into a Google Cloud.
So what we're going to cover today
are a couple of endpoints that create
and upload endpoints to show you how to programmatically get
data in, and why don't we start off by looking at a demo.
MARK MCDONALD: So this first demo
is a Python sample that's hosted using Google's App Engine.
We'll load it up straight away and get straight into it.
We start off with looking at some projects
that you'll have attached to your account,
so you can group your different mapping projects
into logical groupings called projects.
With this demo, we simply just upload a shapefile.
A shapefile is a zip file of a bunch
of sort of component files that form
some vector data in a table format.
We can provide a description and some tags
to describe our table if we want to find it later
using the APIs, and then we can just go ahead and upload it.
JOSH LIVNI: OK, so it turns out this
is probably not about kittens.
We'll just put state borders, hit Upload, and what
will happen in the back end here is
we're creating a sort of skeleton asset,
saying what files are going to be involved in the upload,
uploading the individual files, and then
getting back a status for Maps Engine,
which we can see on the screen.
MARK MCDONALD: Once that status is processed
and we're ready to go, we'll get a link showing us
on the page, which can send us back to the Maps Engine web
interface, where we'll be able to get a preview of the vector
data that's been uploaded.
As you can see here, there's a couple little blue outlines,
which show the data that we did upload.
Everything's been successful.
So that's all good.
JOSH LIVNI: Yeah, and if I go ahead
and refresh this page over here, we
should see that the processing status is complete.
It usually takes a few seconds, gives us some metadata back
about the data that we uploaded.
So that's the kind of example that you
might want to build so that people can use your workflow
to get the data in.
This code is available on it GitHub.
You can download it at the link below, fork it, modify it,
use it as a starting point for working with App Engine
and OAuth and the syntax for uploading data to Maps Engine.
MARK MCDONALD: And if you've got any opportunities
for improvement that you think we'd like to know about,
feel free to send them our way.
We love getting pull requests.
JOSH LIVNI: Indeed we do.
So let's go ahead and walk through a little bit
more detail the code and kind of the flow of getting data
in with this second example here, which you can download
as part of our Python Client Library.
So if you go and look for the Google API Python Client,
there's a bunch of samples.
And in the samples, there's a Maps Engine sample
that we'll walk through.
You can just download the zip or clone the project
to get this sample.
MARK MCDONALD: So on the first run with a sample like this,
it would walks through an OAuth flow,
just to find out who you are and make
sure you've got permission to access the data.
We'll skip straight past that, but before you
get started on your own project, even
if you're running this sample, you'll
need to go ahead and get an API key
and set up a project on Google's API console
before you'll be able to start this.
There's more docs on developers.google.com,
or you can ask in the comments.
JOSH LIVNI: Excellent.
So as part of setting up that developer console project,
you'll get an API key, and you can at that point
download the client_secrets, which
you can see that I have put into my samples folder here.
That's client_secrets.json.
And once I have that in there, I can go ahead and run my sample.
And what it will do is create an authorized request
to the project's endpoint, get me back a list of projects.
I'm going to pick a project here like this one
that I have access to, get the ID of the project,
and pass that in as an argument, projects argument.
Run the script again, and what you
can see flying by you on the screen
up here is this skeleton asset that we're creating.
It's going through now, uploading each file
individually down here, and then pulling for the processing
status to see how that upload is doing.
MARK MCDONALD: And that's exactly the same process
that we went through in the previous demo,
just on the command line.
JOSH LIVNI: Right.
And now that we have a little 5-second wait here,
it would say successfully processed, give us the table ID
back.
And now why don't we go ahead and take a look
at the actual code.
MARK MCDONALD: When Josh first ran the program earlier,
it was just a list project, which basically just
uses this simple get request of this URL you can see below.
It's as simple as it looks.
It is a get request.
We don't need any parameters.
We just take the JSON response that comes back
from the server, and we log it straight to the output.
Once we've done that, we want to upload our shapefile,
so that was the second run through that Josh did.
It takes the upload URL below, which is a /tables endpoint.
And basically, before we can start uploading data,
we need to create an empty table asset.
So down here, we go through each of the shapefile suffixes
that we're going to use, which are mapped
to each of the corresponding shape component files that
are in the zip file we used and create an empty metadata
structure, which describes the table
that we're about to start uploading.
Once we push this to the server, we
get back an ID which corresponds to the table
that we're going to use to upload content
when we do each of the shapefiles
and also when we go to pull the server later.
So then we go straight into the file suffixes and upload them
straight to the endpoint we used before,
just with a /files on the end, and push those files straight
up to the server.
Once that's done, we use the ID we got back
from the original request to check on the table status
and make sure that everything's all good.
JOSH LIVNI: Awesome.
Thanks for the walkthrough.
That looks pretty straightforward.
Just to summarize it, we're going
to go ahead and go through the OAuth workflow, which
happens like magic in the Python samples for you.
But we end up with an authorized HTTP request,
and then we go ahead and post a sort of skeleton asset, which
says these are the files we're going to be putting in,
these are the different tags, description,
and name of the project.
And once we post that, we get back an ID.
We use that ID to go ahead and push the various files in, pole
for the processing status, and we're done.
And the cool thing is, this works very similarly
for images.
So, for example, if you're uploading
a georeferenced image, you can have that PNG, for example,
in the sidecar file that has the world extent
and do the exact same pattern.
A couple other details, like you might
be including some additional things
like that date of the image, but generally the same pattern.
And then in addition, we have a create endpoint,
so you can create an empty vector table
without having to have an existing shapefile, or CSV,
or KML or anything like that, and then just push data
into it later using the insert endpoint.
So go ahead and check out these code samples.
MARK MCDONALD: Yeah, they're available on GitHub,
and if you've got any questions about it,
you can either ask in the comments
or jump on StackOverflow.
There's a big community of users there
who are happy to help you out, and good luck.
If you have any more questions, I guess,
there's documentation we can check out
on developers.google.com.
But have fun.
JOSH LIVNI: Cheers, guys, until next time.