/** * @see ValueFormatter::format * * @since 0.1 * * @param GlobeCoordinateValue $value The value to format * * @return string * @throws InvalidArgumentException */ public function format($value) { if (!$value instanceof GlobeCoordinateValue) { throw new InvalidArgumentException('The GlobeCoordinateFormatter can only format instances of GlobeCoordinateValue.'); } $formatter = new GeoCoordinateFormatter($this->options); return $formatter->formatLatLongValue($value->getLatLong(), $value->getPrecision()); }
/** * @see ValueFormatter::format * * @since 0.1 * * @param GlobeCoordinateValue $value The value to format * * @return string * @throws InvalidArgumentException */ public function format($value) { if (!$value instanceof GlobeCoordinateValue) { throw new InvalidArgumentException('Data value type mismatch. Expected a GlobeCoordinateValue.'); } $formatter = new GeoCoordinateFormatter($this->options); return $formatter->formatLatLongValue($value->getLatLong(), $value->getPrecision()); }
/** * @dataProvider validProvider */ public function testFormatterRoundTrip(GlobeCoordinateValue $coord, $expectedValue, FormatterOptions $options) { $formatter = new GlobeCoordinateFormatter($options); $parser = new GlobeCoordinateParser(new ParserOptions(array('precision' => $coord->getPrecision()))); $formatted = $formatter->format($coord); $parsed = $parser->parse($formatted); // NOTE: $parsed may be != $coord, because of rounding, so we can't compare directly. $formattedParsed = $formatter->format($parsed); $this->assertEquals($formatted, $formattedParsed); }
/** * Normalizes latitude to [-90°..+90°]. Normalizes longitude to [-180°..+180°[ on Earth and * Moon and to [0°..+360°[ on all other globes. * @see http://planetarynames.wr.usgs.gov/TargetCoordinates * * @param GlobeCoordinateValue $value * * @return GlobeCoordinateValue */ public function normalizeGlobeCoordinate(GlobeCoordinateValue $value) { return new GlobeCoordinateValue($this->normalizeGlobeLatLong($value->getLatLong(), $value->getGlobe()), $value->getPrecision(), $value->getGlobe()); }
public function testArrayValueCompatibility() { // These serializations where generated using revision f91f65f989cc3ffacbe924012d8f5b574e0b710c // The strings are the result of calling getArrayValue on the objects and then feeding this to serialize. $serialization = 'a:5:{s:8:"latitude";d:-4.2000000000000002;s:9:"longitude";d:42;s:8:"altitude";N;s:9:"precision";d:0.01;s:5:"globe";s:4:"mars";}'; $arrayForm = unserialize($serialization); $globeCoordinate = GlobeCoordinateValue::newFromArray($arrayForm); $this->assertEquals(-4.2, $globeCoordinate->getLatitude()); $this->assertEquals(42, $globeCoordinate->getLongitude()); $this->assertEquals(0.01, $globeCoordinate->getPrecision()); $this->assertEquals('mars', $globeCoordinate->getGlobe()); $serialization = 'a:5:{s:8:"latitude";d:-4.2000000000000002;s:9:"longitude";d:-42;s:8:"altitude";d:9001;s:9:"precision";d:1;s:5:"globe";s:33:"http://www.wikidata.org/entity/Q2";}'; $arrayForm = unserialize($serialization); $globeCoordinate = GlobeCoordinateValue::newFromArray($arrayForm); $this->assertEquals(-4.2, $globeCoordinate->getLatitude()); $this->assertEquals(-42, $globeCoordinate->getLongitude()); $this->assertEquals(1, $globeCoordinate->getPrecision()); $this->assertEquals('http://www.wikidata.org/entity/Q2', $globeCoordinate->getGlobe()); }