PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ create_multilinestring()

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

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

403 {
404  SHPObject *obj;
405  POINT4D p4d;
406  uint32_t i, j;
407 
408  double *xpts, *ypts, *zpts, *mpts;
409 
410  int *shpparts, shppointtotal = 0, shppoint = 0;
411 
412  /* Allocate storage for ring pointers */
413  shpparts = malloc(sizeof(int) * lwmultilinestring->ngeoms);
414 
415  /* First count through all the points in each linestring so we now how much memory is required */
416  for (i = 0; i < lwmultilinestring->ngeoms; i++)
417  shppointtotal += lwmultilinestring->geoms[i]->points->npoints;
418 
419  LWDEBUGF(3, "Total number of points: %d", shppointtotal);
420 
421  /* Allocate storage for points */
422  xpts = malloc(sizeof(double) * shppointtotal);
423  ypts = malloc(sizeof(double) * shppointtotal);
424  zpts = malloc(sizeof(double) * shppointtotal);
425  mpts = malloc(sizeof(double) * shppointtotal);
426 
427  /* Iterate through each linestring setting up shpparts to point to the beginning of each line */
428  for (i = 0; i < lwmultilinestring->ngeoms; i++)
429  {
430  /* For each linestring, store the integer coordinate offset for the start of each line */
431  shpparts[i] = shppoint;
432 
433  for (j = 0; j < lwmultilinestring->geoms[i]->points->npoints; j++)
434  {
435  p4d = getPoint4d(lwmultilinestring->geoms[i]->points, j);
436 
437  xpts[shppoint] = p4d.x;
438  ypts[shppoint] = p4d.y;
439  zpts[shppoint] = p4d.z;
440  mpts[shppoint] = p4d.m;
441 
442  LWDEBUGF(4, "Linestring %d - Point: %g %g %g %g", i, xpts[shppoint], ypts[shppoint], zpts[shppoint], mpts[shppoint]);
443 
444  /* Increment the point counter */
445  shppoint++;
446  }
447  }
448 
449  obj = SHPCreateObject(state->outshptype, -1, lwmultilinestring->ngeoms, shpparts, NULL, shppoint, xpts, ypts, zpts, mpts);
450 
451  free(xpts);
452  free(ypts);
453  free(zpts);
454  free(mpts);
455 
456  return obj;
457 }
POINT4D getPoint4d(const POINTARRAY *pa, uint32_t n)
Definition: lwgeom_api.c:108
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void * malloc(YYSIZE_T)
void free(void *)
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
POINTARRAY * points
Definition: liblwgeom.h:498
LWLINE ** geoms
Definition: liblwgeom.h:562
uint32_t ngeoms
Definition: liblwgeom.h:567
double m
Definition: liblwgeom.h:429
double x
Definition: liblwgeom.h:429
double z
Definition: liblwgeom.h:429
double y
Definition: liblwgeom.h:429
uint32_t npoints
Definition: liblwgeom.h:442

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().

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