Skip to content

Commit

Permalink
Convert Geometry.BBox API code snippets from JS to Py
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 563240005
  • Loading branch information
jdbcode authored and copybara-github committed Oct 6, 2023
1 parent f577013 commit fbefc1d
Show file tree
Hide file tree
Showing 30 changed files with 964 additions and 0 deletions.
30 changes: 30 additions & 0 deletions samples/python/apidocs/ee_geometry_bbox_area.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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_bbox_area]
# Define a BBox object.
bbox = ee.Geometry.BBox(-122.09, 37.42, -122.08, 37.43)

# Apply the area method to the BBox object.
bbox_area = bbox.area(maxError=1)

# Print the result.
display('bbox.area(...) =', bbox_area)

# Display relevant geometries on the map.
m = geemap.Map()
m.set_center(-122.085, 37.422, 15)
m.add_ee_layer(bbox, {'color': 'black'}, 'Geometry [black]: bbox')
m
# [END earthengine__apidocs__ee_geometry_bbox_area]
31 changes: 31 additions & 0 deletions samples/python/apidocs/ee_geometry_bbox_bounds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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_bbox_bounds]
# Define a BBox object.
bbox = ee.Geometry.BBox(-122.09, 37.42, -122.08, 37.43)

# Apply the bounds method to the BBox object.
bbox_bounds = bbox.bounds()

# Print the result.
display('bbox.bounds(...) =', bbox_bounds)

# Display relevant geometries on the map.
m = geemap.Map()
m.set_center(-122.085, 37.422, 15)
m.add_ee_layer(bbox, {'color': 'black'}, 'Geometry [black]: bbox')
m.add_ee_layer(bbox_bounds, {'color': 'red'}, 'Result [red]: bbox.bounds')
m
# [END earthengine__apidocs__ee_geometry_bbox_bounds]
31 changes: 31 additions & 0 deletions samples/python/apidocs/ee_geometry_bbox_buffer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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_bbox_buffer]
# Define a BBox object.
bbox = ee.Geometry.BBox(-122.09, 37.42, -122.08, 37.43)

# Apply the buffer method to the BBox object.
bbox_buffer = bbox.buffer(distance=100)

# Print the result.
display('bbox.buffer(...) =', bbox_buffer)

# Display relevant geometries on the map.
m = geemap.Map()
m.set_center(-122.085, 37.422, 15)
m.add_ee_layer(bbox, {'color': 'black'}, 'Geometry [black]: bbox')
m.add_ee_layer(bbox_buffer, {'color': 'red'}, 'Result [red]: bbox.buffer')
m
# [END earthengine__apidocs__ee_geometry_bbox_buffer]
31 changes: 31 additions & 0 deletions samples/python/apidocs/ee_geometry_bbox_centroid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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_bbox_centroid]
# Define a BBox object.
bbox = ee.Geometry.BBox(-122.09, 37.42, -122.08, 37.43)

# Apply the centroid method to the BBox object.
bbox_centroid = bbox.centroid(maxError=1)

# Print the result.
display('bbox.centroid(...) =', bbox_centroid)

# Display relevant geometries on the map.
m = geemap.Map()
m.set_center(-122.085, 37.422, 15)
m.add_ee_layer(bbox, {'color': 'black'}, 'Geometry [black]: bbox')
m.add_ee_layer(bbox_centroid, {'color': 'red'}, 'Result [red]: bbox.centroid')
m
# [END earthengine__apidocs__ee_geometry_bbox_centroid]
34 changes: 34 additions & 0 deletions samples/python/apidocs/ee_geometry_bbox_containedin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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_bbox_containedin]
# Define a BBox object.
bbox = ee.Geometry.BBox(-122.09, 37.42, -122.08, 37.43)

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

# Apply the containedIn method to the BBox object.
bbox_contained_in = bbox.containedIn(right=input_geom, maxError=1)

# Print the result.
display('bbox.containedIn(...) =', bbox_contained_in)

# Display relevant geometries on the map.
m = geemap.Map()
m.set_center(-122.085, 37.422, 15)
m.add_ee_layer(bbox, {'color': 'black'}, 'Geometry [black]: bbox')
m.add_ee_layer(input_geom, {'color': 'blue'}, 'Parameter [blue]: input_geom')
m
# [END earthengine__apidocs__ee_geometry_bbox_containedin]
34 changes: 34 additions & 0 deletions samples/python/apidocs/ee_geometry_bbox_contains.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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_bbox_contains]
# Define a BBox object.
bbox = ee.Geometry.BBox(-122.09, 37.42, -122.08, 37.43)

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

