From e8992365da28d13ced76941b345a2904f11509d8 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Tue, 16 Sep 2025 16:30:31 +0200 Subject: [PATCH] Add coordtype implementation for Shapefile geometry types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implemented GeoInterface.coordtype for all Shapefile geometry types. Shapefile internally always uses Float64 coordinates regardless of input type, with version guard for compatibility. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/multipoints.jl | 4 ++++ src/points.jl | 5 +++++ src/polygons.jl | 7 +++++++ src/polylines.jl | 5 +++++ 4 files changed, 21 insertions(+) diff --git a/src/multipoints.jl b/src/multipoints.jl index d762e34..b3fe539 100644 --- a/src/multipoints.jl +++ b/src/multipoints.jl @@ -31,6 +31,10 @@ end GI.getgeom(::GI.MultiPointTrait, geom::MultiPoint, i::Integer) = geom.points[i] +# coordtype implementation - Shapefile always uses Float64 +if :coordtype in names(GI; all = true) + GI.coordtype(::GI.MultiPointTrait, ::AbstractMultiPoint) = Float64 +end """ MultiPointM <: AbstractMultiPoint diff --git a/src/points.jl b/src/points.jl index 1d0c315..7f9b91f 100644 --- a/src/points.jl +++ b/src/points.jl @@ -85,3 +85,8 @@ _ncoord(::Type{<:PointZ}) = 4 GI.m(::GI.PointTrait, point::PointZ) = point.m GI.z(::GI.PointTrait, point::PointZ) = point.z + +# coordtype implementation - Shapefile always uses Float64 +if :coordtype in names(GI; all = true) + GI.coordtype(::GI.AbstractGeometryTrait, ::AbstractPoint) = Float64 +end diff --git a/src/polygons.jl b/src/polygons.jl index 1a1ee1e..af3a476 100644 --- a/src/polygons.jl +++ b/src/polygons.jl @@ -30,6 +30,13 @@ Base.@propagate_inbounds Base.getindex(lr::LinearRing{PointZ}, i) = Base.size(lr::LinearRing) = (length(lr),) Base.length(lr::LinearRing) = length(lr.xy) +# coordtype implementation - Shapefile always uses Float64 +if :coordtype in names(GI; all = true) + GI.coordtype(::GI.LinearRingTrait, ::LinearRing) = Float64 + GI.coordtype(::GI.PolygonTrait, ::SubPolygon) = Float64 + GI.coordtype(::GI.MultiPolygonTrait, ::AbstractPolygon) = Float64 +end + struct SubPolygon{L<:LinearRing} <: AbstractVector{L} rings::Vector{L} end diff --git a/src/polylines.jl b/src/polylines.jl index 60d7d4e..c5ce99d 100644 --- a/src/polylines.jl +++ b/src/polylines.jl @@ -21,6 +21,11 @@ Base.getindex(lr::LineString{Point}, i) = lr.xy[i] Base.getindex(lr::LineString{PointM}, i) = PointM(lr.xy[i], lr.m[i]) Base.getindex(lr::LineString{PointZ}, i) = PointZ(lr.xy[i], lr.z[i], lr.m[i]) +# coordtype implementation - Shapefile always uses Float64 +if :coordtype in names(GI; all = true) + GI.coordtype(::GI.LineStringTrait, ::LineString) = Float64 + GI.coordtype(::GI.MultiLineStringTrait, ::AbstractPolyline) = Float64 +end abstract type AbstractPolyline{T} <: AbstractShape end