Conversion of map latitude and longitude coordinates to screen coordinates (Android version)

Source: Internet
Author: User

When we develop the GIS system, the first thing to solve is the visualization of the map, the crux of the problem is how to convert the coordinates of the map to screen coordinates, and then to render coloring, labeling and so on. The following is the WGS84 latitude and longitude coordinates as the benchmark, introduce the map latitude and longitude coordinates and screen coordinate conversion problems.

First, scale

First, the map itself is to express the Earth's various things on the spatial distribution, contact and time of development and change of the state of drawing. How to display a large amount of space information on the Earth on a limited map, which is related to the scale problem. Scale = ratio of distance to actual distance on the graph.

Scales have two concepts of resolution and scale

Resolution is the ratio of the distance between a pixel on the screen and the map it displays on the actual ground.

Scale is the ratio of the length of the segment on the graph to the actual length of the distance on the ground

In general, computers use the concept of resolution, and the concept of scale is used in people's lives, because resolution is calculated directly using screen pixels, so performance is faster than the extent.

// Calculate Resolution Double Resolution=map.width/ screen.width// calculatescalefloat dpi=this. View.getresources (). Getdisplaymetrics (). xdpi; Double Pixel_size= (1/dpi) *0.0254; Pixel_size= (1/dpi) *0.0254double scale=resolution* metersperunit/pixel_size//  0.0254 is 1 inches = 0.0254 meters

Second, map coordinates and screen coordinates of the conversion

, because the earth is spherical, the same two meridians, the higher the latitude, the shorter the straight line between the meridians, but the longitude remains constant, so in the northern hemisphere or the southern hemisphere any two lines between the meridians and parallels are similar to the trapezoid, because the upper left and bottom left corner of this trapezoid, the upper right corner and the lower right corner of the longitude are the same, So we can think of this trapezoid as a rectangle, after the projection transformation, on the screen to see the map is stretched rectangular.

Because the farther north, the shorter the actual distance between the two meridians, so, to be projected into a rectangle, you must determine the length of a longitude:metersperunit=111319.4908

// map coordinates go to screen coordinates:screenpt.x=screen.center.x+ ((mappt.x-mapextent.center.x)/resolution+0.5); screenpt.y =screen.center.y-(MAPPT.Y-MAPEXTENT.CENTER.Y)/resolution+0.5); // screen coordinates go map coordinates:mappt.x=mapextent.center.x+ (screenpt.x-screen.center.x) *resolution;mappt.y= mapextent.center.y-(screenpt.x-screen.center.x) *resolution;

Conversion of map latitude and longitude coordinates to screen coordinates (Android version)

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.