PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ create_multilinestring()

static SHPObject * create_multilinestring ( SHPDUMPERSTATE state,
LWMLINE lwmultilinestring 
)
static

Definition at line 377 of file pgsql2shp-core.c.

References free(), LWMLINE::geoms, getPoint4d(), LWDEBUGF, POINT4D::m, malloc(), LWMLINE::ngeoms, POINTARRAY::npoints, shp_dumper_state::outshptype, LWLINE::points, SHPCreateObject(), POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by ShpLoaderGenerateShapeRow().

378 {
379  SHPObject *obj;
380  POINT4D p4d;
381  uint32_t i, j;
382 
383  double *xpts, *ypts, *zpts, *mpts;
384 
385  int *shpparts, shppointtotal = 0, shppoint = 0;
386 
387  /* Allocate storage for ring pointers */
388  shpparts = malloc(sizeof(int) * lwmultilinestring->ngeoms);
389 
390  /* First count through all the points in each linestring so we now how much memory is required */
391  for (i = 0; i < lwmultilinestring->ngeoms; i++)
392  shppointtotal += lwmultilinestring->geoms[i]->points->npoints;
393 
394  LWDEBUGF(3, "Total number of points: %d", shppointtotal);
395 
396  /* Allocate storage for points */
397  xpts = malloc(sizeof(double) * shppointtotal);
398  ypts = malloc(sizeof(double) * shppointtotal);
399  zpts = malloc(sizeof(double) * shppointtotal);
400  mpts = malloc(sizeof(double) * shppointtotal);
401 
402  /* Iterate through each linestring setting up shpparts to point to the beginning of each line */
403  for (i = 0; i < lwmultilinestring->ngeoms; i++)
404  {
405  /* For each linestring, store the integer coordinate offset for the start of each line */
406  shpparts[i] = shppoint;
407 
408  for (j = 0; j < lwmultilinestring->geoms[i]->points->npoints; j++)
409  {
410  p4d = getPoint4d(lwmultilinestring->geoms[i]->points, j);
411 
412  xpts[shppoint] = p4d.x;
413  ypts[shppoint] = p4d.y;
414  zpts[shppoint] = p4d.z;
415  mpts[shppoint] = p4d.m;
416 
417  LWDEBUGF(4, "Linestring %d - Point: %g %g %g %g", i, xpts[shppoint], ypts[shppoint], zpts[shppoint], mpts[shppoint]);
418 
419  /* Increment the point counter */
420  shppoint++;
421  }
422  }
423 
424  obj = SHPCreateObject(state->outshptype, -1, lwmultilinestring->ngeoms, shpparts, NULL, shppoint, xpts, ypts, zpts, mpts);
425 
426  free(xpts);
427  free(ypts);
428  free(zpts);
429  free(mpts);
430 
431  return obj;
432 }
double x
Definition: liblwgeom.h:354
SHPObject SHPAPI_CALL1 * SHPCreateObject(int nSHPType, int nShapeId, int nParts, const int *panPartStart, const int *panPartType, int nVertices, const double *padfX, const double *padfY, const double *padfZ, const double *padfM);SHPObject SHPAPI_CALL1(*) SHPCreateSimpleObject(int nSHPType, int nVertices, const double *padfX, const double *padfY, const double *padfZ
double m
Definition: liblwgeom.h:354
unsigned int uint32_t
Definition: uthash.h:78
POINT4D getPoint4d(const POINTARRAY *pa, uint32_t n)
Definition: lwgeom_api.c:96
double z
Definition: liblwgeom.h:354
uint32_t ngeoms
Definition: liblwgeom.h:483
LWLINE ** geoms
Definition: liblwgeom.h:485
void free(void *)
void * malloc(YYSIZE_T)
double y
Definition: liblwgeom.h:354
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
POINTARRAY * points
Definition: liblwgeom.h:424
uint32_t npoints
Definition: liblwgeom.h:373
Here is the call graph for this function:
Here is the caller graph for this function: