Serial port and GPS

BmpMap Structure

Map in a bitmap.

For a list of all members of this type, see BmpMap Members.

System.Object
   System.ValueType
      serial.BmpMap

[Visual Basic]
Public Structure BmpMap
[C#]
public struct BmpMap

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

A map definition consists of a bitmap file, for example a scan of a paper map or a screenshot from Google Earth, and from coordinates of the corners of this map.

A map object can be initialized from a textual description, consisting of either 4 or 8 coordinates and the name of the bitmap file containing the scan or screenshot of the map. The coordinates and the name of the file are separated with one of the characters: whitespace, comma or semicolon. The coordinate strings are parsed using Utils.coord2dec(), so that both decimal representation or representation with degrees, minutes and seconds can be used. The initializaction string has the following format:
  1. The longitude of the left upper corner.
  2. The latitude of the left upper corner.
  3. The longitude of the right bottom corner.
  4. The latitude of the right bottom boundary.
  5. Optional. The program checks the overal number of items in the map description. For less than 9 items in the description it entirely ignores the coordinates listed here and assumes the 5th item to be the name of the bitmap file. The coordinates of the right upper and left bottom corner are then set so, as if the bitmap described a rectangle. Else the name of the bitmap file is expected in the 9th item and the four remaining items have the following meaning:
    • The latitude of the right upper corner.
    • The longitude of the right upper corner.
    • The latitude of the left bottom corner.
    • The longitude of the left bottom corner.
  6. The name of the bitmap file. If the name is an absolute path, then it is used as it is. Else the name is completed by the path of the exexuting assembly. This class doesn't validate the type of the bitmap, but generally bitmap types should be used, which can be presented in the form BndBmpForm. The form uses System.Drawing.Graphics.DrawImage() which is able to handle the most popular formats like bmp, jpg or png.

Map pictures, regardless if Google Earth screenshots or scans of real maps are not rectangles. Mostly the are surfaces of ellipsoids. In order to simplify the problem (and in order to loose some accuracy, of course) they can be presented as trapezes. For the northern half of the Earth the trapeze is wider on the bottom and it becomes taller on the top, for the southern part - the opposite. In fact the maps can be sometimes rotated or stretched, especially if one is toying to much with the mouse while using Google Earth.

The picture above presents a piece of a map with corners at real corrdinates in p1 (x1, y1), p4 (x4, y4), p2 (x1, y2), and p3 (x3, y3). This map is squeezed to a rectangle with the left top in psq1 (xsq1, ysq1) and the right bottom corner in psql2 (xsq1, ysq2). The target of the code in this class is to find coordinates xsq, ysq of the point psq, which corresponds in this squeezed world to the point p with the real coordinates x and y. You can imagine the rectangle in the right part of the picture as a bitmap with the screenshot of Google Earth or the scan of a map, where the coordinates xsq1 and ysq2 are 0 (the begin of the bitmap), the coordinate xsq2 equals the width of the bitmap and the coordinate ysq1 equals the heigth of the bitmap. The real coordinates x1, y1 ... x4, y4 can be found on the map, you're scanning or read from Google Earth by moving the mouse pointer to the particular corner and reading the coordinates from the bottom of the Google Earth screen. The corrdinates x, y are the coordinates of the current position reported by GPS.

By the recalculation from (x, y) to (xsq, ysq) the following applies:

The coordinates xr1, and xr2 equal the coordinate x of the point p. Similar the coordinates yr3 and yr4 equal the coordinate y. The coordinate yr1 can be computed by estimating the equation y = ax + b of the straight line connecting points p1 and p4 and computing and computing yr2 = a * xr2 + b (see also class StraightLine). The coordinate yr1 can be computed similarly from the straight line equation for the line connecting the points p3 and p2. For the coordinates xr3 and xr4 the straight line equations x = cy + d of the lines either connecting the points p3 and p1 or the points p2 and p4 can be used in order to compute xr3 = c * yr3 + d and xr4 = c * yr4 + d.

With this assumptions we can compute the searched coordinates:

[C#]

            using System;
            using serial;
            public void maptest() {
            BmpMap      m;
            double      x, y;
            m = new BmpMap("11d59m05.60sE 49d33m16.05sN 12d00m36.03sE 49d32m21.97sN sbach.bmp"));
            x = Utils.coord2dec("12s00m00.00sE", false);
            y = Utils.coord2dec("49d00m00.00sN", true);
            if (m.pointInside(x, y))
            Console.WriteLine("Point is inside of the map");
            else
            Console.WriteLine("Point is not inside of the map");
            }
            

Requirements

Namespace: serial

Assembly: map (in map.exe)

See Also

BmpMap Members | serial Namespace | StraightLine | Utils.coord2dec