GCS BigQuery GIS - ghdrako/doc_snipets GitHub Wiki
ST_GEOGPOINT ST_GEOGPOINT(longitude, latitude) Creates a GEOGRAPHY with a single point. ST_GEOGPOINT creates a point from the specified FLOAT64 longitude and latitude parameters and returns that point in a GEOGRAPHY value.
ST_MAKELINE ST_MAKELINE(geography_1, geography_2)
ST_MAKELINE(array_of_geography)
Creates a GEOGRAPHY with a single linestring by concatenating the point or line vertices of each of the input GEOGRAPHYs in the order they are given.
Every edge must span strictly less than 180 degrees.
ST_MAKEPOLYGON ST_MAKEPOLYGON(geography_expression[, array_of_geography])
Creates a GEOGRAPHY containing a single polygon from linestring inputs, where each input linestring is used to construct a polygon ring.
For every input GEOGRAPHY containing exactly one linestring, the following must be true:
The linestring must consist of at least three distinct vertices. The linestring must be closed: that is, the first and last vertex have to be the same. If the first and last vertex differ, the function constructs a final edge from the first vertex to the last.
Constraints
Together, the input rings must form a valid polygon:
The polygon shell must cover each of the polygon holes. There can be only one polygon shell (which has to be the first input ring). This implies that polygon holes cannot be nested. Polygon rings may only intersect in a vertex on the boundary of both rings. Every edge must span strictly less than 180 degrees
ST_BOUNDARY ST_BOUNDARY(geography_expression)
Description
Returns a single GEOGRAPHY that contains the union of the boundaries of each component in the given input GEOGRAPHY.
ST_CENTROID ST_CENTROID(geography_expression)
Description
Returns the centroid of the input GEOGRAPHY as a single point GEOGRAPHY.
ST_CLOSESTPOINT ST_CLOSESTPOINT(geography_1, geography_2[, use_spheroid])
Description
Returns a GEOGRAPHY containing a point on geography_1 with the smallest possible distance to geography_2.
ST_DIFFERENCE ST_DIFFERENCE(geography_1, geography_2)
Description
Returns a GEOGRAPHY that represents the point set difference of geography_1 and geography_2.
ST_DISTANCE ST_DISTANCE(geography_1, geography_2[, use_spheroid])
Description
Returns the shortest distance in meters between two non-empty GEOGRAPHYs.
Total distance travelled by each bicycle in the dataset.
WITH
trip_distance AS (
SELECT
bikeid,
ST_Distance(ST_GeogPoint(s.longitude,
s.latitude),
ST_GeogPoint(e.longitude,
e.latitude)) AS distance
FROM
bigquery-public-data.new_york_citibike.citibike_trips
,
bigquery-public-data.new_york_citibike.citibike_stations
as s,
bigquery-public-data.new_york_citibike.citibike_stations
as e
WHERE
start_station_id = s.station_id
AND end_station_id = e.station_id )
SELECT
bikeid,
SUM(distance)/1000 AS total_distance
FROM
trip_distance
GROUP BY
bikeid
ORDER BY
total_distance DESC
LIMIT
5
ST_LENGTH ST_LENGTH(geography_expression[, use_spheroid])
Description
Returns the total length in meters of the lines in the input GEOGRAPHY.
ST_MAXDISTANCE ST_MAXDISTANCE(geography_1, geography_2[, use_spheroid])
Returns the longest distance in meters between two non-empty GEOGRAPHYs; that is, the distance between two vertices where the first vertex is in the first GEOGRAPHY, and the second vertex is in the second GEOGRAPHY