/** @brief Binary to hexewkb conversion function */
char *convert_bytes_to_hex(uint8_t *ewkb, size_t size);
+static SHPObject *
+create_point_empty(SHPDUMPERSTATE *state, LWPOINT *lwpoint)
+{
+ SHPObject *obj;
+ const uint8_t ndr_nan[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x7f};
+ double double_nan;
+
+ memcpy(&double_nan, ndr_nan, 8);
+ obj = SHPCreateObject(state->outshptype, -1, 0, NULL, NULL, 1, &double_nan, &double_nan, &double_nan, &double_nan);
+ return obj;
+}
static SHPObject *
create_point(SHPDUMPERSTATE *state, LWPOINT *lwpoint)
switch (lwgeom->type)
{
case POINTTYPE:
- obj = create_point(state, lwgeom_as_lwpoint(lwgeom));
+ if (lwgeom_is_empty(lwgeom))
+ {
+ obj = create_point_empty(state, lwgeom_as_lwpoint(lwgeom));
+ }
+ else
+ {
+ obj = create_point(state, lwgeom_as_lwpoint(lwgeom));
+ }
break;
case MULTIPOINTTYPE:
FLAGS_SET_Z(dims, state->has_z);
FLAGS_SET_M(dims, state->has_m);
- /* Allocate memory for our array of LWPOINTs and our dynptarrays */
- lwmultipoints = malloc(sizeof(LWPOINT *) * obj->nVertices);
-
- /* We need an array of pointers to each of our sub-geometries */
- for (u = 0; u < obj->nVertices; u++)
+ /* POINT EMPTY encoded as POINT(NaN NaN) */
+ if (obj->nVertices == 1 && isnan(obj->padfX[0]) && isnan(obj->padfY[0]))
+ {
+ lwgeom = lwpoint_as_lwgeom(lwpoint_construct_empty(state->from_srid, state->has_z, state->has_m));
+ }
+ /* Not empty */
+ else
{
- /* Create a ptarray containing a single point */
- POINTARRAY *pa = ptarray_construct_empty(state->has_z, state->has_m, 1);
+ /* Allocate memory for our array of LWPOINTs and our dynptarrays */
+ lwmultipoints = malloc(sizeof(LWPOINT *) * obj->nVertices);
- /* Generate the point */
- point4d.x = obj->padfX[u];
- point4d.y = obj->padfY[u];
+ /* We need an array of pointers to each of our sub-geometries */
+ for (u = 0; u < obj->nVertices; u++)
+ {
+ /* Create a ptarray containing a single point */
+ POINTARRAY *pa = ptarray_construct_empty(state->has_z, state->has_m, 1);
- if (state->has_z)
- point4d.z = obj->padfZ[u];
- if (state->has_m)
- point4d.m = obj->padfM[u];
+ /* Generate the point */
+ point4d.x = obj->padfX[u];
+ point4d.y = obj->padfY[u];
- /* Add in the point! */
- ptarray_append_point(pa, &point4d, LW_TRUE);
+ if (state->has_z)
+ point4d.z = obj->padfZ[u];
+ if (state->has_m)
+ point4d.m = obj->padfM[u];
- /* Generate the LWPOINT */
- lwmultipoints[u] = lwpoint_as_lwgeom(lwpoint_construct(state->from_srid, NULL, pa));
- }
+ /* Add in the point! */
+ ptarray_append_point(pa, &point4d, LW_TRUE);
- /* If we have more than 1 vertex then we are working on a MULTIPOINT and so generate a MULTIPOINT
- rather than a POINT */
- if ((obj->nVertices > 1) || force_multi)
- {
- lwgeom = lwcollection_as_lwgeom(lwcollection_construct(MULTIPOINTTYPE, state->from_srid, NULL, obj->nVertices, lwmultipoints));
- }
- else
- {
- lwgeom = lwmultipoints[0];
- lwfree(lwmultipoints);
+ /* Generate the LWPOINT */
+ lwmultipoints[u] = lwpoint_as_lwgeom(lwpoint_construct(state->from_srid, NULL, pa));
+ }
+
+ /* If we have more than 1 vertex then we are working on a MULTIPOINT and so generate a MULTIPOINT
+ rather than a POINT */
+ if ((obj->nVertices > 1) || force_multi)
+ {
+ lwgeom = lwcollection_as_lwgeom(lwcollection_construct(MULTIPOINTTYPE, state->from_srid, NULL, obj->nVertices, lwmultipoints));
+ }
+ else
+ {
+ lwgeom = lwmultipoints[0];
+ lwfree(lwmultipoints);
+ }
}
if (state->config->use_wkt)