# Apply the contains method to the BBox object.
bbox_contains = bbox.contains(right=input_geom, maxError=1)

# Print the result.
display('bbox.contains(...) =', bbox_contains)

# Display relevant geometries on the map.
m = geemap.Map()
m.set_center(-122.085, 37.422, 15)
m.add_ee_layer(bbox, {'color': 'black'}, 'Geometry [black]: bbox')
m.add_ee_layer(input_geom, {'color': 'blue'}, 'Parameter [blue]: input_geom')
m
# [END earthengine__apidocs__ee_geometry_bbox_contains]
33 changes: 33 additions & 0 deletions samples/python/apidocs/ee_geometry_bbox_convexhull.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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_bbox_convexhull]
# Define a BBox object.
bbox = ee.Geometry.BBox(-122.09, 37.42, -122.08, 37.43)

# Apply the convexHull method to the BBox object.
bbox_convex_hull = bbox.convexHull(maxError=1)

# Print the result.
display('bbox.convexHull(...) =', bbox_convex_hull)

# Display relevant geometries on the map.
m = geemap.Map()
m.set_center(-122.085, 37.422, 15)
m.add_ee_layer(bbox, {'color': 'black'}, 'Geometry [black]: bbox')
m.add_ee_layer(
bbox_convex_hull, {'color': 'red'}, 'Result [red]: bbox.convexHull'
)
m
# [END earthengine__apidocs__ee_geometry_bbox_convexhull]
30 changes: 30 additions & 0 deletions samples/python/apidocs/ee_geometry_bbox_coordinates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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_bbox_coordinates]
# Define a BBox object.
bbox = ee.Geometry.BBox(-122.09, 37.42, -122.08, 37.43)

# Apply the coordinates method to the BBox object.
bbox_coordinates = bbox.coordinates()

# Print the result.
display('bbox.coordinates(...) =', bbox_coordinates)

# Display relevant geometries on the map.
m = geemap.Map()
m.set_center(-122.085, 37.422, 15)
m.add_ee_layer(bbox, {'color': 'black'}, 'Geometry [black]: bbox')
m
# [END earthengine__apidocs__ee_geometry_bbox_coordinates]
37 changes: 37 additions & 0 deletions samples/python/apidocs/ee_geometry_bbox_difference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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_bbox_difference]
# Define a BBox object.
bbox = ee.Geometry.BBox(-122.09, 37.42, -122.08, 37.43)

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

# Apply the difference method to the BBox object.
bbox_difference = bbox.difference(right=input_geom, maxError=1)

# Print the result.
display('bbox.difference(...) =', bbox_difference)

# Display relevant geometries on the map.
m = geemap.Map()
m.set_center(-122.085, 37.422, 15)
m.add_ee_layer(bbox, {'color': 'black'}, 'Geometry [black]: bbox')
m.add_ee_layer(input_geom, {'color': 'blue'}, 'Parameter [blue]: input_geom')
m.add_ee_layer(
bbox_difference, {'color': 'red'}, 'Result [red]: bbox.difference'
)
m
# [END earthengine__apidocs__ee_geometry_bbox_difference]
34 changes: 34 additions & 0 deletions samples/python/apidocs/ee_geometry_bbox_disjoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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_bbox_disjoint]
# Define a BBox object.
bbox = ee.Geometry.BBox(-122.09, 37.42, -122.08, 37.43)

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

# Apply the disjoint method to the BBox object.
bbox_disjoint = bbox.disjoint(right=input_geom, maxError=1)

# Print the result.
display('bbox.disjoint(...) =', bbox_disjoint)

# Display relevant geometries on the map.
m = geemap.Map()
m.set_center(-122.085, 37.422, 15)
m.add_ee_layer(bbox, {'color': 'black'}, 'Geometry [black]: bbox')
m.add_ee_layer(input_geom, {'color': 'blue'}, 'Parameter [blue]: input_geom')
m
# [END earthengine__apidocs__ee_geometry_bbox_disjoint]
31 changes: 31 additions & 0 deletions samples/python/apidocs/ee_geometry_bbox_dissolve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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_bbox_dissolve]
# Define a BBox object.
bbox = ee.Geometry.BBox(-122.09, 37.42, -122.08, 37.43)

# Apply the dissolve method to the BBox object.
bbox_dissolve = bbox.dissolve(maxError=1)

# Print the result.
display('bbox.dissolve(...) =', bbox_dissolve)

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

0 comments on commit fbefc1d

Please sign in to comment.