evetion / GeoDataFrames.jl

Simple geographical vector interaction built on top of ArchGDAL
https://www.evetion.nl/GeoDataFrames.jl/dev/
MIT License
67 stars 6 forks source link

Makie ext #74

Open ConnectedSystems opened 2 months ago

ConnectedSystems commented 2 months ago

Draft PR for #66 - currently just a proof of concept.

There's currently some issue with GDAL.jl which prevents successful precompilation. I've resolved it temporarily with:

add GDAL_jll@301.900

~Plotting certain types of polygons currently does not work!~ Now correctly supports points and multipolys but need to test with a wider variety of data.

using Revise, Infiltrator
using GeoMakie, WGLMakie
import GeoDataFrames as GDF
using Downloads

# Point data
if !@isdefined point_gdf_fn
    point_gdf_fn = Downloads.download("https://github.com/ngageoint/GeoPackage/raw/master/docs/examples/java/example.gpkg")
end

point_gdf = GDF.read(point_gdf_fn)
pnt_fig = GDF.plot(point_gdf, :geometry)

# Polygon data
if !@isdefined poly_gdf_fn
    poly_gdf_fn = Downloads.download("http://www.geopackage.org/data/sample1_2.gpkg")
end

poly_gdf = GDF.read(poly_gdf_fn)
poly_fig = GDF.plot(poly_gdf, :Shape)

GDF.plot(poly_gdf)
ConnectedSystems commented 2 months ago

Would appreciate any input @evetion @asinghvi17 as I'm not so familiar with GeoMakie/GeoInterface internals.

asinghvi17 commented 2 months ago

Hey, thanks for the PR! In this case it's probably better to stick with the existing Makie machinery in e.g GeoInterfaceMakie, and maybe make an extension on that as well as regular Makie. I think Shapefile.jl does something similar, and GeoMakie loads GeoInterfaceMakie which brings all of these extensions as well.

The issue here, though, is that GeoDataFrames are not their own type, but rather a simple DataFrame. This means that there is no way to disambiguate between a GeoDataFrame and a regular dataframe. If we do create a GeoDataFrame type, even if just by wrapping a DataFrame and forwarding all possible method combinations, then this issue goes away and it's a lot easier to plot these.

Is there a fundamental difference between e.g. plot(gdf.geometry) and plot(gdf, :geometry) for your usecase? The number of characters is similar and IMO plot(gdf.geometry) should already work with the GeoInterface/Makie/ArchGDAL integration. I also have a PR https://github.com/JuliaGeo/GeoInterface.jl/pull/139 which fixes plotting Vector{<: Missing, Geometry} which is the last step to smooth integration. This plus my earlier PR should also remove the need to use eg GeoMakie.to_multipoly since the Makie recipe for vectors of geometries calls that internally.