Click here to Skip to main content
15,878,852 members
Articles / Database Development / MySQL

Semantic Maps

Rate me:
Please Sign up or sign in to vote.
4.55/5 (5 votes)
1 Aug 2009GPL313 min read 36.7K   1.4K   23  
A MediaWiki extension that allows you to insert, edit, view and aggregate coordinate data
<?php

/**
 * A class that holds static helper functions for Semantic Maps
 *
 * @file Maps_Utils.php
 * @ingroup Maps
 *
 * @author Robert Buzink
 * @author Yaron Koren
 * @author Jeroen De Dauw
 */

if( !defined( 'MEDIAWIKI' ) ) {
	die( 'Not an entry point.' );
}

class MapsUtils {

	public static function getLatLon($param2) {
		$coordinates = preg_split("/,/", $param2);
		if (count($coordinates) == 2) {
			$lat = MapsUtils::convertCoord($coordinates[0]);
			$lon = MapsUtils::convertCoord($coordinates[1]);
			return array($lat, $lon);
		}
		return array(null, null);
	}

	private static function degree2Decimal($deg_coord="") {
		$dpos=strpos($deg_coord,'°');
		$mpos=strpos($deg_coord,'.');
		$spos=strpos($deg_coord,'"');
		$mlen=(($mpos-$dpos)-1);
		$slen=(($spos-$mpos)-1);
		$direction=substr(strrev($deg_coord),0,1);
		$degrees=substr($deg_coord,0,$dpos);
		$minutes=substr($deg_coord,$dpos+1,$mlen);
		$seconds=substr($deg_coord,$mpos+1,$slen);
		$seconds=($seconds/60);
		$minutes=($minutes+$seconds);
		$minutes=($minutes/60);
		$decimal=($degrees+$minutes);
		//South latitudes and West longitudes need to return a negative result
		if (($direction=="S") or ($direction=="W")) {
			$decimal *= -1;
		}
		return $decimal;
	}

	private static function decDegree2Decimal($deg_coord = "") {
		$direction = substr(strrev($deg_coord), 0, 1);
		$decimal = floatval($deg_coord);
		if (($direction == "S") or ($direction == "W")) {
			$decimal *= -1;
		}
		return $decimal;
	}

	private static function convertCoord($deg_coord = "") {
		if (preg_match('/°/', $deg_coord)) {
			if (preg_match('/"/', $deg_coord)) {
				return MapsUtils::degree2Decimal($deg_coord);
			} else {
				return MapsUtils::decDegree2Decimal($deg_coord);
			}
		}
		return $deg_coord;
	}

	public static function latDecimal2Degree($decimal) {
		if ($decimal < 0) {
			return abs($decimal) . "° S";
		} else {
			return $decimal . "° N";
		}
	}

	public static function lonDecimal2Degree($decimal) {
		if ($decimal < 0) {
			return abs($decimal) . "° W";
		} else {
			return $decimal . "° E";
		}
	}
	
	/**
	 * Add 'px' to a provided width/heigt value
	 *
	 * @param unknown_type $value
	 */
	public static function makePxValue(&$value) {
		if (substr($value, strlen($value) - 2) != 'px') $value .= 'px';
	}

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer
Belgium Belgium
I am a free and open source software enthusiast and freelance software developer with multiple years of experience in both web and desktop development. Currently my primarily focus is on MediaWiki and Semantic MediaWiki work. I'm in the all time top 10 MediaWiki comitters and am one of the WikiWorks consultants. You can contact me at jeroendedauw at gmail for development jobs and questions related to my work.

More info can be found on my website [0] and my blog [1]. You can also follow me on twitter [2] and identi.ca [3].

[0] http://www.jeroendedauw.com/
[1] http://blog.bn2vs.com/
[2] https://twitter.com/#!/JeroenDeDauw
[3] http://identi.ca/jeroendedauw

Comments and Discussions