Geolocation Library

In development of my generic geosocial media engine, part of the task was to develop a Geolocaiton library for geospatial calculations. This has since been developed and released at https://github.com/rickogden/Location. This contains a variety of geospatial classes: Point, Line, Multipoint Line, Polygon. On top of these it has a Distance class which is used to output the units of measurement for the distance calculations.

It is very simple to use, you can install it through composer:

 require: "ricklab/location" : "dev-master" 

Once installed it can be used simply as follows:

use Ricklab\Location;

$pointOne = new Location\Point(53.234321, -2.34321);
$pointTwo = $pointOne->getRelativePoint(5, 30, 'miles'); //returns a Point object which is 5 miles away with the bearing of 30 degrees.
$distanceObject = $pointOne->distanceTo($pointTwo);
echo $distanceObject->to('km');

$line = new Location\Line($pointOne, $pointTwo);
echo $line->getBearing(); //returns the bearing of the line
echo $line->getMidPoint(); //returns the mid point of the line
echo $line->length()->to('miles'); //length works identically to distanceTo from a Point object

There are also MultipointLine (for paths rather than straight lines) and Polygon classes. They also have a length method which allows for a total length or perimeter measurement.

The MBR class takes in a Point and a radius around that point. This is useful for when doing SQL geospatial searches as it returns the minimum and maximum latitude and longitude values.

Finally they all implement a toSql() method which converts the SQL to a WKT syntax and implement jsonSerializable. This can be plugged straight into an SQL statement and used to query SQL databases (tested on MySQL but should work also on PostGIS). The jsonSerializable converts the geometry into GeoJSON and can be used with databases like MongoDB.

echo json_encode($pointOne);

Please feel free to use it, and let me know of any bugs which you discover!

Happy New Year and Updates

With it being the festive season, I have not done a huge amount of interest recently. I’m hoping to have a few things for you soon. Currently I have been experimenting with Drupal, having never used it (properly) before, this is a real learning curve.

Also I am working on getting suPHP to work with userdir, to allow users of a server to have their own webspace in a secure fashion. I will be blogging about this when it is done.

However, I have found a few things that may be of interest:
Things you probably didn’t know about PHP – Some really interesting and neat things you can do with PHP.

PHP Object Generator – Generates class structures and objects, so you don’t have to

Breadth Vs Depth

Something that I’ve recently been thinking about a lot is what should be taught at Universities, particularly in my area (Computer Science). What has been bugging me is trying to think about the balance between coverage and detail. Is there a bias as in you should focus more on one and not the other, or should they be covered in equal amounts.

A great way of applying this is using development concepts. Do you teach students many programming languages, giving them experience of many different syntaxes, and methodologies of programming. Or do you concentrate on fewer languages, but going into more detail about what you can do with them.

Personally, I’m inclined to go with the latter (to a point). Concentrate your efforts and get them able to apply their current knowledge to other areas, which they have not been taught. However, this has problems. Could the jeopardise the students in the future, make them feel restricted from branching into the unknown? Could it also mean that they don’t look as good to an employer?

Although I’ve used programming as an analogy (as it’s something I’m familiar with), this balance can be applied to any learning situation.

Comments please.

Welcome

Welcome to my new website. There is not much on it at the moment, but that will change over time.

This site is going to include tutorials, presentations, scripts and other things which I have written, and also information about what I am doing (in music and technology). Please bear with me while I finish this site, and get it up and running.

However, for now, I am off to phpnw09 conference in Manchester. To those of you going, see you there!