I am doing a project for a telecom company. I have to render circles on the map(assuming the center of the circle as tower and circle as the area covered by that signal), I am using base layers as Google Maps,Yahoo maps(Spherical Mercator) So I have used CreateGeodesicPolygon() successfully to create circles by reading the values from DB.

Now Since I have to render lot of circles, it made me switch to geoserver. Since the data is being provided by telecom company , they provide Lat,Lon,Gt,Gr,Pt,Pr,lambda(I think their meaning is irrelevant here) values. These values are stored in the database as they are. Now should use a equation(FRIIS transmission equation) and substitute each row(of a tower) values to find the distance covered by the tower.Then I have to create circles with that distance(considered as radius) and lon/lat and render them on map using geoserver.

Please suggest me any ideas of how to carry on this task.... I wud be thankful to your guidance

My Idea is to use these steps once I get distance from the equation.Will this work???

CREATE TABLE circles (cid int4,point_circle st_geometry);

INSERT INTO circles 
        ST_BUFFER(ST_GeomFromText('POINT(lon lat)',SRID),radius,'quad-segs=8')

Create a POSTGIS store in geoserver and this circles table as a layer.

  • Can you create views in the database? Is it a PostGIS db?
    – underdark
    Jun 1, 2011 at 20:22
  • @underdark, Yes it is a postgisdb, But I never created any views Jun 1, 2011 at 21:04
  • 1
    You'll have to reproject your data before buffering. (You don't get real circles if you buffer using degrees.) Then it should work.
    – underdark
    Jun 1, 2011 at 21:54
  • @underdark, SRID: 4326 gives buffers in metres. But since I am using google maps as base layers whose projection is 900913, where should I transform the buffer projection, in JS or SQL query itself?? Jun 2, 2011 at 6:33

3 Answers 3


Using EPSG:4326 you'll buffer in degrees, EPSG:900913 will let you buffer in meters. Google Mercator doesn't lead to correct length measurements but if you just want to get an approximate feel for your data, you should be fine.

This will create a view containing the circles in Google Mercator projection:

   ) AS tower_circle
FROM towers;
  • the equation I am to use for calculating radius is radius=(lambda/4*pi)*sqrt((PtGtGr)/Pr)..... My towers table contains the following columns tid,lat,lon,lambda,Pt,Gt,Gr,Pr.... so can I use the query CREATE VIEW circles AS SELECT tower_id, ST_BUFFER( ST_Transform( ST_SetSRID( ST_MakePoint(lon,lat), 4326), 900913, (lambda/4*pi)*sqrt((PtGtGr)/Pr) ) AS tower_circle FROM towers; Jun 2, 2011 at 10:40
  • 1
    looks good to me
    – underdark
    Jun 2, 2011 at 10:50

Have a look at this blog post http://geo-solutions.blogspot.com/2010/11/fun-stuff-computing-circular-buffers-in.html that discusses using the WPS service in GeoServer to produce circles. It also shows why what you are trying to do will probably not produce the results you expect for largish distances.

  • 1
    Wont this work: insert point,radius values in postgis table using ST_Buffer() and just add this postgis table to geoserver, ofcourse the prerequisite is to calculate the radius(distance) from the equation Jun 1, 2011 at 21:12

You can do it with JavaScript if you'd like and have the client browser take care of it: You can test the code on this website: http://jsfiddle.net/NtuEv/

Basically the function takes a 3 arguments: latitude, longitude and radius. It will return the coordinates that make up the circle.

You can play with the following line of code to output the coordinates however you like either in linestring fashion or whatever:

response += lon_rad.toDeg() + "," + lat_rad.toDeg() + ",0 ";

Javascript Code:

var divElement = $('div#info');

// extend Number object with methods for converting degrees/radians
/** Convert numeric degrees to radians */
if (typeof (String.prototype.toRad) === "undefined") {
    Number.prototype.toRad = function () {
        return this * Math.PI / 180;

/** Convert radians to numeric (signed) degrees */
if (typeof (String.prototype.toDeg) === "undefined") {
    Number.prototype.toDeg = function () {
        return this * 180 / Math.PI;

function fmod (X, Y) {
 return X % Y;

function GetCircleCoordinates (lat, lng, radius) {

        var response = "";
        var rLat = lat.toRad();
        var rLon = lng.toRad();

        var d_rad = radius / 6378137;

        for (i = 0; i <= 360; i++) {

            var radial = i.toRad();
            var lat_rad = Math.asin(Math.sin(rLat) * Math.cos(d_rad) + Math.cos(rLat) * Math.sin(d_rad) * Math.cos(radial));
            var dlon_rad = Math.atan2(Math.sin(radial) * Math.sin(d_rad) * Math.cos(rLat), Math.cos(d_rad) - Math.sin(rLat) * Math.sin(lat_rad));
            var lon_rad = fmod((rLon + dlon_rad + Math.PI), 2 * Math.PI) - Math.PI;
            response += lon_rad.toDeg() + "," + lat_rad.toDeg() + ",0 ";

        return response;

var circlecoords = GetCircleCoordinates(22.26, -73.34, 1100);


EDIT #1: Updated jsfiddle link.... it was wrong, it is: http://jsfiddle.net/NtuEv/

  • I have many circles to render, using javascript I think I cannot do for more than 50. This is why I switched to geoserver. Am I right? Jun 2, 2011 at 18:18
  • 1
    That's correct, i wouldn't use the JS then. I'll leave the answer up in case someone else needs a javascript to make circles.
    – CaptDragon
    Jun 2, 2011 at 18:53

Your Answer

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

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