How to read geojson with vega

会有一股神秘感。 提交于 2019-12-23 03:12:18

问题


It sounds super simple, but I can't get how can I use geojson, not topojson, for my polygons.

that's my current attempt:

"data": [
    {
      "name": "nabs",
      "url": "both_boundaries.geojson",
      "format": {"type": "json"},
      "transform": [
      {
        "type": "geopath", "projection": "mercator",
        "scale": 74, "center": [-73.99,40.72]
      }
    ]
    }
  ]

回答1:


You have to parse the features using property within your format:

   "format": {"type": "json", "property":"features"},

Full example spec:

{"$schema": "https://vega.github.io/schema/vega/v3.0.json",
  "width": 500,
  "height": 600,
  "autosize": "none",
  "signals": [
    {
      "name": "translate0",
      "update": "width / 2"
    },
    {
      "name": "translate1",
      "update": "height / 2"
    }
  ],
  "projections": [
    {
      "name": "projection",
      "size": {"signal": "[width, height]"},
      "fit": {"signal": "data('netherlands')"}
    }
  ],
  "data": [
    {
      "name": "netherlands",
      "url": "https://raw.githubusercontent.com/mattijn/datasets/master/NL_outline_geo.json",
      "format": {
        "type": "json",
        "property": "features"
      }
    }
  ],
  "marks": [
    {
      "type": "shape",
      "from": {
        "data": "netherlands"
      },
      "encode": {
        "update": {
          "strokeWidth": {
            "value": 0.5
          },
          "stroke": { 
            "value": "darkblue"
          },
          "fill": {
            "value": "lightblue"
          },
          "fillOpacity": {
            "value": 0.5
          }
        },
        "hover": {
          "fill": {
            "value": "#66C2A5"
          },
          "strokeWidth": {
            "value": 2
          },
          "stroke": {
            "value": "#FC8D62"
          }
        }
      },
      "transform": [
        {
          "type": "geoshape",
          "projection": "projection"
        }
      ]
    }
  ]
}


来源:https://stackoverflow.com/questions/48031542/how-to-read-geojson-with-vega

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!