PostGIS  2.1.10dev-r@@SVN_REVISION@@
int GeneratePointGeometry ( SHPLOADERSTATE state,
SHPObject obj,
char **  geometry,
int  force_multi 
)

Generate an allocated geometry string for shapefile object obj using the state parameters if "force_multi" is true, single points will instead be created as multipoints with a single vertice.

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

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_TRUE, lwcollection_as_lwgeom(), lwcollection_construct(), lwfree(), lwgeom_free(), lwgeom_to_hexwkb(), lwgeom_to_wkt(), lwpoint_as_lwgeom(), lwpoint_construct(), POINT4D::m, shp_loader_state::message, MULTIPOINTTYPE, SHPObject::nVertices, SHPObject::padfM, SHPObject::padfX, SHPObject::padfY, SHPObject::padfZ, ptarray_append_point(), ptarray_construct_empty(), SHPLOADERERR, SHPLOADERMSGLEN, SHPLOADEROK, shp_loader_config::use_wkt, WKB_EXTENDED, WKT_EXTENDED, WKT_PRECISION, POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by ShpLoaderGenerateSQLRowStatement().

248 {
249  LWGEOM **lwmultipoints;
250  LWGEOM *lwgeom = NULL;
251 
252  POINT4D point4d;
253 
254  int dims = 0;
255  int u;
256 
257  char *mem;
258  size_t mem_length;
259 
260  FLAGS_SET_Z(dims, state->has_z);
261  FLAGS_SET_M(dims, state->has_m);
262 
263  /* Allocate memory for our array of LWPOINTs and our dynptarrays */
264  lwmultipoints = malloc(sizeof(LWPOINT *) * obj->nVertices);
265 
266  /* We need an array of pointers to each of our sub-geometries */
267  for (u = 0; u < obj->nVertices; u++)
268  {
269  /* Create a ptarray containing a single point */
270  POINTARRAY *pa = ptarray_construct_empty(state->has_z, state->has_m, 1);
271 
272  /* Generate the point */
273  point4d.x = obj->padfX[u];
274  point4d.y = obj->padfY[u];
275 
276  if (state->has_z)
277  point4d.z = obj->padfZ[u];
278  if (state->has_m)
279  point4d.m = obj->padfM[u];
280 
281  /* Add in the point! */
282  ptarray_append_point(pa, &point4d, LW_TRUE);
283 
284  /* Generate the LWPOINT */
285  lwmultipoints[u] = lwpoint_as_lwgeom(lwpoint_construct(state->from_srid, NULL, pa));
286  }
287 
288  /* If we have more than 1 vertex then we are working on a MULTIPOINT and so generate a MULTIPOINT
289  rather than a POINT */
290  if ((obj->nVertices > 1) || force_multi)
291  {
292  lwgeom = lwcollection_as_lwgeom(lwcollection_construct(MULTIPOINTTYPE, state->from_srid, NULL, obj->nVertices, lwmultipoints));
293  }
294  else
295  {
296  lwgeom = lwmultipoints[0];
297  lwfree(lwmultipoints);
298  }
299 
300  if (state->config->use_wkt)
301  {
302  mem = lwgeom_to_wkt(lwgeom, WKT_EXTENDED, WKT_PRECISION, &mem_length);
303  }
304  else
305  {
306  mem = lwgeom_to_hexwkb(lwgeom, WKB_EXTENDED, &mem_length);
307  }
308 
309  if ( !mem )
310  {
311  snprintf(state->message, SHPLOADERMSGLEN, "unable to write geometry");
312  return SHPLOADERERR;
313  }
314 
315  /* Free all of the allocated items */
316  lwgeom_free(lwgeom);
317 
318  /* Return the string - everything ok */
319  *geometry = mem;
320 
321  return SHPLOADEROK;
322 }
double x
Definition: liblwgeom.h:308
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Definition: lwout_wkb.c:776
SHPLOADERCONFIG * config
double m
Definition: liblwgeom.h:308
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:30
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition: lwout_wkt.c:655
void lwfree(void *mem)
Definition: lwutil.c:190
int nVertices
Definition: shapefil.h:349
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:57
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
#define MULTIPOINTTYPE
Definition: liblwgeom.h:63
double * padfX
Definition: shapefil.h:350
double * padfY
Definition: shapefil.h:351
#define FLAGS_SET_Z(flags, value)
Definition: liblwgeom.h:112
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_TRUE, then a duplicate point will not be added.
Definition: ptarray.c:141
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:51
#define SHPLOADEROK
double z
Definition: liblwgeom.h:308
#define WKB_EXTENDED
Definition: liblwgeom.h:1769
#define WKT_PRECISION
#define WKT_EXTENDED
Definition: liblwgeom.h:1778
char message[SHPLOADERMSGLEN]
double * padfZ
Definition: shapefil.h:352
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:254
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:96
#define SHPLOADERERR
double y
Definition: liblwgeom.h:308
double * padfM
Definition: shapefil.h:353
#define SHPLOADERMSGLEN
#define FLAGS_SET_M(flags, value)
Definition: liblwgeom.h:113
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:219

Here is the call graph for this function:

Here is the caller graph for this function: