Skip to content

Operations

Spatial operations

GeoDataFrames reuses GeometryOps.jl for geometry predicates and operations.

julia
using GeoDataFrames
using GeoDataFrames: setcrs!
using NaturalEarth

countries = select(
    DataFrame(naturalearth("admin_0_countries", 50)),
    :NAME,
    :geometry,
)

regions = subset(
    countries,
    :NAME => ByRow(name -> name in ["Greece", "Italy", "Norway"]),
)
hulls = select(
    regions,
    :NAME,
    :geometry => ByRow(GeometryOps.convex_hull) => :geometry,
)
hulls
3×2 DataFrame
RowNAMEgeometry
StringPolygon…
1NorwayGeoInterface.Wrappers.Polygon([GeoInterface.Wrappers.LinearRing([(-9.098876953125,70.8548812866211),…(19)…,(-9.098876953125,70.8548812866211)])])
2ItalyGeoInterface.Wrappers.Polygon([GeoInterface.Wrappers.LinearRing([(6.627734184265137,45.11796951293945),…(19)…,(6.627734184265137,45.11796951293945)])])
3GreeceGeoInterface.Wrappers.Polygon([GeoInterface.Wrappers.LinearRing([(19.646484375,39.76708984375),…(21)…,(19.646484375,39.76708984375)])])

Metadata

Set geometry and CRS metadata on a DataFrame:

julia
table = DataFrame(geom=[GeoInterface.Point(4, 52)], name=["home"])
GeoDataFrames.setgeometrycolumn!(table, :geom)  # set geometry column
GeoDataFrames.setcrs!(table, EPSG(4326))  # set coordinate reference system
(GeoInterface.geometrycolumns(table), GeoInterface.crs(table))
((:geom,), EPSG{1}((4326,)))

Plotting

julia
using CairoMakie

fig = plot(
    regions.geometry;
    color = (:lightgray, 0.35),
    strokecolor = :gray,
    axis = (; title = "Country geometries and their convex hulls"),
)
plot!(hulls.geometry; color = (:tomato, 0.2), strokecolor = :tomato)
fig

For advanced workflows (layers and write options, reprojection strategy, spatial joins, native-driver behavior), use: