Skip to content
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

[WIP] Tutorial to clip a feature collection #206

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ makedocs(;
"Tutorials" => [
"Creating Geometry" => "tutorials/creating_geometry.md",
"Spatial Joins" => "tutorials/spatial_joins.md",
"Clipping a FeatureCollection" => "tutorials/clipping_featurecollection.md",
],
"Explanations" => [
"Paradigms" => "explanations/paradigms.md",
Expand Down
41 changes: 41 additions & 0 deletions docs/src/tutorials/clipping_featurecollection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Clipping a FeatureCollection by a polygon

Often, one might want to clip a feature collection (maybe from Shapefile or GeoJSON)

```@example clipping_featurecollection
function clip_or_empty(polygon, clipper)
#=
result = GO.intersection(polygon, clipper; target = GI.PolygonTrait())
if isempty(result)
null_point = GI.is3d(polygon) ? (GI.ismeasured(polygon) ? (NaN, NaN, NaN, NaN) : (NaN, NaN, NaN)) : (NaN, NaN)
contents = GI.LinearRing.([[null_point, null_point, null_point]])
return GI.Polygon{GI.is3d(polygon),GI.ismeasured(polygon),typeof(contents),Nothing, typeof(GI.crs(polygon))}(contents, nothing, GI.crs(polygon))
else
return GI.MultiPolygon(result; crs = GI.crs(polygon))
end
=#
return GO.intersection(GO.GEOS(), polygon, clipper)
end
```
First, let's load our data:
```@example clipping_featurecollection
df = nothing # DataFrame(Shapefile.Table(...))
```
and plot it:
```@example clipping_featurecollection
f, a, p = poly(df.geometry)
```
Now, we can define some polygon in that space, that we want to use to clip all geometries by!
```@example clipping_featurecollection
clipping_poly = GI.Polygon([[(880_000, 990_000), (910_000, 990_000), (910_000, 1030_000), (880_000, 1030_000), (880_000, 990_000)]])
poly!(a, clipping_poly; color = Makie.Cycled(2))
f
```
Finally, we clip, and show the output:
```@example clipping_featurecollection
clipped_geoms = clip_or_empty.(df.geometry, (clipping_poly,))
```
```@example clipping_featurecollection
poly!(a, clipped_geoms; color = Makie.Cycled(3), strokewidth = 0.75, strokecolor = :forestgreen)
f
```
Loading