Skip to content

Instantly share code, notes, and snippets.

@aeden
Created September 22, 2010 13:14
Show Gist options
  • Save aeden/591634 to your computer and use it in GitHub Desktop.
Save aeden/591634 to your computer and use it in GitHub Desktop.
ruby-1.8.7-p249 > Geokit::Bounds.from_point_and_radius([53.91848,-122.776584], 4993)
=> #<Geokit::Bounds:0x1050e7580 @ne=#<Geokit::LatLng:0x1050e8e08 @lat=53.897792470202, @lng=-43.4942376451051>, @sw=#<Geokit::LatLng:0x1050e8e58 @lat=-18.265247529798, @lng=-202.058930354895>>
ruby-1.8.7-p249 > Geokit::Bounds.from_point_and_radius([53.91848,-122.776584], 4997)
=> #<Geokit::Bounds:0x1050dee08 @ne=#<Geokit::LatLng:0x1050e0690 @lat=53.8399645290606, @lng=-43.4579700787395>, @sw=#<Geokit::LatLng:0x1050e06e0 @lat=-18.3230754709394, @lng=-202.09519792126>>
@aeden
Copy link
Author

aeden commented Sep 22, 2010

Shouldn't @lat=53.8399645290606 in line 4 be a larger value than @lat=53.897792470202 found on line 2?

@jlecour
Copy link

jlecour commented Sep 22, 2010

what bothers me much is the @lng=-202.xxx Is it even valid?

@jlecour
Copy link

jlecour commented Sep 22, 2010

What formula and distance unit do you use ?

@aeden
Copy link
Author

aeden commented Sep 22, 2010

Here is the relavent section of the config:

Geokit::default_units = :kilometers
Geokit::default_formula = :sphere

I didn't write this code, but when looking at the Geokit code, isn't kilometers supposed to be expressed as :kms or can it use :kilometers as specified in the config?

@rubyredrick
Copy link

I don't know Geokit but.

IIUC, you are asking for the bounding rectangle around a circle, there are two points there, It looks like the first is the bottom left corner, and for a larger radius it should be further west, and south, and it seems to be, The second is further east and north.

@aeden
Copy link
Author

aeden commented Sep 22, 2010

@rubyredrick Are you saying that lat/long pair associated with @ne is actually the bottom left corner (i.e. the southwest corner)?

@aeden
Copy link
Author

aeden commented Sep 22, 2010

@rubyredrick I think that the first pair, ie. @ne=#<Geokit::LatLng:0x1050e0690 @lat=53.8399645290606, @lng=-43.4579700787395> is the northeast corner. If this is true then a larger bounding box should result in lat moving farther from 0 and lng moving closer to 0, no?

@jlecour
Copy link

jlecour commented Sep 22, 2010

@aeden I can confirm that the @ne point is the North/East corner and @sw is the South/West corner.

GoogleMaps uses the same representation for bounds.

@aeden
Copy link
Author

aeden commented Sep 22, 2010

@jlecour Thanks for confirming it. Do you agree then that the lat in the ne value should be moving away from 0 given the increase in the radius (i.e the increase in the distance)?

@rubyredrick
Copy link

Ok I didn't notice the iv names.

There's another thing wonky here, going 4993 km north should change the longitude by about 45 degrees (approx 111 km/degree) instead in both cases it's only changing about a tenth of 1 degree.

@jlecour
Copy link

jlecour commented Sep 22, 2010

I guess that with such big distances, it's crossing the usual limits of -180/+180 for the longitude and -90/+90° for the longitude.

I think that Geokit does good with crossing the longitude limits, but I don't know about latitude.

@rubyredrick
Copy link

Yep, I'm sure that's the problem.

As I pointed out the diameter either of those circles should be around 90 degrees in latitude, at 40 degrees north each degree of latitude is only 85 km, and at 54 north even less, so the diameter in longitude is greater than 120 degrees

@kmayer
Copy link

kmayer commented Sep 23, 2010

Generalized spherical geometry for navigation has a singularity at each pole. Things get really wonky near the arctic circles, too. 54deg North is pretty "up there" I'd try shrinking your radius to 10km and then increase it again until you see things break.

Also, it depends on which algorithm GeoKit is using. There's a simplified formula which doesn't account for sign changes; it works fine for small ranges and is much faster; it just won't cross poles or the international dateline. In addition, like I said, these formulae start to break down as you get near the poles -- somewhere sine(theta) is approaching 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment