(10) The principle of transformation between geographical coordinates and screen coordinates in Webgis

Source: Internet
Author: User

1. Preface
The map itself is owned coordinates, generally can be broadly divided into planar coordinates and latitude and longitude coordinates, where we collectively referred to as geographical coordinates, such as Beijing, (115.9°e, 39.6°n) and (506340,304400) are their geographical coordinates, but the form is different.
In the previous chapter, we explained the origin of the data in the vector layer, and finally raised an unresolved question, namely, how to convert the geographic (Geometry) coordinates in the data to screen coordinates in the screen after we have obtained the vector data. So that the various uicomponent (elements) in the screen-side canvas are drawn out?
We will explain this transition in this chapter.
2. Conversion Prerequisites
The prerequisite for enabling screen coordinates to be converted to geographic coordinates is:
1). Know the true geographic coordinates (SCREENGEOBOUNDS.LEFT, screengeobounds.top) that correspond to the upper-left corner of the screen.
2). Know the actual geographic length (slicelevellength) of each tile at the level at which the map is located.
3). Know the size of the tile, which is the screen pixel (tilesize) owned by a tile.
3. How to obtain these prerequisite parameters 3.1 tilesize Parameters
Since this parameter is a fixed parameter, it is very simple to obtain, consistent with the actual tile size.
3.2 Slicelevellength Parameter acquisition
This parameter requires a certain algorithm to obtain, the specific algorithm and principles can be in the third chapter, "The geographical range to obtain the number of tiles," the detailed explanation. Here I give the formula directly:
resolution=scale*inch2centimeter/dpi;
Slicelevellength=tilesize*resolution;
The English language represents the following meanings:
Inch2centimeter: Inches turn inside the parameters.
Dpi: The pixels contained in an inch.
Resolution: The actual unit length represented by the unit pixel.
Acquisition of 3.3 screengeobounds
The actual meaning of this parameter is the geographic coordinates (SCREENGEOBOUNDS.LEFT, screengeobounds.top) corresponding to the screen coordinates (0,0). Screengeobounds is a parameter value of uncertainty and dynamic change. This screengeobounds changes as the map pans, zooms in, and shrinks.
Referring to the third chapter of the content (our entire system, the content of the third chapter is the focus), we can know that every time we trigger the tile request, will recalculate the screen at this point coordinates the actual geographical coordinates.
And, in the later chapters to discuss the Webgis function, when explaining the map translation function, we can also understand that, in fact, each time the map translation event occurs, our screen coordinates will also be added to reduce the same amount of geographic translation.
4. Conversion formula
Below I will give the Tilesize, Slicelevellength, screengeobounds based on three parameters of geographical coordinates and screen coordinates to convert each other formula.
4.1 screen coordinates converted to geographic coordinates
geoxy.x = screengeobounds.left + ScreenX * slicelevellength/tilesize;
GEOXY.Y = Screengeobounds.top-screeny * slicelevellength/tilesize;
4.2 Geographical coordinates converted to screen coordinates
screenxy.x = (geox-screengeobounds.left)/(slicelevellength/tilesize);
SCREENXY.Y = (Screengeobounds.top-geoy)/(slicelevellength/tilesize);
4.3 Simple explanation of the formula
The two conversion formulas are first calculated on the screen of a pixel corresponding to the unit geographic length, and then according to the transformation needs of the conversion required. It is important to note that on a real map, y is the latitude, the higher the latitude, and the more on the screen, the more The Y will go up the smaller. So look closely at the transformations in the two conversion formulas about latitude and the y-coordinate of the screen to find out.
Use of coordinate conversion formulas in 5.WebGIS
These two conversion formulas are often used in conjunction with each other. For example, there is a requirement: the mouse click on the map after the need to query the mouse click on the feature attribute information, and the query to the features on the map (in fact, this requirement is an I query needs).
Our implementation method is to convert the screen coordinates of the mouse click to geographical coordinates, and then add tolerance after a geometry range, from the front-end issue I query the request URL, through the geographic server to get the returned vector data, At the front end, the geographic coordinates in the vector data are converted to screen coordinates, the features are plotted in the uicomponent based on this screen coordinates, and the atrributes carried in the vector data are parsed as the property data of the query.
The following flowchart for this process:

6. Summary

In this chapter, we know how to convert the geographic coordinates of the resulting vector data into screen coordinates, and the next thing we do is to draw the shape of the feature in uicomponent based on the resulting screen coordinates. After understanding how the vectors are obtained and the usage of the vector data, we can finally design the feature and vector layer in the next two chapters. We welcome your continued attention.

--Welcome reprint, but retain the copyright, please indicate the source in obvious place: http://www.cnblogs.com/naaoveGIS/

At the time of research and a few of the same people in Beijing for a year, eat and live work and study together, we have a good relationship, so-called on the battlefield to carry a gun friend. Later, three doctoral seniors were on the ground and continued their country. Yesterday, a senior brother contacted me, said he another sci to be published, heartily for him to feel happy. Think of that year we 21 want to group band, go to Central conservatory buy textbooks, to Big Bell temple near buy guitar, evening work back after also pounded drum guitar day, really miss. Of course, I also remember the words we said, when I was a green emperor, the newspaper and Peach Blossom one place. But I know that I am not engaged in scientific research material, so I did not like relatives and friends to continue to read Bo, but, dear brother, I have never stopped learning, hope to be the same as you in a foreign country, a little progress every day. I wish you all the best over there.

(10) The principle of conversion between geographical coordinates and screen coordinates in Webgis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.