PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ ptarray_from_SFCGAL()

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

Definition at line 142 of file lwgeom_sfcgal.c.

143 {
144  POINT4D point;
145  uint32_t i, npoints;
146  POINTARRAY *pa = NULL;
147  int is_3d;
148  int is_measured = 0;
149 
150  assert(geom);
151 
152  is_3d = sfcgal_geometry_is_3d(geom);
153 
154 #if POSTGIS_SFCGAL_VERSION >= 10308
155  is_measured = sfcgal_geometry_is_measured(geom);
156 #endif
157 
158  switch (sfcgal_geometry_type_id(geom))
159  {
160  case SFCGAL_TYPE_POINT: {
161  pa = ptarray_construct(want3d, is_measured, 1);
162  point.x = sfcgal_point_x(geom);
163  point.y = sfcgal_point_y(geom);
164 
165  if (is_3d)
166  point.z = sfcgal_point_z(geom);
167  else if (want3d)
168  point.z = 0.0;
169 
170 #if POSTGIS_SFCGAL_VERSION >= 10308
171  if (is_measured)
172  point.m = sfcgal_point_m(geom);
173 #endif
174 
175  ptarray_set_point4d(pa, 0, &point);
176  }
177  break;
178 
179  case SFCGAL_TYPE_LINESTRING: {
180  npoints = sfcgal_linestring_num_points(geom);
181  pa = ptarray_construct(want3d, is_measured, npoints);
182 
183  for (i = 0; i < npoints; i++)
184  {
185  const sfcgal_geometry_t *pt = sfcgal_linestring_point_n(geom, i);
186  point.x = sfcgal_point_x(pt);
187  point.y = sfcgal_point_y(pt);
188 
189  if (is_3d)
190  point.z = sfcgal_point_z(pt);
191  else if (want3d)
192  point.z = 0.0;
193 
194 #if POSTGIS_SFCGAL_VERSION >= 10308
195  if (is_measured)
196  point.m = sfcgal_point_m(pt);
197 #endif
198 
199  ptarray_set_point4d(pa, i, &point);
200  }
201  }
202  break;
203 
204  case SFCGAL_TYPE_TRIANGLE: {
205  pa = ptarray_construct(want3d, is_measured, 4);
206 
207  for (i = 0; i < 4; i++)
208  {
209  const sfcgal_geometry_t *pt = sfcgal_triangle_vertex(geom, (i % 3));
210  point.x = sfcgal_point_x(pt);
211  point.y = sfcgal_point_y(pt);
212 
213  if (is_3d)
214  point.z = sfcgal_point_z(pt);
215  else if (want3d)
216  point.z = 0.0;
217 
218 #if POSTGIS_SFCGAL_VERSION >= 10308
219  if (is_measured)
220  point.m = sfcgal_point_m(pt);
221 #endif
222 
223  ptarray_set_point4d(pa, i, &point);
224  }
225  }
226  break;
227 
228  /* Other types should not be called directly ... */
229  default:
230  lwerror("ptarray_from_SFCGAL: Unknown Type");
231  break;
232  }
233  return pa;
234 }
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:51
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
Definition: lwgeom_api.c:369
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
double m
Definition: liblwgeom.h:414
double x
Definition: liblwgeom.h:414
double z
Definition: liblwgeom.h:414
double y
Definition: liblwgeom.h:414

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

Referenced by SFCGAL2LWGEOM().

Here is the call graph for this function:
Here is the caller graph for this function: