In PostGIS (2.1.8) I use function ST_NumGeometries
for nums of count geometry
. This function have one argument 'geometry' type.
I need this function for geography
type. I looked for but I didn't find it.
-
2Have you tried to cast into geometry first? You can do it on-the-fly.– user30184Dec 8, 2017 at 14:01
-
I don't understand. You mean like this? ST_NumGeometries(geog::geometry)– ondrusuDec 8, 2017 at 14:05
1 Answer
From the docs
ST_NumGeometries
— If geometry is aGEOMETRYCOLLECTION
(orMULTI*
) return the number of geometries, for single geometries will return 1, otherwise return NULL.
So, as mentioned in the comments, simply cast first with ::geometry
SELECT ST_NumGeometries( geog::geometry )
FROM CAST( ST_Multi(ST_MakePoint(1,1)) AS geography) AS geog;
SELECT ST_NumGeometries( geog::geometry )
FROM CAST( ST_ForceCollection(ST_MakePoint(1,1)) AS geography) AS geog;