Creates a geometry. Note that a creating a Geometry from a ComputedObject cannot have have any overrides from the arguments proj, geodesic, or evenOdd. Args: geo_json: The GeoJSON object describing the geometry or a computed object to be reinterpred as a Geometry. Support
(
self,
geo_json: dict[str, Any] | computedobject.ComputedObject | Geometry,
proj: Any | None = None,
geodesic: bool | None = None,
evenOdd: bool | None = None, # pylint: disable=g-bad-name
)
| 35 | |
| 36 | @_utils.accept_opt_prefix('opt_proj', 'opt_geodesic', 'opt_evenOdd') |
| 37 | def __init__( |
| 38 | self, |
| 39 | geo_json: dict[str, Any] | computedobject.ComputedObject | Geometry, |
| 40 | proj: Any | None = None, |
| 41 | geodesic: bool | None = None, |
| 42 | evenOdd: bool | None = None, # pylint: disable=g-bad-name |
| 43 | ): |
| 44 | """Creates a geometry. |
| 45 | |
| 46 | Note that a creating a Geometry from a ComputedObject cannot have have any |
| 47 | overrides from the arguments proj, geodesic, or evenOdd. |
| 48 | |
| 49 | Args: |
| 50 | geo_json: The GeoJSON object describing the geometry or a computed object |
| 51 | to be reinterpred as a Geometry. Supports CRS specifications as per the |
| 52 | GeoJSON spec, but only allows named (rather than "linked" CRSs). If this |
| 53 | includes a 'geodesic' field, and geodesic is not specified, it will be |
| 54 | used as geodesic. |
| 55 | proj: An optional projection specification, either as an ee.Projection, as |
| 56 | a CRS ID code or as a WKT string. If specified, overrides any CRS found |
| 57 | in the geo_json parameter. If unspecified and the geo_json does not |
| 58 | declare a CRS, defaults to "EPSG:4326" (x=longitude, y=latitude). |
| 59 | geodesic: Whether line segments should be interpreted as spherical |
| 60 | geodesics. If false, indicates that line segments should be interpreted |
| 61 | as planar lines in the specified CRS. If absent, defaults to true if the |
| 62 | CRS is geographic (including the default EPSG:4326), or to false if the |
| 63 | CRS is projected. |
| 64 | evenOdd: If true, polygon interiors will be determined by the even/odd |
| 65 | rule, where a point is inside if it crosses an odd number of edges to |
| 66 | reach a point at infinity. Otherwise polygons use the left-inside rule, |
| 67 | where interiors are on the left side of the shell's edges when walking |
| 68 | the vertices in the given order. If unspecified, defaults to True. |
| 69 | |
| 70 | Raises: |
| 71 | EEException: if the given geometry isn't valid. |
| 72 | """ |
| 73 | self.initialize() |
| 74 | |
| 75 | # pylint: disable-next=protected-access |
| 76 | has_resolved_geometry_type = getattr(geo_json, '_type', None) is not None |
| 77 | computed = isinstance(geo_json, computedobject.ComputedObject) and not ( |
| 78 | isinstance(geo_json, Geometry) and has_resolved_geometry_type |
| 79 | ) |
| 80 | options = proj is not None or geodesic is not None or evenOdd is not None |
| 81 | if computed: |
| 82 | if options: |
| 83 | raise ee_exception.EEException( |
| 84 | 'Setting the CRS or geodesic on a computed Geometry is not ' |
| 85 | 'supported. Use Geometry.transform().') |
| 86 | else: |
| 87 | super().__init__(geo_json.func, geo_json.args, geo_json.varName) |
| 88 | return |
| 89 | |
| 90 | # Below here we're working with a GeoJSON literal. |
| 91 | if isinstance(geo_json, Geometry): |
| 92 | geo_json = geo_json.encode() |
| 93 | |
| 94 | if not Geometry._isValidGeometry(geo_json): |
nothing calls this directly
no test coverage detected