How to use "is_null()"?

Hi,

my flex-import using lua is getting better ad better :slight_smile:

using

a.geom = object.as_multipolygon()

somtimes leads to empty geometries, which is ok if the boundary is incomplete or damaged.

I need to filter this releations, but how?

the documentations says

as_multipolygon() 	Create (multi)polygon geometry from OSM way/relation object.

The as_* functions will return a NULL geometry (check with is_null())
if the geometry can not be created for some reason,
for instance a polygon can only be created from closed ways.
This can also happen if your input data is incomplete,
for instance when missing nodes referenced from a way.

but i don’t know how to use that. Tryed a lot but nothing works.

a.geom = object.as_multipolygon()
if a.geom.is_null() then
   a.is_closed = false
else
   a.is_closed = true
end
2022-09-23 15:13:31  [0] ERROR: Failed to execute Lua function 'osm2pgsql.process_relation': lua/global.lua:175: bad argument #1 to 'is_null' (osm2pgsql.Geometry expected, got no value)
stack traceback:
	[C]: in field 'is_null'
	lua/global.lua:175: in function 'process_relation'
	lua/global.lua:199: in function <lua/global.lua:198>.

Any working example would be nice.

Regards
walter

When calling functions on an object in Lua, you need to use a colon. So your example should be

a.geom = object:as_multipolygon()
if a.geom:is_null() then
   a.is_closed = false
else
   a.is_closed = true
end

Also note that if all you want is to skip inserting a row if the geometry is invalid, you can also set the geometry column to not_null. See Osm2pgsql Manual - osm2pgsql for more information.

thanks

to really read a manual to the end might be useful :wink:

Regards
walter