PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ ARRAY2GEOS()

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

Definition at line 2940 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().

2941 {
2942  ArrayIterator iterator;
2943  Datum value;
2944  bool isnull;
2945  bool gotsrid = false;
2946  uint32_t i = 0;
2947 
2948  GEOSGeometry** geos_geoms = palloc(nelems * sizeof(GEOSGeometry*));
2949 
2950 #if POSTGIS_PGSQL_VERSION >= 95
2951  iterator = array_create_iterator(array, 0, NULL);
2952 #else
2953  iterator = array_create_iterator(array, 0);
2954 #endif
2955 
2956  while(array_iterate(iterator, &value, &isnull))
2957  {
2958  GSERIALIZED *geom = (GSERIALIZED*) DatumGetPointer(value);
2959 
2960  if (isnull)
2961  {
2962  continue;
2963  }
2964 
2965  *is3d = *is3d || gserialized_has_z(geom);
2966 
2967  geos_geoms[i] = POSTGIS2GEOS(geom);
2968  if (!geos_geoms[i])
2969  {
2970  uint32_t j;
2971  lwpgerror("Geometry could not be converted to GEOS");
2972 
2973  for (j = 0; j < i; j++) {
2974  GEOSGeom_destroy(geos_geoms[j]);
2975  }
2976  return NULL;
2977  }
2978 
2979  if (!gotsrid)
2980  {
2981  *srid = gserialized_get_srid(geom);
2982  gotsrid = true;
2983  }
2984  else if (*srid != gserialized_get_srid(geom))
2985  {
2986  uint32_t j;
2988 
2989  for (j = 0; j <= i; j++) {
2990  GEOSGeom_destroy(geos_geoms[j]);
2991  }
2992  return NULL;
2993  }
2994 
2995  i++;
2996  }
2997 
2998  array_free_iterator(iterator);
2999  return geos_geoms;
3000 }
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:338
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:99
Here is the call graph for this function:
Here is the caller graph for this function: