PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ ARRAY2GEOS()

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

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

2749 {
2750  ArrayIterator iterator;
2751  Datum value;
2752  bool isnull;
2753  bool gotsrid = false;
2754  uint32_t i = 0;
2755 
2756  GEOSGeometry** geos_geoms = palloc(nelems * sizeof(GEOSGeometry*));
2757 
2758 #if POSTGIS_PGSQL_VERSION >= 95
2759  iterator = array_create_iterator(array, 0, NULL);
2760 #else
2761  iterator = array_create_iterator(array, 0);
2762 #endif
2763 
2764  while(array_iterate(iterator, &value, &isnull))
2765  {
2766  GSERIALIZED *geom = (GSERIALIZED*) DatumGetPointer(value);
2767 
2768  if (isnull)
2769  {
2770  continue;
2771  }
2772 
2773  *is3d = *is3d || gserialized_has_z(geom);
2774 
2775  geos_geoms[i] = POSTGIS2GEOS(geom);
2776  if (!geos_geoms[i])
2777  {
2778  uint32_t j;
2779  lwpgerror("Geometry could not be converted to GEOS");
2780 
2781  for (j = 0; j < i; j++) {
2782  GEOSGeom_destroy(geos_geoms[j]);
2783  }
2784  return NULL;
2785  }
2786 
2787  if (!gotsrid)
2788  {
2789  *srid = gserialized_get_srid(geom);
2790  gotsrid = true;
2791  }
2792  else if (*srid != gserialized_get_srid(geom))
2793  {
2794  uint32_t j;
2796 
2797  for (j = 0; j <= i; j++) {
2798  GEOSGeom_destroy(geos_geoms[j]);
2799  }
2800  return NULL;
2801  }
2802 
2803  i++;
2804  }
2805 
2806  array_free_iterator(iterator);
2807  return geos_geoms;
2808 }
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: