J
J
Jhonnyman2022-02-23 09:45:13
Geometry
Jhonnyman, 2022-02-23 09:45:13

How to correlate real coordinates with map coordinates?

There are a number of points with real coordinates that need to be displayed on the map, and vice versa, get real coordinates from points on the map.
I'm using d3js and there's a scaleLinear function that expects two ranges, after which I can enter any number from the first range and get the corresponding number from the second.
And it seems like everything is simple, but taking into account the inversion of the y-axis (so as on real maps), and the rectangularity of the map, the points are drawn incorrectly, not to scale and elongated.
Maybe there is some formula or a general algorithm of actions?

Here's how I'm doing it now

map: {
    width: 1000,
    height: 500,
},
real: {
    minX: 50000,
    maxX: 100000,
    minY: 50000,
    maxY: 100000,
},
// ...

var mapCoef = this.map.height / this.map.width;
this.mapX = d3.scaleLinear().domain([this.real.minX, this.real.maxX]).range([0, this.map.width]);
this.mapY = d3.scaleLinear().domain([this.real.minX * mapCoef, this.real.maxX * mapCoef]).range([this.map.height, 0]);

// this.mapX, this.mapY - функции получения карточных координат по реальным координатам

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hint000, 2022-02-24
@hint000

If there are difficulties with the finished function, then what the hell, it’s faster to do it with your hands than to suffer, the formulas are the simplest:

// map.minX=0;
// map.maxX=map.width;
// map.minY=0;
// map.maxY=map.height;
// realX=...
// realY=...
// mapX=...
// mapY=...
realX=real.minX+(real.maxX-real.minX)*(mapX-map.minX)/(map.maxX-map.minX);
mapX=map.minX+(map.maxX-map.minX)*(realX-real.minX)/(real.maxX-real.minX);
realY=real.minY+(real.maxY-real.minY)*(map.maxY-mapY)/(map.maxY-map.minY);
mapY=map.minY+(map.maxY-map.minY)*(real.maxY-realY)/(real.maxY-real.minY);

I don't know any particular language, so make sure the operations are real and not integer.

A
alekseiami, 2022-03-09
@alekseiami

The coordinates of a point on the ground are latitude and longitude. Angular values. Let there be phi and lambda.
The coordinates of a point on the map are linear values. Relatively speaking, x and y.
x = f1(phi, lambda)
y = f2(phi, lambda).
There can be many feature sets...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question