From ace2fb62d39e4b7dd826d7e836d824ee4726a796 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 31 Aug 2025 19:33:57 +0000 Subject: [PATCH 1/4] Initial plan From 36b37e491b651c70448e646c7ca6b4cba9754d54 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 31 Aug 2025 19:49:40 +0000 Subject: [PATCH 2/4] Add firstindex support for all indexable GeoJSON types Co-authored-by: asinghvi17 <32143268+asinghvi17@users.noreply.github.com> --- src/geojson_types.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/geojson_types.jl b/src/geojson_types.jl index 45413f5..5f54c76 100644 --- a/src/geojson_types.jl +++ b/src/geojson_types.jl @@ -109,6 +109,7 @@ function Base.show(io::IO, G::AbstractGeometry{D,T}) where {D,T} end Base.length(g::AbstractGeometry) = length(coordinates(g)) +Base.firstindex(g::AbstractGeometry) = 1 Base.lastindex(g::AbstractGeometry) = length(coordinates(g)) Base.size(g::AbstractGeometry) = size(coordinates(g)) Base.axes(g::AbstractGeometry) = axes(coordinates(g)) @@ -144,6 +145,7 @@ geometry(g::GeometryCollection) = getfield(g, :geometries) Base.show(io::IO, x::GeometryCollection{D,T}) where {D,T} = print(io, "GeometryCollection with $(length(x.geometries)) $(D)D geometries") Base.length(g::GeometryCollection) = length(geometry(g)) +Base.firstindex(g::GeometryCollection) = 1 Base.lastindex(g::GeometryCollection) = length(geometry(g)) Base.size(g::GeometryCollection) = size(geometry(g)) Base.axes(g::GeometryCollection) = axes(geometry(g)) @@ -262,6 +264,7 @@ Base.show(io::IO, fc::FeatureCollection) = print(io, "FeatureCollection with $(l Base.eltype(::Type{<:AbstractFeatureCollection{D,T}}) where {D,T} = Feature{D,T} Base.IteratorEltype(::Type{<:AbstractFeatureCollection}) = Base.HasEltype() Base.length(fc::AbstractFeatureCollection) = length(features(fc)) +Base.firstindex(fc::AbstractFeatureCollection) = 1 Base.lastindex(fc::AbstractFeatureCollection) = length(features(fc)) Base.IteratorSize(::Type{<:AbstractFeatureCollection}) = Base.HasLength() Base.size(fc::AbstractFeatureCollection) = size(features(fc)) From 0c785d8020c52c90b0dbf327ecd24b768d1c096e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 31 Aug 2025 20:02:38 +0000 Subject: [PATCH 3/4] Add comprehensive tests for firstindex and begin indexing Co-authored-by: asinghvi17 <32143268+asinghvi17@users.noreply.github.com> --- test/runtests.jl | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 36f58db..97845e6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -379,6 +379,37 @@ include("geojson_samples.jl") "{\"type\":\"Point\",\"coordinates\":[1.0,2.0,3]}" end + @testset "firstindex and begin indexing" begin + # Test Point geometry + p = GeoJSON.read("""{"type":"Point","coordinates":[30,10]}""") + @test firstindex(p) == 1 + @test p[begin] == p[1] + @test p[begin] == 30.0f0 + + # Test LineString geometry + ls = GeoJSON.read("""{"type":"LineString","coordinates":[[100.0,0.0],[101.0,1.0]]}""") + @test firstindex(ls) == 1 + @test ls[begin] == ls[1] + @test ls[begin] == (100.0f0, 0.0f0) + + # Test Polygon geometry + poly = GeoJSON.read("""{"type":"Polygon","coordinates":[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]]]}""") + @test firstindex(poly) == 1 + @test poly[begin] == poly[1] + + # Test GeometryCollection + gc = GeoJSON.read("""{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[100.0,0.0]},{"type":"LineString","coordinates":[[101.0,0.0],[102.0,1.0]]}]}""") + @test firstindex(gc) == 1 + @test gc[begin] == gc[1] + @test gc[begin] isa GeoJSON.AbstractGeometry + + # Test FeatureCollection + fc = GeoJSON.read("""{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[102.0,0.5]},"properties":{"prop0":"value0"}}]}""") + @test firstindex(fc) == 1 + @test fc[begin] == fc[1] + @test fc[begin] isa GeoJSON.Feature + end + @testset "Tables" begin # try a namedtuple table t1 = map(tuple.(1:10, 1:10), rand(10), ["abc" for i in 1:10]) do geometry, prop1, prop2 From 55b3bcd9c19337198dc73ca2f2f3ac5a916cb75d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 1 Sep 2025 02:00:26 +0000 Subject: [PATCH 4/4] Add comprehensive tests for lastindex and end indexing functionality Co-authored-by: asinghvi17 <32143268+asinghvi17@users.noreply.github.com> --- test/runtests.jl | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 97845e6..a249019 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -410,6 +410,37 @@ include("geojson_samples.jl") @test fc[begin] isa GeoJSON.Feature end + @testset "lastindex and end indexing" begin + # Test Point geometry + p = GeoJSON.read("""{"type":"Point","coordinates":[30,10]}""") + @test lastindex(p) == length(p) + @test p[end] == p[lastindex(p)] + @test p[end] == 10.0f0 + + # Test LineString geometry + ls = GeoJSON.read("""{"type":"LineString","coordinates":[[100.0,0.0],[101.0,1.0]]}""") + @test lastindex(ls) == length(ls) + @test ls[end] == ls[lastindex(ls)] + @test ls[end] == (101.0f0, 1.0f0) + + # Test Polygon geometry + poly = GeoJSON.read("""{"type":"Polygon","coordinates":[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]]]}""") + @test lastindex(poly) == length(poly) + @test poly[end] == poly[lastindex(poly)] + + # Test GeometryCollection + gc = GeoJSON.read("""{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[100.0,0.0]},{"type":"LineString","coordinates":[[101.0,0.0],[102.0,1.0]]}]}""") + @test lastindex(gc) == length(gc) + @test gc[end] == gc[lastindex(gc)] + @test gc[end] isa GeoJSON.AbstractGeometry + + # Test FeatureCollection + fc = GeoJSON.read("""{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[102.0,0.5]},"properties":{"prop0":"value0"}}]}""") + @test lastindex(fc) == length(fc) + @test fc[end] == fc[lastindex(fc)] + @test fc[end] isa GeoJSON.Feature + end + @testset "Tables" begin # try a namedtuple table t1 = map(tuple.(1:10, 1:10), rand(10), ["abc" for i in 1:10]) do geometry, prop1, prop2