PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ ARRAY2GEOS()

GEOSGeometry** ARRAY2GEOS ( ArrayType *  array,
uint32_t  nelems,
int *  is3d,
int *  srid 
)

Definition at line 3048 of file postgis/lwgeom_geos.c.

References error_if_srid_mismatch(), dumpnode::geom, GEOSnoop(), gserialized_get_srid(), gserialized_has_z(), PG_FUNCTION_INFO_V1(), POSTGIS2GEOS(), and genraster::value.

Referenced by clusterintersecting_garray(), and polygonize_garray().

3049 {
3050  ArrayIterator iterator;
3051  Datum value;
3052  bool isnull;
3053  bool gotsrid = false;
3054  uint32_t i = 0;
3055 
3056  GEOSGeometry** geos_geoms = palloc(nelems * sizeof(GEOSGeometry*));
3057 
3058 #if POSTGIS_PGSQL_VERSION >= 95
3059  iterator = array_create_iterator(array, 0, NULL);
3060 #else
3061  iterator = array_create_iterator(array, 0);
3062 #endif
3063 
3064  while(array_iterate(iterator, &value, &isnull))
3065  {
3066  GSERIALIZED *geom = (GSERIALIZED*) DatumGetPointer(value);
3067 
3068  if (isnull)
3069  {
3070  continue;
3071  }
3072 
3073  *is3d = *is3d || gserialized_has_z(geom);
3074 
3075  geos_geoms[i] = (GEOSGeometry*) POSTGIS2GEOS(geom);
3076  if (!geos_geoms[i]) /* exception thrown at construction */
3077  {
3078  uint32_t j;
3079  lwpgerror("Geometry could not be converted to GEOS");
3080 
3081  for (j = 0; j < i; j++) {
3082  GEOSGeom_destroy(geos_geoms[j]);
3083  }
3084  return NULL;
3085  }
3086 
3087  if (!gotsrid)
3088  {
3089  *srid = gserialized_get_srid(geom);
3090  gotsrid = true;
3091  }
3092  else if (*srid != gserialized_get_srid(geom))
3093  {
3094  uint32_t j;
3096 
3097  for (j = 0; j <= i; j++) {
3098  GEOSGeom_destroy(geos_geoms[j]);
3099  }
3100  return NULL;
3101  }
3102 
3103  i++;
3104  }
3105 
3106  array_free_iterator(iterator);
3107  return geos_geoms;
3108 }
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:371
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:45
unsigned int uint32_t
Definition: uthash.h:78
LWGEOM * geom
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
int value
Definition: genraster.py:61
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:100
Here is the call graph for this function:
Here is the caller graph for this function: