Archive for May 2012

Programming Part II

with one comment

This is a follow-up to the previous post Programming a new start… After familiarising myself with the old friend – C and completing a simple program, It was time for a bigger, better and more complex stuff. The search was around a problem which involves geo coordinates and their manipulation into producing a visual output.  There was 2 parts to the problem, one was the analysis part and the other was the visualisation part. C was enough for the analysis part, with its insanely simple tools; one can do anything to a pair of coordinates given to it. It was the visualisation part which was proving to be  tricky, provided the complexity of the system which needs to be visualised (since it is not a simple Cartesian plane which needs to be mapped) and the graphical operations which needs to be carried out, which I felt would be really difficult do in a platform like C. I kept on searching for something in Java, JavaScript, etc. where I can draw things visually on a screen with coordinate data and save it in a file structure which can be read by others. The search went on for a long time until I found KML.

Keyhole Mark-up Language (KML) proved to be the solution to all the geographic visualisations I needed to do. The advantages were that it had XML roots – which makes it easy to learn, It had simple vertex based mapping – where all the drawing and projection systems are taken care by the viewer (Google Earth) and I was a simple text based file system – which enables one to create a KML file by just writing in plain text. By combining, KML and C one gets the power to carry out complex calculations and at the same time, store them and display them through a standard format which is widely used. So now my aim was to create a program which creates a KML file from a set of data provided to it in a standard format.

After two days of continuous coding and debugging, the final version of the program is here. What it does is to take input from a text file as pointed by the user and looks for points defined by delimited data (Space, tab or newline) in four columned arrays [name, latitude, longitude and distance] and draws a circle around the points with a radius of distance specified and stores those polygons in a KML file which can be viewed in Google earth. Since I don’t want to get into really minute details of the concepts and directions, as I did last time, I will mention the broad concepts which I learned and extensively used in the program below,

  1. File management in C – Opening, reading and writing text files through C.
  2. KML Specification – Constructing different types of geometry in Google Earth through KML files
  3. Geometry and projection system – Ellipses, Circles, spheres and how they are defined in Cartesian geometry and how do they transform when projected on earth.

The program as of now has two major drawbacks,

  1. It assumes the earth to be sphere and not a spheroid which can cause small errors in extreme latitudes
  2. There cannot be any space in the name field of the data, which will cause the program to read it as a delimiter and go berserk with the rest of the data.

The download link is given below. Feel free to point out any blunders, problems and ways for improving the program.

Download Link:

https://sourceforge.net/projects/kmlbuffer/files/KmlBuffer/

Screenshots:

Input

Processing

Output

Written by sbmkvp

May 24, 2012 at 12:56 pm