If you don’t practice martial arts, you’re in vain. Learning GIS development, the coordinate system is not around the past, this is the basic concept, must be clear. Having been engaged in the development of WEB GIS for almost 2 years, I always feel fuzzy about this coordinate system. Because of solving a problem these days, I have a little awareness.

In the GIS world, there are so many coordinate systems, and they are described so abstractly that we, who have no talent and lack spatial imagination, get confused. However, for ArcGIS for JSAPI developers, there are probably only two kinds of coordinate systems that they are often exposed to:

Usually, when we say that a point on a map has latitude and longitude, we refer to this kind of coordinate system.

This coordinate system belongs to the geographic coordinate system. Because the earth is a sphere, this is a spherical coordinate system.

Full name: GCS_WGS_1984, ID 4326, general GPS, remote sensing images, field surveying and mapping data, etc. Of course, there are other geographic coordinates, like Beijing54, xian80 and so on, 4326 is just one of them.

var sr4326 = new SpatialReference({wkid: 4326 });
Copy the code

Two, 102113 projection coordinate system

102113, full name: GCS_WGS_1984_web_mercator_auxiliary_sphere, also known as plane cartesian coordinate system, Cartesian plane coordinate system, used in Google online maps.

As mentioned above, the 4326 geographic coordinate system is a spherical coordinate system, whereas the 2-dimensional map we use is planar, so we usually use planar coordinates. How to convert spherical coordinate system to plane coordinate system, using projection method. There are many projection methods, such as Miller projection, Mercator projection, Gauss projection, and so on. In ArcGIS, it seems to be the Mercator projection in general. Mercator’s a nice name. I like it. 102113 is the Mercator projection, so you could call it the Mercator projection coordinate system, right?

The Mercator projection works like this: Suppose you have a cone or cylinder that just surrounds the earth (that is, it’s tangent to the earth’s equator), and then the center of the Earth shines, projecting the earth’s longitude and latitude onto the cone or cylinder, and you get the earth’s plane coordinates. A cylinder can be regarded as a special cone whose vertex is at infinity.





A projected map obtained in this way would be elongated at the poles, but with parallel lines of latitude and longitude. As shown in the figure:

var sr102113 = new SpatialReference({wkid: 102113 });
Copy the code

We can also refer directly to the map object’s:

var sr102113 = map.spatialReference;
Copy the code

If you are not sure about the coordinate system of the map object, you can directly look at the map service of the map:



Baidu Map uses 102100 (GCS_WGS_1984_web_mercator), which should also be a Mercator projection coordinate system.

3. Why coordinate system transformation?

Of course you have to switch.

In general, the spatial data that we get is latitude and longitude, which is what’s called a spherical coordinate system, whereas a planar map is a planar coordinate system, and it can’t be used without transformation. But in my normal development, I have no interest in this, because the API automatically does the conversion. For example, I declare a point object:

var pt = new Point(longitude, latitude, new SpatialReference({wkid: 4326 });// The last parameter specifies the coordinate system to be used to create the object
Copy the code

Now, how do longitude and latitude translate into point coordinates in plane coordinates? What are the units of the converted points? Mercator projection, the coordinates of the points coming out, in meters. So latitude and longitude, when translated into plane coordinates, are very large:

XMin: 7750103.171888566 YMin: 1252344.2714235506 XMax: 1.693722247553803E7 YMax: 7973910.790707026 Spatial Reference: 102113 (3785).Copy the code

The code:

var _f = 6378137, _p = 0.017453292519943;
function lngLatToXY(pt){// Latitude and longitude are converted to plane coordinates

	var lng = pt[0];/ / longitude
	var lat = pt[1];/ / latitude
	
	if (lat > 89.999999){
		lat = 89.999999;
	}
	else if (lat < -89.999999){
		lat = -89.999999;
	}
	var c = lat * _p;
	x = lng * _p * _f;
	y = _f / 2 * Math.log((1 + Math.sin(c)) / (1 - Math.sin(c)));
	
	return [x,y];
}
Copy the code

There are interchangeable codes for latitude, longitude and plane coordinates in the resources, which seem a little different from the ones I gave you. This code was given to me by my colleague, who is the GIS authority and expert of our company. I didn’t compare them. Let me write them down.

Four, the practical application of a car, known the current coordinates, speed and direction, after a period of time, the car is expected to arrive where?

1. Coordinate transformation is used here. Because latitude and longitude are measured in degrees and seconds, not meters, so let’s say 15 minutes later, the car has traveled 10 kilometers, where do you think it’s going to be? Near the equator, one degree of latitude and longitude is about 111 kilometers; But at the North and South poles, the distance between longitude is 0! Therefore, the longitude and latitude should be first converted into plane coordinates, and then participate in the operation.

2. This problem is to find the coordinates of points on the arc given the center of the circle (the current position of the vehicle), radius (the distance traveled by the vehicle) and Angle (direction). In arcGIS map, the due north direction is 0 degrees, counting clockwise. In other words, the positive Y-axis is 0 degrees. There are:

The parametric equation of the circle with the center coordinates of the circle (a,b) and radius R (which can be obtained according to the definition of trigonometric ratio) is: X = a + r * sin t y = b + r * cos t So the coordinates of any point on the circle are P(a + r * sin t, b + r * cos t), where t is the degree of a point on the circle.

function drawSpeed(car){
	var t = car;
	varSp = transform into plane coordinates ([t. night,t.latitude]);/ / starting point
	varFp = obtain the plane coordinates of the end point (SP, T. sid, T. direction);/ / the end
	
	var sr102113 = map.spatialReference;
	
	var line ={geometry: {"paths":[[sp,fp]],
			"spatialReference":sr102113},
		"symbol": {"color":_cbd,
			"width":1."type":"esriSLS"."style":"esriSLSSolid"}};return new Graphic(line);
}
Copy the code

Lucky for you.

Interconversion of latitude, longitude and plane coordinates using Miller projection method Web Mercator coordinates and WGS84 coordinates