Tag Archives: PHP

Convert Decimal Degrees to Degree-Minute-Second in MySQL

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

PHP point-in-polygon algorithm

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