CC: | Jim [...] Gibson.org |
Subject: | lon off by 360° if $geo->at( @origin, $range, $bearing ); crossing prime meridian |
Date: | Wed, 26 Mar 2014 19:17:01 +0100 |
To: | bug-geo-ellipsoid [...] rt.cpan.org |
From: | Lixus Zoran <lixus [...] muellers.ms> |
Hello,
I would like to draw circles around locations,
e.g. a 300km circle around paris and store it as gpx track.
This works fine using $geo->at(...) but it returns strange lon values
if crossing prime meridian, so i added the fix in line 22 (commented out in this example)
which works for me but i do not understand why.
1 use Geo::Ellipsoid;
2
3 $geo = Geo::Ellipsoid->new(
4 ellipsoid=>'WGS84',
5 units=>'degrees',
6 distance_units => 'kilometer',
7 );
8
9 my @origin = ( 48.849954, 2.333179 ); # paris
10 my $range = 300;
11
12 print<<EOF;
13 <?xml version="1.0"?>
14 <gpx version="1.0" creator="Geo::Ellipsoid" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/0" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
15 <trk>
16 <name>Track</name>
17 <trkseg>
18 EOF
19
20 for($bearing=0; $bearing<=360; $bearing +=10 ) {
21 my ($lat,$lon) = $geo->at( @origin, $range, $bearing );
22 #$lon = $lon - 360 if $lon > 180;
23 printf("\t\t<trkpt lat=\"%s\" lon=\"%s\"></trkpt>\n", $lat, $lon);
24 }
25
26 print<<EOF;
27 </trkseg>
28 </trk>
29 </gpx>
30 EOF
This returns these values, but as you can see in line 28 the output has lon="359.809374330679"
this can be fixed with "$lon = $lon - 360 if $lon > 180;" I would like to understand why
and 180 was just a guess.
1 <?xml version="1.0"?>
2 <gpx version="1.0" creator="Geo::Ellipsoid" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/0" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
3 <trk>
4 <name>Track</name>
5 <trkseg>
6 <trkpt lat="51.546998949586" lon="2.333179"></trkpt>
7 <trkpt lat="51.5036953778651" lon="3.08318739911697"></trkpt>
8 <trkpt lat="51.3753396739588" lon="3.80639279801629"></trkpt>
9 <trkpt lat="51.1665130456171" lon="4.47739812085026"></trkpt>
10 <trkpt lat="50.8845809546462" lon="5.07346914659855"></trkpt>
11 <trkpt lat="50.539319549186" lon="5.57552362983861"></trkpt>
12 <trkpt lat="50.1424483024434" lon="5.96878457958342"></trkpt>
13 <trkpt lat="49.7071107601912" lon="6.24308617339316"></trkpt>
14 <trkpt lat="49.2473425643629" lon="6.39286886592435"></trkpt>
15 <trkpt lat="48.7775584101813" lon="6.41693111348806"></trkpt>
16 <trkpt lat="48.3120799353" lon="6.31801680015862"></trkpt>
17 <trkpt lat="47.864717061353" lon="6.10231330110236"></trkpt>
18 <trkpt lat="47.4484075391441" lon="5.77892110945565"></trkpt>
19 <trkpt lat="47.0749140294542" lon="5.35933804187563"></trkpt>
20 <trkpt lat="46.7545749304819" lon="4.85698366932089"></trkpt>
21 <trkpt lat="46.4961038896551" lon="4.28677529920804"></trkpt>
22 <trkpt lat="46.3064329258887" lon="3.66475641413431"></trkpt>
23 <trkpt lat="46.1905947940517" lon="3.00777171107457"></trkpt>
24 <trkpt lat="46.1516412330701" lon="2.333179"></trkpt>
25 <trkpt lat="46.1905947940517" lon="1.65858628892543"></trkpt>
26 <trkpt lat="46.3064329258887" lon="1.00160158586569"></trkpt>
27 <trkpt lat="46.4961038896551" lon="0.379582700791956"></trkpt>
28 <trkpt lat="46.7545749304819" lon="359.809374330679"></trkpt>
29 <trkpt lat="47.0749140294542" lon="359.307019958124"></trkpt>
30 <trkpt lat="47.4484075391441" lon="358.887436890544"></trkpt>
31 <trkpt lat="47.864717061353" lon="358.564044698898"></trkpt>
32 <trkpt lat="48.3120799353" lon="358.348341199841"></trkpt>
33 <trkpt lat="48.7775584101813" lon="358.249426886512"></trkpt>
34 <trkpt lat="49.2473425643629" lon="358.273489134076"></trkpt>
35 <trkpt lat="49.7071107601912" lon="358.423271826607"></trkpt>
36 <trkpt lat="50.1424483024434" lon="358.697573420417"></trkpt>
37 <trkpt lat="50.539319549186" lon="359.090834370161"></trkpt>
38 <trkpt lat="50.8845809546462" lon="359.592888853401"></trkpt>
39 <trkpt lat="51.1665130456171" lon="0.188959879149733"></trkpt>
40 <trkpt lat="51.3753396739588" lon="0.859965201983715"></trkpt>
41 <trkpt lat="51.5036953778651" lon="1.58317060088303"></trkpt>
42 <trkpt lat="51.546998949586" lon="2.333179"></trkpt>
43 </trkseg>
44 </trk>
45 </gpx>
Thanks in advance
Lixus
Message body is not shown because sender requested not to inline it.
Message body not shown because it is not plain text.
Message body is not shown because sender requested not to inline it.