PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ GenerateLineStringGeometry()

int GenerateLineStringGeometry ( SHPLOADERSTATE state,
SHPObject obj,
char **  geometry 
)

Generate an allocated geometry string for shapefile object obj using the state parameters.

Definition at line 320 of file shp2pgsql-core.c.

321{
322
323 LWGEOM **lwmultilinestrings;
324 LWGEOM *lwgeom = NULL;
325 POINT4D point4d;
326 int dims = 0;
327 int u, v, start_vertex, end_vertex;
328 char *mem;
329 size_t mem_length;
330
331
332 FLAGS_SET_Z(dims, state->has_z);
333 FLAGS_SET_M(dims, state->has_m);
334
335 if (state->config->simple_geometries == 1 && obj->nParts > 1)
336 {
337 snprintf(state->message, SHPLOADERMSGLEN, _("We have a Multilinestring with %d parts, can't use -S switch!"), obj->nParts);
338
339 return SHPLOADERERR;
340 }
341
342 /* Allocate memory for our array of LWLINEs and our dynptarrays */
343 lwmultilinestrings = malloc(sizeof(LWPOINT *) * obj->nParts);
344
345 /* We need an array of pointers to each of our sub-geometries */
346 for (u = 0; u < obj->nParts; u++)
347 {
348 /* Create a ptarray containing the line points */
349 POINTARRAY *pa = ptarray_construct_empty(state->has_z, state->has_m, obj->nParts);
350
351 /* Set the start/end vertices depending upon whether this is
352 a MULTILINESTRING or not */
353 if ( u == obj->nParts-1 )
354 end_vertex = obj->nVertices;
355 else
356 end_vertex = obj->panPartStart[u + 1];
357
358 start_vertex = obj->panPartStart[u];
359
360 for (v = start_vertex; v < end_vertex; v++)
361 {
362 /* Generate the point */
363 point4d.x = obj->padfX[v];
364 point4d.y = obj->padfY[v];
365
366 if (state->has_z)
367 point4d.z = obj->padfZ[v];
368 if (state->has_m)
369 point4d.m = obj->padfM[v];
370
371 ptarray_append_point(pa, &point4d, LW_FALSE);
372 }
373
374 /* Generate the LWLINE */
375 lwmultilinestrings[u] = lwline_as_lwgeom(lwline_construct(state->from_srid, NULL, pa));
376 }
377
378 /* If using MULTILINESTRINGs then generate the serialized collection, otherwise just a single LINESTRING */
379 if (state->config->simple_geometries == 0)
380 {
381 lwgeom = lwcollection_as_lwgeom(lwcollection_construct(MULTILINETYPE, state->from_srid, NULL, obj->nParts, lwmultilinestrings));
382 }
383 else
384 {
385 lwgeom = lwmultilinestrings[0];
386 lwfree(lwmultilinestrings);
387 }
388
389 if (!state->config->use_wkt)
391 else
392 mem = lwgeom_to_wkt(lwgeom, WKT_EXTENDED, WKT_PRECISION, &mem_length);
393
394 if ( !mem )
395 {
396 snprintf(state->message, SHPLOADERMSGLEN, "unable to write geometry");
397 return SHPLOADERERR;
398 }
399
400 /* Free all of the allocated items */
401 lwgeom_free(lwgeom);
402
403 /* Return the string - everything ok */
404 *geometry = mem;
405
406 return SHPLOADEROK;
407}
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
char * lwgeom_to_hexwkb_buffer(const LWGEOM *geom, uint8_t variant)
Definition lwout_wkb.c:845
#define LW_FALSE
Definition liblwgeom.h:94
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
#define MULTILINETYPE
Definition liblwgeom.h:106
#define WKT_EXTENDED
Definition liblwgeom.h:2221
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition lwout_wkt.c:708
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition ptarray.c:59
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition lwline.c:42
void lwfree(void *mem)
Definition lwutil.c:248
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition lwgeom.c:367
#define WKB_EXTENDED
Definition liblwgeom.h:2212
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE,...
Definition ptarray.c:147
#define FLAGS_SET_M(flags, value)
Definition liblwgeom.h:173
#define FLAGS_SET_Z(flags, value)
Definition liblwgeom.h:172
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition lwgeom.c:337
void * malloc(YYSIZE_T)
#define WKT_PRECISION
#define SHPLOADERMSGLEN
#define SHPLOADERERR
#define SHPLOADEROK
#define _(String)
Definition shpcommon.h:24
double m
Definition liblwgeom.h:414
double x
Definition liblwgeom.h:414
double z
Definition liblwgeom.h:414
double y
Definition liblwgeom.h:414
char message[SHPLOADERMSGLEN]
SHPLOADERCONFIG * config
double * padfX
Definition shapefil.h:390
double * padfY
Definition shapefil.h:391
double * padfZ
Definition shapefil.h:392
int * panPartStart
Definition shapefil.h:386
double * padfM
Definition shapefil.h:393

References _, shp_loader_state::config, FLAGS_SET_M, FLAGS_SET_Z, shp_loader_state::from_srid, shp_loader_state::has_m, shp_loader_state::has_z, LW_FALSE, lwcollection_as_lwgeom(), lwcollection_construct(), lwfree(), lwgeom_free(), lwgeom_to_hexwkb_buffer(), lwgeom_to_wkt(), lwline_as_lwgeom(), lwline_construct(), POINT4D::m, malloc(), shp_loader_state::message, MULTILINETYPE, tagSHPObject::nParts, tagSHPObject::nVertices, tagSHPObject::padfM, tagSHPObject::padfX, tagSHPObject::padfY, tagSHPObject::padfZ, tagSHPObject::panPartStart, ptarray_append_point(), ptarray_construct_empty(), SHPLOADERERR, SHPLOADERMSGLEN, SHPLOADEROK, shp_loader_config::simple_geometries, shp_loader_config::use_wkt, WKB_EXTENDED, WKT_EXTENDED, WKT_PRECISION, POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by ShpLoaderGenerateSQLRowStatement().

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