Shapefile.jl
Shapefile.jl copied to clipboard
The `Shapefile.LinearRing` of this Polygon is not closed
The Polygon in this shapefile does not have a closed LinearRing:
https://drive.google.com/file/d/11UWltt3HKgGKyAI7wCyhFa65khLEVAXT/view?usp=sharing
Does this mean the shapefile is invalid? Should Shapefile.jl throw an error when this happens?
Thanks in advance to the maintainers for their attention.
The code below can be used to check this:
julia> using Tables
julia> import Shapefile as SHP
julia> import GeoInterface as GI
julia> tb = SHP.Table("poly.shp")
Shapefile.Table{Union{Missing, Shapefile.Polygon}} with 1 rows and the following 2 columns:
geometry, all_missing
julia> geom = Tables.getcolumn(tb, :geometry)
1-element Vector{Union{Missing, Shapefile.Polygon}}:
Polygon(270 Points)
julia> poly = GI.getgeom(first(geom)) |> first
1-element Shapefile.SubPolygon{Shapefile.LinearRing{Shapefile.Point, Nothing, Nothing}}:
[Shapefile.Point(-48.171018231988946, -18.247322704250113), Shapefile.Point(-48.17101963904955, -18.24732326352786), Shapefile.Point(-48.171166414267645, -18.247384611203163), Shapefile.Point(-48.17123873091134, -18.24742071080391), Shapefile.Point(-48.17154130244691, -18.247570296969965), Shapefile.Point(-48.17165832222795, -18.247624452830525), Shapefile.Point(-48.17176866962341, -18.247679340108416), Shapefile.Point(-48.17190070959351, -18.247741647228782), Shapefile.Point(-48.17213461853433, -18.24785014015957), Shapefile.Point(-48.17233698373535, -18.24794613391215) … Shapefile.Point(-48.16942155997931, -18.248163131147656), Shapefile.Point(-48.16975009226726, -18.24796171136208), Shapefile.Point(-48.17002955190942, -18.247791917870092), Shapefile.Point(-48.17028344506759, -18.247639364278832), Shapefile.Point(-48.17049368601856, -18.24751511071119), Shapefile.Point(-48.170613880516, -18.247447773228185), Shapefile.Point(-48.17072170297917, -18.247391464122753), Shapefile.Point(-48.170794728119, -18.247359370679074), Shapefile.Point(-48.170860165849845, -18.24733737438331), Shapefile.Point(-48.17089013490942, -18.24733007375713)]
julia> ring = GI.getexterior(poly)
270-element Shapefile.LinearRing{Shapefile.Point, Nothing, Nothing}:
Shapefile.Point(-48.171018231988946, -18.247322704250113)
Shapefile.Point(-48.17101963904955, -18.24732326352786)
Shapefile.Point(-48.171166414267645, -18.247384611203163)
Shapefile.Point(-48.17123873091134, -18.24742071080391)
Shapefile.Point(-48.17154130244691, -18.247570296969965)
Shapefile.Point(-48.17165832222795, -18.247624452830525)
Shapefile.Point(-48.17176866962341, -18.247679340108416)
Shapefile.Point(-48.17190070959351, -18.247741647228782)
Shapefile.Point(-48.17213461853433, -18.24785014015957)
Shapefile.Point(-48.17233698373535, -18.24794613391215)
⋮
Shapefile.Point(-48.16975009226726, -18.24796171136208)
Shapefile.Point(-48.17002955190942, -18.247791917870092)
Shapefile.Point(-48.17028344506759, -18.247639364278832)
Shapefile.Point(-48.17049368601856, -18.24751511071119)
Shapefile.Point(-48.170613880516, -18.247447773228185)
Shapefile.Point(-48.17072170297917, -18.247391464122753)
Shapefile.Point(-48.170794728119, -18.247359370679074)
Shapefile.Point(-48.170860165849845, -18.24733737438331)
Shapefile.Point(-48.17089013490942, -18.24733007375713)
julia> GI.geomtrait(ring)
GeoInterface.LinearRingTrait()
julia> GI.isclosed(ring)
false
julia> GI.isring(ring)
false
Probably we should load anything and let the user fix it afterwards. But we could have a keyword to check for validity and add a warning?
I've been thinking we should add validation and repair methods to GeometryOps.jl to close polygons like this.
Probably we should load anything and let the user fix it afterwards. But we could have a keyword to check for validity and add a warning?
Maybe adding the keyword and fixing the issue by default is more conservative and user-friendly. If someone cares about deactivating the keyword for performance reasons, that user knows what to do.
Youre welcome to make a PR that does that.