Fix error raised when decoding JSON with string representations of integer values in coordinates by new contributor @IceDragon200.
Potentially breaking change: Default decoded GeoJSON to SRID 4326 (WGS 84)
This aligns our GeoJSON decoding with the GeoJSON spec by making all decoded GeoJSON infer the WGS 84 datum (SRID 4326) by default. Whereas previously when you called Geo.JSON.decode/1
or decode!/1
, we would return geometries with an :srid
of nil
, we now return srid: 4326
. Likewise when encoding GeoJSON, we explicitly output a crs
field indicating the datum.
This is unlikely to break real-world usage unless your implementation was assuming a different datum by default.
A couple examples of the changes:
Before:
iex> Geo.JSON.decode!(%{"type" => "Point", "coordinates" => [1.0, 2.0]})
%Geo.Point{
coordinates: {1.0, 2.0},
# Note the old default nil SRID!
srid: nil
}
After
iex> Geo.JSON.decode!(%{"type" => "Point", "coordinates" => [1.0, 2.0]})
%Geo.Point{
coordinates: {1.0, 2.0},
# New explicit default of WGS 84
srid: 4326
}
If you were to then encode this value again, you'd end up with a new crs
field in the output GeoJSON:
iex> %{"type" => "Point", "coordinates" => [1.0, 2.0]}
...> |> Geo.JSON.decode!()
...> |> GeoJSON.encode!()
%{
"type" => "Point",
"coordinates" => [1.0, 2.0],
# Note the new `crs` field which was not present in the input to Geo.JSON.decode!/1
"crs" => %{"properties" => %{"name" => "EPSG:4326"}, "type" => "name"}
}
This last behavior is the most potentially troublesome. However, we don't have a good way of distinguishing a case where you explicitly had the crs
set in the input to the decoding function (in which case you would probably also like to have it present in the re-encoded version) compared to one in which it's been inferred.
Thanks to @gworkman for reporting this issue (#129).
Potentially breaking change: Convert string coordinates to floats, or raise an error
This fixes an issue where we were silently accepting non-numeric coordinates in the GeoJSON decoder, such that you could wind up doing things like decoding a point like %Geo.Point{coordinates: {"100.0", "-10.0"}}
. This would obviously not have gone well for you later in your processing pipeline, and it violates our typespecs.
The fix here, suggested by @LostKobrakai, is to convert those strings to numbers where we can do so unambiguously. While such inputs are clearly invalid, it's easy enough to handle them in the way that the user was hoping that we should probably just do it. In cases where there's any ambiguity at all, we raise an ArgumentError
.
- Support GeoJSON Feature object with nested GeometryCollection by new contributor @carstenpiepel (🎉)
- Fix typo in the README by @caspg
- Fix typo by new contributor @preciz (🎉)
- Optional dependency bump for
jason
to v1.4.4 - Dev dependency bumps for ex_doc, benchee, stream_data
As of v3.6.0, geo
(like geo_postgis
) is being maintained by the Felt team. As a company building a geospatial product on Elixir, with a track record of supporting open source software, we're excited for the future of the project.
- Add support for empty point by new contributor @bolek
- Add support for LineStringZM by new contributor @kanatohodets
- Support decoding MultiLineStringZ by new contributor @caspg
- Fix compile warnings (#186 by @s3cur3)
- Docs improvements (#177 by new contributor @ghecho, #182 by @s3cur3)
- Dependency updates:
ex_doc
(#185),jason
(#183),stream_data
(#184)
Full Changelog: https://github.com/felt/geo/compare/v3.5.1...v3.6.0
- Enhancement
- Fix
- Fix
-
Add
Geo.WKB.encode_to_iodata
-
Enhancements
- The implementation of encoding and decoding WKBs has been updated to use iodata instead of binaries, improving overall performance.
Geo.WKB.decode!
andGeo.WKB.decode
can now take iodata in addition to binary data
- Fix
- Enhancement
- Fixed
- Typespec on Point
- Fixed
- Some optimizations based on benchmarking
- Fixed
- Bugs found while property testing
-
Fixed
-
Added
-
Add
Geo.WKT.encode!
Geo.WKT.decode!
Geo.WKB.encode!
Geo.WKB.decode!
Geo.JSON.encode!
Geo.JSON.decode!
-
Enhancement
- Geometry struct now have a
properties
field. This is used to convert GeoJSON properties
- Geometry struct now have a
-
Breaking
Geo.WKT.encode
now returns either{:ok, binary}
or{:error, exception}
Geo.WKT.decode
now returns either{:ok, geometry}
or{:error, exception}
Geo.WKB.encode
now returns either{:ok, binary}
or{:error, exception}
Geo.WKB.decode
now returns either{:ok, geometry}
or{:error, exception}
Geo.JSON.encode
now returns either{:ok, map}
or{:error, exception}
Geo.JSON.decode
now returns either{:ok, geom}
or{:error, exception}
- All Ecto.Type behaviour implementations were removed. This may not effect too many people, but it was moved to the geo_postgis package
- Fix
- Make stricter patterns for casts functions so that error pattern is used when types are wrong
- Change handling of EPSG/SRID to match standard
- Fix String.strip() deprecations in Elixir 1.5+
- Breaking
- Split out PostGIS functionality into its own library, geo_postgis
- Enhancement
- Enhancements
- Enhancements
- Relax Poison dependency requirement
-
Enhancements
-
Breaking
- Now only supports Postgrex 0.13+
- Now only supports Ecto 2.1+
- Enhancements
- Enhancements
- Bug Fixes
- WKBs that are GeometryCollections with one element should now properly decode
- Enhancements
- Added
Geo.JSON.EncodeError
andGeo.JSON.DecodeError
thrown wheneverGeo.JSON.encode
orGeo.JSON.decode
are given invalid data
- Added
- Enhancements
- Add Geo.Geometry custom Ecto type to allow multiple geometries in a single field
- Enhancements
- Fixed warnings that appeared in Elixir 1.3
- Enhancements
- Update to allow use with Ecto 2.0
- Enhancements
- Ecto.Type: matching on geojson properties so that Ecto.DataType can be used by users
- Enhancements
- Updated dependencies to allow for using ecto 2.0 release candidate versions
- Enhancements
- Updated dependencies to allow for using ecto 2.0 beta versions
- Enhancements
- Updated Postgrex and Poison optional dependencies
- Enhancements
- Made Postgrex, Ecto, and Poison optional dependencies
- Breaking
- Geo.JSON.encode and Geo.JSON.decode now do not do any JSON parsing at all and instead work on a map representation of GeoJSON. All JSON encoding and decoding must be done before or after calling those functions.
- Enhancements
- Made Postgrex a required dependency
- Enhancements
- Updated to Ecto 1.0
- Enhancements
- Added an
opts
parameter toGeo.JSON.encode
to allow for skipping JSON encoding
- Added an
- Enhancements
- Fixed st_dwithin macro
- Enhancements
- Updated cast function on structs to handle maps and strings
- Now reading the srid from geo json
- Enhancements
- Basic Support for Geography datatype
-
Enhancements
- Added PostGIS function macros for use in Ecto Queries. Currently only the OpenGIS ones
-
Breaking
Geo.PostGIS
is nowGeo.PostGIS.Extension
- Changed from Jazz to Poison for JSON encoding and decoding
- Enhancements
- Geo.PostGIS is now a Postgrex Extension
- Updated to work with latest version of Ecto
- Bug fixes
- Correctly decoding WKB strings that caused invalid geometries to be produced when there is one element in a multi geometry
- Bug fixes
- Fixed bug when decoding multi geometry wkb with one geometry inside would cause a crash
-
Enhancements
- Created structs for the supported geospatial types (Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, GeometryCollection)
- GeoJson module will encode the srid as a crs property if an srid exists
-
Backwards incompatible changes
- Removed the Geometry struct. Use one of the geometry type structs instead
- The base coordinate pairs are now tuples ({0,0} instead of [0,0])