Error message displayed when attempting to render a D3.js geoPath map: <path> attribute d is expecting a number

Currently struggling with creating a map using D3.js

The given code functions properly with certain JSON files, but when I try to use the necessary data, it's throwing a series of errors like this:

Error: attribute d: Expected number, "….21478248741596,NaNL547.70469610…".

Instead of the expected map of England, I'm seeing a different image

This is the code snippet in question:

const width = 800
const height = 800

const svg = d3.select('svg')
  .append('g')
  .attr('class', 'map');

const projection = d3.geoMercator()

Promise.all([
  d3.json('https://raw.githubusercontent.com/joewretham/d3_map_project/main/Clinical_Commissioning_Groups__April_2019__Boundaries_EN_BUC.json')
]).then(
  d => ready(null, d[0], d[1])
);

function ready(error, data) {

  var fixed = data.features.map(function(feature) {
    return turf.rewind(feature, {
      reverse: true
    });
  });

  const path = d3.geoPath().projection(projection);

  projection.fitSize([width, height], {
    "type": "FeatureCollection",
    "features": fixed
  })

  svg.append('g')
    .attr('class', 'countries')
    .selectAll('path')
    .data(fixed)
    .enter().append('path')
    .attr('d', path)
    .style('fill', "teal")
    .style('stroke', 'white')
    .style('opacity', 0.8)
    .style('stroke-width', 0.3);
};
<script src="https://d3js.org/d3.v5.min.js"></script>
<script src='https://npmcdn.com/@turf/turf/turf.min.js'></script>
<svg id="partitionSVG" width="800" height="800">"</svg>

Seeking assistance on why this error occurs specifically with this set of data compared to others that work without issues. I assume it has something to do with the coordinates requiring transformation, but I lack expertise in geographic data to understand how to resolve it.

Appreciate any guidance provided

Joe

Answer №1

Your JSON data features a unique projection that differs from the standard lat/long format. While latitude and longitude are commonly used, there are various projections due to the complexities of representing a spherical earth mathematically. The prevalent WGS84 (4326) system typically employs lat/long coordinates, but different national systems like the UK's OSGB36 also exist.

By utilizing this tool, I successfully converted your data from OSGB36 to WGS84 for accurate results:

const width = 800
const height = 800

// Code block for data processing using D3.js and Turf.js

If you have control over the data generation process, consider adjusting the input file once or apply this transformation as needed.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The JavaScript rock, paper, scissors application is experiencing issues with displaying correctly

Currently, I am in the process of learning JavaScript and working on developing a rock, paper, scissors game using only JavaScript. The game will have two modes- a single round mode and a three-round mode. However, after completing the code for the singl ...

The Jquery click menu is functional, but appears completely translucent in Safari and the majority of mobile browsers

I have implemented a link that, when clicked, should reveal a menu on the website. This feature is specifically optimized for smaller browser windows with a breakpoint set at 965px. However, I am encountering some varied behaviors across different browsers ...

Get rid of the loaded element once the fancybox is closed

Is there a way to clear the data loaded through an ajax call so that when I click on another image, only the relevant images are displayed? Below is my code for implementing fancybox: $(document).ready(function () { $("[data-fancybox]").fancybox({ ...

Combine identical items in a JavaScript array based on how often they appear

I have an array in JavaScript that looks like this: [ { quantity: 1, name: 'Menu sandwiches' }, { quantity: 1, name: 'Menu sandwiches' }, { quantity: 1, name: 'Menu sandwiches' }, { quantity: 1, name: 'Pizza' ...

Generating Google Charts using PHP Arrays

Can someone assist me in incorporating PHP data into Google Charts? I have managed to create a basic array $chart_arr = array($year, $new_balance); json_encode($chart_arr); When I execute <?php echo json_encode($chart_arr);?> I receive the follo ...

Is there a way to calculate the bounding box of an object using Three.js?

function loadModel(){ switchCamera("orthographic"); var modelLoader = new THREE.JSONLoader(); modelLoader.load("models/sphere.json", callBack); } function callBack(object3D_geometry){ var material = new THREE.MeshLambertMaterial( { color ...

Retrieving the values of multiple selected options from various select fields simultaneously

Picture having a dynamic number of select fields (the value of this variable is not fixed). I am looking to extract the values of the selected option from each select field using jQuery (or vanilla JavaScript). This is my approach: var cars = $(".sele ...

I'm struggling to find a solution that allows FOSRestBundle to seamlessly integrate JSON and HTML formats

I am working on a blog site where the main entities are Blogposts and Users. My goal is to make these blogposts visible through JSON GET requests for mobile devices, while also having a default route that returns the HTML (including CSS). Despite searchin ...

Setting the content-type for static assets in NuxtJS

I'm trying to use the Nuxt built-in server to serve the static file /.well-known/apple-app-site-association with a content-type of application/json. Unfortunately, because the file does not have a .json extension, it is returning as application/octet- ...

Implementing Kendo UI dataSource to interact with a PHP function

Greetings Everyone, I have a category.php file within my code that handles CRUD functions. However, I am unsure how to call these functions in the Kendo UI dataSource/transport. Previously, I had separated the PHP files, but now I want to consolidate them ...

Using Jackson in Java to handle JSON data without the use of Plain Old

I am in the process of migrating a node project to Dropwizard. Currently, the node project stores JSON data from the client as a string and serves it back to the client as application/JSON when requested - essentially functioning as a Key/value store reset ...

What could be causing the undefined value of this Angular class property?

Currently, I am working on an Angular project that aims to create lobbies for various web games. The concept is to gather players through the application so that a web game can be initiated quickly. However, I have encountered an issue where data retrieve ...

Setting up Node.js for production on Nginx: A comprehensive guide

I am working on developing a chat system using angularjs and nodejs. To enable message sending and receiving, I have implemented socket.io. Initially, I set up a node.js server using localhost cmd. Everything is functioning properly, but now I need to dep ...

Tips for implementing jQuery overlay to display radio buttons in a popup window

Following a tutorial, I created an alert window with radio buttons added for user input. You can view the online demo here. The modified source code with the radio buttons is provided below. Below you'll find where I added the radio buttons and how I ...

This function is designed to only work under specific conditions

Looking for assistance with a function that takes an item ID as input and changes its border when pressed. The goal is to increase the border width by 2px when there is no border, and remove the border completely when pressed again. Currently, only the f ...

Update the link to a KML file used by Google Maps when a button is clicked

On the initial page load, I want to showcase an 8 Day Average KML file on Google Maps. However, users should have the option to click on the "1 Day" and "3 Day" buttons to switch the reference in Google Maps from the "8 Day" file. The aim is to design a s ...

Generating consecutive numerical values within the auto table JSPDF column VusJs

https://i.sstatic.net/idhrw.png columns: [ { header: 'No', dataKey: 'Index', }, { header: 'No Registrasi', dataKey: 'no_register' }, { header: 'Kode Partai', data ...

json.decoder.JSONDecodeError: Additional content found at line 1, character 139810, which is causing an error in decoding

My goal is to access the values.json file (which can be found at ) but I'm encountering an error. values = json.load(file) r = requests.get("https://www.rolimons.com/itemapi/itemdetails") with open("values.json", " ...

Unresolved promise: Internal server issue

I encountered an exception while working on my Nativescript app. EXCEPTION: Uncaught (in promise): Server error JS: ORIGINAL STACKTRACE: JS: Error: Uncaught (in promise): Server error JS: at resolvePromise (/data/data/com.yourdomain.appname/files/app/ ...

Vue.js 2.0 experiences delays when making changes to irrelevant data

Imagine you have an input field in Vue.JS with a v-model that binds to a String data property, and a long list of random numbers that are completely unrelated to the first String. data: { input: "", randoms: [] } <input type="text" v-model="input" ...