{
char hasSRID;
uchar *loc;
- int ptsize = pointArray_ptsize(line->points);
- unsigned int u;
+ int ptsize;
+ size_t size;
#ifdef PGIS_DEBUG_CALLS
lwnotice("lwline_serialize_buf(%p, %p, %p) called",
if (line == NULL)
lwerror("lwline_serialize:: given null line");
+ if ( TYPE_GETZM(line->type) != TYPE_GETZM(line->points->dims) )
+ lwerror("Dimensions mismatch in lwline");
+
+ ptsize = pointArray_ptsize(line->points);
+
hasSRID = (line->SRID != -1);
buf[0] = (uchar) lwgeom_makeType_full(
#endif
//copy in points
- if (TYPE_NDIMS(line->type) == 3)
- {
- if ( TYPE_HASZ(line->type) )
- {
- for (u=0; u<line->points->npoints; u++)
- {
- getPoint3dz_p(line->points, u, (POINT3DZ *)loc);
- loc += ptsize;
- }
- }
- else
- {
- for (u=0; u<line->points->npoints; u++)
- {
- getPoint3dm_p(line->points, u, (POINT3DM *)loc);
- loc += ptsize;
- }
- }
- }
- else if (TYPE_NDIMS(line->type) == 2)
- {
- for (u=0; u<line->points->npoints; u++)
- {
- getPoint2d_p(line->points, u, (POINT2D *)loc);
- loc+= 16;
- }
- }
- else if (TYPE_NDIMS(line->type) == 4)
- {
- for (u=0; u<line->points->npoints; u++)
- {
- getPoint4d_p(line->points, u, (POINT4D *)loc);
- loc+= 32;
- }
- }
+ size = line->points->npoints*ptsize;
+ memcpy(loc, getPoint_internal(line->points, 0), size);
+ loc += size;
#ifdef PGIS_DEBUG
lwnotice("lwline_serialize_buf copied serialized_pointlist (%d bytes)",
int size=1;
char hasSRID;
uchar *loc;
+ int ptsize = pointArray_ptsize(point->point);
+
+ if ( TYPE_GETZM(point->type) != TYPE_GETZM(point->point->dims) )
+ lwerror("Dimensions mismatch in lwpoint");
//printLWPOINT(point);
#ifdef PGIS_DEBUG_CALLS
}
//copy in points
-
- if (TYPE_NDIMS(point->type) == 3)
- {
- if (TYPE_HASZ(point->type))
- getPoint3dz_p(point->point, 0, (POINT3DZ *)loc);
- else
- getPoint3dm_p(point->point, 0, (POINT3DM *)loc);
- }
- else if (TYPE_NDIMS(point->type) == 2)
- getPoint2d_p(point->point, 0, (POINT2D *)loc);
- else if (TYPE_NDIMS(point->type) == 4)
- getPoint4d_p(point->point, 0, (POINT4D *)loc);
+ memcpy(loc, getPoint_internal(point->point, 0), ptsize);
if (retsize) *retsize = size;
}
void
lwpoly_serialize_buf(LWPOLY *poly, uchar *buf, size_t *retsize)
{
- int size=1; // type byte
+ size_t size=1; // type byte
char hasSRID;
- int t,u;
- int total_points = 0;
- int npoints;
+ int t;
uchar *loc;
+ int ptsize;
#ifdef PGIS_DEBUG_CALLS
lwnotice("lwpoly_serialize_buf called");
#endif
+ ptsize = sizeof(double)*TYPE_NDIMS(poly->type);
+
hasSRID = (poly->SRID != -1);
size += 4; // nrings
size += 4*poly->nrings; //npoints/ring
- for (t=0;t<poly->nrings;t++) {
- total_points += poly->rings[t]->npoints;
- }
- size += sizeof(double)*TYPE_NDIMS(poly->type)*total_points;
-
buf[0] = (uchar) lwgeom_makeType_full(
TYPE_HASZ(poly->type), TYPE_HASM(poly->type),
hasSRID, POLYGONTYPE, poly->bbox ? 1 : 0);
for (t=0;t<poly->nrings;t++)
{
POINTARRAY *pa = poly->rings[t];
- npoints = poly->rings[t]->npoints;
- memcpy(loc, &npoints, sizeof(int32)); //npoints this ring
+ size_t pasize;
+ uint32 npoints;
+
+ if ( TYPE_GETZM(poly->type) != TYPE_GETZM(pa->dims) )
+ lwerror("Dimensions mismatch in lwpoly");
+
+ npoints = pa->npoints;
+
+ memcpy(loc, &npoints, sizeof(uint32)); //npoints this ring
loc+=4;
- if (TYPE_NDIMS(poly->type) == 3)
- {
- if ( TYPE_HASZ(poly->type) )
- {
- for (u=0;u<npoints;u++)
- {
- getPoint3dz_p(pa, u, (POINT3DZ *)loc);
- loc+= 24;
- }
- }
- else
- {
- for (u=0;u<npoints;u++)
- {
- getPoint3dm_p(pa, u, (POINT3DM *)loc);
- loc+= 24;
- }
- }
- }
- else if (TYPE_NDIMS(poly->type) == 2)
- {
- for (u=0;u<npoints;u++)
- {
- getPoint2d_p(pa, u, (POINT2D *)loc);
- loc+= 16;
- }
- }
- else if (TYPE_NDIMS(poly->type) == 4)
- {
- for (u=0;u<npoints;u++)
- {
- getPoint4d_p(pa, u, (POINT4D *)loc);
- loc+= 32;
- }
- }
+
+ pasize = npoints*ptsize;
+ size += pasize;
+
+ // copy points
+ memcpy(loc, getPoint_internal(pa, 0), pasize);
+ loc += pasize;
+
}
if (retsize) *retsize = size;