Skip to content

Commit 7416fe6

Browse files
authored
Move raster footprint functionality into a class (#396)
* feat: sinusoidal projection raster footprint geometry - supplements existing raster footprint with new densification method and projection to lon/lat that does not wrap longitudes * refactor: a little cleaner subclassing, better projection parameters * refactor: separate out a base class - 2 subclasses: default and sinusoidal * wip * refactor: make single class - add instance creation methods - remove sinusoidal class * fix: remove unnecessary change from test_raster_footprint.py * fix: remove unneccessary modis test files * fix: prevent potential subclassing problem - return `cls` rather than `RasterFootprint` from a classmethod * fix: generalize return types from class methods * fix: docstring fixups * refactor: free `reproject_polygon()` * docs: deprecated existing free functions * refactor: make optional argument order consistent * docs: remove unrelated doc changes - Removes doc and docstring edits to the round utility, which are more appropriately addressed in a new PR. * fix: modify cogify_subdatasets tests to pass * fix: revert test_subdataset test * fixups: PR review fixups * feat: update cli and add densify tests - update cli to use new RasterFootprint class method - test densification methods * chore: update CHANGELOG * docs: update footprint.rst contents * fix: add accidentally deleted changelog contents
1 parent ef6b5e7 commit 7416fe6

File tree

6 files changed

+869
-240
lines changed

6 files changed

+869
-240
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- `stactools.core.utils.round` for rounding Item geometry and Item and Collection bboxes to a specified precision ([#384](https://github.com/stac-utils/stactools/pull/384))
13+
- `stactools.core.utils.raster_footprint.densify_by_distance` for densifying polygons at distance intervals ([#396](https://github.com/stac-utils/stactools/pull/396))
14+
- `stactools.core.utils.raster_footprint.reproject_polgyon` for reprojecting a polygon and removing duplicate vertices caused by rounding ([#396](https://github.com/stac-utils/stactools/pull/396))
15+
- `stactools.core.utils.raster_footprint.RasterFootprint` class for customizing raster data footrpint creation behaviour via subclassing ([#396](https://github.com/stac-utils/stactools/pull/396))
1316

1417
### Changed
1518

1619
- Freed `recursive_round` function from `round_coordinates` in `stactools.core.utils.round` ([#390](https://github.com/stac-utils/stactools/pull/390))
20+
- Exposed the private `_densify` function as `densify_by_factor` in `stactools.core.utils.raster_footprint` ([#396](https://github.com/stac-utils/stactools/pull/396))
1721

18-
### [0.4.3] - 2022-12-16
22+
### Deprecated
23+
24+
- `update_geometry_from_asset_footprint`, `data_footprints_for_data_assets`, and `data_footprint` functions will be removed from `stactools.core.utils.raster_footprint` in v0.6.0 ([#396](https://github.com/stac-utils/stactools/pull/396))
25+
26+
## [0.4.3] - 2022-12-16
1927

2028
### Added
2129

docs/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Reprojection
8686
.. automodule:: stactools.core.projection
8787
:members:
8888

89-
Raster Footprint Generation
89+
Raster footprint generation
9090
~~~~~~~~~~~~~~~~~~~~~~~~~~~
9191

9292
.. automodule:: stactools.core.utils.raster_footprint

docs/footprint.rst

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ bounding box of the entire image, both
1111
data and no data. By footprint, we mean a vector that balances many competing
1212
factors, and generally represents a shape
1313
covering the data in an image. Figuring out the right parameter values to the
14-
methods in the ``raster_footprint``
14+
methods in the :mod:`~stactools.core.utils.raster_footprint`
1515
module will usually require some experimental validation, to find exactly the
1616
right values for your data, CRS, and
1717
use cases.
@@ -74,9 +74,9 @@ result in false positives where a search geometry intersects the
7474
geometry of an Item, but the only pixels within the
7575
geometry are no data, but in practice this is rarely a problem.
7676

77-
When using the raster_footprint functions, the ``no_data`` parameter
78-
value can be used to pass in the value
79-
used for no data if it not defined in the image metadata.
77+
When using the :mod:`~stactools.core.utils.raster_footprint` functions, the
78+
``no_data`` parameter value can be used to pass in the value
79+
used for no data if it is not defined in the image metadata.
8080

8181
Reprojected Geometry Accurately Represents the Footprint
8282
--------------------------------------------------------
@@ -90,15 +90,15 @@ to EPSG:4326, it will still result in a 5 point
9090
polygon, as the points have simply been reprojected into the new CRS.
9191
This new polygon may not accurately represent
9292
original polygon if there is significant curved distortion between
93-
the CRSes. An example of this is most apparent in
93+
the CRSs. An example of this is most apparent in
9494
reprojecting the sinusoidal geometry of MODIS to EPSG:4326. Simply
9595
reprojecting the 5 point polygon would result in
9696
a parallelogram, whereas a more accurate representation is two
9797
parallel straight sides and two curved sides.
9898

9999
.. image:: _static/modis.png
100100

101-
The increase the accuracy of the reprojected shape, we can first
101+
To increase the accuracy of the reprojected shape, we can first
102102
densify the polygon. Here we add additional, redundant
103103
points between existing points in the polygon, so that the
104104
reprojected shape will have points that more closely match
@@ -108,9 +108,9 @@ each "side" of the polygon has 11 points representing it instead
108108
of 2, and we get a "curved" side that more closely
109109
matches the raster reprojection.
110110

111-
When using the raster_footprint functions, the
112-
``densification_factor`` parameter can be used to densify the
113-
geometry before reprojection. This will require some
111+
When using the methods in the :mod:`~stactools.core.utils.raster_footprint`
112+
module, the ``densification_factor`` or ``densification_distance`` parameter
113+
can be used to densify the geometry before reprojection. This will require some
114114
experimentation to find the appropriate value for the CRS of your data.
115115

116116
Simplifying the Geometry
@@ -122,17 +122,14 @@ it is a 2400x2400 pixel image and two sides are curves after reprojection.
122122
However, a polygon this dense both makes
123123
the Item body very large and increases the computation required to perform
124124
an intersects calculation during search,
125-
with little benefit. These polygons can be simplified by defining a minimum
126-
distance, in degrees, for which two points
127-
may be collapsed into one. This is also useful when the polygon in the native
125+
with little benefit. These polygons can be simplified by defining a maximum
126+
distance, in degrees, within which the simplified polygon must be to original
127+
polygon points. This is also useful when the polygon in the native
128128
CRS has a large number of points, so
129129
that the end result is a polygon of a more manageable size.
130130

131-
When using the raster_footprint functions, the ``simplify_tolerance`` parameter
132-
defines the a minimum distance,
133-
in degrees, for which points should be combined. This will require some
134-
experimentation to find the appropriate
135-
value for the CRS of your data.
136-
137-
138-
131+
When using the methods in the :mod:`~stactools.core.utils.raster_footprint`
132+
module, the ``simplify_tolerance`` parameter defines the distance within which
133+
the simplified polygon must be to the original polygon points. This will
134+
require some experimentation to find the appropriate value for the CRS of your
135+
data.

src/stactools/cli/commands/update_geometry.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ def create_update_geometry_command(cli: Group) -> Command:
3737
type=int,
3838
help="The factor by which to increase point density within the polygon.",
3939
)
40+
@click.option(
41+
"-i",
42+
"--densification-distance",
43+
type=float,
44+
help="The distance interval at which to increase point density within the polygon",
45+
)
4046
@click.option(
4147
"-s",
4248
"--simplify-tolerance",
@@ -60,28 +66,40 @@ def create_update_geometry_command(cli: Group) -> Command:
6066
default="1",
6167
show_default=True,
6268
)
69+
@click.option(
70+
"-e",
71+
"--skip-errors",
72+
help="Do not raise errors for missing hrefs or footprint calculation failures",
73+
type=bool,
74+
default=True,
75+
show_default=True,
76+
)
6377
def update_geometry_command_raster_command(
6478
item_path: str,
6579
asset_names: List[str],
6680
precision: int,
6781
densification_factor: Optional[int],
82+
densification_distance: Optional[float],
6883
simplify_tolerance: Optional[float],
6984
no_data: Optional[int],
7085
bands: str,
86+
skip_errors: bool,
7187
) -> None:
7288
item = Item.from_file(item_path)
7389
if bands.lower() == "all":
7490
band_list = []
7591
else:
7692
band_list = list(int(band) for band in bands.split(","))
77-
success = raster_footprint.update_geometry_from_asset_footprint(
93+
success = raster_footprint.RasterFootprint.update_geometry_from_asset_footprint(
7894
item,
7995
asset_names=asset_names,
8096
precision=precision,
8197
densification_factor=densification_factor,
98+
densification_distance=densification_distance,
8299
simplify_tolerance=simplify_tolerance,
83100
no_data=no_data,
84101
bands=band_list,
102+
skip_errors=skip_errors,
85103
)
86104
if success:
87105
item.save_object()

0 commit comments

Comments
 (0)