I have got data using OpenStreetMaps Ways of many areas. I would now like to write a function which would return "true or false" if an single latitude/longitude point is found in that area or not.

I have already seen many answers to this question such as this answer however none of these deal with the issue when the Greenwich meridian line is crossed. Most of my area searches will occur in London which means I need a function that can cope with both negative and positive values for the lat/long points in the area.

Is there a known way on how to solve this?

  • what language are you using?
    – Ian Turton
    Apr 25, 2018 at 12:21
  • Currently I'm using PHP but the language doesn't matter too much (I'm sure I can convert a function in almost any language to PHP) Apr 25, 2018 at 12:22
  • how is your data stored? in postgres?
    – Mapperz
    Apr 25, 2018 at 14:06
  • MySql db. Values stored as JSON in a string field Apr 26, 2018 at 8:55

1 Answer 1


It doesn't matter if the Greenwich meridian (longitude = 0) is crossed. The standard point-in-polygon algorithms work with both positive and negative values for coordinates. The only difficulty is if the polygon has lines which cross the anti-Greenwich meridian (longitude = plus or minus 180) and which therefore jump from -180 to +180.

My solution is to convert both the polygon and the point to be tested into the Lambert azimuthal equal-area projection, centred at the North Pole, then use the Horman-Agathos algorithm to see if the point is in the polygon. This is fine as long as the polygon doesn't contain the South pole, which in practice is unlikely.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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