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: https://pasteboard.co/Qsrt4CyZXwAy.png

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

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
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
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
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
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
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
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New

We're in Beta

About us Mission Statement