Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-4759

OPENGIS - artificial (not oficial) support to circle

    Details

    • Type: Task
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Fix Version/s: None
    • Component/s: None
    • Labels:

      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));
      	} 
      

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            rspadim roberto spadim added a comment -

            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);

            Show
            rspadim roberto spadim added a comment - 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);
            Hide
            holyfoot Alexey Botchkov added a comment -

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

            Show
            holyfoot Alexey Botchkov added a comment - ST_BUFFER(POINT(10,20), 30) returns just the polygon-from-circle centered in the POINT.

              People

              • Assignee:
                Unassigned
                Reporter:
                rspadim roberto spadim
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: