Skip to content

FeatureCollection decoded into GeometryCollection #228

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

Open
evancloutier opened this issue Jan 22, 2025 · 0 comments
Open

FeatureCollection decoded into GeometryCollection #228

evancloutier opened this issue Jan 22, 2025 · 0 comments

Comments

@evancloutier
Copy link

Hiya!

I started using this library to transform results from GDAL ogr2ogr CLI executions into structured GeoJSON.

I noticed that if a FeatureCollection is passed into Geo.JSON.decode!/1, it is returned as a %Geo.GeometryCollection{}.

As an example, consider the following GeoJSON:

%{
  "features" => [
    %{
      "geometry" => %{
        "coordinates" => [
          [
            [-76.34699604768392, 36.33170421172728],
            [-76.33589514587374, 36.332348509701035],
            [-76.33512736015777, 36.32399799501997],
            [-76.34610029768193, 36.32337940277699],
            [-76.34699604768392, 36.33170421172728]
          ]
        ],
        "type" => "Polygon"
      },
      "properties" => %{"id" => "567"},
      "type" => "Feature"
    },
    %{
      "geometry" => %{
        "coordinates" => [
          [
            [-76.33554324408723, 36.3323227378844],
            [-76.32210699405763, 36.33325051791261],
            [-76.3202515119107, 36.325080519630006],
            [-76.33487143158575, 36.32410109324975],
            [-76.33554324408723, 36.3323227378844]
          ]
        ],
        "type" => "Polygon"
      },
      "properties" => %{"id" => "456"},
      "type" => "Feature"
    },
    %{
      "geometry" => %{
        "coordinates" => [
          [
            [-76.36231977093198, 36.33703883835424],
            [-76.35771305663607, 36.337296540535085],
            [-76.3571372173491, 36.331420718930794],
            [-76.36174393164497, 36.331420718930794],
            [-76.36231977093198, 36.33703883835424]
          ]
        ],
        "type" => "Polygon"
      },
      "properties" => %{"id" => "234"},
      "type" => "Feature"
    },
    %{
      "geometry" => %{
        "coordinates" => [
          [
            [-76.31868394940722, 36.31925532901004],
            [-76.30972644938747, 36.32023481628918],
            [-76.30793494938354, 36.3127594703222],
            [-76.31702041368928, 36.31162521726675],
            [-76.31868394940722, 36.31925532901004]
          ]
        ],
        "type" => "Polygon"
      },
      "properties" => %{"id" => "123"},
      "type" => "Feature"
    }
  ],
  "name" => "farm_fields",
  "type" => "FeatureCollection"
}

Calling Geo.JSON.decode! on this data will result in a %Geo.GeometryCollection{} to be returned. The properties are preserved in the Geo structs – which is great – but won't be interpreted by other GeoJSON consumers (unless I'm misunderstanding here) because they're not technically part of the spec.

Is there a reason why there isn't first class FeatureCollection support in Geo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant