Exemplo n.º 1
0
LWCURVEPOLY *
lwcurvepoly_deserialize(uchar *srl)
{
	LWCURVEPOLY *result;
	LWGEOM_INSPECTED *insp;
	int type = lwgeom_getType(srl[0]);
	int i;

	LWDEBUG(3, "lwcurvepoly_deserialize called.");

	if (type != CURVEPOLYTYPE)
	{
		lwerror("lwcurvepoly_deserialize called on NON curvepoly: %d",
		        type);
		return NULL;
	}

	insp = lwgeom_inspect(srl);

	result = lwalloc(sizeof(LWCURVEPOLY));
	result->type = insp->type;
	result->SRID = insp->SRID;
	result->nrings = insp->ngeometries;
	result->rings = lwalloc(sizeof(LWGEOM *)*insp->ngeometries);

	if (lwgeom_hasBBOX(srl[0]))
	{
		result->bbox = lwalloc(sizeof(BOX2DFLOAT4));
		memcpy(result->bbox, srl + 1, sizeof(BOX2DFLOAT4));
	}
	else result->bbox = NULL;

	for (i = 0; i < insp->ngeometries; i++)
	{
		result->rings[i] = lwgeom_deserialize(insp->sub_geoms[i]);
		if (lwgeom_getType(result->rings[i]->type) != CIRCSTRINGTYPE
		        && lwgeom_getType(result->rings[i]->type) != LINETYPE
		        && lwgeom_getType(result->rings[i]->type) != COMPOUNDTYPE)
		{
			lwerror("Only Circular curves, Linestrings and Compound curves are supported as rings, not %s (%d)", lwgeom_typename(result->rings[i]->type), result->rings[i]->type);
			lwfree(result);
			lwfree(insp);
			return NULL;
		}
		if (TYPE_NDIMS(result->rings[i]->type) != TYPE_NDIMS(result->type))
		{
			lwerror("Mixed dimensions (curvepoly %d, ring %d)",
			        TYPE_NDIMS(result->type), i,
			        TYPE_NDIMS(result->rings[i]->type));
			lwfree(result);
			lwfree(insp);
			return NULL;
		}
	}
	return result;
}
Exemplo n.º 2
0
LWMPOLY *
lwmpoly_deserialize(uchar *srl)
{
    LWMPOLY *result;
    LWGEOM_INSPECTED *insp;
    int type = lwgeom_getType(srl[0]);
    int i;

    LWDEBUG(2, "lwmpoly_deserialize called");

    if ( type != MULTIPOLYGONTYPE )
    {
        lwerror("lwmpoly_deserialize called on NON multipoly: %d",
                type);
        return NULL;
    }

    insp = lwgeom_inspect(srl);

    result = lwalloc(sizeof(LWMPOLY));
    result->type = insp->type;
    result->SRID = insp->SRID;
    result->ngeoms = insp->ngeometries;

    if ( insp->ngeometries )
    {
        result->geoms = lwalloc(sizeof(LWPOLY *)*insp->ngeometries);
    }
    else
    {
        result->geoms = NULL;
    }

    if (lwgeom_hasBBOX(srl[0]))
    {
        result->bbox = lwalloc(sizeof(BOX2DFLOAT4));
        memcpy(result->bbox, srl+1, sizeof(BOX2DFLOAT4));
    }
    else result->bbox = NULL;

    for (i=0; i<insp->ngeometries; i++)
    {
        result->geoms[i] = lwpoly_deserialize(insp->sub_geoms[i]);
        if ( TYPE_NDIMS(result->geoms[i]->type) != TYPE_NDIMS(result->type) )
        {
            lwerror("Mixed dimensions (multipoly:%d, poly%d:%d)",
                    TYPE_NDIMS(result->type), i,
                    TYPE_NDIMS(result->geoms[i]->type)
                   );
            return NULL;
        }
    }

    return result;
}
Exemplo n.º 3
0
LWCOMPOUND *
lwcompound_deserialize(uchar *serialized)
{
        LWCOMPOUND *result;
        LWGEOM_INSPECTED *insp;
        int type = lwgeom_getType(serialized[0]);
        int i;

        if(type != COMPOUNDTYPE)
        {
                lwerror("lwcompound_deserialize called on non compound: %d", type);
                return NULL;
        }

        insp = lwgeom_inspect(serialized);

        result = lwalloc(sizeof(LWCOMPOUND));
        result->type = insp->type;
        result->SRID = insp->SRID;
        result->ngeoms = insp->ngeometries;
        result->geoms = lwalloc(sizeof(LWGEOM *)*insp->ngeometries);

        if(lwgeom_hasBBOX(serialized[0]))
        {
                result->bbox = lwalloc(sizeof(BOX2DFLOAT4));
                memcpy(result->bbox, serialized + 1, sizeof(BOX2DFLOAT4));
        }
        else result->bbox = NULL;

        for(i = 0; i < insp->ngeometries; i++)
        {
                if(lwgeom_getType(insp->sub_geoms[i][0]) == LINETYPE)
                        result->geoms[i] = (LWGEOM *)lwline_deserialize(insp->sub_geoms[i]);
                else
                        result->geoms[i] = (LWGEOM *)lwcircstring_deserialize(insp->sub_geoms[i]);
                if(TYPE_NDIMS(result->geoms[i]->type) != TYPE_NDIMS(result->type))
                {
                        lwerror("Mixed dimensions (compound: %d, line/circularstring %d:%d)",
                            TYPE_NDIMS(result->type), i,
                            TYPE_NDIMS(result->geoms[i]->type)
                        );
                        lwfree(result);
                        return NULL;
                }
        }
        return result;
}
Exemplo n.º 4
0
void printLWCIRCSTRING(LWCIRCSTRING *curve)
{
	lwnotice("LWCIRCSTRING {");
	lwnotice("    ndims = %i", (int)TYPE_NDIMS(curve->type));
	lwnotice("    SRID = %i", (int)curve->SRID);
	printPA(curve->points);
	lwnotice("}");
}
Exemplo n.º 5
0
void printLWLINE(LWLINE *line)
{
	lwnotice("LWLINE {");
	lwnotice("    ndims = %i", (int)TYPE_NDIMS(line->type));
	lwnotice("    SRID = %i", (int)line->SRID);
	printPA(line->points);
	lwnotice("}");
}
Exemplo n.º 6
0
void printLWPOINT(LWPOINT *point)
{
	lwnotice("LWPOINT {");
	lwnotice("    ndims = %i", (int)TYPE_NDIMS(point->type));
	lwnotice("    BBOX = %i", TYPE_HASBBOX(point->type) ? 1 : 0 );
	lwnotice("    SRID = %i", (int)point->SRID);
	printPA(point->point);
	lwnotice("}");
}
Exemplo n.º 7
0
LWCIRCSTRING *
lwcircstring_addpoint(LWCIRCSTRING *curve, LWPOINT *point, unsigned int where)
{
	POINTARRAY *newpa;
	LWCIRCSTRING *ret;

	newpa = ptarray_addPoint(curve->points,
	                         getPoint_internal(point->point, 0),
	                         TYPE_NDIMS(point->type), where);
	ret = lwcircstring_construct(curve->SRID, NULL, newpa);

	return ret;
}
Exemplo n.º 8
0
LWLINE *
lwline_addpoint(LWLINE *line, LWPOINT *point, unsigned int where)
{
	POINTARRAY *newpa;
	LWLINE *ret;

	newpa = ptarray_addPoint(line->points,
	                         getPoint_internal(point->point, 0),
	                         TYPE_NDIMS(point->type), where);

	ret = lwline_construct(line->SRID, ptarray_compute_box2d(newpa), newpa);

	return ret;
}
Exemplo n.º 9
0
/* find length of this deserialized point */
size_t
lwpoint_serialize_size(LWPOINT *point)
{
	size_t size = 1; /* type */

	LWDEBUG(2, "lwpoint_serialize_size called");

	if ( point->SRID != -1 ) size += 4; /* SRID */
	if ( point->bbox ) size += sizeof(BOX2DFLOAT4);

	size += TYPE_NDIMS(point->type) * sizeof(double); /* point */

	LWDEBUGF(3, "lwpoint_serialize_size returning %d", size);

	return size; 
}
Exemplo n.º 10
0
/*
 * Convert this point into its serialize form writing it into
 * the given buffer, and returning number of bytes written into
 * the given int pointer.
 * result's first char will be the 8bit type.  See serialized form doc
 */
