[MDEV-4759] OPENGIS - artificial (not oficial) support to circle Created: 2013-07-05  Updated: 2014-03-03  Resolved: 2014-03-03

Status: Closed
Project: MariaDB Server
Component/s: None
Fix Version/s: None

Type: Task Priority: Major
Reporter: roberto spadim Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: opengis


 Description   

opengis is very nice, but we don't have a CIRCLE (ok it's mercator and blablabla), maybe we could use a circle->polygon converter.... example:

polygonfromtext("CIRCLE(10 20 30)")

could return a circle with radius 10, center point(20,30)
we could add a variable (a variable that should be placed in query cache flags or a global variable that should be used in replications) @@opengis_circle_points=360

we will do something like... (cos and sin are degree not radian)

for(i=0;i<360;i+=360/@@opengis_circle_points)
   poligon point to (x=center+cos(i)*radius, y=center+sin(i)*radius)
poligon point to (x=center+cos(360)*radius, y=center+sin(360)*radius)

with this we create a poligon in each circle point
it's a nice feature since many code is done at client side and we could put it in server side

this function could return something like:

polygon(x0 y0, x1 y1, x2 y2 ... x360 y360)   where 0=0degree,1=1degree..360=360degree)

i didn't read the mariadb gis source yet, but i think it's a easy function
we will not save circle, just polygons
javascript (using gmaps)

	function drawCircle(lng,lat,kmRadius) {
		var Cradius = 1;		// km radius
		var Ccolor = '#0000ff';		// color blue
		var Cwidth = 3;			// width pixels
		var d2r = Math.PI/180;		// degrees to radians
		var r2d = 180/Math.PI;		// radians to degrees
		var Clat = (kmRadius/6378.8)*r2d;   //  using 6378.8 as earth's radius
		var Clng = Clat/Math.cos(lat*d2r);
		var Cpoints = [];
		var i, theta, Cx, Cy;
		var npoints=33;
		for (i=0; i < npoints; i++){
			theta = Math.PI * (i/Math.floor(npoints/2));
			Cx = lng + (Clng * Math.cos(theta));
			Cy = lat + (Clat * Math.sin(theta));
			Cpoints.push(new GLatLng(Cy,Cx));
		}
		map.addOverlay(new GPolyline(Cpoints,Ccolor,Cwidth));
	} 



 Comments   
Comment by roberto spadim [ 2013-07-05 ]

Example:
SELECT ASWKT(GEOMFROMTEXT("CIRCLE(10 10 20)"))
should return something like:
POLYGON((x0 y0),(x1 y1),(x2 y2), ... ,(x0 y0))

at spatial.cc (mariadb 10.0.3 - line 181)

Geometry *Geometry::create_from_wkt(Geometry_buffer *buffer,
Gis_read_stream *trs, String *wkt,
bool init_stream)
{
LEX_STRING name;
Class_info *ci;
char next_sym;

if (trs->get_next_word(&name))

{ trs->set_error_msg("Geometry name expected"); return NULL; }

if (!(ci= find_class(name.str, name.length)) ||
wkt->reserve(1 + 4, 512))
return NULL;
>===< here we could put the circle feature and rewrite the WKT, or maybe create a new class just to circle and save it as polygon
Geometry *result= (*ci->m_create_func)(buffer->data);

Comment by Alexey Botchkov [ 2014-03-03 ]

ST_BUFFER(POINT(10,20), 30) returns just the polygon-from-circle centered in the POINT.

Generated at Thu Feb 08 06:58:56 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.