Leveraging D3 for converting NZTM2000 coordinates to WGS84

I've been having some difficulties converting NZTM2000, a variant of the Transverse Mercator projection used in New Zealand (), to WSG84 latitude/longitude coordinates.

The specifications for NZTM2000 state that the TM is set up with the following parameters:

  • Origin latitude: ° 00' 00" South
  • Origin longitude / central meridian:173° 00' 00" East
  • False Northing:10,000,000 meters North
  • False Easting:1,600,000 meters East
  • Central meridian scale factor:0.9996

I attempted to apply them in S3:

var projection = d3.geo.transverseMercator()
    .rotate([origin_lat, origin_lng])
    .scale(scale_factor)
    .center([false_northing, false_easting])

(as well as other methods).

I was working with a small dataset containing known WGS84 values:

NZTM2000                WSG84
---------------------   -------------------------------
Northing     Easting     Latitude        Longitude
5771280.5   1900560.5   38 09 22.691 S  176 25 48.538 E
5771280.5   1900570.5   38 09 22.679 S  176 25 48.948 E
5771280.5   1900571.5   38 09 22.678 S  176 25 48.989 E
5771280.5   1900572.5   38 09 22.677 S  176 25 49.030 E

Any assistance would be greatly appreciated.

Many thanks

Answer №1

I recently discovered a helpful solution on the LINZ site. They have already developed the algorithm in C, which can be found at .

Furthermore, someone has converted it to C# and shared it on GitHub at https://github.com/leighghunt/nztm/blob/master/nztm/nztm.cs.

I took this latest version and successfully ported it to JavaScript.

If you're interested, feel free to reach out to me for my version.

========= Would you mind sharing the JavaScript version on GitHub? I could really use it.

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

Trouble with running dynamically injected <SCRIPT> tags in Firefox version 47.0

After making an AJAX call, I receive an HTML snippet that looks like this: <SCRIPT src="..." type="text/javascript"></SCRIPT> <SCRIPT type="text/javascript"> function showForumGrid() { ... }; function f() { ...} </SCRIPT> < ...

Select DOM Elements Using JavaScript CSS Queries

As I delved into JavaScript in an attempt to craft my personal slider, I stumbled upon a perplexing discovery. I encountered a CSS regulation that looked like this: html.js #slideshow .slides img { position: absolute; } The explanation suggested that ...

how to change class on vue function result

I need a way to display the content stored in requestData as li elements. Each list item should have an onclick function that, when clicked (selected), adds a specific value from a reference to an array. If clicked again (unselected), it should remove the ...

Is there a library available that can assist me in writing JavaScript code within C#?

Currently, I am in search of a tool that can assist me in writing C# code that will automatically convert to JavaScript. The main benefits I am seeking are improved code-completion and type-safety. Specifically, I am interested in the following features: ...

Ways to update a component when the value of a Promise is altered

I am struggling with Vue component re-rendering due to a problem related to consuming data from a Promise. The data is fetched and stored under the specific property chain (visualData.layout.cube...), where I assign values to DATA properties (such as label ...

JavaScript function to close mobile menu when menu item is clicked

https://i.sstatic.net/GfKem.png I have a dilemma with my HTML code. I am trying to figure out how to collapse the menu when clicking on a menu item using JavaScript. I have been stuck on this for two days now. Can anyone provide a solution with an explanat ...

What are the best techniques for achieving flawless ring geometry in three.js?

I'm struggling to achieve perfect ring geometry in three.js, similar to the image here: https://i.sstatic.net/ArxKa.png After spending over a day troubleshooting, my code currently looks like this: var scene = new THREE.Scene(); var camera = new TH ...

What is the proper way to retrieve an object from a json file?

My JSON structure looks like this: { "total": 4367, "page": 1, "per_page": 10, "paging": { "next": "/videos?query=second%20world%20war&per_page=10&access_token=XXX&page=2", "previous": null, "first": "/v ...

Struggling to incorporate blocks into Jade for Express. Encountering errors like "Max Stack Size Exceeded" and issues with setHeader

I am currently using Express along with a simple express-generator server that I created. My first task was to focus on creating the view layout and extending the index page, but unfortunately, I have encountered some challenges. Throughout my process, I& ...

I am looking to modify the background color of the columns in an Ant Design table based on whether the index of my data is even or odd

I am trying to change the background color of the columns in an Ant Design table based on the index of my data being even. Can anyone provide suggestions on how to achieve this? I have my data in a list and I want to set a condition through a loop to cha ...

Tips for aligning the camera to ensure the object maintains a consistent pixel width and height on the screen

I am grappling with a challenge that I'm unsure how to approach, hoping someone can offer me a clue on the solution. My goal is to position the camera at a specific z index so that a cube appears on the screen with consistent pixel dimensions regardl ...

Is it necessary to wait for client responses in order to execute code with socket.io?

When both clients have submitted their answers, I want to execute certain code using the functions finish() and datarequest();. Currently, the code waits for both responses and does not emit just after one client answers. However, it fails to reach my if ...

Ways to maintain scroll position unaffected by postback?

In my JavaScript code, I have an event set to trigger at regular time intervals that clicks on a specific ASP button. This event is part of a chat room application where the gridview inside a panel needs to be refreshed frequently to display new chats. H ...

The error in ReactJS is coming from the render method of the `News` component

While working with React JS, I encountered an error when trying to run a particular code snippet. The error message displayed was: "Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got ...

Determine the difference in time

There are two input types for time: 1. Time of entry. 2. Time of exit. For example: Start: 00:00 End: 01:30 Result: 1.5 Start: 14:00 End: 00:00 Result: 10 An algorithm needs to be created to calculate the number of employees working at a given time. Th ...

Encountering a CORS policy error in Three.js when attempting to run locally

I'm just starting out on this website and I'm eager to dive into learning javascript. My initial attempt at following this example from resulted in an error without any animation or background showing up. Instead, all I see is a photo displayin ...

Express.js fails to handle HTTPS POST requests

I am facing an issue with serving HTTPS and listening to POST requests as the server is not responding to the request. My environment includes node 0.12.6 and express 4.13.3. I suspect that the routing configuration might be causing the problem, but I am ...

Building secure applications with React and Express using private routes

In my experience, I have primarily utilized server-side rendering solutions to transfer data from the server to the client and display it in the browser. One of the key advantages of this approach is the ability to access data and send it to the client wi ...

Demonstration of Concurrent Page Processing in Flask

Currently, I am working on an application that heavily utilizes graphics using libraries such as Raphael and graphdracula. The main functionality of the application involves drawing various graphs across different pages named graph1, graph2, and graph3. L ...

Is it advisable to incorporate Material-UI into a React project?

When it comes to designing a login page in react, I stumbled upon material-ui. The real question is, should we utilize Material-UI for this purpose? Furthermore, how can we manage styles in a separate file in the given examples? It seems logical to place t ...