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)