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

Resolves felt/geo#193 #194

Merged
merged 5 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/geo/json/decoder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,16 @@ defmodule Geo.JSON.Decoder do
defp do_decode("Feature", nil, _properties, _id), do: nil

defp do_decode("Feature", geometry, properties, _id) do
do_decode(Map.get(geometry, "type"), Map.get(geometry, "coordinates"), properties, nil)
if geometry["type"] == "GeometryCollection" do
geometry_collection = decode!(geometry)
s3cur3 marked this conversation as resolved.
Show resolved Hide resolved

%GeometryCollection{
geometries: geometry_collection.geometries,
properties: properties
}
else
do_decode(Map.get(geometry, "type"), Map.get(geometry, "coordinates"), properties, nil)
end
end

defp do_decode(type, [x, y, _z], properties, crs) do
Expand Down
54 changes: 54 additions & 0 deletions test/geo/json_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,58 @@

assert(Geo.JSON.encode!(gc, feature: true) == expected)
end

test "Decode Feature with GeometryCollection geometry" do
# Similar to response from https://api.weather.gov/zones/county/FLC017
json = """
{
"@context": {
"@version": "1.1"
},
"id": "https://api.weather.gov/zones/county/FLC017",
"type": "Feature",
"geometry": {
"type": "GeometryCollection",
"geometries": [
{
"type": "MultiPolygon",
"coordinates": [[[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],[[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],[[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]]
},
{
"type": "MultiPolygon",
"coordinates": [[[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],[[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],[[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]]
}
]
},
"properties": {
"@id": "https://api.weather.gov/zones/county/FLC017",
"@type": "wx:Zone",
"id": "FLC017",
"type": "county",
"name": "Citrus",
"effectiveDate": "2023-09-19T18:00:00+00:00",
"expirationDate": "2200-01-01T00:00:00+00:00",
"state": "FL",
"cwa": [
"TBW"
],
"forecastOffices": [
"https://api.weather.gov/offices/TBW"
],
"timeZone": [
"America/New_York"
],
"observationStations": [],
"radarStation": null
}
}
"""

geom = Jason.decode!(json) |> Geo.JSON.decode!()

assert %GeometryCollection{} = geom

Check failure on line 525 in test/geo/json_test.exs

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.14.4, 23.3.4)

** (CompileError) test/geo/json_test.exs:525: GeometryCollection.__struct__/0 is undefined, cannot expand struct GeometryCollection. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code

Check failure on line 525 in test/geo/json_test.exs

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.13.4, 22.3)

** (CompileError) test/geo/json_test.exs:525: GeometryCollection.__struct__/0 is undefined, cannot expand struct GeometryCollection. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code

Check failure on line 525 in test/geo/json_test.exs

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.14.4, 25.3.2)

** (CompileError) test/geo/json_test.exs:525: GeometryCollection.__struct__/0 is undefined, cannot expand struct GeometryCollection. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code

Check failure on line 525 in test/geo/json_test.exs

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.11.4, 22.3)

** (CompileError) test/geo/json_test.exs:525: GeometryCollection.__struct__/0 is undefined, cannot expand struct GeometryCollection. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code

Check failure on line 525 in test/geo/json_test.exs

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.12.3, 23.3.4)

** (CompileError) test/geo/json_test.exs:525: GeometryCollection.__struct__/0 is undefined, cannot expand struct GeometryCollection. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code

Check failure on line 525 in test/geo/json_test.exs

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.13.4, 25.3.2)

** (CompileError) test/geo/json_test.exs:525: GeometryCollection.__struct__/0 is undefined, cannot expand struct GeometryCollection. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code

Check failure on line 525 in test/geo/json_test.exs

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.11.4, 24.3.4)

** (CompileError) test/geo/json_test.exs:525: GeometryCollection.__struct__/0 is undefined, cannot expand struct GeometryCollection. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code

Check failure on line 525 in test/geo/json_test.exs

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.12.3, 22.3)

** (CompileError) test/geo/json_test.exs:525: GeometryCollection.__struct__/0 is undefined, cannot expand struct GeometryCollection. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code

Check failure on line 525 in test/geo/json_test.exs

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.12.3, 24.3.4)

** (CompileError) test/geo/json_test.exs:525: GeometryCollection.__struct__/0 is undefined, cannot expand struct GeometryCollection. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code

Check failure on line 525 in test/geo/json_test.exs

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.11.4, 23.3.4)

** (CompileError) test/geo/json_test.exs:525: GeometryCollection.__struct__/0 is undefined, cannot expand struct GeometryCollection. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code

Check failure on line 525 in test/geo/json_test.exs

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.13.4, 23.3.4)

** (CompileError) test/geo/json_test.exs:525: GeometryCollection.__struct__/0 is undefined, cannot expand struct GeometryCollection. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code

Check failure on line 525 in test/geo/json_test.exs

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.14.4, 24.3.4)

** (CompileError) test/geo/json_test.exs:525: GeometryCollection.__struct__/0 is undefined, cannot expand struct GeometryCollection. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code

Check failure on line 525 in test/geo/json_test.exs

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.14.4, 26.0.2)

** (CompileError) test/geo/json_test.exs:525: GeometryCollection.__struct__/0 is undefined, cannot expand struct GeometryCollection. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code

Check failure on line 525 in test/geo/json_test.exs

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.13.4, 24.3.4)

** (CompileError) test/geo/json_test.exs:525: GeometryCollection.__struct__/0 is undefined, cannot expand struct GeometryCollection. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code
assert length(geom.geometries) == 2
assert Enum.all?(geom.geometries, &match?(%Geo.MultiPolygon{}, &1))
assert geom.properties["id"] == "FLC017"
end
end
Loading