Пример #1
0
 /**
  * Renders and returns the output.
  * @see ParserHook::render
  * 
  * @since 0.7
  * 
  * @param array $parameters
  * 
  * @return string
  */
 public function render(array $parameters)
 {
     $destination = MapsGeoFunctions::findDestination($parameters['location']->getCoordinates(), $parameters['bearing'], $parameters['distance']);
     $options = new \ValueFormatters\FormatterOptions(array(GeoCoordinateFormatter::OPT_FORMAT => $parameters['format'], GeoCoordinateFormatter::OPT_DIRECTIONAL => $parameters['directional']));
     $formatter = new GeoCoordinateFormatter($options);
     $geoCoords = new \DataValues\LatLongValue($destination['lat'], $destination['lon']);
     $output = $formatter->format($geoCoords);
     return $output;
 }
Пример #2
0
 /**
  * Renders and returns the output.
  * @see ParserHook::render
  * 
  * @since 0.7
  * 
  * @param array $parameters
  * 
  * @return string
  * @throws MWException
  */
 public function render(array $parameters)
 {
     /**
      * @var \DataValues\LatLongValue $coordinates1
      * @var \DataValues\LatLongValue $coordinates2
      */
     $coordinates1 = $parameters['location1']->getCoordinates();
     $coordinates2 = $parameters['location2']->getCoordinates();
     $distance = MapsGeoFunctions::calculateDistance($coordinates1, $coordinates2);
     $output = MapsDistanceParser::formatDistance($distance, $parameters['unit'], $parameters['decimals']);
     return $output;
 }
Пример #3
0
 public function execute()
 {
     global $wgUser, $egMapsDefaultGeoService, $egMapsDistanceDecimals, $egMapsDistanceUnit;
     $params = $this->extractRequestParams();
     $geoCoordinateParser = new DataValues\Geo\Parsers\GeoCoordinateParser();
     $results = array();
     if (Maps\Geocoders::canGeocode()) {
         $location = Maps\Geocoders::attemptToGeocode($params['location'], $egMapsDefaultGeoService);
     } else {
         $location = $geoCoordinateParser->parse($params['location']);
     }
     $query = "{{#ask:[[Bundesland::+]][[aktiv::wahr]][[Lage::+]]|?Lage|?=Name|mainlabel=-|format=array|link=none|headers=plain|headersep==|sep=<BV>}}";
     $mainpage = Title::newMainPage();
     $options = new ParserOptions();
     $localparser = new Parser();
     $localparser->Title($mainpage);
     $localparser->Options($options);
     $localparser->clearState();
     $bedarfsverkehre = $localparser->RecursiveTagParse($query);
     $bedarfsverkehre = explode('&lt;BV&gt;', $bedarfsverkehre);
     foreach ($bedarfsverkehre as $key => $props) {
         $props = explode('&lt;PROP&gt;', $props);
         $bedarfsverkehre[$key] = array();
         foreach ($props as $prop) {
             $prop = explode('=', $prop);
             $bedarfsverkehre[$key][$prop[0]] = $prop[1];
         }
         $bvlocation = $geoCoordinateParser->parse($bedarfsverkehre[$key]['Lage']);
         if ($location && $bvlocation) {
             $bedarfsverkehre[$key]['Distanz'] = MapsGeoFunctions::calculateDistance($location, $bvlocation);
         } else {
             // The locations should be valid when this method gets called.
             throw new MWException('Attempt to find the distance between locations of at least one is invalid' . $bedarfsverkehre[$key]['Name']);
         }
     }
     usort($bedarfsverkehre, array("ApiBVdistances", "distanceSort"));
     $results = array_slice($bedarfsverkehre, 0, 10);
     $this->getResult()->addValue(null, 'results', $results);
 }
Пример #4
0
 /**
  * Renders and returns the output.
  * @see ParserHook::render
  * 
  * @since 0.7
  * 
  * @param array $parameters
  * 
  * @return string
  */
 public function render(array $parameters)
 {
     $canGeocode = MapsGeocoders::canGeocode();
     if ($canGeocode) {
         $location = MapsGeocoders::attemptToGeocode($parameters['location'], $parameters['geoservice'], $parameters['mappingservice']);
     } else {
         $location = MapsCoordinateParser::parseCoordinates($parameters['location']);
     }
     // TODO
     if ($location) {
         $destination = MapsGeoFunctions::findDestination($location, $parameters['bearing'], MapsDistanceParser::parseDistance($parameters['distance']));
         $output = MapsCoordinateParser::formatCoordinates($destination, $parameters['format'], $parameters['directional']);
     } else {
         // The location should be valid when this method gets called.
         throw new MWException('Attempt to find a destination from an invalid location');
     }
     return $output;
 }
 /**
  * Returns the lat and lon limits of a bounding box around a circle defined by the provided parameters.
  * 
  * @since 0.6
  * 
  * @param array $centerCoordinates Array containing non-directional float coordinates with lat and lon keys. 
  * @param float $circleRadius The radidus of the circle to create a bounding box for, in m.
  * 
  * @return An associative array containing the limits with keys north, east, south and west.
  */
 protected static function getBoundingBox(array $centerCoordinates, $circleRadius)
 {
     $north = MapsGeoFunctions::findDestination($centerCoordinates, 0, $circleRadius);
     $east = MapsGeoFunctions::findDestination($centerCoordinates, 90, $circleRadius);
     $south = MapsGeoFunctions::findDestination($centerCoordinates, 180, $circleRadius);
     $west = MapsGeoFunctions::findDestination($centerCoordinates, 270, $circleRadius);
     return array('north' => $north['lat'], 'east' => $east['lon'], 'south' => $south['lat'], 'west' => $west['lon']);
 }
Пример #6
0
 public function __construct(&$results, SMWPrintRequest $printRequest, SRFFiltered &$queryPrinter)
 {
     global $wgParser;
     parent::__construct($results, $printRequest, $queryPrinter);
     if (!defined('Maps_VERSION') || version_compare(Maps_VERSION, '1.0', '<')) {
         throw new FatalError('You need to have the <a href="http://www.mediawiki.org/wiki/Extension:Maps">Maps</a> extension version 1.0 or higher installed in order to use the distance filter.<br />');
     }
     MapsGeocoders::init();
     $params = $this->getActualParameters();
     if (array_key_exists('distance filter origin', $params)) {
         $origin = MapsGeocoders::attemptToGeocode($wgParser->recursiveTagParse($params['distance filter origin']));
     } else {
         $origin = array('lat' => '0', 'lon' => '0');
     }
     if (array_key_exists('distance filter unit', $params)) {
         $this->mUnit = MapsDistanceParser::getValidUnit($wgParser->recursiveTagParse($params['distance filter unit']));
     } else {
         $this->mUnit = MapsDistanceParser::getValidUnit();
     }
     // Is the real position stored in a property?
     if (array_key_exists('distance filter property', $params)) {
         $property = trim($wgParser->recursiveTagParse($params['distance filter property']));
         $locations = array();
     } else {
         $property = null;
         $locations = null;
     }
     $targetLabel = $printRequest->getLabel();
     foreach ($this->getQueryResults() as $id => $filteredItem) {
         $row = $filteredItem->getValue();
         // $filteredItem is of class SRF_Filtered_Item
         // $row is an array of SMWResultArray
         foreach ($row as $field) {
             // $field is an SMWResultArray
             $label = $field->getPrintRequest()->getLabel();
             if ($label === $targetLabel) {
                 $field->reset();
                 $dataValue = $field->getNextDataValue();
                 // only use first value
                 if ($dataValue !== false) {
                     $posText = $dataValue->getShortText(SMW_OUTPUT_WIKI, false);
                     if ($property === null) {
                         // position is directly given
                         $pos = MapsGeocoders::attemptToGeocode($posText);
                     } else {
                         // position is given in a property of a page
                         // if we used this page before, just look up the coordinates
                         if (array_key_exists($posText, $locations)) {
                             $pos = $locations[$posText];
                         } else {
                             // query the position's page for the coordinates or address
                             $posText = SMWQueryProcessor::getResultFromFunctionParams(array($posText, '?' . $property), SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY, true);
                             //
                             if ($posText !== '') {
                                 // geocode
                                 $pos = MapsGeocoders::attemptToGeocode($posText);
                             } else {
                                 $pos = array('lat' => '0', 'lon' => '0');
                             }
                             // store coordinates in case we need them again
                             $locations[$posText] = $pos;
                         }
                     }
                     if (is_array($pos)) {
                         $distance = round(MapsGeoFunctions::calculateDistance($origin, $pos) / MapsDistanceParser::getUnitRatio($this->mUnit));
                         if ($distance > $this->mMaxDistance) {
                             $this->mMaxDistance = $distance;
                         }
                     } else {
                         $distance = -1;
                     }
                 } else {
                     $distance = -1;
                     // no location given
                 }
                 $filteredItem->setData('distance-filter', $distance);
                 break;
             }
         }
     }
     if (array_key_exists('distance filter max distance', $params) && is_numeric($maxDist = trim($wgParser->recursiveTagParse($params['distance filter max distance'])))) {
         // this assignation ^^^ is ugly, but intentional
         $this->mMaxDistance = $maxDist;
     } else {
         if ($this->mMaxDistance > 1) {
             $base = pow(10, floor(log10($this->mMaxDistance)));
             $this->mMaxDistance = ceil($this->mMaxDistance / $base) * $base;
         }
     }
 }
Пример #7
0
 /**
  * Renders and returns the output.
  * @see ParserHook::render
  * 
  * @since 0.7
  * 
  * @param array $parameters
  * 
  * @return string
  */
 public function render(array $parameters)
 {
     if (MapsGeocoders::canGeocode()) {
         $start = MapsGeocoders::attemptToGeocode($parameters['location1'], $parameters['geoservice'], $parameters['mappingservice']);
         $end = MapsGeocoders::attemptToGeocode($parameters['location2'], $parameters['geoservice'], $parameters['mappingservice']);
     } else {
         $start = MapsCoordinateParser::parseCoordinates($parameters['location1']);
         $end = MapsCoordinateParser::parseCoordinates($parameters['location2']);
     }
     if ($start && $end) {
         $output = MapsDistanceParser::formatDistance(MapsGeoFunctions::calculateDistance($start, $end), $parameters['unit'], $parameters['decimals']);
     } else {
         // The locations should be valid when this method gets called.
         throw new Exception('Attempt to find the distance between locations of at least one is invalid');
     }
     return $output;
 }
 /**
  * @return float[] An associative array containing the limits with keys north, east, south and west.
  */
 protected function getBoundingBox()
 {
     $center = new LatLongValue($this->center->getLatitude(), $this->center->getLongitude());
     $north = MapsGeoFunctions::findDestination($center, 0, $this->radius);
     $east = MapsGeoFunctions::findDestination($center, 90, $this->radius);
     $south = MapsGeoFunctions::findDestination($center, 180, $this->radius);
     $west = MapsGeoFunctions::findDestination($center, 270, $this->radius);
     return array('north' => $north['lat'], 'east' => $east['lon'], 'south' => $south['lat'], 'west' => $west['lon']);
 }