0

I am trying to make sense of the Google S2 library for spherical math (it works like this). I need to get a rectangle for searching for nearby entities in a database, based on a point and a distance (say, 10km, the distances do not have to be exact, I filter the entities later).

In the S2 library there is a function with the signature:

RectFromCenterSize(center, size LatLng)

Both parameters are latitude/longitude pairs.

I am having difficulty understanding what this means (the documentation is unfortunately very poor). The center point I get, but how does the a lat/lng pair specify the size?

Any help would be greatly appreciated.

  • Just realised that this looks like a re-phrasing of the same question by the same asker so I think that should have been done via an edit to the original question. If it is a different but related question then perhaps an edit to this one to explain why it is not a duplicate cen get it re-opened. – PolyGeo Jul 18 '13 at 21:39
  • I've voted to mark the new question as a duplicate of this slightly older question. Hence I'm voting to keep this old question Open. – Devdatta Tengshe Jul 19 '13 at 3:13
  • Yes, this is an attempt at getting an answer to the previous question. After several days of the previous question being ignored, I tried to rephrase it so someone would actually be interested in answering it. However, I do not feel it has been answered sufficiently yet. The code quoted below helps very little... the question is about being able to specify an amount of (roughly) x meters, and being able to specify a rectangle to accomplish that. At the moment, using S2 is still a big mystery to me, I must admit. – yngling Jul 19 '13 at 5:08
  • My plan was to add a question (or ask that one was added) to the previous question if I got one. I feel the previous question is much better phrased so that others in the same situation can search for it and get a good answer. This question, admittedly, was just phrased so that someone would see the simplicity of the question (both questions are not really about S2, it is about understanding how to specify a rectangle size using a lat/lng, so that it is possible to use S2 for proximity searches). – yngling Jul 19 '13 at 5:15
1

From the code it appears that they are using the size to construct half of the rectangle, and then possibly mirroring this half rectangle about the center point, thereby creating the full rectangle.

func RectFromCenterSize(center, size LatLng) Rect {
        half := LatLng{size.Lat / 2, size.Lng / 2}
        return RectFromLatLng(center).expanded(half)
  • Yes, thank you. What I am trying to understand is how that can help me specify a rectangle of a certain distance... like, say, 10km from the centre in every direction. Can I say 0.089982311915998 degrees latitude and some degree longitude as the size, and that will give me such a rectangle? – yngling Jul 18 '13 at 19:55
  • 1
    Well that would be a circle, not a rectangle. Or it would be a square (which is also a rectangle) if by every direction you mean along the axes. Also, the distance between degrees of latitude is roughly (+/- ~1km) the same throughout the world, while the distance for longitude changes drastically. See Wikipedia. – Paul Jul 18 '13 at 20:02
  • Yes, that would be a circle. What I really try to say in the question is that I need to specify a rectangle that is as small as possible, but that will give me a minimum of x meters to each edge. I must admit, despite getting the feeling that the GIS people here think me an idiot, that I have trouble understanding how to specify the size... am I right in what I say above? Should lat/lng be in degrees from the center, but that I need to calculate how many? Or is it a point on the rectangle relative to the center? etc etc – yngling Jul 19 '13 at 5:03
  • the lat/lon in the size arg. is the length of the sides. So, if you want a box 10 degrees in latitude and 15 degrees in longitude, your size is 10, 15. The box will be 10 x 15 degrees, centered on the point in the first arg. If you want a box whose side is in meters, you will have to convert meters to degrees. The conversion of longitude degrees to meters will depend on the latitude. Since the box is a rectangle on a sphere, the two sides parallel to the equator will have different lengths. – Llaves Aug 19 '13 at 3:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.