diff options
author | Alexey Botchkov <holyfoot@askmonty.org> | 2017-01-24 02:29:04 +0400 |
---|---|---|
committer | Alexey Botchkov <holyfoot@askmonty.org> | 2017-01-24 02:29:04 +0400 |
commit | 0d107a85b3dd6969e66cc9cb4bd29e1cc92a7d18 (patch) | |
tree | 4ea2e72a0886dae95c31ecdc9556b381c4e097d5 /sql/item_create.cc | |
parent | 1f3ad6a4ba63074c51c84dff449c35a8314a7f36 (diff) | |
download | mariadb-git-0d107a85b3dd6969e66cc9cb4bd29e1cc92a7d18.tar.gz |
MDEV-11042 Implement GeoJSON functions.
ST_AsGeoJSON and ST_GeomFromGeoJSON functions implemented.
Diffstat (limited to 'sql/item_create.cc')
-rw-r--r-- | sql/item_create.cc | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/sql/item_create.cc b/sql/item_create.cc index a506ab948d1..add8da67810 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -1262,6 +1262,34 @@ protected: #ifdef HAVE_SPATIAL +class Create_func_geometry_from_json : public Create_native_func +{ +public: + virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list); + + static Create_func_geometry_from_json s_singleton; + +protected: + Create_func_geometry_from_json() {} + virtual ~Create_func_geometry_from_json() {} +}; + + +class Create_func_as_geojson : public Create_native_func +{ +public: + virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list); + + static Create_func_as_geojson s_singleton; + +protected: + Create_func_as_geojson() {} + virtual ~Create_func_as_geojson() {} +}; +#endif /*HAVE_SPATIAL*/ + + +#ifdef HAVE_SPATIAL class Create_func_geometry_type : public Create_func_arg1 { public: @@ -4533,6 +4561,101 @@ Create_func_geometry_from_wkb::create_native(THD *thd, LEX_STRING name, #ifdef HAVE_SPATIAL +Create_func_geometry_from_json Create_func_geometry_from_json::s_singleton; + +Item* +Create_func_geometry_from_json::create_native(THD *thd, LEX_STRING name, + List<Item> *item_list) +{ + Item *func= NULL; + int arg_count= 0; + + if (item_list != NULL) + arg_count= item_list->elements; + + switch (arg_count) { + case 1: + { + Item *json= item_list->pop(); + func= new (thd->mem_root) Item_func_geometry_from_json(thd, json); + thd->lex->uncacheable(UNCACHEABLE_RAND); + break; + } + case 2: + { + Item *json= item_list->pop(); + Item *options= item_list->pop(); + func= new (thd->mem_root) Item_func_geometry_from_json(thd, json, options); + break; + } + case 3: + { + Item *json= item_list->pop(); + Item *options= item_list->pop(); + Item *srid= item_list->pop(); + func= new (thd->mem_root) Item_func_geometry_from_json(thd, json, options, + srid); + break; + } + default: + { + my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str); + break; + } + } + + return func; +} + + +Create_func_as_geojson Create_func_as_geojson::s_singleton; + +Item* +Create_func_as_geojson::create_native(THD *thd, LEX_STRING name, + List<Item> *item_list) +{ + Item *func= NULL; + int arg_count= 0; + + if (item_list != NULL) + arg_count= item_list->elements; + + switch (arg_count) { + case 1: + { + Item *geom= item_list->pop(); + func= new (thd->mem_root) Item_func_as_geojson(thd, geom); + thd->lex->uncacheable(UNCACHEABLE_RAND); + break; + } + case 2: + { + Item *geom= item_list->pop(); + Item *max_dec= item_list->pop(); + func= new (thd->mem_root) Item_func_as_geojson(thd, geom, max_dec); + break; + } + case 3: + { + Item *geom= item_list->pop(); + Item *max_dec= item_list->pop(); + Item *options= item_list->pop(); + func= new (thd->mem_root) Item_func_as_geojson(thd, geom, max_dec, options); + break; + } + default: + { + my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str); + break; + } + } + + return func; +} +#endif /*HAVE_SPATIAL*/ + + +#ifdef HAVE_SPATIAL Create_func_geometry_type Create_func_geometry_type::s_singleton; Item* @@ -6723,6 +6846,7 @@ static Native_func_registry func_array[] = { { C_STRING_WITH_LEN("STR_TO_DATE") }, BUILDER(Create_func_str_to_date)}, { { C_STRING_WITH_LEN("ST_AREA") }, GEOM_BUILDER(Create_func_area)}, { { C_STRING_WITH_LEN("ST_ASBINARY") }, GEOM_BUILDER(Create_func_as_wkb)}, + { { C_STRING_WITH_LEN("ST_ASGEOJSON") }, GEOM_BUILDER(Create_func_as_geojson)}, { { C_STRING_WITH_LEN("ST_ASTEXT") }, GEOM_BUILDER(Create_func_as_wkt)}, { { C_STRING_WITH_LEN("ST_ASWKB") }, GEOM_BUILDER(Create_func_as_wkb)}, { { C_STRING_WITH_LEN("ST_ASWKT") }, GEOM_BUILDER(Create_func_as_wkt)}, @@ -6748,6 +6872,7 @@ static Native_func_registry func_array[] = { { C_STRING_WITH_LEN("ST_GEOMETRYFROMWKB") }, GEOM_BUILDER(Create_func_geometry_from_wkb)}, { { C_STRING_WITH_LEN("ST_GEOMETRYN") }, GEOM_BUILDER(Create_func_geometryn)}, { { C_STRING_WITH_LEN("ST_GEOMETRYTYPE") }, GEOM_BUILDER(Create_func_geometry_type)}, + { { C_STRING_WITH_LEN("ST_GEOMFROMGEOJSON") }, GEOM_BUILDER(Create_func_geometry_from_json)}, { { C_STRING_WITH_LEN("ST_GEOMFROMTEXT") }, GEOM_BUILDER(Create_func_geometry_from_text)}, { { C_STRING_WITH_LEN("ST_GEOMFROMWKB") }, GEOM_BUILDER(Create_func_geometry_from_wkb)}, #ifndef DBUG_OFF |