Question - Drawing a circle on a map

159 views
Skip to first unread message

Megha Vishwanath

unread,
Sep 19, 2011, 8:50:40 AM9/19/11
to data...@googlegroups.com
Hi All,

Assumed this would be a good place to ask, given a lot of you all play around with map API.

I was trying to use GPS Visualizer and Google provisions for drawing circles of given radius around a point, unsuccessfully though. So, I hoping I can ask around here for experiences of using these.

The reqt, is that I draw a circle on our map here, centered around a certain point, like Cantonment Station maybe. So, questions

1) GPS Visualiser helps me with some text file with the circle's coordinates, a gpx format , a kml format which I'm not sure how i can use with my existing map. Any pointers to a write up or tips here in would be helpful.

2) How can I work independent off GPS Visualizer to generate these gpx(s) and kml(s)? Have any of you used any other libraries? I understand Google Map allows the URL request parameters to determine this circle. But there seems to be some close kml dependencies. 

Appreciate any responses. Thanks right away...

Regards,
Megha

Samuel Rajkumar

unread,
Sep 19, 2011, 9:04:32 AM9/19/11
to data...@googlegroups.com
Just saw that this is easy to do with Google Fusion tables in the dev
fest on the 15th. Cant find the slides, but here is the Mexico
presentation http://mano-demos.googlecode.com/svn/trunk/slides/mexicocity2011/fusiontables-developer.html#1

Look at slide 14 - Intersections

Cheers,

Gautam John

unread,
Sep 19, 2011, 9:05:20 AM9/19/11
to data...@googlegroups.com

Gautam John

unread,
Sep 19, 2011, 9:18:11 AM9/19/11
to data...@googlegroups.com

Arun Ganesh

unread,
Sep 19, 2011, 9:27:57 AM9/19/11
to data...@googlegroups.com
On Mon, Sep 19, 2011 at 6:20 PM, Megha Vishwanath <megha.vi...@gmail.com> wrote:
The easiest way to achieve this is to use a vector marker. Openlayers supports vector markers, not so sure about the gmap api. See an example here: http://openlayers.org/dev/examples/stylemap.html
The marker are centred on a point, and then styled to give it a radius and other properties.

If you want the circles in a kml/gpx format, its more complex since you have to construct a polygon shape (made up of multiple lines to form a circle). You would need to brush up your math skills before you can attempt this :)


Appreciate any responses. Thanks right away...

Regards,
Megha




--
j.mp/ArunGanesh

Thejesh GN

unread,
Sep 19, 2011, 11:05:16 AM9/19/11
to data...@googlegroups.com

Here us an example code for the same. It draws a rough circle on google maps given center and radius.

http://code.thejeshgn.com/snippets/changeset/edb68565278d

--
Thanks,
Thejesh GN
http://thejeshgn.com
This is nexus one...

On Sep 19, 2011 6:58 PM, "Arun Ganesh" <arung...@gmail.com> wrote:
> On Mon, Sep 19, 2011 at 6:20 PM, Megha Vishwanath <
> megha.vi...@gmail.com> wrote:
>
>> Hi All,
>>
>> Assumed this would be a good place to ask, given a lot of you all play
>> around with map API.
>>
>> I was trying to use GPS Visualizer <http://www.gpsvisualizer.com> and Google
>> provisions<http://sites.google.com/site/gmapstips/plotting-a-radius-circle>for drawing circles of given radius around a point, unsuccessfully though.

>> So, I hoping I can ask around here for experiences of using these.
>>
>> The reqt, is that I draw a circle on our map here<http://klp.org.in/visualization?type=school>,

Arun Ganesh

unread,
Sep 19, 2011, 11:55:07 AM9/19/11
to data...@googlegroups.com
On Mon, Sep 19, 2011 at 8:35 PM, Thejesh GN <i...@thejeshgn.com> wrote:

Here us an example code for the same. It draws a rough circle on google maps given center and radius.

http://code.thejeshgn.com/snippets/changeset/edb68565278d

The need to draw such circles itself sounds a bit odd. Megha, what are you trying to visualize by giving such a circular buffer to each point? Density of schools is the most obvious thing that pops to my mind, and I feel something like that is better represented by a heatmap. All those overlapping circles is going to create a lot of clutter.



--
j.mp/ArunGanesh

Gautam John

unread,
Sep 19, 2011, 3:24:04 PM9/19/11
to data...@googlegroups.com
On Mon, Sep 19, 2011 at 9:25 PM, Arun Ganesh <arung...@gmail.com> wrote:

> The need to draw such circles itself sounds a bit odd. Megha, what are you
> trying to visualize by giving such a circular buffer to each point? Density
> of schools is the most obvious thing that pops to my mind, and I feel
> something like that is better represented by a heatmap. All those
> overlapping circles is going to create a lot of clutter.

I can try and answer:

1. The Right to Education mandates a primary school within 2KM and a
secondary school within 3KM. One option is to draw circles at those
radii from each primary and secondary schools and to figure out where
gaps are.
2. We get a lot of enquiries of the type:
2.1 I live in X - what are the schools within 1/2/3/4/5 KM?
2.2. Donor Y says what are the schools within 1/2/3/4/5 KM of my
office that I can volunteer at.

In which case for 2, what we thought we could do is tale the point of
their house or office (either they can mark it on the map or we can
input a lat/lon and it returns those schools (points with lat/long)
within that area.

Maybe there's a better way of doing this?

Arun Ganesh

unread,
Sep 19, 2011, 3:53:12 PM9/19/11
to data...@googlegroups.com
I can try and answer:

1. The Right to Education mandates a primary school within 2KM and a
secondary school within 3KM. One option is to draw circles at those
radii from each primary and secondary schools and to figure out where
gaps are.
It would be interesting to see how the 'as the crow flies' distance will compare to the actual path distance. In rural areas, i would expect quite a big difference between the two, especially if there are geographical features like a hill or river that come in the way.

In any case, a properly calibrated heatmap will do the trick quite nicely. That way, it would take into consideration the distance of a point from a school as well, instead of just a binary yes/no interpretation. Worth a try: http://geochalkboard.wordpress.com/2009/03/11/density-mapping-in-google-maps-with-heatmapapi/
 
 2. We get a lot of enquiries of the type: 
2.1 I live in X - what are the schools within 1/2/3/4/5 KM?
2.2. Donor Y says what are the schools within 1/2/3/4/5 KM of my
office that I can volunteer at.

In which case for 2, what we thought we could do is tale the point of
their house or office (either they can mark it on the map or we can
input a lat/lon and it returns those schools (points with lat/long)
within that area.

Maybe there's a better way of doing this?
Ah, so you draw the circle at the home/office location, makes sense. This is fairly simple to implement with a postgis query. Or it can get even simpler if you approximate the circular area to a square bounding box instead.


--
j.mp/ArunGanesh

Gautam John

unread,
Sep 20, 2011, 12:52:25 AM9/20/11
to data...@googlegroups.com
On Tue, Sep 20, 2011 at 1:23 AM, Arun Ganesh <arung...@gmail.com> wrote:

> It would be interesting to see how the 'as the crow flies' distance will
> compare to the actual path distance. In rural areas, i would expect quite a
> big difference between the two, especially if there are geographical
> features like a hill or river that come in the way.

Indeed but is there a way to calculate straight line vs. actual path
distance? Because the latter is more meaningful.

> In any case, a properly calibrated heatmap will do the trick quite nicely.

Cool. Thanks.

> Ah, so you draw the circle at the home/office location, makes sense. This is
> fairly simple to implement with a postgis query. Or it can get even simpler
> if you approximate the circular area to a square bounding box instead.

That's what I have been told. Apparently a square is easier than a
circle. Why is that?

Sailendra Mishra

unread,
Sep 20, 2011, 1:05:22 AM9/20/11
to data...@googlegroups.com
There are few examples to calculate both driving distance( Actual road distance) and straight line distance using google map API.

http://briancray.com/2009/06/23/calculate-driving-distance-google-maps-api/
Demo: http://briancray.com/wp-content/uploads/2009/04/distance.html

Straight distance using gmap api:
http://www.movable-type.co.uk/scripts/latlong.html
--
"Few people in this world who make mistakes in right direction."

Arun Ganesh

unread,
Sep 20, 2011, 1:09:40 AM9/20/11
to data...@googlegroups.com
On Tue, Sep 20, 2011 at 10:22 AM, Gautam John <gkj...@gmail.com> wrote:
On Tue, Sep 20, 2011 at 1:23 AM, Arun Ganesh <arung...@gmail.com> wrote:

> It would be interesting to see how the 'as the crow flies' distance will
> compare to the actual path distance. In rural areas, i would expect quite a
> big difference between the two, especially if there are geographical
> features like a hill or river that come in the way.

Indeed but is there a way to calculate straight line vs. actual path
distance? Because the latter is more meaningful.

It can be done, although with a bit of effort. The biggest challenge for this is a vector database of the road networks. If the openstreetmap data for the area of interest is good, this can be processed in qgis/grass to generate actual shapefiles of the coverage area. I dont think there is any other way of doing this without using a gis application.

 
> In any case, a properly calibrated heatmap will do the trick quite nicely.

Cool. Thanks.

> Ah, so you draw the circle at the home/office location, makes sense. This is
> fairly simple to implement with a postgis query. Or it can get even simpler
> if you approximate the circular area to a square bounding box instead.

That's what I have been told. Apparently a square is easier than a
circle. Why is that?
A box is defined by four edges and you can find points using lesser than, greater than operators. With a circle, you would need to do some complex maths or have a db with a gis extension. Operations in a cartesian space are much simpler than polar ones.
--
j.mp/ArunGanesh

Arun Ganesh

unread,
Sep 20, 2011, 1:28:34 AM9/20/11
to data...@googlegroups.com
On Tue, Sep 20, 2011 at 10:35 AM, Sailendra Mishra <biot...@gmail.com> wrote:
There are few examples to calculate both driving distance( Actual road distance) and straight line distance using google map API.

http://briancray.com/2009/06/23/calculate-driving-distance-google-maps-api/
Demo: http://briancray.com/wp-content/uploads/2009/04/distance.html

Straight distance using gmap api:
http://www.movable-type.co.uk/scripts/latlong.html

This is good if you have two points. In this case we have one point and the distance, and we want all the points that will come in that range.

Here is an example of how it would be done in grass:
 

On Tue, Sep 20, 2011 at 10:22 AM, Gautam John <gkj...@gmail.com> wrote:
On Tue, Sep 20, 2011 at 1:23 AM, Arun Ganesh <arung...@gmail.com> wrote:

> It would be interesting to see how the 'as the crow flies' distance will
> compare to the actual path distance. In rural areas, i would expect quite a
> big difference between the two, especially if there are geographical
> features like a hill or river that come in the way.

Indeed but is there a way to calculate straight line vs. actual path
distance? Because the latter is more meaningful.

> In any case, a properly calibrated heatmap will do the trick quite nicely.

Cool. Thanks.

> Ah, so you draw the circle at the home/office location, makes sense. This is
> fairly simple to implement with a postgis query. Or it can get even simpler
> if you approximate the circular area to a square bounding box instead.

That's what I have been told. Apparently a square is easier than a
circle. Why is that?



--
"Few people in this world who make mistakes in right direction."




--
j.mp/ArunGanesh

Thejesh GN

unread,
Sep 20, 2011, 4:12:34 AM9/20/11
to data...@googlegroups.com
On Tue, Sep 20, 2011 at 10:58 AM, Arun Ganesh <arung...@gmail.com> wrote:


On Tue, Sep 20, 2011 at 10:35 AM, Sailendra Mishra <biot...@gmail.com> wrote:
There are few examples to calculate both driving distance( Actual road distance) and straight line distance using google map API.

http://briancray.com/2009/06/23/calculate-driving-distance-google-maps-api/
Demo: http://briancray.com/wp-content/uploads/2009/04/distance.html

Straight distance using gmap api:
http://www.movable-type.co.uk/scripts/latlong.html

This is good if you have two points. In this case we have one point and the distance, and we want all the points that will come in that range.

Here is an example of how it would be done in grass:

We can take an hybrid approach. For a distance d, get all the points within distance 2d (by flying). And for those points calculate the distance by road using Gmaps API. Filter those within the range of d.
Looks like very workable approach.

Megha Vishwanath

unread,
Sep 20, 2011, 6:17:59 AM9/20/11
to data...@googlegroups.com
Thanks guys! 

For the time being, I've used Tejesh's snippet - more to get it out of the door. Now to sit back and think what's a good way of doing this, and will use all your inputs in here...

Regards,
-Megha

On Mon, Sep 19, 2011 at 8:35 PM, Thejesh GN <i...@thejeshgn.com> wrote:
Reply all
Reply to author
Forward
0 new messages