Currently I have a problem while developing an app - I use Open Street Map and draw a Circle and pass it to a Python backend, as central point and point on the perimeter on the Circle. Next I am describing that circle with 20-sided Polygon, and return both to the front and I see, that actually is no more circle-like, but it looks like an Ellipse.

More to that - I have written an algorithm which defines if my route crosses that zone - and it works on the data from Polygon, but not the Circle from the front (look picture)enter image description here
The relevant code is: Getting Radius from central Circle point and point on the perimeter:

def edit_radius(point, radius):
    xc, yc = point[0], point[1]
    rad_x, rad_y = radius[0], radius[1]
    return math.sqrt((xc - rad_x) ** 2 + (yc - rad_y) ** 2)

The similar result I can reach with mpu.haversine_distance(point, radius)/100 - which returns Haversine distance between that points (and it differs with Euqlidean distance).

Drawing polygon with 20 sides, and radius passed from previous function:

def polygon(sides, radius=1, rotation=0, translation=None):
    one_segment = math.pi * 2 / sides

    points = [
        (math.sin(one_segment * i + rotation) * radius,
         math.cos(one_segment * i + rotation) * radius)
        for i in range(sides)]

    if translation:
        points = [[sum(pair) for pair in zip(point, translation)]
                  for point in points]

    return points

I can't understand what I am missing. Should I convert to another coordinates system? But as I have read OpenStretMap (and Leaflet) are using "flat" EPSG:3857 system. Can somebody explain what is going on?

  • Can you provide an example set of coordinates and a radius? – Mikkel Lydholm Rasmussen Jan 17 at 12:00
  • 5
    A "circle" in a warped projection like Web Mercator should look like an ellipse. If it looks like a circle, then you do have an ellipse, which is flattened in a ratio to the sine of the latitude. – Vince Jan 17 at 12:15

This is almost certainly going to turn out to be related to the coordinate reference system (or systems) which you are using. Once you start to think about drawing specific shapes on a map then you can't get away from needing to understand this (or you need someone with the skills and knowledge to set you up with a system where you can avoid worrying about it because someone did that for you).

For a technical answer to your question you're going to need to provide more detail related to this issue. I'm guessing from the lack of that information that you're not on top of this (forgive me if I'm wrong).

Bear in mind that 'I'm using Openstreetmap' doesn't help. The data for OSM is recorded in one coordinate reference system - but that doesn't mean that the same system is used for any one particular map you're looking at. It could be drawn into a map with any reference system you choose. (I think OSM data is in 'WGS84'/EPSG:4326 and the main www.openstreetmap.org mapping is in 'WGS84 Web Mercator'/EPSG:3857 )

If this seems difficult to understand then try the following. Draw a straight line or circle on a piece of paper or stretchy piece of fabric. Now wrap it around an orange leaving no gaps or wrinkles . Or wrap paper or stretchy fabric around an orange (cut it to fit) and draw a circle on it, then flatten this out. What you've drawn won't survive the transformation intact (straight won't be straight, circular won't be circular).

  • thank you for your answer, actually we tested to draw a circle at (0, 0) and it really looks like a circle, but when we move it to the north - it transforms to ellipse. Can you please tell where can I find more information about what system of coordinates is used? I have googled and answers says that Openstreetmap actualy uses 4326 (if I have not missed something). Should I transform the output data somehow or the input data? – Chiefir Jan 17 at 12:36
  • I can provide an example set of coordinates if it will help somehow understand the problem – Chiefir Jan 17 at 12:38
  • 1
    Do you want your 'circle' to represent a circle on the ground (in real life) or a circle on the map (which will often not be a circle on the ground)? - To illustrate: every line on this image (link) is a circle on the ground. None are a circle on the map. upload.wikimedia.org/wikipedia/commons/thumb/5/56/… – Rostranimin Jan 17 at 14:34
  • 1
    A key fact for you is whether your 'app' will be used in a limited geographic location (e.g. something roughly the size of the UK or smaller). If so, you may be able to work with circles which are circles both on the map and on the ground (because the error in these won't be big enough to see). To achieve this would mean using a projected coordinate reference system - BOTH for your data AND for the background mapping - which is appropriate for that specific area. Outside the area everything will look very odd. – Rostranimin Jan 17 at 14:43
  • 1
    As @Rostranimin says, but not any projCRS. EPSG:3857 does a lot of north-south stretching (as most Mercator-based projCRS do. You need a conic or even UTM should give better results. Building the circle in the projCRS is the only to always guarantee a circle in that CRS. – mkennedy Jan 17 at 18:08

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.