SearchTransform¶
- class geodesic.boson.SearchTransform(*args, **kwargs)[source]¶
Bases:
geodesic.boson.middleware._Middleware
- static rename_fields(case=None, field_map={})[source]¶
rename fields in the properties of a search response
- static combine_fields(new_field, fields, separator='', sprintf='')[source]¶
combine fields in the properties of a search response
- Parameters
new_field (str) – name of the new field to create
fields (List[str]) – fields to combine
separator (str, optional) – separator to use when combining fields. Defaults to ” “.
sprintf (str, optional) – sprintf format to use when combining fields. This uses golang
instance (format strings to format the fields into one combined string field. For) –
:param : :param “%d.2 %s” would print “2.00 dollars” if the field values were 2 and “dollars”.: :param For more information about the formatting see https: //pkg.go.dev/fmt. :param All fields must have values for the sprintf to be executed. Defaults to “”.:
- static centroid()[source]¶
Calculate the centroid of the queried geometry
This middleware will calculate the centroid of the geometry and return it in a new collection called “centroid”. In the case of multi-geometries, the centroid of the entire geometry will be calculated.
When creating this middleware, most of the time you will want to apply it after any filtering happens, so that the centroid is calculated on the filtered geometry. This is done by adding it to the search_transforms_after list in the MiddlewareConfig. See the below example.
- Returns
middleware to calculate the centroid of the queried geometry
- Return type
Examples
>>> # Add the centroid middleware to a dataset view >>> ds_with_centroid = ds.view( ... middleware=MiddlewareConfig( ... search_transforms_after=[SearchTransform.centroid()] ... ) ... )
- static convex_hull()[source]¶
Calculate the convex hull of the queried geometry
This middleware will calculate the convex hull of the geometry and return it in a new collection called “convex_hull”. The convex hull is the smallest convex polygon that encloses the geometry. In the case of multi-geometries, the convex hull of the entire geometry will be calculated.
When creating this middleware, most of the time you will want to apply it after any filtering happens, so that the centroid is calculated on the filtered geometry. This is done by adding it to the search_transforms_after list in the MiddlewareConfig. See the below example.
- Returns
middleware to calculate the convex hull of the queried geometry
- Return type
Examples
>>> # Add the convex_hull middleware to a dataset view >>> ds_with_convex_hull = ds.view( ... middleware=MiddlewareConfig( ... search_transforms_after=[SearchTransform.convex_hull()] ... ) ... )
- static bounds()[source]¶
Calculate the bounds of the queried geometry
This middleware will calculate the bounds of the geometry and return it in a new collection called “bounds”. The bounds in this case are a rectangle that encloses the geometry. In the case of multi-geometries, the bounds of the entire geometry will be calculated.
When creating this middleware, most of the time you will want to apply it after any filtering happens, so that the centroid is calculated on the filtered geometry. This is done by adding it to the search_transforms_after list in the MiddlewareConfig. See the below example.
- Returns
middleware to calculate the bounds of the queried geometry
- Return type
Examples
>>> # Add the bounds middleware to a dataset view >>> ds_with_bounds = ds.view( ... middleware=MiddlewareConfig( ... search_transforms_after=[SearchTransform.bounds()] ... ) ... )
- static simplify(threshold, stride=2)[source]¶
Simplify the queried geometry
This middleware will simplify the geometry by removing points according to the `Ramer-Douglas-Peucker Algorithm<https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm>`_. This is useful for reducing the size of the geometry for visualization or other purposes. The threshold is approximately the scale at which points will be removed. A smaller threshold will cause more points of the original geometry to be kept, and larger will cause more to be thrown away. The stride parameter controls how many points are checked against the threshold when simplifying. A larger stride will simplify the geometry faster but may result in a less accurate simplification. If you are not familiar with this algorithm, it is recommended that you leave stride at the default value of 2.
When creating this middleware, most of the time you will want to apply it after any filtering happens, so that the centroid is calculated on the filtered geometry. This is done by adding it to the search_transforms_after list in the MiddlewareConfig. See the below example.
Note
The units of the threshold are the same as the units of the spatial reference of the geometry. For instance, if the geometry is in EPSG:4326, the threshold will be in degrees.
- Parameters
- Returns
middleware to simplify the queried geometry
- Return type
Examples
>>> # Add the simplify middleware to a dataset view >>> simplified_ds = ds.view( ... middleware=MiddlewareConfig( ... search_transforms_after=[SearchTransform.simplify(threshold=0.01, stride=3)] ... ) ... )