Getting started with Geospatial Analysis
Geo for Good User Summit 2018
Karin Tuxen-Bettman
#GeoForGood18
Goal & Agenda
In this session, you’ll learn about some new tools, some cool functions, and get your hands dirty just enough to be dangerous!
|
|
|
|
|
|
|
|
| |
#GeoForGood18
Disclaimers
|
|
|
|
|
|
|
|
| |
#GeoForGood18
Visualization tools vs. Analysis tools
great for visualization
great for analysis
#GeoForGood18
Some geospatial analysis functions
#GeoForGood18
What is BigQuery?
Convenience of�standard SQL
Fully managed�and serverless
Google Cloud Platform’s enterprise data warehouse for analytics
Encrypted, durable
and highly available
Petabyte-scale storage�and queries
Real-time analytics on �streaming data
#GeoForGood18
What is BigQuery GIS?
New geography�data type
New geospatial functions
New mapping visualization
01
02
03
#GeoForGood18
Point
Linestring
Polygon
Multi-polygon
Collections
Data type:
Formats:
WKT
GeoJSON� WKB
#GeoForGood18
Native SQL support in BigQuery
for the most commonly used �ST_* functions
Function types: |
Constructors |
Parsers |
Formatters |
Transformations |
Predicates |
Accessors |
Measures |
Aggregates |
#GeoForGood18
Constructors
ST_GEOGPOINT(longitude, latitude)�ST_MAKELINE(geography_1, geography_2)�ST_MAKELINE(array_of_geography)�ST_MAKEPOLYGON(geography_expression)�ST_MAKEPOLYGON(geography_expression, array_of_geography)�ST_MAKEPOLYGONORIENTED(array_of_geography)
Build geographies from �coordinates or existing geographies
#GeoForGood18
Parsers & formatters
ST_GEOGFROMGEOJSON(geojson_string)�ST_GEOGFROMTEXT(wkt_string)�ST_GEOGFROMWKB(wkb_bytes)
�ST_ASGEOJSON(geography_expression)�ST_ASTEXT(geography_expression)�ST_ASBINARY(geography_expression)
Create/export geographies �between formats
((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 0 1 0, 0 1 1, 0 0 1, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
((1 1 1, 1 0 1, 0 0 1, 0 1 1, 1 1 1)),
((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1))
#GeoForGood18
Transformations
ST_INTERSECTION(geography_1, geography_2)�ST_UNION(geography_1, geography_2) �ST_UNION(array_of_geography)�ST_UNION_AGG(geography)�ST_DIFFERENCE(geography_1, geography_2)�ST_CENTROID(geography_expression)�ST_CLOSESTPOINT(geography_1, geography_2[,spheroid=FALSE])�ST_BOUNDARY(geography_expression)�ST_SNAPTOGRID(geography_expression, grid_size)
Create new geographies �with similar properties
#GeoForGood18
Predicates
ST_CONTAINS(geography_1, geography_2) �ST_COVEREDBY(geography_1, geography_2)�ST_COVERS(geography_1, geography_2)�ST_DISJOINT(geography_1, geography_2)�ST_DWITHIN(geography_1, geography_2, distance[, spheroid=FALSE])�ST_EQUALS(geography_1, geography_2)�ST_INTERSECTS(geography_1, geography_2)�ST_INTERSECTSBOX(geography, lng1, lat1, lng2, lat2)�ST_TOUCHES(geography_1, geography_2)�ST_WITHIN(geography_1, geography_2)
Filter geographies �(TRUE/FALSE)
TRUE
1
2
#GeoForGood18
Accessors
ST_ISEMPTY(geography_expression)�ST_ISCOLLECTION(geography_expression)�ST_DIMENSION(geography_expression)�ST_NUMPOINTS(geography_expression)
Access properties �of geographies
18 (vertices)
#GeoForGood18
Measures
ST_DISTANCE(geography_1, geography_2[, spheroid=FALSE])�ST_LENGTH(geography_expression[, spheroid=FALSE])�ST_PERIMETER(geography_expression[, spheroid=FALSE])�ST_AREA(geography_expression[, spheroid=FALSE])�ST_MAXDISTANCE(geography_1, geography_2[, spheroid=FALSE])
Compute measurements �of geographies
3967 (meters)
#GeoForGood18
Joins
JOIN on ST_INTERSECTS�JOIN on ST_DWITHIN�JOIN on ST_CONTAINS�JOIN on ST_WITHIN�JOIN on ST_COVERS�JOIN on ST_COVEREDBY�JOIN on ST_EQUALS
JOIN on geography �Predicates statements
#GeoForGood18
Regular, Non-GIS, Query First
#standardSQL� SELECT� id,� name,� longitude,
latitude� FROM� `bigquery-public-data.ghcn_d.ghcnd_stations`
#GeoForGood18
Weather stations within 50 km of a (lat, long) point
#standardSQL�WITH params AS (� SELECT ST_GeogPoint(-122.021,37.406) AS center, 50 AS maxdist_km ),�
#GeoForGood18
Weather stations within 50 km of a (lat, long) point
#standardSQL�WITH params AS (� SELECT ST_GeogPoint(-122.021,37.406) AS center, 50 AS maxdist_km ),�distance_from_center AS (� SELECT� id,� name,� ST_GeogPoint(longitude, latitude) AS loc,� ST_Distance(ST_GeogPoint(longitude, latitude), params.center) AS dist_meters�
#GeoForGood18
Weather stations within 50 km of a (lat, long) point
#standardSQL�WITH params AS (� SELECT ST_GeogPoint(-122.021,37.406) AS center, 50 AS maxdist_km ),�distance_from_center AS (� SELECT� id,� name,� ST_GeogPoint(longitude, latitude) AS loc,� ST_Distance(ST_GeogPoint(longitude, latitude), params.center) AS dist_meters� FROM� `bigquery-public-data.ghcn_d.ghcnd_stations`, params�
#GeoForGood18
Weather stations within 50 km of a (lat, long) point
#standardSQL�WITH params AS (� SELECT ST_GeogPoint(-122.021,37.406) AS center, 50 AS maxdist_km ),�distance_from_center AS (� SELECT� id,� name,� ST_GeogPoint(longitude, latitude) AS loc,� ST_Distance(ST_GeogPoint(longitude, latitude), params.center) AS dist_meters� FROM� `bigquery-public-data.ghcn_d.ghcnd_stations`, params� WHERE ST_DWithin(ST_GeogPoint(longitude, latitude), params.center, params.maxdist_km*1000)�)�
#GeoForGood18
Weather stations within 50 km of a (lat, long) point
#standardSQL�WITH params AS (� SELECT ST_GeogPoint(-122.021,37.406) AS center, 50 AS maxdist_km ),�distance_from_center AS (� SELECT� id,� name,� ST_GeogPoint(longitude, latitude) AS loc,� ST_Distance(ST_GeogPoint(longitude, latitude), params.center) AS dist_meters� FROM� `bigquery-public-data.ghcn_d.ghcnd_stations`, params� WHERE ST_DWithin(ST_GeogPoint(longitude, latitude), params.center, params.maxdist_km*1000)�)�SELECT * from distance_from_center
#GeoForGood18
Weather stations within 50 km of a (lat, long) point
#standardSQL�WITH params AS (� SELECT ST_GeogPoint(-122.021,37.406) AS center, 50 AS maxdist_km ),�distance_from_center AS (� SELECT� id,� name,� ST_GeogPoint(longitude, latitude) AS loc,� ST_Distance(ST_GeogPoint(longitude, latitude), params.center) AS dist_meters� FROM� `bigquery-public-data.ghcn_d.ghcnd_stations`, params� WHERE ST_DWithin(ST_GeogPoint(longitude, latitude), params.center, params.maxdist_km*1000)�)�SELECT * from distance_from_center
#GeoForGood18
173 results
Download as CSV
Save Query
#GeoForGood18
BigQuery Geo Viz
WHAT IT IS
WHAT IT IS NOT
#GeoForGood18
Click Run. 173 results.
#GeoForGood18
Select the
Geography column.
#GeoForGood18
Hands-on w/ BigQuery GIS
#GeoForGood18
Data we’ll be playing with
#GeoForGood18
Go to BigQuery & Log in
User name:
Password:
guest100@earthoutreach.org
Ludwigia2662
Open incognito Chrome window, and
#GeoForGood18
Weather stations within 50 km of a (lat, long) point
#standardSQL�WITH params AS (� SELECT ST_GeogPoint(-122.021,37.406) AS center, 50 AS maxdist_km ),�distance_from_center AS (� SELECT� id,� name,� ST_GeogPoint(longitude, latitude) AS loc,� ST_Distance(ST_GeogPoint(longitude, latitude), params.center) AS dist_meters� FROM� `bigquery-public-data.ghcn_d.ghcnd_stations`, params� WHERE ST_DWithin(ST_GeogPoint(longitude, latitude), params.center, params.maxdist_km*1000)�)�SELECT * from distance_from_center
#GeoForGood18
173 results
Download as CSV
Save Query
#GeoForGood18
Add the
g4g-bigquery
Project ID here.
#GeoForGood18
Click Run. 173 results.
#GeoForGood18
Select the
Geography column.
#GeoForGood18
Current air quality within 100 km of a specific zip code
#standardsql
WITH params AS (
SELECT 94043 AS zipcode,
100 AS maxdist_km
),
zipcode AS (
SELECT ST_GeogFromText(WKT) AS polygon
FROM `cloud-training-demos.demos.zipcode_polygon2017`, params
WHERE ZCTA5CE10 = params.zipcode
),
airquality AS (
SELECT
location, city, country, pollutant, value, unit, timestamp, averaged_over_in_hours, source_name,
ST_GeogPoint(longitude, latitude) AS loc,
ST_Distance(ST_GeogPoint(longitude, latitude), zipcode.polygon) AS dist_meters
FROM
`bigquery-public-data.openaq.global_air_quality`,
params,
zipcode
WHERE ST_DWithin(ST_GeogPoint(longitude, latitude), zipcode.polygon, params.maxdist_km*1000) AND pollutant = "pm25"
)
SELECT * from airquality
ORDER BY dist_meters ASC
LIMIT 1000
#GeoForGood18
#GeoForGood18
#GeoForGood18
Add style to make the stations with higher PM 2.5 larger...
#GeoForGood18
...and opacity so that air quality stations closer are darker than those farther away.
#GeoForGood18
Next Steps for BigQuery GIS
1 | Explore the docs at cloud.google.com/bigquery/docs/gis | |
2 | Find more BigQuery Public Data here. | |
3 | Find all air quality stations within Mongolia. | |
4 | Visualize the data in BigQuery Geo Viz. | |
5 | Follow along on this article on how to use BigQuery GIS to interpolate values. |
#GeoForGood18
#GeoForGood18
Visualize your SQL query
in BigQuery Geo Viz
Easy mapping
No export or loading necessary
Style the viz �interactively
Copy and run�the query
Analyze in �BigQuery
#GeoForGood18
Visualize your findings �in Google Earth Engine
Load data into �Earth Engine
Export data �to GCS
Analyze in �BigQuery
CSV + GeoJSON CSV + WKT
SHP → EE UI
#GeoForGood18
Basic geospatial functions in Earth Engine
Buffer
Computed Area Filter
Distance
#GeoForGood18
#GeoForGood18
#GeoForGood18
#GeoForGood18
Interpolate (inverse distance) PM 2.5 points
// Load a Fusion Table corresponding to mean annual PM2.5 concentrations at points.
var airQualityMeasurements = ee.FeatureCollection('ft:14BLob4jGA6au2MB1cx0GhxYDvZc-lVLAWhqBAZuN');
Map.addLayer(airQualityMeasurements, {}, 'Mean annual PM2.5 concentrations (micrograms/m^3)');
// This is the name of the property to interpolate.
var propertyToInterpolate = 'ArithmeticMean';
// Combine mean and SD reducers for efficiency.
var combinedReducer = ee.Reducer.mean().combine({
reducer2: ee.Reducer.stdDev(),
sharedInputs: true
});
// Estimate global mean and standard deviation (SD) from the points.
var stats = airQualityMeasurements.reduceColumns({
reducer: combinedReducer,
selectors: [propertyToInterpolate]
});
// Do the interpolation, valid to 50 kilometers.
var interpolatedPM25 = airQualityMeasurements.inverseDistance({
range: 50 * 1000,
propertyName: propertyToInterpolate,
mean: stats.get('mean'),
stdDev: stats.get('stdDev'),
gamma: 0.5
});
// Visualize the resulting interpolated raster.
var vis = {min: 0, max: 15, palette: ['blue', 'green', 'red']};
Map.setCenter(-121.7944, 36.9235, 7);
Map.addLayer(interpolatedPM25, vis, 'Interpolated PM2.5 concentration');
#GeoForGood18
#GeoForGood18
#GeoForGood18
Upload your own data, too!
#GeoForGood18
Next Steps for Earth Engine
1 | Explore the docs at developers.google.com/earth-engine/ | |
2 | Find more Earth Engine Public Data in the Earth Engine Data Catalog and the Vector Datasets Catalog. | |
3 | Upload your own shapefiles to Earth Engine. | |
4 | Take an Earth Engine 101 session here at Geo for Good 2018! |
#GeoForGood18
Thank you!
Geo for Good User Summit 2018
karintuxen@google.com
#GeoForGood18
Geometry vs. Geography
Geometry
Shortest distance between 2 points�is a straight line
Geography
Shortest distance�is a great circle.
Wait, what??!!
Geography from space
Euclid was right
#GeoForGood18
Try the new UI
click on
#GeoForGood18
Try the new UI
#GeoForGood18
Accessing the BigQuery Public Data
Enter the following URL to open the public datasets in the new BigQuery UI: https://console.cloud.google.com/marketplace/partners/bigquery-public-data.
Once you have the public dataset project open, you can pin the project.
#GeoForGood18
Other test usernames & passwords
guest100@earthoutreach.org: Ludwigia2662
guest101@earthoutreach.org: Lupinus5153
guest102@earthoutreach.org: Luzula6823
guest103@earthoutreach.org: Lycium5845
guest104@earthoutreach.org: Lythrum3590
guest105@earthoutreach.org: Madia3550
guest106@earthoutreach.org: Malva3596
guest107@earthoutreach.org: Marah3499
guest108@earthoutreach.org: Medicago7867
guest109@earthoutreach.org: Melica3863
guest110@earthoutreach.org: Menodora4202
guest111@earthoutreach.org: Mentha5660
guest112@earthoutreach.org: Micropus8175
guest113@earthoutreach.org: Mimulus7110
guest114@earthoutreach.org: Montia6419
guest115@earthoutreach.org: Myosotis3552
guest116@earthoutreach.org: Myosurus3514
guest117@earthoutreach.org: Najas4339
guest118@earthoutreach.org: Nolina9727
guest119@earthoutreach.org: Opuntia5504
guest120@earthoutreach.org: Orcuttia7783
guest121@earthoutreach.org: Oxalis1112
guest122@earthoutreach.org: Packera8063
guest123@earthoutreach.org: Panicum9944
guest124@earthoutreach.org: Papaver4038
guest125@earthoutreach.org: Paspalum1803
#GeoForGood18