Type-less geometry column

19 views
Skip to first unread message

Ben Harper

unread,
Sep 22, 2010, 3:35:18 AM9/22/10
to SpatiaLite Users
Hi,
Is there any way to create an untyped geometry column? All I really
want is to be able to create a column that can accept MULTIPOLYGON as
well as POLYGON types (and likewise for LINESTRING).

From digging in the code a bit, it seems like the best solution is to
add a 'GEOMETRY' datatype that will accept any value. I've tried doign
this with AddGeometryColumn(), and I notice that it accepts type
'GEOMETRY', and this appears so far to work.

However, the docs mention nothing about this, so I'm wondering what
the thinking is here?

Thanks,
Ben

a.furieri

unread,
Sep 22, 2010, 5:18:02 AM9/22/10
to SpatiaLite Users
Hi Ben,

your question is a really old one:
and it's since OGC-SFS introduction
that a 'standard' answer exists:

a) a LINESTRING simply is a MULTILINESTRING
containing only one entity
b) the same is for POLYGON vs MULTIPOLYGON

so, when using any OGC-SFS DMBS, you simply have to:
- declare a MULTIxxxx column
- then representing any single-geometry using the
corresponding MULTI-format

SpatiaLite make things even easier:
you can use the appropriate type-casting
function e.g.:

CastToMultiLinestring(linestring)
CastToMultiPolygon(polygon)

this is completely harmless, so you can
safely invoke the followings as well:

CastToMultiLinestring(multilinestrin)
CastToMultiPolygon(multipolyon)

you'll get back anyway a MULTIxxxxx
in any case.

please note: this approach is exactly the
same implemented by PostGIS and by many others
OGC-SFS compliant DBMS

bye
Sandro

Ben Harper

unread,
Sep 22, 2010, 6:18:32 AM9/22/10
to SpatiaLite Users
Thanks a lot!
I was jumping hoops around PostGIS, ripping out the constraints etc.
I'll do as you suggest.

Regards,
Ben
Reply all
Reply to author
Forward
0 new messages