# Creating circles using formula

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.

How do I carry on this task?

My Idea is to use these steps once I get distance from the equation.

``````CREATE TABLE circles (cid int4,point_circle st_geometry);

INSERT INTO circles
VALUES(1,
);
``````

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

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:

``````CREATE VIEW circles
AS
SELECT
tower_id,
ST_BUFFER(
ST_Transform(
ST_SetSRID(
ST_MakePoint(lon,lat),
4326),
900913,
) AS tower_circle
FROM towers;
``````

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.

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") {
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 = "";

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