afhuertass

afhuertass

Plot map/geojson using Vega in Livebook

Hi!

I’m new to elixir world and to learn a few things I got into a project of fetching data from an API and plotting some stuff. The data I want to plot is map/geo data from a Finnish WebFeatureServer.

After fetching the data, I’m doing something like:

base_map =
  Vl.new(width: 400, height: 400)
  |> Vl.data_from_values(features ,format: :json , type: :featureCollection)
  |> Vl.projection(type: :mercator)
  |> Vl.mark(:geoshape)
  |> Vl.encode_field(:color, "properties.naiset", type: :quantitative)

where features is the list of features from the server, but the result is not what I hoped for: Pasteboard - Uploaded Image

I tried analysing the Vega Spec output, since I’m also new to Vega I’m not quite sure what I’m doing wrong (my guess is something with the scale or projection)

%{
  "$schema" => "https://vega.github.io/schema/vega-lite/v5.json",
  "data" => %{
    "format" => "json",
    "type" => "featurecollection",
    "values" => [
      %{
        "bbox" => [243238.7074, 7276001.5097, 627859.7, 7776430.911],
        "geometry" => %{
          "coordinates" => [
            [
              [412373.1985, 7276001.5097],
              [413803.717, 7277425.091],
              [427779.649, 7292121.84],
              [444538.768, 7291543.363],
              [451429.652, 7295129.029],
              [461616.22, 7300363.885],
              [461385.917, 7289578.81],
              [491950.939, 7286610.701],
              [503301.393, 7289791.985],
              [518535.957, 7313104.574],
              [523951.184, 7311273.286],
              [529768.18, 7315646.993],
              [534776.431, 7300873.374],
              [555960.827, 7298229.095],
              [569086.753, 7303600.565],
              [568767.928, 7308451.269],
              [562371.144, 7316158.058],
              [563104.105, 7320196.602],
              [570051.364, 7321770.669],
              [575008.83, 7319436.645],
              [579288.478, 7321216.143],
              [579928.398, 7325866.071],
              [573532.923, 7328766.401],
              [572435.541, 7335122.877],
              [577450.11, 7336119.469],
              [578610.673, 7349374.686],
              [571535.284, 7350680.086],
              [568892.525, 7357831.516],
              [575470.26, 7375090.259],
              [600847.92, 7367226.299],
              [600723.816, 7369982.334],
              [614767.566, 7370520.926],
              [612103.6, 7377488.2],
              [609809.277, 7382629.323],
              [606883.5, 7386978.2],
              [605693.5, 7389646.3],
              [604456, 7393092.6],
              [594548.9, 7408533.9],
              [593130.4, ...],
              [...],
              ...
            ]
          ],
          "type" => "Polygon"
        },
        "geometry_name" => "geom",
        "id" => "avi_vaki2020.6",
        "properties" => %{
          "avi" => "6",
          "ika_0_14" => 26094,
          "ika_0_14p" => 14.8,
          "ika_15_64" => 104662,
          "ika_15_64p" => 59.2,
          "ika_65_" => 45909,
          "ika_65_p" => 26,
          "miehet" => 88437,
          "miehet_p" => 50.1,
          "naiset" => 88228,
          "naiset_p" => 49.9,
          "name" => "Lapland AVI",
          "namn" => "Lapplands RFV",
          "nimi" => "Lapin AVI",
          "til_vuosi" => 2020,
          "vaesto" => 176665,
          "vaesto_p" => 3.2,
          "vuosi" => 2021
        },
        "type" => "Feature"
      }
    ]
  },
  "encoding" => %{"color" => %{"field" => "properties.naiset", "type" => "quantitative"}},
  "height" => 400,
  "mark" => "geoshape",
  "projection" => %{"type" => "mercator"},
  "width" => 400
}

Any ideas what can be going wrong?

Thanks for your time and I appreciate any help!

Thanks!

Where Next?

Popular in Questions Top

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New

We're in Beta

About us Mission Statement