It is common to use PHP (or ASP, JavaScript, etc…) to convert DD to DMS in web projects. However, when the coordinates are stored in a database, it is also possible to do the conversion in the database itself when the data is queried, thus simplifying the code of your webpages.
Here is how to create a function in MySQL to convert Decimal Degrees to Degree-Minute-Second: Continue reading →
The title pretty much says it all: this JavaScript code takes a decimal number and converts it into a fraction.
This code:
- recognizes 0.3333333 as 1/3
- allows not to extract the integral part: 1.5 can return 1 1/2 (by default) or 3/2
- works with negative numbers
Continue reading →
The point-in-polygon algorithm allows you to programmatically check if a particular point is inside a polygon or outside of it. A common way to tackle the problem is to count how many times a line drawn from the point (in any direction) intersects with the polygon boundary. If the line and the polygon intersect an even number of times (or not at all), then the point is outside. If they intersect an odd number of times, the point is inside. It is true even for complex forms that have a lot of coordinates and thus create a very precise boundary.
Let’s see a sample image before we get to the code.
Continue reading →