@@ -83,6 +83,7 @@ TRAMPOLINE(app_as_geometrycollection, as_geometrycollection)
8383TRAMPOLINE(geom_len, __len)
8484TRAMPOLINE(geom_tostring, __tostring)
8585TRAMPOLINE(geom_geometrytype, geometrytype)
86+ TRAMPOLINE(geom_is_null, is_null)
8687TRAMPOLINE(geom_srid, srid)
8788TRAMPOLINE(geom_area, area)
8889TRAMPOLINE(geom_centroid, centroid)
@@ -678,7 +679,7 @@ void output_flex_t::write_column(
678679 // called, because for 'add_row()' geometry columns are handled
679680 // earlier and 'write_column()' is not called.
680681 if (ltype == LUA_TUSERDATA) {
681- auto const *geom = unpack_geometry (lua_state ());
682+ auto const *const geom = unpack_geometry (lua_state ());
682683 if (geom && !geom->is_null ()) {
683684 if (geom->srid () == column.srid ()) {
684685 // OSM id not available here, so use dummy 0, it is used
@@ -951,30 +952,40 @@ int output_flex_t::app_as_geometrycollection()
951952 return 1 ;
952953}
953954
955+ // XXX Implementation for Lua __tostring function on geometries. Currently
956+ // just returns the type as string. This could be improved, for instance by
957+ // showing a WKT representation of the geometry.
954958int output_flex_t::geom_tostring ()
955959{
956960 return geom_geometrytype ();
957961}
958962
959963int output_flex_t::geom_geometrytype ()
960964{
961- auto const *input_geometry = unpack_geometry (lua_state ());
965+ auto const *const input_geometry = unpack_geometry (lua_state ());
962966 auto const type = geometry_type (*input_geometry);
963967 lua_pushlstring (lua_state (), type.data (), type.size ());
964968 return 1 ;
965969}
966970
967971int output_flex_t::geom_len ()
968972{
969- auto const *input_geometry = unpack_geometry (lua_state ());
973+ auto const *const input_geometry = unpack_geometry (lua_state ());
970974 lua_pushinteger (lua_state (),
971975 static_cast <lua_Integer>(num_geometries (*input_geometry)));
972976 return 1 ;
973977}
974978
979+ int output_flex_t::geom_is_null ()
980+ {
981+ auto const *const input_geometry = unpack_geometry (lua_state ());
982+ lua_pushboolean (lua_state (), input_geometry->is_null ());
983+ return 1 ;
984+ }
985+
975986int output_flex_t::geom_srid ()
976987{
977- auto const *input_geometry = unpack_geometry (lua_state ());
988+ auto const *const input_geometry = unpack_geometry (lua_state ());
978989 lua_pushinteger (lua_state (),
979990 static_cast <lua_Integer>(input_geometry->srid ()));
980991 return 1 ;
@@ -986,7 +997,7 @@ int output_flex_t::geom_area()
986997 throw std::runtime_error{" No parameter(s) needed for area()." };
987998 }
988999
989- auto const *input_geometry = unpack_geometry (lua_state ());
1000+ auto const *const input_geometry = unpack_geometry (lua_state ());
9901001 double const area = geom::area (*input_geometry);
9911002 lua_pushnumber (lua_state (), area);
9921003
@@ -999,7 +1010,7 @@ int output_flex_t::geom_centroid()
9991010 throw std::runtime_error{" No parameter(s) needed for centroid()." };
10001011 }
10011012
1002- auto const *input_geometry = unpack_geometry (lua_state ());
1013+ auto const *const input_geometry = unpack_geometry (lua_state ());
10031014
10041015 create_lua_geometry_object (lua_state (), [&](geom::geometry_t *geom) {
10051016 *geom = geom::centroid (*input_geometry);
@@ -1027,7 +1038,7 @@ int output_flex_t::geom_transform()
10271038 int const srid = lua_tointeger (lua_state (), -1 );
10281039 lua_pop (lua_state (), 1 ); // srid parameter
10291040
1030- auto const *input_geometry = unpack_geometry (lua_state ());
1041+ auto const *const input_geometry = unpack_geometry (lua_state ());
10311042
10321043 if (input_geometry->srid () != 4326 ) {
10331044 throw std::runtime_error{
@@ -1050,7 +1061,7 @@ int output_flex_t::geom_split_multi()
10501061 throw std::runtime_error{" No parameter(s) needed for split_multi()." };
10511062 }
10521063
1053- auto const *input_geometry = unpack_geometry (lua_state ());
1064+ auto const *const input_geometry = unpack_geometry (lua_state ());
10541065 auto const geoms = geom::split_multi (*input_geometry, true );
10551066
10561067 lua_createtable (lua_state (), (int )geoms.size (), 0 );
@@ -1081,7 +1092,7 @@ int output_flex_t::geom_simplify()
10811092 double const tolerance = lua_tonumber (lua_state (), -1 );
10821093 lua_pop (lua_state (), 1 ); // tolerance parameter
10831094
1084- auto const *input_geometry = unpack_geometry (lua_state ());
1095+ auto const *const input_geometry = unpack_geometry (lua_state ());
10851096
10861097 create_lua_geometry_object (lua_state (), [&](geom::geometry_t *geom) {
10871098 *geom = geom::simplify (*input_geometry, tolerance);
@@ -2237,6 +2248,7 @@ void output_flex_t::init_lua(std::string const &filename)
22372248 lua_trampoline_geom_tostring);
22382249 lua_pushvalue (lua_state (), -1 );
22392250 lua_setfield (lua_state (), -2 , " __index" );
2251+ luaX_add_table_func (lua_state (), " is_null" , lua_trampoline_geom_is_null);
22402252 luaX_add_table_func (lua_state (), " srid" , lua_trampoline_geom_srid);
22412253 luaX_add_table_func (lua_state (), " area" , lua_trampoline_geom_area);
22422254 luaX_add_table_func (lua_state (), " geometrytype" ,
0 commit comments