Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Float32 coordinates #122

Merged
merged 2 commits into from
Oct 3, 2024
Merged

Conversation

eliascarv
Copy link
Contributor

@eliascarv eliascarv commented Oct 3, 2024

The Shapefile specification requires coordinate values ​​to be in Float64:

image

This PR adds missing coordinate conversions to Float64, thus adding support for writing geometries with Float32 coordinates:

main:

julia> using Shapefile, GeoJSON

julia> geojson = GeoJSON.read("countries.geojson")
FeatureCollection with 177 Features

julia> Shapefile.write("countries.shp", geojson)
┌ Warning: Could not convert CRS of type `GeoFormatTypes.EPSG{1}` to `GeoFormatTypes.ESRIWellKnownText{GeoFormatTypes.CRS}`.  `using ArchGDAL` may load the necessary `Base.convert` method.  The CRS WILL NOT BE SAVED as a .prj file.
└ @ Shapefile ~/Documentos/JuliaDev/Shapefile.jl/src/writer.jl:26
ERROR: AssertionError: rec_bytes == calc_rec_bytes
Stacktrace:
 [1] write(path::String, o::Shapefile.Writer; force::Bool)
   @ Shapefile ~/Documentos/JuliaDev/Shapefile.jl/src/writer.jl:213
 [2] write
   @ ~/Documentos/JuliaDev/Shapefile.jl/src/writer.jl:93 [inlined]
 [3] write(path::String, obj::GeoJSON.FeatureCollection{2, Float32})
   @ Shapefile ~/Documentos/JuliaDev/Shapefile.jl/src/writer.jl:269
 [4] top-level scope
   @ REPL[6]:1

PR:

julia> using Shapefile, GeoJSON

julia> geojson = GeoJSON.read("countries.geojson")
FeatureCollection with 177 Features

julia> Shapefile.write("countries.shp", geojson)
┌ Warning: Could not convert CRS of type `GeoFormatTypes.EPSG{1}` to `GeoFormatTypes.ESRIWellKnownText{GeoFormatTypes.CRS}`.  `using ArchGDAL` may load the necessary `Base.convert` method.  The CRS WILL NOT BE SAVED as a .prj file.
└ @ Shapefile ~/Documentos/JuliaDev/Shapefile.jl/src/writer.jl:26
180812

julia> Shapefile.Table("countries.shp")
Shapefile.Table{Union{Missing, Shapefile.Polygon}} with 177 rows and the following 3 columns:

geometry, COUNTRY, REGION

Link to download the countries.geojson file: https://github.com/JuliaEarth/geospatial-data-science-with-julia/blob/main/data/countries.geojson

Copy link
Member

@rafaqz rafaqz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! this looks good to me

@eliascarv
Copy link
Contributor Author

Would it be possible to release a patch after merging the PR please?

@rafaqz rafaqz merged commit b75c1b9 into JuliaGeo:main Oct 3, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants