The sql2gee Package

Submodules

sql2gee.sql2gee module

class sql2gee.sql2gee.SQL2GEE(sql, geojson=None, flags=None)[source]

Bases: object

Takes an SQL-like query and relates it to Google’s Earth Engine syntax (specifically the Python 2.7 GEE API). Designed to perform operations on two types of geo-objects, Polygons (Feature Collections) or Rasters (Images). For the rasters there are only a specific number of valid operations (retrieve metadata, histogram data, or get summary statistics). We use postgis-like functions as the syntax to do this, and check to see if this is given in the sql string to detect the user intention.

If geojson data is provided, we will assume that a user intends for us to subset an image, by these data.

apply_group(fc, group)[source]

Given a fc (feature_collection) object and group operation, return a new fc object, extended by a method of the feature grouping operation.

extract_postgis_arguments(argument_string, list_of_expected)[source]

Expects a string list of arguments passed to postgis function, and an ordered list of keys needed In this way, we should be able to handle any postgis argument arrangements: value_string, ordered keyword list: [‘raster’, ‘band_id’, ‘n_bins’])

fields

A list of all fields in SQL query. If the FROM keyword is encountered the list is immediately returned.

static generate_in(left, comp, right, exist_not)[source]
static generate_is(left, comp, right)[source]
generate_like(left, comp, right, exist_not)[source]
geojson_from_STGeomFromGeoJSON()[source]

Extract geojson dictionary, and crs code from a complex SQL command using Regex

group_functions

Returns the group function with column names specified in the query: e.g. from sql input of ‘select count(pepe) from mytable’, a dictionary of {‘function’: ‘COUNT’, ‘value’: ‘pepe’} should be returned by self.group_functions

histogram

Retrieve ST_HISTOGRAM()-like info. This will return a dictionary object with bands as keys, and for each band a nested list of (2xn) for bin and frequency. If the user wants us to use the optimum bin number, they can pass n-bins ‘auto’ instead of an integer.

limit

If LIMIT keyword set, this returns an integer to limit the maximum return from a feature collection query

parse_comparison(comparison)[source]
parse_conditions(tokens)[source]
parse_list(tokens)[source]
static remove_quotes(input_str)[source]

Checks the first and last characters of an input_str to see if they are quotation marks [‘ or “], if so the function will strip them and return the string. :type input_str: str

response

Execute the GEE object in GEE Server. This is the function that, when called, actually sends the SQL request (which was converted to GEE-speak) to Google’s servers for execution and returns the result.

st_bandmetadata

Return only metadata for a specifically requested band, like postgis function

st_metadata

The image property Metadata dictionary returned from Earth Engine.

st_valuecount

Return only metadata for a specifically requested band, like postgis function

summary_stats

Return a dictionary object of summary stats like the postgis function ST_SUMMARYSTATS().

target_data

Set target_data property using sql tokens, assuming it is the first token of type Identifier after the ‘FROM’ keyword also of type Identifier. If not found, raise an Exception.

static token_to_dictionary(token_list)[source]

Receives a token e.g.(‘count(pepe)’) and converts it into a dict with key:values for function and value .

where

Returns filter object obtained from where of the query in GEE format