Constructors
Let’s see how to use the extended constructors available through eemont!
Before anything, let’s import our modules and authenticate in Google Earth Engine:
import ee, eemont
ee.Authenticate()
ee.Initialize()
Now, we are ready to go!
Overview
The eemont package extends the ee.Geometry, ee.Feature and ee.FeatureCollection classes with the following constructors:
ee.Geometry
|
Constructs an ee.Geometry describing a bounding box from a query submitted to a geodocer using the geopy package. |
|
Constructs an ee.Geometry describing a linear ring from a list of Plus Codes. |
|
Constructs an ee.Geometry describing a line from a list of Plus Codes. |
|
Constructs an ee.Geometry describing multiple lines from a list of lists of Plus Codes. |
|
Constructs an ee.Geometry describing multiple points from a list of Plus Codes. |
|
Constructs an ee.Geometry describing a multi-point from a query submitted to a geodocer using the geopy package. |
|
Constructs an ee.Geometry describing multiple polygons from a list of lists of Plus Codes. |
|
Constructs an ee.Geometry describing a point from a Plus Code. |
|
Constructs an ee.Geometry describing a point from a query submitted to a geodocer using the geopy package. |
|
Constructs an ee.Geometry describing a polygon from a list of Plus Codes. |
|
Constructs an ee.Geometry describing a rectangle from a list of two Plus Code corners. |
ee.Feature
|
Constructs an ee.Feature describing a bounding box from a query submitted to a geodocer using the geopy package. |
|
Constructs an ee.Feature describing a point from a query submitted to a geodocer using the geopy package. |
ee.FeatureCollection
|
Constructs an ee.Feature describing a point from a query submitted to a geodocer using the geopy package. |
Usage
Constructors By Query
The constructors by query use the geopy package to construct geometries, features and feature collections.
The simplest geometry to construct is the Point, and can be constructed for ee.Geometry and ee.Feature classes;
geometry = ee.Geometry.PointFromQuery('Cali, Colombia',user_agent = 'eemont-user-guide-constructors')
feature = ee.Feature.PointFromQuery('Cali, Colombia',user_agent = 'eemont-user-guide-constructors')
It has to be noted that the user_agent argument is mandatory and it can be set to any string representing the app or the GEE username.
Warning
If the user_agent argument is not defined, the constructor will raise an Exception.
By default, to geocode the query, the Nominatim geocoder is used. If required, this parameter can be modified:
geometry = ee.Geometry.PointFromQuery('Cali, Colombia',geocoder = 'arcgis',user_agent = 'eemont-user-guide-constructors')
The second geometry to construct is the MultiPoint, and can be constructed for ee.Geometry and ee.FeatureCollection classes:
geometry = ee.Geometry.MultiPointFromQuery('Colombia',user_agent = 'eemont-user-guide-constructors')
feature_collection = ee.FeatureCollection.MultiPointFromQuery('Colombia',user_agent = 'eemont-user-guide-constructors')
Note
When a query is submitted, a set of locations is retrieved. The MultiPoint constructors create a class taking all locations into account. The Point constructors just take the first one.
The last geometry to construct is the Bounding Box, and can be constructed for ee.Geometry and ee.Feature classes:
geometry = ee.Geometry.BBoxFromQuery('Europe',user_agent = 'eemont-user-guide-constructors')
feature = ee.Feature.BBoxFromQuery('Europe',user_agent = 'eemont-user-guide-constructors')
Note
When using constructors for ee.Feature and ee.FeatureCollection classes, the raw properties of the location, or locations, are set for the feature or feature collection.
Constructors By Plus Codes
Note
The awesome Plus Codes constructors and methods were created by Aaron Zuspan (creator of sankee).
Plus Codes are street addresses that represent an area based on longitude and latitude coordinates (e.g. “89MH+PW”).
Warning
In order to use Plus Codes constructors, it is required to install openlocationcode. Please install it by running pip install openlocationcode.
There are two ways to use the Plus Codes constructors.
By using a full Plus Code (e.g. “85FPQXGV+XH”).
By using a short Plus Code (e.g. “QXGV+XH Denver, CO, USA”).
When using full Plus Codes, just use it as the principal argument in the constructor:
point = ee.Geometry.PointFromPlusCode("85FPQXGV+XH")
When using a short Plus Code, it is required to use a geocoder (just like the constructors by queries), and therefore, an user agent must be declared:
point = ee.Geometry.PointFromPlusCode("QXGV+XH Denver, CO, USA",user_agent = 'eemont-user-guide-constructors')
More complex geometries can be constructed using a list of Plus Codes or a nested list of Plus Codes:
codes = ['85FQ2222+22', '85FR2222+22', '85GR2222+22']
multipoint = ee.Geometry.MultiPointFromPlusCodes(codes)
linestring = ee.Geometry.LineStringFromPlusCodes(codes)
polygon = ee.Geometry.PolygonFromPlusCodes(codes)
nestedCodes = [
['85FQ2222+22', '85FR2222+22', '85GR2222+22'],
['85FP8PC2+G2', '85FPJF23+G4', '85FPMW2R+RP'],
['85FPRJ5W+82', '85GP3M67+CP', '85GQ2R7C+38'],
]
multilinestring = ee.Geometry.MultiLineStringFromPlusCodes(nestedCodes)
multipolygon = ee.Geometry.MultiPolygonFromPlusCodes(nestedCodes)