PostGIS  2.5.2dev-r@@SVN_REVISION@@

◆ ptarray_from_SFCGAL()

static POINTARRAY * ptarray_from_SFCGAL ( const sfcgal_geometry_t *  geom,
int  force3D 
)
static

Definition at line 119 of file liblwgeom/lwgeom_sfcgal.c.

References lwerror(), ptarray_construct(), ptarray_set_point4d(), POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by SFCGAL2LWGEOM().

120 {
121  POINT4D point;
122  uint32_t i, npoints;
123  POINTARRAY* pa = NULL;
124 
125  assert(geom);
126 
127  switch (sfcgal_geometry_type_id(geom))
128  {
129  case SFCGAL_TYPE_POINT:
130  {
131  pa = ptarray_construct(want3d, 0, 1);
132  point.x = sfcgal_point_x(geom);
133  point.y = sfcgal_point_y(geom);
134 
135  if (sfcgal_geometry_is_3d(geom))
136  point.z = sfcgal_point_z(geom);
137  else if (want3d)
138  point.z = 0.0;
139 
140  ptarray_set_point4d(pa, 0, &point);
141  }
142  break;
143 
144  case SFCGAL_TYPE_LINESTRING:
145  {
146  npoints = sfcgal_linestring_num_points(geom);
147  pa = ptarray_construct(want3d, 0, npoints);
148 
149  for (i = 0; i < npoints; i++)
150  {
151  const sfcgal_geometry_t* pt = sfcgal_linestring_point_n(geom, i);
152  point.x = sfcgal_point_x(pt);
153  point.y = sfcgal_point_y(pt);
154 
155  if (sfcgal_geometry_is_3d(geom))
156  point.z = sfcgal_point_z(pt);
157  else if (want3d)
158  point.z = 0.0;
159 
160  ptarray_set_point4d(pa, i, &point);
161  }
162  }
163  break;
164 
165  case SFCGAL_TYPE_TRIANGLE:
166  {
167  pa = ptarray_construct(want3d, 0, 4);
168 
169  for (i = 0; i < 4; i++)
170  {
171  const sfcgal_geometry_t* pt = sfcgal_triangle_vertex(geom, (i%3));
172  point.x = sfcgal_point_x(pt);
173  point.y = sfcgal_point_y(pt);
174 
175  if ( sfcgal_geometry_is_3d(geom))
176  point.z = sfcgal_point_z(pt);
177  else if (want3d)
178  point.z = 0.0;
179 
180  ptarray_set_point4d(pa, i, &point);
181  }
182  }
183  break;
184 
185  /* Other types should not be called directly ... */
186  default:
187  lwerror("ptarray_from_SFCGAL: Unknown Type");
188  break;
189  }
190  return pa;
191 }
double x
Definition: liblwgeom.h:354
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
Definition: ptarray.c:62
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
Definition: lwgeom_api.c:435
unsigned int uint32_t
Definition: uthash.h:78
double z
Definition: liblwgeom.h:354
double y
Definition: liblwgeom.h:354
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
Here is the call graph for this function:
Here is the caller graph for this function: