Translate Latitude and Longitude values into X and Y coordinates on an Albers projection map

Trying to plot a point on a map with Albers projection using the given latitude and longitude coordinates, but encountering issues. The map is built with the Albers projection using standard parallels at 52 and 64 degrees with WGS 84. I attempted to implement the formulas for Albers projection in Javascript, but the results are incorrect. Seeking guidance as existing similar questions online did not provide relevant answers for my specific scenario.

// lat and long of left top corner
f0 = 66 * (Math.PI/180); 
a0 = 36 * (Math.PI/180);
// lat and long of my point
f = 55 * (Math.PI/180);
a = 37 * (Math.PI/180); 
// Standart parallers
f1 = 52 * (Math.PI/180);
f2 = 64 * (Math.PI/180);

n = 1/2 * (Math.sin(f1)+Math.sin(f2));
c = Math.pow(Math.cos(f1),2) + 2*n*Math.sin(f1);
t = n*(a*(180/Math.PI) - a0*(180/Math.PI))* (Math.PI/180);
p0 = 1/n * Math.sqrt(c-2*n*Math.sin(f0));
p=1/n*Math.sqrt(c-2*n*Math.sin(f));

x=p*Math.sin(t);
y=p0-p*Math.cos(t);

Any assistance would be greatly appreciated. Thank you.

Answer №1

Issue resolved Great news! I also need to calculate the Central Meridian for my map, and this code does the trick.

function albers(lat, lng) {

    var lat0 = 66 * (Math.PI/180),   // Latitude_Of_Origin
        lng0 = 105 * (Math.PI/180),  // Central_Meridian
        phi1 = 52 * (Math.PI/180),   // Standard_Parallel_1
        phi2 = 64 * (Math.PI/180),  // Standard_Parallel_2


        n = 0.5 * (Math.sin(phi1) + Math.sin(phi2)),
        c = Math.cos(phi1),
        C = c*c + 2*n*Math.sin(phi1),
        p0 = Math.sqrt(C - 2*n*Math.sin(lat0)) / n,
        theta = n * (lng * Math.PI/180 - lng0),
        p = Math.sqrt(C - 2*n*Math.sin(lat* Math.PI/180)) / n,

        x = p * Math.sin(theta),
        y = p0 - p * Math.cos(theta)

        return [x,y]
}

All accolades are due to https://gist.github.com/RandomEtc/476238

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

Creating a MongoDB query using Mongoose to simulate JavaScript filtering operations (including filter and every) for searching with multiple terms

Introducing a New Search Feature In my current project, I am implementing a search functionality using MongoDB with Mongoose ODM. The existing codebase already has a search feature using JavaScript. Here is a snippet of the code: terms.every((term) => ...

I am encountering difficulties trying to create a draggable stacked bar chart using d3 v4. The main challenge lies in properly translating the svg elements during the dragging process

const dragFunction = d3.drag() .on("start", startDrag) .on("drag", duringDrag) .on("end", endDrag) function startDrag(d) { d3.event.sourceEvent.stopPropagation(); d3.event.sourceEvent.pre ...

Guide on integrating an HTML and CSS register form in Django

I have successfully created a responsive register and login using HTML and CSS. Instead of utilizing the standard register form and login provided by Django upon configuration, I want to apply my own custom template. To summarize, while I am familiar with ...

Inquiry from a newcomer: ASP.NET with jQuery

I am working on a webform with a file upload button that has some specific requirements. Whenever the file is uploaded using the button, I need the C# code behind to execute first before any jquery functions are called. <script> $(document.read ...

What is the best way to trigger a JavaScript onclick event for a button that is located within a dropdown menu on an HTML page

I've implemented a feature that resizes the font size within a text area based on the selected font size. It was functioning flawlessly... until I decided to place the font size selection in a drop-down menu, which caused the feature to stop working. ...

"Angular encountering an error with converting a string to a date due to

I have a date stored as a string in the format '2022-07-15T09:29:24.958922Z[GMT]'. When I try to convert it to a date object, I am getting an error saying it is an invalid date. Can anyone help me with this issue? const myDate = response; / ...

A guide to exporting a class in ReactJS

I am currently working on exporting some classes from my music player file - specifically playlist, setMusicIndex, and currentMusicIndex. const playlist = [ {name: 'September', src: september, duration: '3:47'}, {name: 'hello ...

What is the best way to utilize a variable across all functions and conditions within an asynchronous function in Node.js?

I need to access the values of k and error both inside and outside a function. Initially, I set k to 0 and error to an empty string, but unexpectedly, the console prints out "executed". var k = 0; var error = ""; const { teamname, event_name, inputcou ...

I encountered an error while trying to deploy my next.js project on Vercel - it seems that the module 'react-icons/Fa' cannot be found, along with

I'm currently in the process of deploying my Next.js TypeScript project on Vercel, but I've encountered an error. Can someone please help me with fixing this bug? Should I try running "npm run build" and then push the changes to GitHub again? Tha ...

Experience Markdown's Single Input Update Feature

I have recently developed a Markdown editor using Vue, similar to the examples found on Vue's website. However, my query is more related to implementation rather than Vue itself. Therefore, I am open to suggestions that do not necessarily involve Vue. ...

How come my uvmapped texture is flipping vertically when using iewebgl + threejs?

Currently in the process of developing a 3D viewer for game pads with the aim of customizing the pad using various colors and materials. Initially, I created a simple ".bin .js" loader with sample materials using Threejs r62 to create a visualizer prototy ...

Uploading CouchDB document attachments using an HTML form and jQuery functionality

I am currently in the process of developing a web form that, upon submission, will generate a couchdb document and attach file(s) to it. I have followed tutorials and visited forums that suggest a two-stage process similar to futon's approach. While I ...

What is the best way to retrieve the current directory of the executed javascript file?

My javascript file is located in a folder at this path: /httpdocs/wp-content/themes/themeName/users/js I have some PHP files in another directory within the same theme, where I need to send Ajax Requests: /httpdocs/wp-content/themes/themeName/users Is ...

Splitting Code in React Components using Webpack within a Ruby on Rails Application

I'm currently integrating ReactJS components into my Rails application using the Webpack gem. However, I am facing an issue where the React components are only being loaded in specific areas within the layout of the Rails application. This results in ...

Utilize the $setValidity function within ng-repeat to validate input fields

I am facing an issue with my form that is being repeated in an ng-repeat. Below is a snippet of the form. I need to implement custom validation using $setValidity in the controller. However, I am struggling to access input names by index in the controlle ...

I'm attempting to create a button using html, but I'm puzzled as to why it's not functioning as expected

I've been working on creating a button that, when pressed, generates a new div string based on the node.innerHTML code. For some reason, my code doesn't seem to be functioning properly and I'm not sure why. Here's the HTML: <input ...

What are the best ways to prioritize custom events over ng-click events?

Recently, I developed a web application using AngularJS. One of the features I included was an input text box with a custom ng-on-blur event handler. Due to some issues with ng-blur, I decided to create my own custom directive called ngOnBlur. Here's ...

Does Next js Backend support multithreading as a default feature?

As I begin my project, I am utilizing the built-in Node js server within Next js by running the next start command. However, I am uncertain as to whether it has multithreading capabilities. My inquiry is this: Would you suggest sticking with the built-in ...

What to do when faced with an unexpected return in a requireJS application while running JSLint?

When setting up my application with `requireJS`, I have two key files: main.js is responsible for configuring everything, while app.js actually "runs" the application. This is how main.js is structured: /*jslint browser: true, indent : 2, nomen : true, ...

Is it possible to insert items into Vue component data? I'm interested in creating a table following JavaScript filtering and manipulation

I'm working on a website that will have multiple pages, each containing tables. To streamline this process, I wanted to create a table component. However, I haven't added any data to the tables yet because I need to manipulate it using JavaScript ...