PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ ARRAY2GEOS()

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

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

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