PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ ptarray_from_SFCGAL()

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

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

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

Referenced by SFCGAL2LWGEOM().

109 {
110  POINT4D point;
111  uint32_t i, npoints;
112  POINTARRAY* pa = NULL;
113 
114  assert(geom);
115 
116  switch (sfcgal_geometry_type_id(geom))
117  {
118  case SFCGAL_TYPE_POINT:
119  {
120  pa = ptarray_construct(want3d, 0, 1);
121  point.x = sfcgal_point_x(geom);
122  point.y = sfcgal_point_y(geom);
123 
124  if (sfcgal_geometry_is_3d(geom))
125  point.z = sfcgal_point_z(geom);
126  else if (want3d)
127  point.z = 0.0;
128 
129  ptarray_set_point4d(pa, 0, &point);
130  }
131  break;
132 
133  case SFCGAL_TYPE_LINESTRING:
134  {
135  npoints = sfcgal_linestring_num_points(geom);
136  pa = ptarray_construct(want3d, 0, npoints);
137 
138  for (i = 0; i < npoints; i++)
139  {
140  const sfcgal_geometry_t* pt = sfcgal_linestring_point_n(geom, i);
141  point.x = sfcgal_point_x(pt);
142  point.y = sfcgal_point_y(pt);
143 
144  if (sfcgal_geometry_is_3d(geom))
145  point.z = sfcgal_point_z(pt);
146  else if (want3d)
147  point.z = 0.0;
148 
149  ptarray_set_point4d(pa, i, &point);
150  }
151  }
152  break;
153 
154  case SFCGAL_TYPE_TRIANGLE:
155  {
156  pa = ptarray_construct(want3d, 0, 4);
157 
158  for (i = 0; i < 4; i++)
159  {
160  const sfcgal_geometry_t* pt = sfcgal_triangle_vertex(geom, (i%3));
161  point.x = sfcgal_point_x(pt);
162  point.y = sfcgal_point_y(pt);
163 
164  if ( sfcgal_geometry_is_3d(geom))
165  point.z = sfcgal_point_z(pt);
166  else if (want3d)
167  point.z = 0.0;
168 
169  ptarray_set_point4d(pa, i, &point);
170  }
171  }
172  break;
173 
174  /* Other types should not be called directly ... */
175  default:
176  lwerror("ptarray_from_SFCGAL: Unknown Type");
177  break;
178  }
179  return pa;
180 }
void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d)
Definition: lwgeom_api.c:536
double x
Definition: liblwgeom.h:336
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
double z
Definition: liblwgeom.h:336
double y
Definition: liblwgeom.h:336
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
Here is the call graph for this function:
Here is the caller graph for this function: