forked from giswqs/qgis-earthengine-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
172 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# GitHub URL: https://github.com/giswqs/qgis-earthengine-examples/tree/master/FeatureCollection/clipping.py | ||
|
||
import ee | ||
from ee_plugin import Map | ||
|
||
roi = ee.Geometry.Polygon( | ||
[[[-73.99891354682285, 40.74560250077625], | ||
[-73.99891354682285, 40.74053023068626], | ||
[-73.98749806525547, 40.74053023068626], | ||
[-73.98749806525547, 40.74560250077625]]]) | ||
|
||
|
||
fc = ee.FeatureCollection('TIGER/2016/Roads').filterBounds(roi) | ||
|
||
clipped = fc.map(lambda f: f.intersection(roi)) | ||
|
||
Map.centerObject(ee.FeatureCollection(roi), 17) | ||
Map.addLayer(ee.Image().paint(roi, 0, 2), {'palette': 'yellow'}, 'ROI') | ||
# Map.setCenter(-73.9596, 40.7688, 12) | ||
Map.addLayer(ee.Image().paint(clipped, 0, 3), {'palette': 'red'}, 'clipped') | ||
Map.addLayer(fc, {}, 'Census roads', False) | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# GitHub URL: https://github.com/giswqs/qgis-earthengine-examples/tree/master/Image/band_stats.py | ||
|
||
import ee | ||
from ee_plugin import Map | ||
|
||
|
||
# get highest value | ||
def maxValue(img, scale=30): | ||
max_value = img.reduceRegion(**{ | ||
'reducer': ee.Reducer.max(), | ||
'geometry': img.geometry(), | ||
'scale': scale, | ||
'maxPixels': 1e9 | ||
}) | ||
return max_value | ||
|
||
|
||
# get lowest value | ||
def minValue(img, scale=30): | ||
min_value = img.reduceRegion(**{ | ||
'reducer': ee.Reducer.min(), | ||
'geometry': img.geometry(), | ||
'scale': scale, | ||
'maxPixels': 1e9 | ||
}) | ||
return min_value | ||
|
||
|
||
# get mean value | ||
def meanValue(img, scale=30): | ||
mean_value = img.reduceRegion(**{ | ||
'reducer': ee.Reducer.mean(), | ||
'geometry': img.geometry(), | ||
'scale': scale, | ||
'maxPixels': 1e9 | ||
}) | ||
return mean_value | ||
|
||
|
||
# get standard deviation | ||
def stdValue(img, scale=30): | ||
std_value = img.reduceRegion(**{ | ||
'reducer': ee.Reducer.stdDev(), | ||
'geometry': img.geometry(), | ||
'scale': scale, | ||
'maxPixels': 1e9 | ||
}) | ||
return std_value | ||
|
||
|
||
dataset = ee.Image('USGS/NED') | ||
dem = dataset.select('elevation') | ||
# dem = ee.Image('srtm90_v4') | ||
vis_params = {'min': 0, 'max': 3000} | ||
Map.addLayer(dem, vis_params, 'NED', False) | ||
|
||
roi = ee.Geometry.Polygon( | ||
[[[-120.18204899532924, 38.53481618819663], | ||
[-120.18204899532924, 36.54889033300136], | ||
[-116.75431462032924, 36.54889033300136], | ||
[-116.75431462032924, 38.53481618819663]]]) | ||
|
||
image = dem.clip(roi) | ||
Map.centerObject(image, 9) | ||
Map.addLayer(image, vis_params, 'DEM') | ||
|
||
scale = image.projection().nominalScale() | ||
print("Resolution: ", scale.getInfo()) | ||
|
||
scale = 30 | ||
|
||
print("Minimum value: ", minValue(image, scale).get('elevation').getInfo()) | ||
print("Maximum value: ", maxValue(image, scale).get('elevation').getInfo()) | ||
print("Average value: ", meanValue(image, scale).get('elevation').getInfo()) | ||
print("Standard deviation: ", stdValue(image, scale).get('elevation').getInfo()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# GitHub URL: https://github.com/giswqs/qgis-earthengine-examples/tree/master/Image/image_stats_by_band.py | ||
|
||
import ee | ||
from ee_plugin import Map | ||
|
||
image = ee.Image('USDA/NAIP/DOQQ/m_3712213_sw_10_1_20140613') | ||
Map.setCenter(-122.466123, 37.769833, 17) | ||
Map.addLayer(image, {'bands': ['N', 'R','G']}, 'NAIP') | ||
|
||
geometry = image.geometry() | ||
|
||
means = image.reduceRegions(geometry, ee.Reducer.mean().forEachBand(image), 10) | ||
|
||
print(means.getInfo()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# GitHub URL: https://github.com/giswqs/qgis-earthengine-examples/tree/master/Visualization/nwi_wetlands_symbology.py | ||
|
||
import ee | ||
from ee_plugin import Map | ||
|
||
# NWI legend: https://www.fws.gov/wetlands/Data/Mapper-Wetlands-Legend.html | ||
def nwi_add_color(fc): | ||
emergent = ee.FeatureCollection( | ||
fc.filter(ee.Filter.eq('WETLAND_TY', 'Freshwater Emergent Wetland'))) | ||
emergent = emergent.map(lambda f: f.set( | ||
'R', 127).set('G', 195).set('B', 28)) | ||
# print(emergent.first()) | ||
|
||
forested = fc.filter(ee.Filter.eq( | ||
'WETLAND_TY', 'Freshwater Forested/Shrub Wetland')) | ||
forested = forested.map(lambda f: f.set('R', 0).set('G', 136).set('B', 55)) | ||
|
||
pond = fc.filter(ee.Filter.eq('WETLAND_TY', 'Freshwater Pond')) | ||
pond = pond.map(lambda f: f.set('R', 104).set('G', 140).set('B', 192)) | ||
|
||
lake = fc.filter(ee.Filter.eq('WETLAND_TY', 'Lake')) | ||
lake = lake.map(lambda f: f.set('R', 19).set('G', 0).set('B', 124)) | ||
|
||
riverine = fc.filter(ee.Filter.eq('WETLAND_TY', 'Riverine')) | ||
riverine = riverine.map(lambda f: f.set( | ||
'R', 1).set('G', 144).set('B', 191)) | ||
|
||
fc = ee.FeatureCollection(emergent.merge( | ||
forested).merge(pond).merge(lake).merge(riverine)) | ||
|
||
base = ee.Image(0).mask(0).toInt8() | ||
img = base.paint(fc, 'R') \ | ||
.addBands(base.paint(fc, 'G') | ||
.addBands(base.paint(fc, 'B'))) | ||
return img | ||
|
||
|
||
fromFT = ee.FeatureCollection("users/wqs/Pipestem/Pipestem_HUC10") | ||
Map.addLayer(ee.Image().paint(fromFT, 0, 2), {}, 'Watershed') | ||
huc8_id = '10160002' | ||
nwi_asset_path = 'users/wqs/NWI-HU8/HU8_' + huc8_id + '_Wetlands' # NWI wetlands for the clicked watershed | ||
clicked_nwi_huc = ee.FeatureCollection(nwi_asset_path) | ||
nwi_color = nwi_add_color(clicked_nwi_huc) | ||
Map.centerObject(clicked_nwi_huc, 10) | ||
Map.addLayer(nwi_color, {'gamma': 0.3, 'opacity': 0.7}, 'NWI Wetlands Color') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# GitHub URL: https://github.com/giswqs/qgis-earthengine-examples/tree/master/Visualization/random_color_visualizer.py | ||
|
||
import ee | ||
from ee_plugin import Map | ||
|
||
dataset = ee.Image('USGS/NLCD/NLCD2016') | ||
landcover = ee.Image(dataset.select('landcover')) | ||
|
||
Map.setCenter(-95, 38, 5) | ||
Map.addLayer(landcover.randomVisualizer(), {}, 'Landcover') |