# PrintingTools - ExportWebMap - Calculate extends from coordinates (point)

495
3
08-24-2021 08:23 AM
by
New Contributor II

Hi

I'm using the PrintingTools - ExportWebMap REST API to get images of a map. As a parameter I get longitude and latitude (East/North) coordinates, which represent the center of the map, which should be printed.

How can I calculate the mapOtions -> extent: xmin, ymin, xmax, ymax from the given coordinates.
{
mapOptions"
: {

"extent": {
"Xmin"2599500.000,
"Ymin"1199700.000,
"Xmax"2600500.000,
"Ymax"1200300.000,
"spatialReference": {
"wkid"2056
}
},
[....]

I tried two different approaches.
The first approach is a a simple linear interpolation, where offsetEastInMeters and offsetNorthInMeters
var xmin = coordinates.East - (offsetEastInMeters / 2);

var ymin = coordinates.North - (offsetNorthInMeters / 2);
var xmax = coordinates.East + (offsetEastInMeters / 2);
var ymax = coordinates.North + (offsetNorthInMeters / 2);

Example I:
East/North: 2600000.000, 1200000.000
offsetEastInMeters: 1000 meters
offsetNorthInMeters: 600 meters

Results in:
xmin = 2599500.000
ymin = 1199700.000
xmax = 2600500.000
Ymax = 1200300.000

The second approach also takes into consideration the output size of the image, dpi and the scale:
image_length[mm] = pixel * 25.4mm (1 in) / dpi
xmin = x_coord - (image_length/1000 * scale)/2
This result in:
xmin = 2599365
ymin= 1199700
xmax = 2600635
ymax = 1200300

The issue with both approaches is, that the center of the returned image is not in the middle of the given longitude and latitude (East/North) coordinates. The given point is always on the left side. See the issue illustrated in the following picture:

How ist the calculation from a point to an area done right? What did I forget?

Tank you for any help!

Tags (4)
1 Solution

Accepted Solutions
by
New Contributor II

The solution is that the base map uses wgs84-web-mercator-auxiliary-sphere. With the converted coordinates into https://spatialreference.org/ref/epsg/ch1903-lv95/ there is a deviation which leads to this inaccuracy. (https://spatialreference.org/ref/sr-org/epsg3857-wgs84-web-mercator-auxiliary-sphere/)

3 Replies
Esri Contributor

i am not sure why that would be off center. add x degree right and left should not change the center. I have 2 suggestion;

The issue might lie with the print endpint. can you try both preserver map scale and map extent?

Secondly, can you take the point and create a buffer then use the extend of the buffer to get your coord and try?

by
New Contributor II

As I figured out the preserve option for map scale sends the scale in the JSON and map extend does not send the scale. Unfortunately, this did not bring the desired centering. The centering is a little better without the scale, but therefor whit out the scale the zoom too far away:

I don't understand what you mean by that:
"[...]you take the point and create a buffer then use the extend of the buffer to get your coord[....]"

Btw, do you know how long the returned URL is valid? Is this documented somewhere?

by
New Contributor II

The solution is that the base map uses wgs84-web-mercator-auxiliary-sphere. With the converted coordinates into https://spatialreference.org/ref/epsg/ch1903-lv95/ there is a deviation which leads to this inaccuracy. (https://spatialreference.org/ref/sr-org/epsg3857-wgs84-web-mercator-auxiliary-sphere/)