Skip to content

Commit

Permalink
Convert Geometry.MultiPolygon API code snippets from JS to Py
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 563244304
  • Loading branch information
jdbcode authored and copybara-github committed Oct 6, 2023
1 parent a3a734c commit 5efadf4
Show file tree
Hide file tree
Showing 30 changed files with 1,296 additions and 0 deletions.
40 changes: 40 additions & 0 deletions samples/python/apidocs/ee_geometry_multipolygon_area.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2023 The Google Earth Engine Community Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START earthengine__apidocs__ee_geometry_multipolygon_area]
# Define a MultiPolygon object.
multipolygon = ee.Geometry.MultiPolygon([
[[
[-122.092, 37.424],
[-122.086, 37.418],
[-122.079, 37.425],
[-122.085, 37.423],
]],
[[[-122.081, 37.417], [-122.086, 37.421], [-122.089, 37.416]]],
])

# Apply the area method to the MultiPolygon object.
multipolygon_area = multipolygon.area(maxError=1)

# Print the result.
display('multipolygon.area(...) =', multipolygon_area)

# Display relevant geometries on the map.
m = geemap.Map()
m.set_center(-122.085, 37.422, 15)
m.add_ee_layer(
multipolygon, {'color': 'black'}, 'Geometry [black]: multipolygon'
)
m
# [END earthengine__apidocs__ee_geometry_multipolygon_area]
43 changes: 43 additions & 0 deletions samples/python/apidocs/ee_geometry_multipolygon_bounds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2023 The Google Earth Engine Community Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START earthengine__apidocs__ee_geometry_multipolygon_bounds]
# Define a MultiPolygon object.
multipolygon = ee.Geometry.MultiPolygon([
[[
[-122.092, 37.424],
[-122.086, 37.418],
[-122.079, 37.425],
[-122.085, 37.423],
]],
[[[-122.081, 37.417], [-122.086, 37.421], [-122.089, 37.416]]],
])

# Apply the bounds method to the MultiPolygon object.
multipolygon_bounds = multipolygon.bounds()

# Print the result.
display('multipolygon.bounds(...) =', multipolygon_bounds)

# Display relevant geometries on the map.
m = geemap.Map()
m.set_center(-122.085, 37.422, 15)
m.add_ee_layer(
multipolygon, {'color': 'black'}, 'Geometry [black]: multipolygon'
)
m.add_ee_layer(
multipolygon_bounds, {'color': 'red'}, 'Result [red]: multipolygon.bounds'
)
m
# [END earthengine__apidocs__ee_geometry_multipolygon_bounds]
43 changes: 43 additions & 0 deletions samples/python/apidocs/ee_geometry_multipolygon_buffer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2023 The Google Earth Engine Community Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START earthengine__apidocs__ee_geometry_multipolygon_buffer]
# Define a MultiPolygon object.
multipolygon = ee.Geometry.MultiPolygon([
[[
[-122.092, 37.424],
[-122.086, 37.418],
[-122.079, 37.425],
[-122.085, 37.423],
]],
[[[-122.081, 37.417], [-122.086, 37.421], [-122.089, 37.416]]],
])

# Apply the buffer method to the MultiPolygon object.
multipolygon_buffer = multipolygon.buffer(distance=100)

# Print the result.
display('multipolygon.buffer(...) =', multipolygon_buffer)

# Display relevant geometries on the map.
m = geemap.Map()
m.set_center(-122.085, 37.422, 15)
m.add_ee_layer(
multipolygon, {'color': 'black'}, 'Geometry [black]: multipolygon'
)
m.add_ee_layer(
multipolygon_buffer, {'color': 'red'}, 'Result [red]: multipolygon.buffer'
)
m
# [END earthengine__apidocs__ee_geometry_multipolygon_buffer]
45 changes: 45 additions & 0 deletions samples/python/apidocs/ee_geometry_multipolygon_centroid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2023 The Google Earth Engine Community Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START earthengine__apidocs__ee_geometry_multipolygon_centroid]
# Define a MultiPolygon object.
multipolygon = ee.Geometry.MultiPolygon([
[[
[-122.092, 37.424],
[-122.086, 37.418],
[-122.079, 37.425],
[-122.085, 37.423],
]],
[[[-122.081, 37.417], [-122.086, 37.421], [-122.089, 37.416]]],
])

# Apply the centroid method to the MultiPolygon object.
multipolygon_centroid = multipolygon.centroid(maxError=1)

# Print the result.
display('multipolygon.centroid(...) =', multipolygon_centroid)

# Display relevant geometries on the map.
m = geemap.Map()
m.set_center(-122.085, 37.422, 15)
m.add_ee_layer(
multipolygon, {'color': 'black'}, 'Geometry [black]: multipolygon'
)
m.add_ee_layer(
multipolygon_centroid,
{'color': 'red'},
'Result [red]: multipolygon.centroid',
)
m
# [END earthengine__apidocs__ee_geometry_multipolygon_centroid]
46 changes: 46 additions & 0 deletions samples/python/apidocs/ee_geometry_multipolygon_containedin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2023 The Google Earth Engine Community Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START earthengine__apidocs__ee_geometry_multipolygon_containedin]
# Define a MultiPolygon object.
multipolygon = ee.Geometry.MultiPolygon([
[[
[-122.092, 37.424],
[-122.086, 37.418],
[-122.079, 37.425],
[-122.085, 37.423],
]],
[[[-122.081, 37.417], [-122.086, 37.421], [-122.089, 37.416]]],
])

# Define other inputs.
input_geom = ee.Geometry.BBox(-122.085, 37.415, -122.075, 37.425)

# Apply the containedIn method to the MultiPolygon object.
multipolygon_contained_in = multipolygon.containedIn(
right=input_geom, maxError=1
)

# Print the result.
display('multipolygon.containedIn(...) =', multipolygon_contained_in)

# Display relevant geometries on the map.
m = geemap.Map()
m.set_center(-122.085, 37.422, 15)
m.add_ee_layer(
multipolygon, {'color': 'black'}, 'Geometry [black]: multipolygon'
)
m.add_ee_layer(input_geom, {'color': 'blue'}, 'Parameter [blue]: input_geom')
m
# [END earthengine__apidocs__ee_geometry_multipolygon_containedin]
44 changes: 44 additions & 0 deletions samples/python/apidocs/ee_geometry_multipolygon_contains.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2023 The Google Earth Engine Community Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START earthengine__apidocs__ee_geometry_multipolygon_contains]
# Define a MultiPolygon object.
multipolygon = ee.Geometry.MultiPolygon([
[[
[-122.092, 37.424],
[-122.086, 37.418],
[-122.079, 37.425],
[-122.085, 37.423],
]],
[[[-122.081, 37.417], [-122.086, 37.421], [-122.089, 37.416]]],
])

# Define other inputs.
input_geom = ee.Geometry.BBox(-122.085, 37.415, -122.075, 37.425)

# Apply the contains method to the MultiPolygon object.
multipolygon_contains = multipolygon.contains(right=input_geom, maxError=1)

# Print the result.
display('multipolygon.contains(...) =', multipolygon_contains)

# Display relevant geometries on the map.
m = geemap.Map()
m.set_center(-122.085, 37.422, 15)
m.add_ee_layer(
multipolygon, {'color': 'black'}, 'Geometry [black]: multipolygon'
)
m.add_ee_layer(input_geom, {'color': 'blue'}, 'Parameter [blue]: input_geom')
m
# [END earthengine__apidocs__ee_geometry_multipolygon_contains]
45 changes: 45 additions & 0 deletions samples/python/apidocs/ee_geometry_multipolygon_convexhull.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2023 The Google Earth Engine Community Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START earthengine__apidocs__ee_geometry_multipolygon_convexhull]
# Define a MultiPolygon object.
multipolygon = ee.Geometry.MultiPolygon([
[[
[-122.092, 37.424],
[-122.086, 37.418],
[-122.079, 37.425],
[-122.085, 37.423],
]],
[[[-122.081, 37.417], [-122.086, 37.421], [-122.089, 37.416]]],
])

# Apply the convexHull method to the MultiPolygon object.
multipolygon_convex_hull = multipolygon.convexHull(maxError=1)

# Print the result.
display('multipolygon.convexHull(...) =', multipolygon_convex_hull)

# Display relevant geometries on the map.
m = geemap.Map()
m.set_center(-122.085, 37.422, 15)
m.add_ee_layer(
multipolygon, {'color': 'black'}, 'Geometry [black]: multipolygon'
)
m.add_ee_layer(
multipolygon_convex_hull,
{'color': 'red'},
'Result [red]: multipolygon.convexHull',
)
m
# [END earthengine__apidocs__ee_geometry_multipolygon_convexhull]
40 changes: 40 additions & 0 deletions samples/python/apidocs/ee_geometry_multipolygon_coordinates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2023 The Google Earth Engine Community Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START earthengine__apidocs__ee_geometry_multipolygon_coordinates]
# Define a MultiPolygon object.
multipolygon = ee.Geometry.MultiPolygon([
[[
[-122.092, 37.424],
[-122.086, 37.418],
[-122.079, 37.425],
[-122.085, 37.423],
]],
[[[-122.081, 37.417], [-122.086, 37.421], [-122.089, 37.416]]],
])

# Apply the coordinates method to the MultiPolygon object.
multipolygon_coordinates = multipolygon.coordinates()

# Print the result.
display('multipolygon.coordinates(...) =', multipolygon_coordinates)

# Display relevant geometries on the map.
m = geemap.Map()
m.set_center(-122.085, 37.422, 15)
m.add_ee_layer(
multipolygon, {'color': 'black'}, 'Geometry [black]: multipolygon'
)
m
# [END earthengine__apidocs__ee_geometry_multipolygon_coordinates]
Loading

0 comments on commit 5efadf4

Please sign in to comment.