5
$\begingroup$

I want to plot the new parliamentary boundaries for the upcoming general election.

This will use an NIHR API to grab the map location of the FID=3, the 3rd parliamentary constituency in alphabetical order - Altrincham and Sale West.

response = 
 URLExecute[
  "https://nihr.opendatasoft.com/api/explore/v2.1/catalog/datasets/\
westminster-parliamentary-constituencies/records?where=fid%3D3&limit=\
20", "JSON"]

coordinates = response[[2, 2, 1, 2, 2, 2, 2, 1]] (* these are the coordinates in the JSON, surely there is a better way to grab this? *) 

enter image description here

GeoListPlot[coordinates[[2, 1]]]

When I go to plot this - it doesn't fail, just plots the world. It seems to be a GeoJSON, and when I go to plot this - it says I cannot import the GeoJSON.

enter image description here

$\endgroup$

1 Answer 1

6
$\begingroup$

You need to fix a few things here:

  • I'd use GeoGraphics not GeoListPlot. If you insist on GeoListPlot use something like:

     GeoListPlot[Polygon[Reverse /@ coordinates[[2, 1]]]]
     GeoListPlot[GeoPosition[Reverse /@ coordinates[[2, 1]]]]
    
  • GeoPolygon[...] - You need a graphics primitive to show up on the map -- coordinates by itself do nothing inside GeoGraphics

  • Reverse - Longitude and Latitude can get reversed in some data formats and systems, like in this case. So I flipped them.

Result after these fixes:

GeoGraphics[{
 EdgeForm[Directive[Red, Thick]], 
 GeoPolygon[Reverse /@ coordinates[[2, 1]]]},
ImageSize -> 1000]

enter image description here

Use GeoBackground for different stylings:

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.