https://github.com/vizzuality/sql2gee
Library to parse SQL-like queries to Google's Earth Engine syntax
https://github.com/vizzuality/sql2gee
google-earth-engine python sql
Last synced: 6 months ago
JSON representation
Library to parse SQL-like queries to Google's Earth Engine syntax
- Host: GitHub
- URL: https://github.com/vizzuality/sql2gee
- Owner: Vizzuality
- License: mit
- Created: 2016-12-30T11:17:10.000Z (over 9 years ago)
- Default Branch: develop
- Last Pushed: 2020-12-15T15:54:12.000Z (over 5 years ago)
- Last Synced: 2024-08-09T04:38:40.866Z (over 1 year ago)
- Topics: google-earth-engine, python, sql
- Language: Python
- Homepage: https://vizzuality.github.io/sql2gee/
- Size: 2.13 MB
- Stars: 11
- Watchers: 13
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/Vizzuality/sql2gee/blob/develop/LICENSE)
[](https://travis-ci.org/Vizzuality/sql2gee)
[](https://codecov.io/gh/Vizzuality/sql2gee)
# sql2gee
[Read the docs](https://vizzuality.github.io/sql2gee/)
A Python 3 library to make SQL-like queries to Google's Earth Engine Main asset data types (Feature Collections, and Fusion Tables, Image Collections and Images). It is able to perform
Postgis-like operations, including returning summary statistics, and histogram data and subsetting by geojson vector data.
### Example usage
1. Import the SQL2GEE class from the sql2gee library in python.
```python
import ee
from sql2gee import SQL2GEE
from utils.jsonSql import JsonSql
ee.Initialize()
sql = "SELECT ST_HISTOGRAM(raster, lossyear, 15, true) FROM 'UMD/hansen/global_forest_change_2015'"
query = SQL2GEE(JsonSql(sql).to_json())
print("Result of my query: ", query.response())
```
```
Result of my query: [{'st_histogram': {'lossyear': [[0.0, 6929647.301960737], [1.0, 0.0], [2.0, 3.0], [3.0, 1.0], [4.0, 13.0], [5.0, 5.0], [6.0, 5.250980392156863], [7.0, 1.0], [8.0, 5.0], [9.0, 9.0], [10.0, 12.0], [11.0, 3.0], [12.0, 6.0], [13.0, 1.0], [14.0, 16.0]]}}]
```
### Execute tests
Test run queries on GEE servers, so you need a GCP service account with access to GEE. Specifically, you need:
- The service account name (a string formatted like `@.iam.gserviceaccount.com`) that has permissions to access GEE.
- A JSON access key for that account.
The account name needs to be set as the `EE_ACCOUNT` environment variable.
The JSON account key needs to be saved as a `privatekey.json` file at the root of the project.
Once both values are set, you can run the tests using tox:
```bash
tox
```
## Development
### Notes
### Want to Contribute?
Submit a pull request and we will review it.