Skip to content

Commit

Permalink
Exports GeoJSON venant de ODS en tant que geojson (#2256)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti authored Mar 22, 2022
1 parent dc1e883 commit 47b8e45
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions apps/transport/lib/transport/import_data.ex
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,12 @@ defmodule Transport.ImportData do
iex> %{"url" => "https://example.com/gbfs/free_bike_status.json", "format" => "json"}
...> |> ImportData.formated_format("bike-scooter-sharing", false)
"json"
iex> ImportData.formated_format(%{"title" => "Export au format GeoJSON", "format" => "json"}, "low-emission-zones", false)
"geojson"
iex> ImportData.formated_format(%{"format" => "GeoJSON"}, "low-emission-zones", false)
"geojson"
"""
@spec formated_format(map(), binary(), bool()) :: binary()
# credo:disable-for-next-line
Expand All @@ -615,12 +621,18 @@ defmodule Transport.ImportData do
is_gtfs?(format) -> "GTFS"
is_siri_lite?(format) -> "SIRI Lite"
is_siri?(format) -> "SIRI"
is_geojson?(resource, format) -> "geojson"
type == "public-transit" and not is_community_resource -> "GTFS"
type == "bike-scooter-sharing" and is_gbfs?(resource) -> "gbfs"
true -> format
end
end

# Classify GeoJSONs from ODS as geojson instead of json
# See https://github.com/opendatateam/udata-ods/issues/211
defp is_geojson?(%{"title" => "Export au format GeoJSON"}, _), do: true
defp is_geojson?(_, format), do: is_format?(format, ["geojson"])

defp is_gbfs?(%{"url" => url}) do
if String.contains?(url, "gbfs") do
Enum.all?(["free_bike", "station"] |> Enum.map(fn w -> not String.contains?(url, w) end))
Expand Down

0 comments on commit 47b8e45

Please sign in to comment.