void
lwpoint_serialize_buf(LWPOINT *point, uchar *buf, size_t *retsize)
{
	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");

	LWDEBUGF(2, "lwpoint_serialize_buf(%p, %p) called", point, buf);
	/*printLWPOINT(point); */

	hasSRID = (point->SRID != -1);

	if (hasSRID) size +=4;  /*4 byte SRID */
	if (point->bbox) size += sizeof(BOX2DFLOAT4); /* bvol */

	size += sizeof(double)*TYPE_NDIMS(point->type);

	buf[0] = (uchar) lwgeom_makeType_full(
		TYPE_HASZ(point->type), TYPE_HASM(point->type),
		hasSRID, POINTTYPE, point->bbox?1:0);
	loc = buf+1;

	if (point->bbox)
	{
		memcpy(loc, point->bbox, sizeof(BOX2DFLOAT4));
		loc += sizeof(BOX2DFLOAT4);
	}

	if (hasSRID)
	{
		memcpy(loc, &point->SRID, sizeof(int32));
		loc += 4;
	}

	/* copy in points */
	memcpy(loc, getPoint_internal(point->point, 0), ptsize);

	if (retsize) *retsize = size;
}
Exemplo n.º 11
0
/* find length of this serialized line */
size_t
lwgeom_size_line(const uchar *serialized_line)
{
	int type = (uchar) serialized_line[0];
	uint32 result = 1;  /*type */
	const uchar *loc;
	uint32 npoints;

        LWDEBUG(2, "lwgeom_size_line called");

	if ( lwgeom_getType(type) != LINETYPE)
		lwerror("lwgeom_size_line::attempt to find the length of a non-line");


	loc = serialized_line+1;

	if (lwgeom_hasBBOX(type))
	{
		loc += sizeof(BOX2DFLOAT4);
		result +=sizeof(BOX2DFLOAT4);
	}

	if ( lwgeom_hasSRID(type))
	{
		loc += 4; /* type + SRID */
		result +=4;
	}

	/* we've read the type (1 byte) and SRID (4 bytes, if present) */
	npoints = lw_get_uint32(loc);
	result += sizeof(uint32); /* npoints */

	result += TYPE_NDIMS(type) * sizeof(double) * npoints;

	LWDEBUGF(3, "lwgeom_size_line returning %d", result);

	return result;
}
Exemplo n.º 12
0
LWMCURVE *
lwmcurve_deserialize(uchar *srl)
{
	LWMCURVE *result;
	LWGEOM_INSPECTED *insp;
	int stype;
	int type = lwgeom_getType(srl[0]);
	int i;

	if (type != MULTICURVETYPE)
	{
		lwerror("lwmcurve_deserialize called on NON multicurve: %d", type);
		return NULL;
	}

	insp = lwgeom_inspect(srl);

	result = lwalloc(sizeof(LWMCURVE));
	result->type = insp->type;
	result->SRID = insp->SRID;
	result->ngeoms = insp->ngeometries;

	if ( insp->ngeometries )
	{
		result->geoms = lwalloc(sizeof(LWGEOM *)*insp->ngeometries);
	}
	else
	{
		result->geoms = NULL;
	}

	if (lwgeom_hasBBOX(srl[0]))
	{
		result->bbox = lwalloc(sizeof(BOX2DFLOAT4));
		memcpy(result->bbox, srl+1, sizeof(BOX2DFLOAT4));
	}
	else result->bbox = NULL;

	for (i = 0; i < insp->ngeometries; i++)
	{
		stype = lwgeom_getType(insp->sub_geoms[i][0]);
		if (stype == CIRCSTRINGTYPE)
		{
			result->geoms[i] = (LWGEOM *)lwcircstring_deserialize(insp->sub_geoms[i]);
		}
		else if (stype == LINETYPE)
		{
			result->geoms[i] = (LWGEOM *)lwline_deserialize(insp->sub_geoms[i]);
		}
		else if (stype == COMPOUNDTYPE)
		{
			result->geoms[i] = (LWGEOM *)lwcompound_deserialize(insp->sub_geoms[i]);
		}
		else
		{
			lwerror("Only Circular strings, Line strings or Compound curves are permitted in a MultiCurve.");

			lwfree(result);
			lwfree(insp);
			return NULL;
		}

		if (TYPE_NDIMS(result->geoms[i]->type) != TYPE_NDIMS(result->type))
		{
			lwerror("Mixed dimensions (multicurve: %d, curve %d:%d)",
			        TYPE_NDIMS(result->type), i,
			        TYPE_NDIMS(result->geoms[i]->type));
			lwfree(result);
			lwfree(insp);
			return NULL;
		}
	}
	return result;
}
Exemplo n.º 13
0
LWMSURFACE *
lwmsurface_deserialize(uchar *srl)
{
	LWMSURFACE *result;
	LWGEOM_INSPECTED *insp;
	int stype;
	int type = lwgeom_getType(srl[0]);
	int i;

	LWDEBUG(2, "lwmsurface_deserialize called");

	if (type != MULTISURFACETYPE)
	{
		lwerror("lwmsurface_deserialize called on a non-multisurface: %d", type);
		return NULL;
	}

	insp = lwgeom_inspect(srl);

	result = lwalloc(sizeof(LWMSURFACE));
	result->type = insp->type;
	result->SRID = insp->SRID;
	result->ngeoms = insp->ngeometries;

	if ( insp->ngeometries )
	{
		result->geoms = lwalloc(sizeof(LWPOLY *)*insp->ngeometries);
	}
	else
	{
		result->geoms = NULL;
	}

	if (lwgeom_hasBBOX(srl[0]))
	{
		result->bbox = lwalloc(sizeof(BOX2DFLOAT4));
		memcpy(result->bbox, srl + 1, sizeof(BOX2DFLOAT4));
	}
	else result->bbox = NULL;

	for (i = 0; i < insp->ngeometries; i++)
	{
		stype = lwgeom_getType(insp->sub_geoms[i][0]);
		if (stype == POLYGONTYPE)
		{
			result->geoms[i] = (LWGEOM *)lwpoly_deserialize(insp->sub_geoms[i]);
		}
		else if (stype == CURVEPOLYTYPE)
		{
			result->geoms[i] = (LWGEOM *)lwcurvepoly_deserialize(insp->sub_geoms[i]);
		}
		else
		{
			lwerror("Only Polygons and Curved Polygons are supported in a MultiSurface.");
			lwfree(result);
			lwfree(insp);
			return NULL;
		}

		if (TYPE_NDIMS(result->geoms[i]->type) != TYPE_NDIMS(result->type))
		{
			lwerror("Mixed dimensions (multisurface: %d, surface %d:%d",
			        TYPE_NDIMS(result->type), i,
			        TYPE_NDIMS(result->geoms[i]->type));
			lwfree(result);
			lwfree(insp);
			return NULL;
		}
	}
	return result;
}