## gpsbabel-misc

 Re: [Gpsbabel-misc] Area calculation From: Marcio Moreira - 2007-01-22 15:04:57 Attachments: Message as HTML ```Hello friends, Thank you for your help. I had previously tried to install Garmin Trip & Waypoint Manager on my mac iBook G4 using two different PC emulators (Virtual PC and Guest PC) and Windows 98 SE. On both cases it didn't work: Garmin software can't find my GPS. Tom, I don't know what is the official projection used here in Brazil. To my need, a flat surface is fine. Norman, your algorithm idea looked simple but I couldn't implement it so I followed your second suggestion, and found a site with a good method to calculate polygon areas. http://mathworld.wolfram.com/PolygonArea.html With this method I wrote a small Python language program to calculate areas of non-self-intersecting polygons (the source is at the end of this email). You just have to save on the same folder two files: the source code file ( area_poligono.py ) and a file with the points of the track ( vertices.dat ). The program looks for a text file called vertices.dat on his folder. Then it opens the file and starts to read it line-by-line. Each line of vertices.dat must have two numbers (UTM coordinates of one point) separated by a TAB (Tab key on the keyboard). Example: 239513 9057996 239515 9057974 239524 9057954 239546 9057936 239547 9057930 If you have a Mac or Linux system your already have Python installed. If you are on Windows, download Python from http://www.python.org To run the program, open a Terminal window (command line). Change to the folder where you saved the two files. Type this to run the program: python area_poligono.py I don't know in which language GPSBabel is written but I believe that is very easy to implement the code below inside GPSBabel, maybe called by a new "Extras > Area calculation..." menu item. When clicked, it could open a File Open dialog box, followed by another dialog with the answer (the polygon area, or a error message). That's my suggestion and I hope you do it! Charlie, thank you for your kind offer. Greetings to all, Marcio Moreira The source code... # Calculate polygon area. # Marcio Moreira. 20/jan/2007. # Teresina, Piaui, Brazil. # Usage: # 1) Create a text file with the UTM coordinates of one point # on each line. The two numbers must be separated # by a TAB. Name this file "vertices.dat" # 2) Put this python program file on the same folder of the # "vertices.dat" file with the name "area_poligono.py" # 3) Run this program with the following command line: # python area_poligono.py # I have used the following reference to write this program: # http://mathworld.wolfram.com/PolygonArea.html import string vertices = [] # Open the file and read all lines f = open("vertices.dat", "r") lines = f.readlines() # Process each line for one_line in lines: # Split line in tokens and convert them to integers str_x, str_y = string.split(one_line) x, y = int(str_x), int(str_y) # Add one vertex to vertices list vertices.append( (x,y) ) determinants = 0 for index in range(len(vertices)): xa = vertices[index][0] ya = vertices[index][1] if index == len(vertices) - 1: n = 0 else: n = index + 1 xb = vertices[n][0] yb = vertices[n][1] # Calculate determinant det = float((xa * yb) - (xb * ya)) determinants = determinants + det # Apply the area formula area = determinants / 2 print "Area:", area __________________________________________________ Fale com seus amigos de graça com o novo Yahoo! Messenger http://br.messenger.yahoo.com/ ```