Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValueDescription.php |
— | — | @@ -1,65 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/** |
5 | | - * File holding the SMGeoCoordsValueDescription class. |
6 | | - * |
7 | | - * @file SM_GeoCoordsValueDescription.php |
8 | | - * @ingroup SemanticMaps |
9 | | - * |
10 | | - * @author Jeroen De Dauw |
11 | | - */ |
12 | | - |
13 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
14 | | - die( 'Not an entry point.' ); |
15 | | -} |
16 | | - |
17 | | -/** |
18 | | - * Description of one data value of type Goegraphical Coordinates. |
19 | | - * |
20 | | - * @author Jeroen De Dauw |
21 | | - * |
22 | | - * @ingroup SemanticMaps |
23 | | - * |
24 | | - * TODO: storing the distance here does not seem quite right |
25 | | - */ |
26 | | -class SMGeoCoordsValueDescription extends SMWValueDescription { |
27 | | - protected $m_distance; |
28 | | - |
29 | | - public function __construct( SMGeoCoordsValue $datavalue, $distance, $comparator = SMW_CMP_EQ ) { |
30 | | - parent::__construct( $datavalue, $comparator ); |
31 | | - $this->m_distance = $distance; |
32 | | - } |
33 | | - |
34 | | - /** |
35 | | - * @see SMWDescription:getQueryString |
36 | | - * @param Boolean $asvalue |
37 | | - */ |
38 | | - public function getQueryString( $asValue = false ) { |
39 | | - if ( $this->m_datavalue !== null ) { |
40 | | - $queryString = $this->m_datavalue->getWikiValue(); |
41 | | - return $asValue ? $queryString : "[[$queryString]]"; |
42 | | - } else { |
43 | | - return $asValue ? '+' : ''; |
44 | | - } |
45 | | - } |
46 | | - |
47 | | - /** |
48 | | - * @see SMWDescription:prune |
49 | | - */ |
50 | | - public function prune( &$maxsize, &$maxdepth, &$log ) { |
51 | | - if ( ( $maxsize < $this->getSize() ) || ( $maxdepth < $this->getDepth() ) ) { |
52 | | - $log[] = $this->getQueryString(); |
53 | | - $result = new SMWThingDescription(); |
54 | | - $result->setPrintRequests( $this->getPrintRequests() ); |
55 | | - return $result; |
56 | | - } else { |
57 | | - $maxsize = $maxsize - $this->getSize(); |
58 | | - $maxdepth = $maxdepth - $this->getDepth(); |
59 | | - return $this; |
60 | | - } |
61 | | - } |
62 | | - |
63 | | - public function getDistance() { |
64 | | - return $this->m_distance; |
65 | | - } |
66 | | -} |
\ No newline at end of file |
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_AreaValueDescription.php |
— | — | @@ -0,0 +1,111 @@ |
| 2 | +<?php
|
| 3 | +
|
| 4 | +/**
|
| 5 | + * File holding the SMAreaValueDescription class.
|
| 6 | + *
|
| 7 | + * @file SM_AreaValueDescription.php
|
| 8 | + * @ingroup SemanticMaps
|
| 9 | + *
|
| 10 | + * @author Jeroen De Dauw
|
| 11 | + */
|
| 12 | +
|
| 13 | +if ( !defined( 'MEDIAWIKI' ) ) {
|
| 14 | + die( 'Not an entry point.' );
|
| 15 | +}
|
| 16 | +
|
| 17 | +/**
|
| 18 | + * Description of one data value of type Goegraphical Areas.
|
| 19 | + *
|
| 20 | + * @author Jeroen De Dauw
|
| 21 | + *
|
| 22 | + * @ingroup SemanticMaps
|
| 23 | + *
|
| 24 | + * TODO: storing the distance here does not seem quite right
|
| 25 | + */
|
| 26 | +class SMAreaValueDescription extends SMWValueDescription {
|
| 27 | + protected $mBounds = false;
|
| 28 | +
|
| 29 | + public function __construct( SMGeoCoordsValue $dataValue, $radius, $comparator = SMW_CMP_EQ ) {
|
| 30 | + parent::__construct( $dataValue, $comparator );
|
| 31 | +
|
| 32 | + // TODO: get user provided distance
|
| 33 | + //global $smgGeoCoordDistance;
|
| 34 | + //$distance = $smgGeoCoordDistance;
|
| 35 | +
|
| 36 | + // If the MapsGeoFunctions class is not loaded, we can not create the bounding box, so don't add any conditions.
|
| 37 | + if ( self::geoFunctionsAreAvailable() ) {
|
| 38 | + $dbKeys = $dataValue->getDBkeys();
|
| 39 | +
|
| 40 | + $this->mBounds = self::getBoundingBox(
|
| 41 | + array(
|
| 42 | + 'lat' => $dbKeys[0],
|
| 43 | + 'lon' => $dbKeys[1]
|
| 44 | + ),
|
| 45 | + $radius
|
| 46 | + );
|
| 47 | + }
|
| 48 | + }
|
| 49 | +
|
| 50 | + /**
|
| 51 | + * @see SMWDescription:getQueryString
|
| 52 | + * @param Boolean $asvalue
|
| 53 | + */
|
| 54 | + public function getQueryString( $asValue = false ) {
|
| 55 | + if ( $this->m_datavalue !== null ) {
|
| 56 | + $queryString = $this->m_datavalue->getWikiValue();
|
| 57 | + return $asValue ? $queryString : "[[$queryString]]";
|
| 58 | + } else {
|
| 59 | + return $asValue ? '+' : '';
|
| 60 | + }
|
| 61 | + }
|
| 62 | +
|
| 63 | + /**
|
| 64 | + * @see SMWDescription:prune
|
| 65 | + */
|
| 66 | + public function prune( &$maxsize, &$maxdepth, &$log ) {
|
| 67 | + if ( ( $maxsize < $this->getSize() ) || ( $maxdepth < $this->getDepth() ) ) {
|
| 68 | + $log[] = $this->getQueryString();
|
| 69 | + $result = new SMWThingDescription();
|
| 70 | + $result->setPrintRequests( $this->getPrintRequests() );
|
| 71 | + return $result;
|
| 72 | + } else {
|
| 73 | + $maxsize = $maxsize - $this->getSize();
|
| 74 | + $maxdepth = $maxdepth - $this->getDepth();
|
| 75 | + return $this;
|
| 76 | + }
|
| 77 | + }
|
| 78 | +
|
| 79 | + public function getBounds() {
|
| 80 | + return $this->mBounds;
|
| 81 | + }
|
| 82 | +
|
| 83 | + /**
|
| 84 | + * Returns the lat and lon limits of a bounding box around a circle defined by the provided parameters.
|
| 85 | + *
|
| 86 | + * @param array $centerCoordinates Array containing non-directional float coordinates with lat and lon keys.
|
| 87 | + * @param float $circleRadius The radidus of the circle to create a bounding box for, in km.
|
| 88 | + *
|
| 89 | + * @return An associative array containing the limits with keys north, east, south and west.
|
| 90 | + */
|
| 91 | + private static function getBoundingBox( array $centerCoordinates, $circleRadius ) {
|
| 92 | + $north = MapsGeoFunctions::findDestination( $centerCoordinates, 0, $circleRadius );
|
| 93 | + $east = MapsGeoFunctions::findDestination( $centerCoordinates, 90, $circleRadius );
|
| 94 | + $south = MapsGeoFunctions::findDestination( $centerCoordinates, 180, $circleRadius );
|
| 95 | + $west = MapsGeoFunctions::findDestination( $centerCoordinates, 270, $circleRadius );
|
| 96 | +
|
| 97 | + return array(
|
| 98 | + 'north' => $north['lat'],
|
| 99 | + 'east' => $east['lon'],
|
| 100 | + 'south' => $south['lat'],
|
| 101 | + 'west' => $west['lon'],
|
| 102 | + );
|
| 103 | + }
|
| 104 | +
|
| 105 | + /**
|
| 106 | + * Returns a boolean indicating if MapsGeoFunctions is available.
|
| 107 | + */
|
| 108 | + private static function geoFunctionsAreAvailable() {
|
| 109 | + global $wgAutoloadClasses;
|
| 110 | + return array_key_exists( 'MapsGeoFunctions', $wgAutoloadClasses );
|
| 111 | + }
|
| 112 | +} |
\ No newline at end of file |
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php |
— | — | @@ -41,16 +41,12 @@ |
42 | 42 | * Defines the layout for the smw_coords table which is used to store value of the GeoCoords type. |
43 | 43 | * |
44 | 44 | * @param array $propertyTables The property tables defined by SMW, passed by reference. |
45 | | - * |
46 | | - * FIXME |
47 | 45 | */ |
48 | 46 | public static function initGeoCoordsTable( array $propertyTables ) { |
49 | | - /* |
50 | 47 | $propertyTables['smw_coords'] = new SMWSQLStore2Table( |
51 | 48 | 'sm_coords', |
52 | 49 | array( 'lat' => 'f', 'lon' => 'f' ) |
53 | 50 | ); |
54 | | - */ |
55 | 51 | return true; |
56 | 52 | } |
57 | 53 | |
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoords.php |
— | — | @@ -18,7 +18,7 @@ |
19 | 19 | $wgAutoloadClasses['SMGeoCoordsValue'] = dirname( __FILE__ ) . '/SM_GeoCoordsValue.php'; |
20 | 20 | |
21 | 21 | // Registration of the Geographical Coordinate value description class. |
22 | | -$wgAutoloadClasses['SMGeoCoordsValueDescription'] = dirname( __FILE__ ) . '/SM_GeoCoordsValueDescription.php'; |
| 22 | +$wgAutoloadClasses['SMAreaValueDescription'] = dirname( __FILE__ ) . '/SM_AreaValueDescription.php'; |
23 | 23 | |
24 | 24 | // Hook for initializing the Geographical Coordinate type. |
25 | 25 | $wgHooks['smwInitDatatypes'][] = 'SMGeoCoordsValue::initGeoCoordsType'; |
— | — | @@ -36,19 +36,14 @@ |
37 | 37 | * Custom SQL query extension for matching geographic coordinates. |
38 | 38 | * |
39 | 39 | * @param string $whereSQL The SQL where condition to expand. |
40 | | - * @param SMGeoCoordsValueDescription $description The description of center coordinate. |
| 40 | + * @param SMAreaValueDescription $description The description of center coordinate. |
41 | 41 | * @param string $tablename |
42 | 42 | * @param string $fieldname |
43 | | - * @param Database $dbs |
| 43 | + * @param DatabaseBase $dbs |
44 | 44 | * |
45 | 45 | * @return true |
46 | 46 | */ |
47 | | - public static function getGeoProximitySQLCondition( &$whereSQL, SMGeoCoordsValueDescription $description, $tablename, $fieldname, DatabaseBase $dbs ) { |
48 | | - // If the MapsGeoFunctions class is not loaded, we can not create the bounding box, so don't add any conditions. |
49 | | - if ( !self::geoFunctionsAreAvailable() ) { |
50 | | - return true; |
51 | | - } |
52 | | - |
| 47 | + public static function getGeoProximitySQLCondition( &$whereSQL, SMAreaValueDescription $description, $tablename, $fieldname, DatabaseBase $dbs ) { |
53 | 48 | $dataValue = $description->getDatavalue(); |
54 | 49 | |
55 | 50 | // Only execute the query when the description's type is geographical coordinates, |
— | — | @@ -56,23 +51,10 @@ |
57 | 52 | if ( ( $dataValue->getTypeID() != '_geo' ) |
58 | 53 | || ( !$dataValue->isValid() ) |
59 | 54 | || ( $description->getComparator() != SM_CMP_NEAR ) |
60 | | - ) return true; |
61 | | - |
62 | | - $dbKeys = $dataValue->getDBkeys(); |
63 | | - |
64 | | - // TODO: get user provided distance |
65 | | - // $dataValue->getDistance() |
66 | | - global $smgGeoCoordDistance; |
67 | | - $distance = $smgGeoCoordDistance; |
| 55 | + ) return true; |
68 | 56 | |
69 | | - $boundingBox = self::getBoundingBox( |
70 | | - array( |
71 | | - 'lat' => $dbKeys[0], |
72 | | - 'lon' => $dbKeys[1] |
73 | | - ), |
74 | | - $distance |
75 | | - ); |
76 | | - |
| 57 | + $boundingBox = $description->getBounds(); |
| 58 | + |
77 | 59 | $north = $dbs->addQuotes( $boundingBox['north'] ); |
78 | 60 | $east = $dbs->addQuotes( $boundingBox['east'] ); |
79 | 61 | $south = $dbs->addQuotes( $boundingBox['south'] ); |
— | — | @@ -83,34 +65,6 @@ |
84 | 66 | return true; |
85 | 67 | } |
86 | 68 | |
87 | | - /** |
88 | | - * Returns the lat and lon limits of a bounding box around a circle defined by the provided parameters. |
89 | | - * |
90 | | - * @param array $centerCoordinates Array containing non-directional float coordinates with lat and lon keys. |
91 | | - * @param float $circleRadius The radidus of the circle to create a bounding box for, in km. |
92 | | - * |
93 | | - * @return An associative array containing the limits with keys north, east, south and west. |
94 | | - */ |
95 | | - private static function getBoundingBox( array $centerCoordinates, $circleRadius ) { |
96 | | - $north = MapsGeoFunctions::findDestination( $centerCoordinates, 0, $circleRadius ); |
97 | | - $east = MapsGeoFunctions::findDestination( $centerCoordinates, 90, $circleRadius ); |
98 | | - $south = MapsGeoFunctions::findDestination( $centerCoordinates, 180, $circleRadius ); |
99 | | - $west = MapsGeoFunctions::findDestination( $centerCoordinates, 270, $circleRadius ); |
100 | 69 | |
101 | | - return array( |
102 | | - 'north' => $north['lat'], |
103 | | - 'east' => $east['lon'], |
104 | | - 'south' => $south['lat'], |
105 | | - 'west' => $west['lon'], |
106 | | - ); |
107 | | - } |
108 | | - |
109 | | - /** |
110 | | - * Returns a boolean indicating if MapsGeoFunctions is available. |
111 | | - */ |
112 | | - private static function geoFunctionsAreAvailable() { |
113 | | - global $wgAutoloadClasses; |
114 | | - return array_key_exists( 'MapsGeoFunctions', $wgAutoloadClasses ); |
115 | | - } |
116 | 70 | } |
117 | 71 | |
Index: trunk/extensions/SemanticMaps/QueryPrinters/SM_MapPrinter.php |
— | — | @@ -131,7 +131,7 @@ |
132 | 132 | |
133 | 133 | $manager = new ValidatorManager(); |
134 | 134 | |
135 | | - $result = $manager->manageMapparameters( $mapProperties, $parameterInfo ); |
| 135 | + $result = $manager->manageParameters( $mapProperties, $parameterInfo ); |
136 | 136 | |
137 | 137 | $showMap = $result !== false; |
138 | 138 | |