/** * Read the dimensionality from a flag, if provided. Then check that the * dimensionality matches that of the pointarray. If the dimension counts * match, ensure the pointarray is using the right "Z" or "M". */ static int wkt_pointarray_dimensionality(POINTARRAY *pa, uint8_t flags) { int hasz = FLAGS_GET_Z(flags); int hasm = FLAGS_GET_M(flags); int ndims = 2 + hasz + hasm; /* No dimensionality or array means we go with what we have */ if( ! (flags && pa) ) return LW_TRUE; LWDEBUGF(5,"dimensionality ndims == %d", ndims); LWDEBUGF(5,"FLAGS_NDIMS(pa->flags) == %d", FLAGS_NDIMS(pa->flags)); /* * ndims > 2 implies that the flags have something useful to add, * that there is a 'Z' or an 'M' or both. */ if( ndims > 2 ) { /* Mismatch implies a problem */ if ( FLAGS_NDIMS(pa->flags) != ndims ) return LW_FALSE; /* Match means use the explicit dimensionality */ else { FLAGS_SET_Z(pa->flags, hasz); FLAGS_SET_M(pa->flags, hasm); } } return LW_TRUE; }
LWGEOM* wkt_parser_curvepolygon_finalize(LWGEOM *poly, char *dimensionality) { uint8_t flags = wkt_dimensionality(dimensionality); int flagdims = FLAGS_NDIMS(flags); LWDEBUG(4,"entered"); /* Null input implies empty return */ if( ! poly ) return lwcurvepoly_as_lwgeom(lwcurvepoly_construct_empty(SRID_UNKNOWN, FLAGS_GET_Z(flags), FLAGS_GET_M(flags))); if ( flagdims > 2 ) { /* If the number of dimensions are not consistent, we have a problem. */ if( flagdims != FLAGS_NDIMS(poly->flags) ) { lwgeom_free(poly); SET_PARSER_ERROR(PARSER_ERROR_MIXDIMS); return NULL; } /* Harmonize the flags in the sub-components with the wkt flags */ if( LW_FAILURE == wkt_parser_set_dims(poly, flags) ) { lwgeom_free(poly); SET_PARSER_ERROR(PARSER_ERROR_OTHER); return NULL; } } return poly; }
POINTARRAY* wkt_parser_ptarray_add_coord(POINTARRAY *pa, POINT p) { POINT4D pt; LWDEBUG(4,"entered"); /* Error on trouble */ if( ! pa ) { SET_PARSER_ERROR(PARSER_ERROR_OTHER); return NULL; } /* Check that the coordinate has the same dimesionality as the array */ if( FLAGS_NDIMS(p.flags) != FLAGS_NDIMS(pa->flags) ) { ptarray_free(pa); SET_PARSER_ERROR(PARSER_ERROR_MIXDIMS); return NULL; } /* While parsing the point arrays, XYM and XMZ points are both treated as XYZ */ pt.x = p.x; pt.y = p.y; if( FLAGS_GET_Z(pa->flags) ) pt.z = p.z; if( FLAGS_GET_M(pa->flags) ) pt.m = p.m; /* If the destination is XYM, we'll write the third coordinate to m */ if( FLAGS_GET_M(pa->flags) && ! FLAGS_GET_Z(pa->flags) ) pt.m = p.z; ptarray_append_point(pa, &pt, LW_TRUE); /* Allow duplicate points in array */ return pa; }
LWGEOM* wkt_parser_compound_add_geom(LWGEOM *col, LWGEOM *geom) { LWDEBUG(4,"entered"); /* Toss error on null geometry input */ if( ! (geom && col) ) { SET_PARSER_ERROR(PARSER_ERROR_OTHER); return NULL; } /* All the elements must agree on dimensionality */ if( FLAGS_NDIMS(col->flags) != FLAGS_NDIMS(geom->flags) ) { lwgeom_free(col); lwgeom_free(geom); SET_PARSER_ERROR(PARSER_ERROR_MIXDIMS); return NULL; } if( LW_FAILURE == lwcompound_add_lwgeom((LWCOMPOUND*)col, geom) ) { lwgeom_free(col); lwgeom_free(geom); SET_PARSER_ERROR(PARSER_ERROR_INCONTINUOUS); return NULL; } return col; }
/* * Size of point represeneted in the POINTARRAY * 16 for 2d, 24 for 3d, 32 for 4d */ int inline ptarray_point_size(const POINTARRAY *pa) { LWDEBUGF(5, "ptarray_point_size: FLAGS_NDIMS(pa->flags)=%x",FLAGS_NDIMS(pa->flags)); return sizeof(double)*FLAGS_NDIMS(pa->flags); }
/* * Add a LWTRIANGLE inside a tgeom * Copy geometries from LWTRIANGLE */ static TGEOM* tgeom_add_triangle(TGEOM *tgeom, LWTRIANGLE *triangle) { int i; assert(tgeom); assert(triangle); if ((tgeom->nfaces + 1) == INT_MAX) lwerror("tgeom_add_triangle: Unable to alloc more than %i faces", INT_MAX); /* Integrity checks on subgeom, dims and srid */ if (tgeom->type != TINTYPE) lwerror("tgeom_add_triangle: Unable to handle %s - %s type", tgeom->type, lwtype_name(tgeom->type)); if (FLAGS_NDIMS(tgeom->flags) != FLAGS_NDIMS(triangle->flags)) lwerror("tgeom_add_triangle: Mixed dimension"); if (tgeom->srid != triangle->srid && (tgeom->srid != 0 && triangle->srid != SRID_UNKNOWN)) lwerror("tgeom_add_triangle: Mixed srid. Tgeom: %i / Triangle: %i", tgeom->srid, triangle->srid); /* handle face array allocation */ if (tgeom->maxfaces == 0) { tgeom->faces = lwalloc(sizeof(TFACE*) * 2); tgeom->maxfaces = 2; } if ((tgeom->maxfaces - 1) == tgeom->nfaces) { tgeom->faces = lwrealloc(tgeom->faces, sizeof(TFACE*) * tgeom->maxfaces * 2); tgeom->maxfaces *= 2; } /* add an empty face */ tgeom->faces[tgeom->nfaces] = lwalloc(sizeof(TFACE)); tgeom->faces[tgeom->nfaces]->rings = NULL; tgeom->faces[tgeom->nfaces]->nrings = 0; tgeom->faces[tgeom->nfaces]->nedges = 0; tgeom->faces[tgeom->nfaces]->maxedges = 0; /* Compute edge on triangle */ for (i=1 ; i < triangle->points->npoints ; i++) { POINT4D p1, p2; getPoint4d_p(triangle->points, i-1, &p1); getPoint4d_p(triangle->points, i, &p2); tgeom_add_face_edge(tgeom, tgeom->nfaces, &p1, &p2); } tgeom->nfaces++; return tgeom; }
LWGEOM* wkt_parser_polygon_add_ring(LWGEOM *poly, POINTARRAY *pa, char dimcheck) { LWDEBUG(4,"entered"); /* Bad inputs are a problem */ if( ! (pa && poly) ) { SET_PARSER_ERROR(PARSER_ERROR_OTHER); return NULL; } /* Rings must agree on dimensionality */ if( FLAGS_NDIMS(poly->flags) != FLAGS_NDIMS(pa->flags) ) { ptarray_free(pa); lwgeom_free(poly); SET_PARSER_ERROR(PARSER_ERROR_MIXDIMS); return NULL; } /* Apply check for minimum number of points, if requested. */ if( (global_parser_result.parser_check_flags & LW_PARSER_CHECK_MINPOINTS) && (pa->npoints < 4) ) { ptarray_free(pa); lwgeom_free(poly); SET_PARSER_ERROR(PARSER_ERROR_MOREPOINTS); return NULL; } /* Apply check for not closed rings, if requested. */ if( (global_parser_result.parser_check_flags & LW_PARSER_CHECK_CLOSURE) && ! (dimcheck == 'Z' ? ptarray_isclosedz(pa) : ptarray_isclosed2d(pa)) ) { ptarray_free(pa); lwgeom_free(poly); SET_PARSER_ERROR(PARSER_ERROR_UNCLOSED); return NULL; } /* If something goes wrong adding a ring, error out. */ if ( LW_FAILURE == lwpoly_add_ring(lwgeom_as_lwpoly(poly), pa) ) { ptarray_free(pa); lwgeom_free(poly); SET_PARSER_ERROR(PARSER_ERROR_OTHER); return NULL; } return poly; }
static LWLINE* lwline_from_gserialized_buffer(uint8_t *data_ptr, uint8_t g_flags, size_t *g_size) { uint8_t *start_ptr = data_ptr; LWLINE *line; uint32_t npoints = 0; assert(data_ptr); line = (LWLINE*)lwalloc(sizeof(LWLINE)); line->srid = SRID_UNKNOWN; /* Default */ line->bbox = NULL; line->type = LINETYPE; line->flags = g_flags; data_ptr += 4; /* Skip past the type. */ npoints = lw_get_uint32_t(data_ptr); /* Zero => empty geometry */ data_ptr += 4; /* Skip past the npoints. */ if ( npoints > 0 ) line->points = ptarray_construct_reference_data(FLAGS_GET_Z(g_flags), FLAGS_GET_M(g_flags), npoints, data_ptr); else line->points = ptarray_construct(FLAGS_GET_Z(g_flags), FLAGS_GET_M(g_flags), 0); /* Empty linestring */ data_ptr += FLAGS_NDIMS(g_flags) * npoints * sizeof(double); if ( g_size ) *g_size = data_ptr - start_ptr; return line; }
static LWPOINT* lwpoint_from_gserialized_buffer(uint8_t *data_ptr, uint8_t g_flags, size_t *g_size) { uint8_t *start_ptr = data_ptr; LWPOINT *point; uint32_t npoints = 0; assert(data_ptr); point = (LWPOINT*)lwalloc(sizeof(LWPOINT)); point->srid = SRID_UNKNOWN; /* Default */ point->bbox = NULL; point->type = POINTTYPE; point->flags = g_flags; data_ptr += 4; /* Skip past the type. */ npoints = lw_get_uint32_t(data_ptr); /* Zero => empty geometry */ data_ptr += 4; /* Skip past the npoints. */ if ( npoints > 0 ) point->point = ptarray_construct_reference_data(FLAGS_GET_Z(g_flags), FLAGS_GET_M(g_flags), 1, data_ptr); else point->point = ptarray_construct(FLAGS_GET_Z(g_flags), FLAGS_GET_M(g_flags), 0); /* Empty point */ data_ptr += npoints * FLAGS_NDIMS(g_flags) * sizeof(double); if ( g_size ) *g_size = data_ptr - start_ptr; return point; }
static LWCIRCSTRING* lwcircstring_from_gserialized_buffer(uint8_t *data_ptr, uint8_t g_flags, size_t *g_size) { uint8_t *start_ptr = data_ptr; LWCIRCSTRING *circstring; uint32_t npoints = 0; assert(data_ptr); circstring = (LWCIRCSTRING*)lwalloc(sizeof(LWCIRCSTRING)); circstring->srid = SRID_UNKNOWN; /* Default */ circstring->bbox = NULL; circstring->type = CIRCSTRINGTYPE; circstring->flags = g_flags; data_ptr += 4; /* Skip past the circstringtype. */ npoints = lw_get_uint32_t(data_ptr); /* Zero => empty geometry */ data_ptr += 4; /* Skip past the npoints. */ if ( npoints > 0 ) circstring->points = ptarray_construct_reference_data(FLAGS_GET_Z(g_flags), FLAGS_GET_M(g_flags), npoints, data_ptr); else circstring->points = ptarray_construct(FLAGS_GET_Z(g_flags), FLAGS_GET_M(g_flags), 0); /* Empty circularstring */ data_ptr += FLAGS_NDIMS(g_flags) * npoints * sizeof(double); if ( g_size ) *g_size = data_ptr - start_ptr; return circstring; }
size_t gbox_serialized_size(uint8_t flags) { if ( FLAGS_GET_GEODETIC(flags) ) return 6 * sizeof(float); else return 2 * FLAGS_NDIMS(flags) * sizeof(float); }
/* * ISO format uses both Z and M qualifiers. * Extended format only uses an M qualifier for 3DM variants, where it is not * clear what the third dimension represents. * SFSQL format never has more than two dimensions, so no qualifiers. */ static void dimension_qualifiers_to_wkt_sb(const LWGEOM *geom, stringbuffer_t *sb, uint8_t variant) { /* Extended WKT: POINTM(0 0 0) */ #if 0 if ( (variant & WKT_EXTENDED) && ! (variant & WKT_IS_CHILD) && FLAGS_GET_M(geom->flags) && (!FLAGS_GET_Z(geom->flags)) ) #else if ( (variant & WKT_EXTENDED) && FLAGS_GET_M(geom->flags) && (!FLAGS_GET_Z(geom->flags)) ) #endif { stringbuffer_append(sb, "M"); /* "M" */ return; } /* ISO WKT: POINT ZM (0 0 0 0) */ if ( (variant & WKT_ISO) && (FLAGS_NDIMS(geom->flags) > 2) ) { stringbuffer_append(sb, " "); if ( FLAGS_GET_Z(geom->flags) ) stringbuffer_append(sb, "Z"); if ( FLAGS_GET_M(geom->flags) ) stringbuffer_append(sb, "M"); stringbuffer_append(sb, " "); } }
LWMLINE * lwmcurve_segmentize(LWMCURVE *mcurve, uint32_t perQuad) { LWMLINE *ogeom; LWGEOM *tmp; LWGEOM **lines; int i; LWDEBUGF(2, "lwmcurve_segmentize called, geoms=%d, dim=%d.", mcurve->ngeoms, FLAGS_NDIMS(mcurve->flags)); lines = lwalloc(sizeof(LWGEOM *)*mcurve->ngeoms); for (i = 0; i < mcurve->ngeoms; i++) { tmp = mcurve->geoms[i]; if (tmp->type == CIRCSTRINGTYPE) { lines[i] = (LWGEOM *)lwcircstring_segmentize((LWCIRCSTRING *)tmp, perQuad); } else if (tmp->type == LINETYPE) { lines[i] = (LWGEOM *)lwline_construct(mcurve->srid, NULL, ptarray_clone_deep(((LWLINE *)tmp)->points)); } else { lwerror("Unsupported geometry found in MultiCurve."); return NULL; } } ogeom = (LWMLINE *)lwcollection_construct(MULTILINETYPE, mcurve->srid, NULL, mcurve->ngeoms, lines); return ogeom; }
/* * Compute the memory size needed to serialize * a TGEOM struct */ static size_t tgeom_serialize_size(const TGEOM *tgeom) { int i,j; size_t size; int dims = FLAGS_NDIMS(tgeom->flags); size = sizeof(uint8_t); /* type */ size += sizeof(uint8_t); /* flags */ size += sizeof(uint32_t); /* srid */ if (tgeom->bbox) size += sizeof(BOX3D); /* bbox */ size += sizeof(int); /* nedges */ size += (sizeof(double) * dims * 2 + 4) * tgeom->nedges;/* edges */ size += sizeof(int); /* nfaces */ for (i=0 ; i < tgeom->nfaces ; i++) { size += sizeof(int); /* nedges */ size += sizeof(int) * tgeom->faces[i]->nedges; /* edges */ size += sizeof(int); /* nrings */ for (j=0 ; j < tgeom->faces[i]->nrings ; j++) { size += sizeof(int); /* npoints */ size += sizeof(double) * dims /* rings */ * tgeom->faces[i]->rings[j]->npoints; } } return size; }
void printLWCIRCSTRING(LWCIRCSTRING *curve) { lwnotice("LWCIRCSTRING {"); lwnotice(" ndims = %i", (int)FLAGS_NDIMS(curve->flags)); lwnotice(" srid = %i", (int)curve->srid); printPA(curve->points); lwnotice("}"); }
LWGEOM* wkt_parser_collection_finalize(int lwtype, LWGEOM *col, char *dimensionality) { uint8_t flags = wkt_dimensionality(dimensionality); int flagdims = FLAGS_NDIMS(flags); /* No geometry means it is empty */ if( ! col ) { return lwcollection_as_lwgeom(lwcollection_construct_empty(lwtype, SRID_UNKNOWN, FLAGS_GET_Z(flags), FLAGS_GET_M(flags))); } /* There are 'Z' or 'M' tokens in the signature */ if ( flagdims > 2 ) { /* If the number of dimensions are not consistent, we have a problem. */ if( flagdims != FLAGS_NDIMS(col->flags) ) { lwgeom_free(col); SET_PARSER_ERROR(PARSER_ERROR_MIXDIMS); return NULL; } /* For GEOMETRYCOLLECTION, the exact type of the dimensions must match too */ if( lwtype == COLLECTIONTYPE && ( (FLAGS_GET_Z(flags) != FLAGS_GET_Z(col->flags)) || (FLAGS_GET_M(flags) != FLAGS_GET_M(col->flags)) ) ) { lwgeom_free(col); SET_PARSER_ERROR(PARSER_ERROR_MIXDIMS); return NULL; } /* Harmonize the collection dimensionality */ if( LW_FAILURE == wkt_parser_set_dims(col, flags) ) { lwgeom_free(col); SET_PARSER_ERROR(PARSER_ERROR_OTHER); return NULL; } } /* Set the collection type */ col->type=lwtype; return col; }
size_t gbox_serialized_size(uchar flags) { if ( ! FLAGS_GET_BBOX(flags) ) return 0; if ( FLAGS_GET_GEODETIC(flags) ) return 6 * sizeof(float); else return 2 * FLAGS_NDIMS(flags) * sizeof(float); }
POINTARRAY * ptarray_simplify(POINTARRAY *inpts, double epsilon, unsigned int minpts) { int *stack; /* recursion stack */ int sp=-1; /* recursion stack pointer */ int p1, split; double dist; POINTARRAY *outpts; POINT4D pt; double eps_sqr = epsilon * epsilon; /* Allocate recursion stack */ stack = lwalloc(sizeof(int)*inpts->npoints); p1 = 0; stack[++sp] = inpts->npoints-1; LWDEBUGF(2, "Input has %d pts and %d dims", inpts->npoints, FLAGS_NDIMS(inpts->flags)); /* Allocate output POINTARRAY, and add first point. */ outpts = ptarray_construct_empty(FLAGS_GET_Z(inpts->flags), FLAGS_GET_M(inpts->flags), inpts->npoints); getPoint4d_p(inpts, 0, &pt); ptarray_append_point(outpts, &pt, LW_FALSE); LWDEBUG(3, "Added P0 to simplified point array (size 1)"); do { ptarray_dp_findsplit(inpts, p1, stack[sp], &split, &dist); LWDEBUGF(3, "Farthest point from P%d-P%d is P%d (dist. %g)", p1, stack[sp], split, dist); if (dist > eps_sqr || ( outpts->npoints+sp+1 < minpts && dist >= 0 ) ) { LWDEBUGF(4, "Added P%d to stack (outpts:%d)", split, sp); stack[++sp] = split; } else { getPoint4d_p(inpts, stack[sp], &pt); LWDEBUGF(4, "npoints , minpoints %d %d", outpts->npoints, minpts); ptarray_append_point(outpts, &pt, LW_FALSE); LWDEBUGF(4, "Added P%d to simplified point array (size: %d)", stack[sp], outpts->npoints); p1 = stack[sp--]; } LWDEBUGF(4, "stack pointer = %d", sp); } while (! (sp<0) ); lwfree(stack); return outpts; }
void printLWPOINT(LWPOINT *point) { lwnotice("LWPOINT {"); lwnotice(" ndims = %i", (int)FLAGS_NDIMS(point->flags)); lwnotice(" BBOX = %i", FLAGS_GET_BBOX(point->flags) ? 1 : 0 ); lwnotice(" SRID = %i", (int)point->srid); printPA(point->point); lwnotice("}"); }
/** * Returns maximum size of rendered pointarray in bytes. */ static size_t pointArray_X3Dsize(POINTARRAY *pa, int precision) { if (FLAGS_NDIMS(pa->flags) == 2) return (OUT_MAX_DIGS_DOUBLE + precision + sizeof(" ")) * 2 * pa->npoints; return (OUT_MAX_DIGS_DOUBLE + precision + sizeof(" ")) * 3 * pa->npoints; }
/** * Returns maximum size of rendered pointarray in bytes. */ static size_t pointArray_geojson_size(POINTARRAY *pa, int precision) { if (FLAGS_NDIMS(pa->flags) == 2) return (OUT_MAX_DIGS_DOUBLE + precision + sizeof(",")) * 2 * pa->npoints + sizeof(",[]"); return (OUT_MAX_DIGS_DOUBLE + precision + sizeof(",,")) * 3 * pa->npoints + sizeof(",[]"); }
GIDX* gidx_from_gbox(GBOX box) { int ndims; GIDX *a; ndims = (FLAGS_GET_GEODETIC(box.flags) ? 3 : FLAGS_NDIMS(box.flags)); a = gidx_new(ndims); gidx_from_gbox_p(box, a); return a; }
/* * Get a pointer to nth point of a POINTARRAY. * You cannot safely cast this to a real POINT, due to memory alignment * constraints. Use getPoint*_p for that. */ uint8_t * getPoint_internal(const POINTARRAY *pa, int n) { size_t size; uint8_t *ptr; #if PARANOIA_LEVEL > 0 if ( pa == NULL ) { lwerror("getPoint got NULL pointarray"); return NULL; } LWDEBUGF(5, "(n=%d, pa.npoints=%d, pa.maxpoints=%d)",n,pa->npoints,pa->maxpoints); if ( ( n < 0 ) || ( n > pa->npoints ) || ( n >= pa->maxpoints ) ) { lwerror("getPoint_internal called outside of ptarray range (n=%d, pa.npoints=%d, pa.maxpoints=%d)",n,pa->npoints,pa->maxpoints); return NULL; /*error */ } #endif size = ptarray_point_size(pa); ptr = pa->serialized_pointlist + size * n; if ( FLAGS_NDIMS(pa->flags) == 2) { LWDEBUGF(5, "point = %g %g", *((double*)(ptr)), *((double*)(ptr+8))); } else if ( FLAGS_NDIMS(pa->flags) == 3) { LWDEBUGF(5, "point = %g %g %g", *((double*)(ptr)), *((double*)(ptr+8)), *((double*)(ptr+16))); } else if ( FLAGS_NDIMS(pa->flags) == 4) { LWDEBUGF(5, "point = %g %g %g %g", *((double*)(ptr)), *((double*)(ptr+8)), *((double*)(ptr+16)), *((double*)(ptr+24))); } return ptr; }
static LWPOLY* lwpoly_from_gserialized_buffer(uint8_t *data_ptr, uint8_t g_flags, size_t *g_size) { uint8_t *start_ptr = data_ptr; LWPOLY *poly; uint8_t *ordinate_ptr; uint32_t nrings = 0; int i = 0; assert(data_ptr); poly = (LWPOLY*)lwalloc(sizeof(LWPOLY)); poly->srid = SRID_UNKNOWN; /* Default */ poly->bbox = NULL; poly->type = POLYGONTYPE; poly->flags = g_flags; data_ptr += 4; /* Skip past the polygontype. */ nrings = lw_get_uint32_t(data_ptr); /* Zero => empty geometry */ poly->nrings = nrings; LWDEBUGF(4, "nrings = %d", nrings); data_ptr += 4; /* Skip past the nrings. */ ordinate_ptr = data_ptr; /* Start the ordinate pointer. */ if ( nrings > 0) { poly->rings = (POINTARRAY**)lwalloc( sizeof(POINTARRAY*) * nrings ); ordinate_ptr += nrings * 4; /* Move past all the npoints values. */ if ( nrings % 2 ) /* If there is padding, move past that too. */ ordinate_ptr += 4; } else /* Empty polygon */ { poly->rings = NULL; } for ( i = 0; i < nrings; i++ ) { uint32_t npoints = 0; /* Read in the number of points. */ npoints = lw_get_uint32_t(data_ptr); data_ptr += 4; /* Make a point array for the ring, and move the ordinate pointer past the ring ordinates. */ poly->rings[i] = ptarray_construct_reference_data(FLAGS_GET_Z(g_flags), FLAGS_GET_M(g_flags), npoints, ordinate_ptr); ordinate_ptr += sizeof(double) * FLAGS_NDIMS(g_flags) * npoints; } if ( g_size ) *g_size = ordinate_ptr - start_ptr; return poly; }
void printLWTRIANGLE(LWTRIANGLE *triangle) { if (triangle->type != TRIANGLETYPE) lwerror("printLWTRIANGLE called with something else than a Triangle"); lwnotice("LWTRIANGLE {"); lwnotice(" ndims = %i", (int)FLAGS_NDIMS(triangle->flags)); lwnotice(" SRID = %i", (int)triangle->srid); printPA(triangle->points); lwnotice("}"); }
/** * Start a point array from the first coordinate. */ POINTARRAY* wkt_parser_ptarray_new(POINT p) { int ndims = FLAGS_NDIMS(p.flags); LWDEBUG(4,"entered"); POINTARRAY *pa = ptarray_construct_empty((ndims>2), (ndims>3), 4); if ( ! pa ) { SET_PARSER_ERROR(PARSER_ERROR_OTHER); return NULL; } return wkt_parser_ptarray_add_coord(pa, p); }
static size_t gserialized_from_lwpoly(const LWPOLY *poly, uint8_t *buf) { int i; uint8_t *loc; int ptsize; int type = POLYGONTYPE; assert(poly); assert(buf); LWDEBUG(2, "lwpoly_to_gserialized called"); ptsize = sizeof(double) * FLAGS_NDIMS(poly->flags); loc = buf; /* Write in the type. */ memcpy(loc, &type, sizeof(uint32_t)); loc += sizeof(uint32_t); /* Write in the nrings. */ memcpy(loc, &(poly->nrings), sizeof(uint32_t)); loc += sizeof(uint32_t); /* Write in the npoints per ring. */ for ( i = 0; i < poly->nrings; i++ ) { memcpy(loc, &(poly->rings[i]->npoints), sizeof(uint32_t)); loc += sizeof(uint32_t); } /* Add in padding if necessary to remain double aligned. */ if ( poly->nrings % 2 ) { memset(loc, 0, sizeof(uint32_t)); loc += sizeof(uint32_t); } /* Copy in the ordinates. */ for ( i = 0; i < poly->nrings; i++ ) { POINTARRAY *pa = poly->rings[i]; size_t pasize; if ( FLAGS_GET_ZM(poly->flags) != FLAGS_GET_ZM(pa->flags) ) lwerror("Dimensions mismatch in lwpoly"); pasize = pa->npoints * ptsize; memcpy(loc, getPoint_internal(pa, 0), pasize); loc += pasize; } return (size_t)(loc - buf); }
LWCIRCSTRING * lwcircstring_addpoint(LWCIRCSTRING *curve, LWPOINT *point, uint32_t where) { POINTARRAY *newpa; LWCIRCSTRING *ret; newpa = ptarray_addPoint(curve->points, getPoint_internal(point->point, 0), FLAGS_NDIMS(point->flags), where); ret = lwcircstring_construct(curve->srid, NULL, newpa); return ret; }
LWGEOM* wkt_parser_collection_add_geom(LWGEOM *col, LWGEOM *geom) { LWDEBUG(4,"entered"); /* Toss error on null geometry input */ if( ! (geom && col) ) { SET_PARSER_ERROR(PARSER_ERROR_OTHER); return NULL; } /* All the elements must agree on dimensionality */ if( FLAGS_NDIMS(col->flags) != FLAGS_NDIMS(geom->flags) ) { lwgeom_free(col); lwgeom_free(geom); SET_PARSER_ERROR(PARSER_ERROR_MIXDIMS); return NULL; } return lwcollection_as_lwgeom(lwcollection_add_lwgeom(lwgeom_as_lwcollection(col), geom)); }
static size_t gserialized_from_lwcircstring_size(const LWCIRCSTRING *curve) { size_t size = 4; /* Type number. */ assert(curve); size += 4; /* Number of points (zero => empty). */ size += curve->points->npoints * FLAGS_NDIMS(curve->flags) * sizeof(double); LWDEBUGF(3, "circstring size = %d", size); return size; }