PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ create_multilinestring()

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

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

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