Code Monkey home page Code Monkey logo

qgis-earthengine-examples's Introduction

qgis-earthengine-examples

License: MIT

A collection of 290+ Python examples for using Google Earth Engine in QGIS

Contact: Qiusheng Wu (https://wetlands.io)

1. Description

This repository is a collection of 290+ Python examples for the Google Earth Engine plugin for QGIS. I developed these Python examples by converting all the JavaScript examples (except those not yet supported by plugin) from the Google Earth Engine API Documentation. Additionally, some examples were adapted from Google Earth Engine plugin and the Earth Engine API examples. Kudos to GEE Community for developing this amazing Google Earth Engine plugin for QGIS.

2. Usage

  • Step 1: Sign up for Google Earth Engine.
  • Step 2: Install QGIS.
  • Step 3: Install the Google Earth Engine Plugin for QGIS and authenticate Google Earth Engine.
  • Step 4: Git clone or download this repository.
  • Step 5: Open the Python console in QGIS and load any downloaded Python script into the QGIS Python Editor.
  • Step 6: Click the Run script button on the Python Editor to execute the script.
  • Step 7: Zoom in/out the QGIS Canvas to inspect the results.

3. Add QGIS Basemaps

  • Open the Python console in QGIS and load the Python script (Basemaps/qgis_basemaps.py) into the QGIS Python Editor.
  • Click the Run script button on the Python Editor to execute the script. This will add many basesmaps as XYZ tiles to QGIS. Select and double click any basemap under XYZ Ttiles to be added to QGIS Canvas. See the screenshot below.
  • Alternatively, you can install the QGIS QuickMapServices plugin. After installing the plugin, go to QGIS -- Web --QuickMapServices -- Settings -- More services -- Get contributed pack -- Save.

QGIS Basemaps

4. Earth Engine QGIS Plugin Demo

qgis-gee-demo

5. Earth Engine and Folium Interactive Mapping

If you do not have QGIS installed on your computer, you can try Earth Engine API and the folium library for interactive mapping. A Jupyter notebook example can be found here.

6. QGIS Examples

The Table of Contents below mimics the structure of the Google Earth Engine API Documentation. I strongly encourage you to check out the API Documentation if you need an in-depth explanation of each Python example. Please note that the list below does not include all the Python examples contained in this repository. You are welcome to explore the repository and find more examples to suit your needs.

qgis-earthengine-examples's People

Contributors

cclauss avatar csaybar avatar giswqs avatar jsparedes avatar lauzadis avatar xaviercll avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qgis-earthengine-examples's Issues

Import shapefile/FilterBound

Hi Dr. Wu,

I'm wondering about if it's possible to use a shapefile polygon loaded in Qgis in order to FilterBound a imageCollection?

Thank you
Geovane

missing example - Geometry Visualization and Information

In the https://developers.google.com/earth-engine/guides/geometry_visualization_info page there are two example codes. The first example can be found within your repository in https://github.com/giswqs/qgis-earthengine-examples/blob/master/Visualization/visualizing_geometries.py (Geometry, Feature, FeatureCollection / Geodesic vs. Planar Geometries and Geometry, Feature, FeatureCollection / Geometry Visualization and Information in the README.md), but the second example is missing. If you have time, could you please transform it to Python and upload to the example codes? Thanks a lot!

QGIS cannot install Google Earth Engine Plugins

Dear Wu, When I tried to install GEE plugin in the QGIS, an error showed:
Couldn't load plugin 'ee_plugin' due to an error when calling its classFactory() method

I know this is the problem when conducting earthengine authenticate, the authenticate page where I can enter my username and passport did not appear.
I am in Beijing, maybe it is the web issue.
Do you have some ideas.
Thank you very much!

Here is the detail of the error:
TypeError: get_authorization_url() missing 1 required positional argument: 'code_challenge'
Traceback (most recent call last):
File "C:\Users\nanshany\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\ee_plugin\extlibs_windows\ee\data.py", line 230, in get_persistent_credentials
tokens = json.load(open(oauth.get_credentials_path()))
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\nanshany/.config/earthengine/credentials'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/nanshany/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ee_plugin\ee_auth.py", line 19, in init
ee.Initialize()
File "C:\Users\nanshany\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\ee_plugin\extlibs_windows\ee_init_.py", line 114, in Initialize
credentials = data.get_persistent_credentials()
File "C:\Users\nanshany\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\ee_plugin\extlibs_windows\ee\data.py", line 241, in get_persistent_credentials
'Please authorize access to your Earth Engine account by '
ee.ee_exception.EEException: Please authorize access to your Earth Engine account by running

earthengine authenticate

in your command line, and then retry.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/PROGRA1/QGIS31.10/apps/qgis-ltr/./python\qgis\utils.py", line 334, in startPlugin
plugins[packageName] = package.classFactory(iface)
File "C:/Users/nanshany/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ee_plugin_init
.py", line 25, in classFactory
from .ee_plugin import GoogleEarthEnginePlugin
File "C:/PROGRA1/QGIS31.10/apps/qgis-ltr/./python\qgis\utils.py", line 792, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "C:/Users/nanshany/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ee_plugin\ee_plugin.py", line 26, in
ee_plugin.ee_auth.init()
File "C:/Users/nanshany/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ee_plugin\ee_auth.py", line 21, in init
authenticate()
File "C:/Users/nanshany/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ee_plugin\ee_auth.py", line 32, in authenticate
auth_url = ee.oauth.get_authorization_url()
TypeError: get_authorization_url() missing 1 required positional argument: 'code_challenge'

Python version: 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)]
QGIS version: 3.10.10-A Coruña A Coruña, 8b051b9a43

I know this is the problem when conducting earthengine authenticate, the authenticate page where I can enter my username and passport did not appear.

I am in Beijing, maybe it is the web issue.

Do you have some ideas.

Thank you very much!

How to export gee table using qgis+python?

ls_collection = dates_modis.map(reduceLandsatNDVI)
dates_landsat = dates_modis.map(extract_landsat_date)
dates_landsat = dates_landsat.toList(20)
print(dates_landsat.get(0))

mytask = ee.batch.Export.table.toDrive(collection=dates_landsat, folder='Qinghai_Lake_Bound', description=csv_title, fileFormat='CSV')

ee.batch.data.startProcessing(mytask.id, mytask.config)

There are errors, could you help me? Many thanks!

Getting an error while using "training = input.addBands(modis).sample({ 'numPixels': 5000, 'seed': 0 })"

import ee
import geemap
ee.Authenticate()

Map = geemap.Map()

Define a region of interest as a point. Change the coordinates

to get a classification of any place where there is imagery.

roi = ee.Geometry.Point(-122.3942, 37.7295)

Load Landsat 5 input imagery.

landsat = ee.Image(ee.ImageCollection('LANDSAT/LT05/C01/T1_TOA')
.filterDate('2011-01-01', '2011-12-31')
.filterBounds(roi)
.sort('CLOUD_COVER')
.first())

Compute cloud score.

cloudScore = ee.Algorithms.Landsat.simpleCloudScore(landsat).select('cloud')

Mask the input for clouds. Compute the min of the input mask to mask

pixels where any band is masked. Combine that with the cloud mask.

input = landsat.updateMask(landsat.mask().reduce('min').And(cloudScore.lte(50)))

Use MODIS land cover, IGBP classification, for training.

modis = ee.Image('MODIS/051/MCD12Q1/2011_01_01')
.select('Land_Cover_Type_1')

Sample the input imagery to get a FeatureCollection of training data.

training = input.addBands(modis).sample({
'numPixels': 5000,
'seed': 0
})

ERROR : ---------------------------------------------------------------------------
EEException Traceback (most recent call last)
in
1 # Sample the input imagery to get a FeatureCollection of training data.
----> 2 training = input.addBands(modis).sample({
3 'numPixels': 5000,
4 'seed': 0
5 })

~\anaconda3\envs\Google_earth_engine\lib\site-packages\ee\apifunction.py in (*args, **kwargs)
203 def MakeBoundFunction(func):
204 # We need the lambda to capture "func" from the enclosing scope.
--> 205 return lambda *args, **kwargs: func.call(*args, **kwargs) # pylint: disable=unnecessary-lambda
206 bound_function = MakeBoundFunction(api_func)
207

~\anaconda3\envs\Google_earth_engine\lib\site-packages\ee\function.py in call(self, *args, **kwargs)
65 to that type.
66 """
---> 67 return self.apply(self.nameArgs(args, kwargs))
68
69 def apply(self, named_args):

~\anaconda3\envs\Google_earth_engine\lib\site-packages\ee\function.py in apply(self, named_args)
78 to that type.
79 """
---> 80 result = computedobject.ComputedObject(self, self.promoteArgs(named_args))
81 return Function._promoter(result, self.getReturnType())
82

~\anaconda3\envs\Google_earth_engine\lib\site-packages\ee\function.py in promoteArgs(self, args)
105 name = spec['name']
106 if name in args:
--> 107 promoted_args[name] = Function._promoter(args[name], spec['type'])
108 elif not spec.get('optional'):
109 raise ee_exception.EEException(

~\anaconda3\envs\Google_earth_engine\lib\site-packages\ee_init_.py in Promote(arg, klass)
222 return ApiFunction.call
('Collection.geometry', arg)
223 else:
--> 224 return Geometry(arg)
225 elif klass in ('FeatureCollection', 'Collection'):
226 # For now Collection is synonymous with FeatureCollection.

~\anaconda3\envs\Google_earth_engine\lib\site-packages\ee\computedobject.py in call(cls, *args, **kwargs)
30 return args[0]
31 else:
---> 32 return type.call(cls, *args, **kwargs)
33
34

~\anaconda3\envs\Google_earth_engine\lib\site-packages\ee\geometry.py in init(self, geo_json, opt_proj, opt_geodesic, opt_evenOdd)
82
83 if not Geometry._isValidGeometry(geo_json):
---> 84 raise ee_exception.EEException('Invalid GeoJSON geometry.')
85
86 super(Geometry, self).init(None, None)

EEException: Invalid GeoJSON geometry.

How to convert GEE JavaScript to Python?

I have many JavaScript codes in gee, now, I work in Qgis using Python, I have convert_js_to_python.py code, But I do not know how to convert js to python, could you give to one example to help me? many thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.