Creating circle-polygons from radius and center point

1,996 views
Skip to first unread message

cryo28

unread,
Apr 26, 2012, 4:55:59 AM4/26/12
to RGeo-Users
Is it possible to create an RGeo circle polygon defined by center
point coordinates and its radius in meters?

Daniel Azuma

unread,
Apr 26, 2012, 6:26:29 PM4/26/12
to RGeo-Users
Use the "buffer" method.

point = my_factory.point(20, 30)
circle = point.buffer(my_radius)

A few notes:

* This is available only through GEOS. So the Geos factories, and the simple_mercator and projected geographic factories will support it, but simple_spherical and simple_cartesian factories will not.

* The "circle" is, of course, a polygon approximation of a circle. The quality of the approximation is determined by the :buffer_resolution parameter you used when you created the factory. A reasonable value for many applications is 8, which will create a 32-gon approximation of a circle.

* Watch the coordinate system. If you want a certain radius IN METERS, you may need to convert it to the appropriate coordinate system. For example, if your coordinate system is a Mercator projection, most of those use meters as the unit of measure at the equator, so as you increase latitude, you'll have to scale by the secant of the latitude (which is the scaling distortion inherent in the projection.) Note also that a circle is usually not a circle in most projections, especially if it's large. If you can be more specific about what your application is, I might be able to help further.

Daniel

Kyle Drake

unread,
Apr 27, 2012, 1:54:09 AM4/27/12
to rgeo-...@googlegroups.com
Sorry, quick correction: It does not let you specify the number of points *for a geography*. Important distinction.

-Kyle

On Thu, Apr 26, 2012 at 22:52, Kyle Drake <kyle...@gmail.com> wrote:
The one area I see circles in frequently is web mapping (Google/Leaflet), which is why I was surprised that circles were not seemingly used very often in the gis community.

I wanted to allow users to make circular representations of boundaries, so I store a buffer polygon in the WKB so that I can index lookup queries (that are based on location), and then store lat/lng/radius in separate columns so I can provide it back to the end user.

Also, from what I can tell, ST_Buffer in PostGIS does not allow you to specify the number of points, so it gives you a fixed one  (I think it was 16 or 32?). I may try to re-implement that transform code in rgeo with your sample code!

-Kyle

Kyle Drake

unread,
Apr 27, 2012, 1:52:26 AM4/27/12
to rgeo-...@googlegroups.com
The one area I see circles in frequently is web mapping (Google/Leaflet), which is why I was surprised that circles were not seemingly used very often in the gis community.

I wanted to allow users to make circular representations of boundaries, so I store a buffer polygon in the WKB so that I can index lookup queries (that are based on location), and then store lat/lng/radius in separate columns so I can provide it back to the end user.

Also, from what I can tell, ST_Buffer in PostGIS does not allow you to specify the number of points, so it gives you a fixed one  (I think it was 16 or 32?). I may try to re-implement that transform code in rgeo with your sample code!

-Kyle


On Thu, Apr 26, 2012 at 15:26, Daniel Azuma <daz...@gmail.com> wrote:

Daniel Azuma

unread,
Apr 27, 2012, 2:51:19 AM4/27/12
to RGeo-Users
Curved boundaries such as circles are rather hotly debated in the GIS community. Some standards (such as SQL-MM) provide partial support for them, where as others (such as GeoJSON) explicitly do not. (Indeed, just a few months ago I watched the GeoJSON working group, after a long debate, reject a proposal to add circles to the format.)

I think the main reason for the hesitation in the community is, once you add one nonlinear type, you almost have to add all arbitrary nonlinear types. For example, you can't simply add a circle type, because then you also have to deal with how to represent the intersection between a circle and another shape, which is probably not a circle. And the math gets absolutely horrid once you introduce curves.

I didn't realize that st_buffer() didn't let you specify a resolution when working with the geography type. But it looks like you're right-- it doesn't. Kind of puzzling but I guess it is what it is. Then yes, your strategy is probably a reasonable one.

Daniel

no...@peden.biz

unread,
Feb 19, 2013, 10:54:47 PM2/19/13
to rgeo-...@googlegroups.com
This is an old post, but since I found it as I searched for this question, I thought I'd share my ruby code to convert lat/lng and radius in meters (from Google maps) to a polygon path:

Reply all
Reply to author
Forward
0 new messages