PostGIS  2.5.2dev-r@@SVN_REVISION@@

◆ ARRAY2GEOS()

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

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

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