Commit 1782102d authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-11042 Implement GeoJSON functions.

        Typenames made into proper character case.
parent 6cdbf202
select st_asgeojson(geomfromtext('POINT(1 1)')); select st_asgeojson(geomfromtext('POINT(1 1)'));
st_asgeojson(geomfromtext('POINT(1 1)')) st_asgeojson(geomfromtext('POINT(1 1)'))
{"type": "POINT", "coordinates": [1, 1]} {"type": "Point", "coordinates": [1, 1]}
select st_asgeojson(geomfromtext('LINESTRING(10 10,20 10,20 20,10 20,10 10)')); select st_asgeojson(geomfromtext('LINESTRING(10 10,20 10,20 20,10 20,10 10)'));
st_asgeojson(geomfromtext('LINESTRING(10 10,20 10,20 20,10 20,10 10)')) st_asgeojson(geomfromtext('LINESTRING(10 10,20 10,20 20,10 20,10 10)'))
{"type": "LINESTRING", "coordinates": [[10, 10], [20, 10], [20, 20], [10, 20], [10, 10]]} {"type": "LineString", "coordinates": [[10, 10], [20, 10], [20, 20], [10, 20], [10, 10]]}
select st_asgeojson(geomfromtext('POLYGON((10 10,20 10,20 20,10 20,10 10))')); select st_asgeojson(geomfromtext('POLYGON((10 10,20 10,20 20,10 20,10 10))'));
st_asgeojson(geomfromtext('POLYGON((10 10,20 10,20 20,10 20,10 10))')) st_asgeojson(geomfromtext('POLYGON((10 10,20 10,20 20,10 20,10 10))'))
{"type": "POLYGON", "coordinates": [[[10, 10], [20, 10], [20, 20], [10, 20], [10, 10]]]} {"type": "Polygon", "coordinates": [[[10, 10], [20, 10], [20, 20], [10, 20], [10, 10]]]}
select st_asgeojson(geomfromtext('MULTIPOLYGON(((10 10,20 10,20 20,10 20,10 10)))')); select st_asgeojson(geomfromtext('MULTIPOLYGON(((10 10,20 10,20 20,10 20,10 10)))'));
st_asgeojson(geomfromtext('MULTIPOLYGON(((10 10,20 10,20 20,10 20,10 10)))')) st_asgeojson(geomfromtext('MULTIPOLYGON(((10 10,20 10,20 20,10 20,10 10)))'))
{"type": "MULTIPOLYGON", "coordinates": [[[[10, 10], [20, 10], [20, 20], [10, 20], [10, 10]]]]} {"type": "MultiPolygon", "coordinates": [[[[10, 10], [20, 10], [20, 20], [10, 20], [10, 10]]]]}
select st_asgeojson(geomfromtext('multilinestring((10 10,20 10,20 20,10 20,10 10))')); select st_asgeojson(geomfromtext('multilinestring((10 10,20 10,20 20,10 20,10 10))'));
st_asgeojson(geomfromtext('multilinestring((10 10,20 10,20 20,10 20,10 10))')) st_asgeojson(geomfromtext('multilinestring((10 10,20 10,20 20,10 20,10 10))'))
{"type": "MULTILINESTRING", "coordinates": [[[10, 10], [20, 10], [20, 20], [10, 20], [10, 10]]]} {"type": "MultiLineString", "coordinates": [[[10, 10], [20, 10], [20, 20], [10, 20], [10, 10]]]}
select st_asgeojson(geomfromtext('multipoint(10 10,20 10,20 20,10 20,10 10)')); select st_asgeojson(geomfromtext('multipoint(10 10,20 10,20 20,10 20,10 10)'));
st_asgeojson(geomfromtext('multipoint(10 10,20 10,20 20,10 20,10 10)')) st_asgeojson(geomfromtext('multipoint(10 10,20 10,20 20,10 20,10 10)'))
{"type": "MULTIPOINT", "coordinates": [[10, 10], [20, 10], [20, 20], [10, 20], [10, 10]]} {"type": "MultiPoint", "coordinates": [[10, 10], [20, 10], [20, 20], [10, 20], [10, 10]]}
select st_asgeojson(st_geomfromtext('GEOMETRYCOLLECTION(POINT(100 0),LINESTRING(101 0,102 1))')); select st_asgeojson(st_geomfromtext('GEOMETRYCOLLECTION(POINT(100 0),LINESTRING(101 0,102 1))'));
st_asgeojson(st_geomfromtext('GEOMETRYCOLLECTION(POINT(100 0),LINESTRING(101 0,102 1))')) st_asgeojson(st_geomfromtext('GEOMETRYCOLLECTION(POINT(100 0),LINESTRING(101 0,102 1))'))
{"type": "GEOMETRYCOLLECTION", "geometries": [{"type": "POINT", "coordinates": [100, 0]}, {"type": "LINESTRING", "coordinates": [[101, 0], [102, 1]]}]} {"type": "GeometryCollection", "geometries": [{"type": "Point", "coordinates": [100, 0]}, {"type": "LineString", "coordinates": [[101, 0], [102, 1]]}]}
SELECT st_astext(st_geomfromgeojson('{"type":"point","coordinates":[1,2]}')); SELECT st_astext(st_geomfromgeojson('{"type":"point","coordinates":[1,2]}'));
st_astext(st_geomfromgeojson('{"type":"point","coordinates":[1,2]}')) st_astext(st_geomfromgeojson('{"type":"point","coordinates":[1,2]}'))
POINT(1 2) POINT(1 2)
......
...@@ -58,12 +58,14 @@ Geometry::Class_info *Geometry::ci_collection[Geometry::wkb_last+1]= ...@@ -58,12 +58,14 @@ Geometry::Class_info *Geometry::ci_collection[Geometry::wkb_last+1]=
static Geometry::Class_info **ci_collection_end= static Geometry::Class_info **ci_collection_end=
Geometry::ci_collection+Geometry::wkb_last + 1; Geometry::ci_collection+Geometry::wkb_last + 1;
Geometry::Class_info::Class_info(const char *name, int type_id, Geometry::Class_info::Class_info(const char *name, const char *geojson_name,
create_geom_t create_func): int type_id, create_geom_t create_func):
m_type_id(type_id), m_create_func(create_func) m_type_id(type_id), m_create_func(create_func)
{ {
m_name.str= (char *) name; m_name.str= (char *) name;
m_name.length= strlen(name); m_name.length= strlen(name);
m_geojson_name.str= (char *) geojson_name;
m_geojson_name.length= strlen(geojson_name);
ci_collection[type_id]= this; ci_collection[type_id]= this;
} }
...@@ -105,26 +107,27 @@ static Geometry *create_geometrycollection(char *buffer) ...@@ -105,26 +107,27 @@ static Geometry *create_geometrycollection(char *buffer)
static Geometry::Class_info point_class("POINT", static Geometry::Class_info point_class("POINT", "Point",
Geometry::wkb_point, create_point); Geometry::wkb_point, create_point);
static Geometry::Class_info linestring_class("LINESTRING", static Geometry::Class_info linestring_class("LINESTRING", "LineString",
Geometry::wkb_linestring, Geometry::wkb_linestring,
create_linestring); create_linestring);
static Geometry::Class_info polygon_class("POLYGON", static Geometry::Class_info polygon_class("POLYGON", "Polygon",
Geometry::wkb_polygon, Geometry::wkb_polygon,
create_polygon); create_polygon);
static Geometry::Class_info multipoint_class("MULTIPOINT", static Geometry::Class_info multipoint_class("MULTIPOINT", "MultiPoint",
Geometry::wkb_multipoint, Geometry::wkb_multipoint,
create_multipoint); create_multipoint);
static Geometry::Class_info static Geometry::Class_info
multilinestring_class("MULTILINESTRING", multilinestring_class("MULTILINESTRING", "MultiLineString",
Geometry::wkb_multilinestring, create_multilinestring); Geometry::wkb_multilinestring, create_multilinestring);
static Geometry::Class_info multipolygon_class("MULTIPOLYGON", static Geometry::Class_info multipolygon_class("MULTIPOLYGON", "MultiPolygon",
Geometry::wkb_multipolygon, Geometry::wkb_multipolygon,
create_multipolygon); create_multipolygon);
static Geometry::Class_info static Geometry::Class_info
geometrycollection_class("GEOMETRYCOLLECTION",Geometry::wkb_geometrycollection, geometrycollection_class("GEOMETRYCOLLECTION", "GeometryCollection",
Geometry::wkb_geometrycollection,
create_geometrycollection); create_geometrycollection);
static void get_point(double *x, double *y, const char *data) static void get_point(double *x, double *y, const char *data)
...@@ -251,14 +254,14 @@ static const int feature_coll_type_len= 17; ...@@ -251,14 +254,14 @@ static const int feature_coll_type_len= 17;
int Geometry::as_json(String *wkt, uint max_dec_digits, const char **end) int Geometry::as_json(String *wkt, uint max_dec_digits, const char **end)
{ {
uint32 len= (uint) get_class_info()->m_name.length; uint32 len= (uint) get_class_info()->m_geojson_name.length;
if (wkt->reserve(4 + type_keyname_len + 2 + len + 2 + 2 + if (wkt->reserve(4 + type_keyname_len + 2 + len + 2 + 2 +
coord_keyname_len + 4, 512)) coord_keyname_len + 4, 512))
return 1; return 1;
wkt->qs_append("{\"", 2); wkt->qs_append("{\"", 2);
wkt->qs_append((const char *) type_keyname, type_keyname_len); wkt->qs_append((const char *) type_keyname, type_keyname_len);
wkt->qs_append("\": \"", 4); wkt->qs_append("\": \"", 4);
wkt->qs_append(get_class_info()->m_name.str, len); wkt->qs_append(get_class_info()->m_geojson_name.str, len);
wkt->qs_append("\", \"", 4); wkt->qs_append("\", \"", 4);
if (get_class_info() == &geometrycollection_class) if (get_class_info() == &geometrycollection_class)
wkt->qs_append((const char *) geometries_keyname, geometries_keyname_len); wkt->qs_append((const char *) geometries_keyname, geometries_keyname_len);
......
...@@ -265,9 +265,11 @@ class Geometry ...@@ -265,9 +265,11 @@ class Geometry
{ {
public: public:
LEX_STRING m_name; LEX_STRING m_name;
LEX_STRING m_geojson_name;
int m_type_id; int m_type_id;
create_geom_t m_create_func; create_geom_t m_create_func;
Class_info(const char *name, int type_id, create_geom_t create_func); Class_info(const char *name, const char *gejson_name,
int type_id, create_geom_t create_func);
}; };
virtual const Class_info *get_class_info() const=0; virtual const Class_info *get_class_info() const=0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment