PostGIS  2.3.7dev-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 227 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, malloc(), 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().

228 {
229  LWGEOM **lwmultipoints;
230  LWGEOM *lwgeom = NULL;
231 
232  POINT4D point4d;
233 
234  int dims = 0;
235  int u;
236 
237  char *mem;
238  size_t mem_length;
239 
240  FLAGS_SET_Z(dims, state->has_z);
241  FLAGS_SET_M(dims, state->has_m);
242 
243  /* Allocate memory for our array of LWPOINTs and our dynptarrays */
244  lwmultipoints = malloc(sizeof(LWPOINT *) * obj->nVertices);
245 
246  /* We need an array of pointers to each of our sub-geometries */
247  for (u = 0; u < obj->nVertices; u++)
248  {
249  /* Create a ptarray containing a single point */
250  POINTARRAY *pa = ptarray_construct_empty(state->has_z, state->has_m, 1);
251 
252  /* Generate the point */
253  point4d.x = obj->padfX[u];
254  point4d.y = obj->padfY[u];
255 
256  if (state->has_z)
257  point4d.z = obj->padfZ[u];
258  if (state->has_m)
259  point4d.m = obj->padfM[u];
260 
261  /* Add in the point! */
262  ptarray_append_point(pa, &point4d, LW_TRUE);
263 
264  /* Generate the LWPOINT */
265  lwmultipoints[u] = lwpoint_as_lwgeom(lwpoint_construct(state->from_srid, NULL, pa));
266  }
267 
268  /* If we have more than 1 vertex then we are working on a MULTIPOINT and so generate a MULTIPOINT
269  rather than a POINT */
270  if ((obj->nVertices > 1) || force_multi)
271  {
272  lwgeom = lwcollection_as_lwgeom(lwcollection_construct(MULTIPOINTTYPE, state->from_srid, NULL, obj->nVertices, lwmultipoints));
273  }
274  else
275  {
276  lwgeom = lwmultipoints[0];
277  lwfree(lwmultipoints);
278  }
279 
280  if (state->config->use_wkt)
281  {
282  mem = lwgeom_to_wkt(lwgeom, WKT_EXTENDED, WKT_PRECISION, &mem_length);
283  }
284  else
285  {
286  mem = lwgeom_to_hexwkb(lwgeom, WKB_EXTENDED, &mem_length);
287  }
288 
289  if ( !mem )
290  {
291  snprintf(state->message, SHPLOADERMSGLEN, "unable to write geometry");
292  return SHPLOADERERR;
293  }
294 
295  /* Free all of the allocated items */
296  lwgeom_free(lwgeom);
297 
298  /* Return the string - everything ok */
299  *geometry = mem;
300 
301  return SHPLOADEROK;
302 }
double x
Definition: liblwgeom.h:351
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Definition: lwout_wkb.c:848
SHPLOADERCONFIG * config
double m
Definition: liblwgeom.h:351
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:43
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition: lwout_wkt.c:669
void lwfree(void *mem)
Definition: lwutil.c:242
int nVertices
Definition: shapefil.h:348
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1063
#define MULTIPOINTTYPE
Definition: liblwgeom.h:87
double * padfX
Definition: shapefil.h:349
double * padfY
Definition: shapefil.h:350
#define FLAGS_SET_Z(flags, value)
Definition: liblwgeom.h:145
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, then a duplicate point will not be added.
Definition: ptarray.c:156
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
#define SHPLOADEROK
double z
Definition: liblwgeom.h:351
#define WKB_EXTENDED
Definition: liblwgeom.h:2048
#define WKT_PRECISION
#define WKT_EXTENDED
Definition: liblwgeom.h:2057
char message[SHPLOADERMSGLEN]
double * padfZ
Definition: shapefil.h:351
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:267
void * malloc(YYSIZE_T)
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:111
#define SHPLOADERERR
double y
Definition: liblwgeom.h:351
double * padfM
Definition: shapefil.h:352
#define SHPLOADERMSGLEN
#define FLAGS_SET_M(flags, value)
Definition: liblwgeom.h:146
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:232

Here is the call graph for this function:

Here is the caller graph for this function: