Пример #1
0
/*
* Optional SRID
*/
static int lwgeom_wkb_needs_srid(const LWGEOM *geom, uint8_t variant)
{
	/* Sub-components of collections inherit their SRID from the parent.
	   We force that behavior with the WKB_NO_SRID flag */
	if ( variant & WKB_NO_SRID )
		return LW_FALSE;
		
	/* We can only add an SRID if the geometry has one, and the 
	   WKB form is extended */	
	if ( (variant & WKB_EXTENDED) && lwgeom_has_srid(geom) )
		return LW_TRUE;
		
	/* Everything else doesn't get an SRID */
	return LW_FALSE;
}
Пример #2
0
/**
* WKT emitter function. Allocates a new *char and fills it with the WKT
* representation. If size_out is not NULL, it will be set to the size of the
* allocated *char.
*
* @param variant Bitmasked value, accepts one of WKT_ISO, WKT_SFSQL, WKT_EXTENDED.
* @param precision Number of significant digits in the output doubles.
* @param size_out If supplied, will return the size of the returned string,
* including the null terminator.
*/
char* lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
{
    stringbuffer_t *sb;
    char *str = NULL;
    if ( geom == NULL )
        return NULL;
    sb = stringbuffer_create();
    /* Extended mode starts with an "SRID=" section for geoms that have one */
    if ( (variant & WKT_EXTENDED) && lwgeom_has_srid(geom) )
    {
        stringbuffer_aprintf(sb, "SRID=%d;", geom->srid);
    }
    lwgeom_to_wkt_sb(geom, sb, precision, variant);
    if ( stringbuffer_getstring(sb) == NULL )
    {
        lwerror("Uh oh");
        return NULL;
    }
    str = stringbuffer_getstringcopy(sb);
    if ( size_out )
        *size_out = stringbuffer_getlength(sb) + 1;
    stringbuffer_destroy(sb);
    return str;
}