-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add proximity
and buffer_metric
functionalities with metric
option based on finding local UTM
#336
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…t to buffer_without_overlap
Tests all passing locally (= will be all good PR #335 is merged) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome functionality!
adehecq
reviewed
Jan 19, 2023
adehecq
reviewed
Jan 19, 2023
adehecq
reviewed
Jan 19, 2023
adehecq
reviewed
Jan 19, 2023
adehecq
approved these changes
Jan 19, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice ! 😄
Merging here as well! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a
proximity()
function to theVector
andRaster
classes that mirrors GDAL's proximity not implemented inrasterio
(rasterio/rasterio#319), and abuffer_metric()
method for theVector
class to avoid the trouble of reprojecting from geographic system, buffer, than reverse-projecting, based on finding a local UTM zone.It also adds a
Raster
methodequal_georeferenced_grid
to check if two rasters have the same georeferencing.In details
Proximity
The proximity is computed using
scipy.distance_transform_edt
(https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.distance_transform_edt.html).The functioning is as follows:
For
Raster
classes, the proximity can be either computed directly from target values of the arrayself.data
, or from aVector
passed as argument that is automatically rasterized onself
. For target values, the default behaviour is the same as GDAL: a list of any number of values can be passed. If none are passed, all non-zero values are targets. For the distance unit, I also implemented both "pixel" and "georeferenced", but put the default as "georeferenced" contrary to GDAL's "pixel".For
Vector
classes, the proximity can be computed fromself
by passing aRaster
object to rasterize the vector on.The resulting proximity values are thoroughly tested against GDAL Python's
gdal.ComputeProximity()
with artificial and real Raster data. All results are the same, except for very complex case where a few percentage of values (<1%) differ by ~1% (not even a floating point issue, GDAL's algorithm is simply slightly different for some cases).Additionally, any
geometry_type
can be passed to rasterize theVector
object with (default:boundary
, which is the most common). And anin_or_out
option can be passed to include only the outside or inside proximity for a geometry that have an area (Polygon
,MultiPolygon
, etc).Buffer metric
This function is to avoid the trouble of reprojecting a
Vector
in a local metric system for buffering without deformation, and then reverse-projecting. This involves finding the local metric system wanted, reprojecting to it, recreating ageopandas.GeoDataFrame
object in the right CRS with the buffergeopandas.GeoSeries
, and reverse-projecting.For now this function only supports reprojecting in the local UTM which, for speed, is approximated by the latitude/longitude coordinates of the centroid of non-projected vector (centroid are not exactly the same depending on projections, but generally robust enough?).
Two new functions
latlon_to_utm
andutm_to_epsg
inprojtools
help converting coordinates to UTM zone and to related EPSG (maybe there's some new stuff out there, but a couple years ago theutm
Python package didn't allow UTM zones near poles, which was annoying, and I didn't know of any package that could interpret the UTM zone into an EPSG code).All functions of
projtools
and thebuffer_metric
method inVector
are tested. I also added themetric
argument inbuffer_without_overlap
function, which does the same procedure.Issues closed
This PR:
And adds tests for all.