-
Notifications
You must be signed in to change notification settings - Fork 266
/
from_polygons.py
31 lines (25 loc) · 930 Bytes
/
from_polygons.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python
"""Create and render a feature collection from polygons."""
import ee
from ee_plugin import Map
Map.setCenter(-107, 41, 6)
fc = ee.FeatureCollection([
ee.Feature(
ee.Geometry.Polygon(
[[-109.05, 41], [-109.05, 37], [-102.05, 37], [-102.05, 41]]),
{'name': 'Colorado', 'fill': 1}),
ee.Feature(
ee.Geometry.Polygon(
[[-114.05, 37.0], [-109.05, 37.0], [-109.05, 41.0],
[-111.05, 41.0], [-111.05, 42.0], [-114.05, 42.0]]),
{'name': 'Utah', 'fill': 2})
])
# Fill, then outline the polygons into a blank image.
image1 = ee.Image(0).mask(0).toByte()
image2 = image1.paint(fc, 'fill') # Get color from property named 'fill'
image3 = image2.paint(fc, 3, 5) # Outline using color 3, width 5.
Map.addLayer(image3, {
'palette': ['000000', 'FF0000', '00FF00', '0000FF'],
'max': 3,
'opacity': 0.5
}, "Colorado & Utah")