PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ create_multilinestring()

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

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

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