static size_t
asgeojson_multipolygon_buf(GEOSGeom mpoly, char *srs, char *output, bbox3D *bbox, int precision)
{
    GEOSGeom poly;
    int i, j, ngeoms = GEOSGetNumGeometries(mpoly);
    char *ptr=output;

    ptr += sprintf(ptr, "{\"type\":\"MultiPolygon\",");
    if (srs) ptr += asgeojson_srs_buf(ptr, srs);
    if (bbox) ptr += asgeojson_bbox_buf(ptr, bbox, GEOS_getWKBOutputDims(mpoly) == 3, precision);
    ptr += sprintf(ptr, "\"coordinates\":[");
    for (i=0; i<ngeoms; i++)
    {
        int nrings; 
        if (i) ptr += sprintf(ptr, ",");
        ptr += sprintf(ptr, "[");
        poly = (GEOSGeom ) GEOSGetGeometryN(mpoly, i);
        nrings = GEOSGetNumInteriorRings(poly);
        for (j=0 ; j < nrings ; j++)
        {
            if (j) ptr += sprintf(ptr, ",");
            ptr += sprintf(ptr, "[");
            ptr += points_to_geojson(*(GEOSGeom*)GEOSGetInteriorRingN(poly, j), ptr, precision);
            ptr += sprintf(ptr, "]");
        }
        ptr += sprintf(ptr, "]");
    }
    ptr += sprintf(ptr, "]}");

    return (ptr - output);
}
示例#2
0
static size_t
asgeojson_multipolygon_buf(const LWMPOLY *mpoly, char *srs, char *output, GBOX *bbox, int precision)
{
	LWPOLY *poly;
	int i, j;
	char *ptr=output;

	ptr += sprintf(ptr, "{\"type\":\"MultiPolygon\",");
	if (srs) ptr += asgeojson_srs_buf(ptr, srs);
	if (bbox) ptr += asgeojson_bbox_buf(ptr, bbox, FLAGS_GET_Z(mpoly->flags), precision);
	ptr += sprintf(ptr, "\"coordinates\":[");
	for (i=0; i<mpoly->ngeoms; i++)
	{
		if (i) ptr += sprintf(ptr, ",");
		ptr += sprintf(ptr, "[");
		poly = mpoly->geoms[i];
		for (j=0 ; j < poly->nrings ; j++)
		{
			if (j) ptr += sprintf(ptr, ",");
			ptr += sprintf(ptr, "[");
			ptr += pointArray_to_geojson(poly->rings[j], ptr, precision);
			ptr += sprintf(ptr, "]");
		}
		ptr += sprintf(ptr, "]");
	}
	ptr += sprintf(ptr, "]}");

	return (ptr - output);
}
    static size_t
asgeojson_multiline_buf(GEOSGeom mline, char *srs, char *output, bbox3D *bbox, int precision)
{
    GEOSGeom line;
    int i, ngeoms = GEOSGetNumGeometries(mline);
    char *ptr=output;

    ptr += sprintf(ptr, "{\"type\":\"MultiLineString\",");
    if (srs) ptr += asgeojson_srs_buf(ptr, srs);
    if (bbox) ptr += asgeojson_bbox_buf(ptr, bbox, GEOS_getWKBOutputDims(mline) == 3, precision);
    ptr += sprintf(ptr, "\"coordinates\":[");

    for (i=0; i<ngeoms; i++)
    {
        if (i) ptr += sprintf(ptr, ",");
        ptr += sprintf(ptr, "[");
        line = (GEOSGeom ) GEOSGetGeometryN(mline, i);
        ptr += points_to_geojson(line, ptr, precision);
        ptr += sprintf(ptr, "]");
    }

    ptr += sprintf(ptr, "]}");

    return (ptr - output);
}
示例#4
0
static size_t
asgeojson_multiline_buf(const LWMLINE *mline, char *srs, char *output, GBOX *bbox, int precision)
{
	LWLINE *line;
	int i;
	char *ptr=output;

	ptr += sprintf(ptr, "{\"type\":\"MultiLineString\",");
	if (srs) ptr += asgeojson_srs_buf(ptr, srs);
	if (bbox) ptr += asgeojson_bbox_buf(ptr, bbox, FLAGS_GET_Z(mline->flags), precision);
	ptr += sprintf(ptr, "\"coordinates\":[");

	for (i=0; i<mline->ngeoms; i++)
	{
		if (i) ptr += sprintf(ptr, ",");
		ptr += sprintf(ptr, "[");
		line = mline->geoms[i];
		ptr += pointArray_to_geojson(line->points, ptr, precision);
		ptr += sprintf(ptr, "]");
	}

	ptr += sprintf(ptr, "]}");

	return (ptr - output);
}
    static size_t
asgeojson_line_buf(GEOSGeom line, char *srs, char *output, bbox3D *bbox, int precision)
{
    char *ptr=output;

    ptr += sprintf(ptr, "{\"type\":\"LineString\",");
    if (srs) ptr += asgeojson_srs_buf(ptr, srs);
    if (bbox) ptr += asgeojson_bbox_buf(ptr, bbox, GEOS_getWKBOutputDims(line) == 3, precision);
    ptr += sprintf(ptr, "\"coordinates\":[");
    ptr += points_to_geojson(line, ptr, precision);
    ptr += sprintf(ptr, "]}");

    return (ptr-output);
}
示例#6
0
static size_t
asgeojson_line_buf(const LWLINE *line, char *srs, char *output, GBOX *bbox, int precision)
{
	char *ptr=output;

	ptr += sprintf(ptr, "{\"type\":\"LineString\",");
	if (srs) ptr += asgeojson_srs_buf(ptr, srs);
	if (bbox) ptr += asgeojson_bbox_buf(ptr, bbox, FLAGS_GET_Z(line->flags), precision);
	ptr += sprintf(ptr, "\"coordinates\":[");
	ptr += pointArray_to_geojson(line->points, ptr, precision);
	ptr += sprintf(ptr, "]}");

	return (ptr-output);
}
示例#7
0
static size_t
asgeojson_point_buf(const LWPOINT *point, char *srs, char *output, GBOX *bbox, int precision)
{
	char *ptr = output;

	ptr += sprintf(ptr, "{\"type\":\"Point\",");
	if (srs) ptr += asgeojson_srs_buf(ptr, srs);
	if (bbox) ptr += asgeojson_bbox_buf(ptr, bbox, FLAGS_GET_Z(point->flags), precision);

	ptr += sprintf(ptr, "\"coordinates\":");
	ptr += pointArray_to_geojson(point->point, ptr, precision);
	ptr += sprintf(ptr, "}");

	return (ptr-output);
}
    static size_t
asgeojson_point_buf(GEOSGeom point, char *srs, char *output, bbox3D *bbox, int precision)
{
    char *ptr = output;

    ptr += sprintf(ptr, "{\"type\":\"Point\",");
    if (srs) ptr += asgeojson_srs_buf(ptr, srs);
    if (bbox) ptr += asgeojson_bbox_buf(ptr, bbox, GEOS_getWKBOutputDims(point) == 3, precision);

    ptr += sprintf(ptr, "\"coordinates\":");
    if ( GEOSisEmpty(point) == 1 )
        ptr += sprintf(ptr, "[]");
    ptr += points_to_geojson(point, ptr, precision);
    ptr += sprintf(ptr, "}");

    return (ptr-output);
}
    static size_t
asgeojson_poly_buf(GEOSGeom poly, char *srs, char *output, bbox3D *bbox, int precision)
{
    int i, nrings = GEOSGetNumInteriorRings(poly);
    char *ptr=output;

    ptr += sprintf(ptr, "{\"type\":\"Polygon\",");
    if (srs) ptr += asgeojson_srs_buf(ptr, srs);
    if (bbox) ptr += asgeojson_bbox_buf(ptr, bbox, GEOS_getWKBOutputDims(poly) == 3, precision);
    ptr += sprintf(ptr, "\"coordinates\":[");
    for (i=0; i<nrings; i++)
    {
        if (i) ptr += sprintf(ptr, ",");
        ptr += sprintf(ptr, "[");
        ptr += points_to_geojson(*(GEOSGeom*) GEOSGetInteriorRingN(poly, i), ptr, precision);
        ptr += sprintf(ptr, "]");
    }
    ptr += sprintf(ptr, "]}");

    return (ptr-output);
}
示例#10
0
static size_t
asgeojson_poly_buf(const LWPOLY *poly, char *srs, char *output, GBOX *bbox, int precision)
{
	int i;
	char *ptr=output;

	ptr += sprintf(ptr, "{\"type\":\"Polygon\",");
	if (srs) ptr += asgeojson_srs_buf(ptr, srs);
	if (bbox) ptr += asgeojson_bbox_buf(ptr, bbox, FLAGS_GET_Z(poly->flags), precision);
	ptr += sprintf(ptr, "\"coordinates\":[");
	for (i=0; i<poly->nrings; i++)
	{
		if (i) ptr += sprintf(ptr, ",");
		ptr += sprintf(ptr, "[");
		ptr += pointArray_to_geojson(poly->rings[i], ptr, precision);
		ptr += sprintf(ptr, "]");
	}
	ptr += sprintf(ptr, "]}");

	return (ptr-output);
}
示例#11
0
static size_t
asgeojson_multipoint_buf(const LWMPOINT *mpoint, char *srs, char *output, GBOX *bbox, int precision)
{
	LWPOINT *point;
	int i;
	char *ptr=output;

	ptr += sprintf(ptr, "{\"type\":\"MultiPoint\",");
	if (srs) ptr += asgeojson_srs_buf(ptr, srs);
	if (bbox) ptr += asgeojson_bbox_buf(ptr, bbox, FLAGS_GET_Z(mpoint->flags), precision);
	ptr += sprintf(ptr, "\"coordinates\":[");

	for (i=0; i<mpoint->ngeoms; i++)
	{
		if (i) ptr += sprintf(ptr, ",");
		point = mpoint->geoms[i];
		ptr += pointArray_to_geojson(point->point, ptr, precision);
	}
	ptr += sprintf(ptr, "]}");

	return (ptr - output);
}
    static size_t
asgeojson_collection_buf(GEOSGeom col, char *srs, char *output, bbox3D *bbox, int precision)
{
    int i, ngeoms = GEOSGetNumGeometries(col);
    char *ptr=output;
    GEOSGeom subgeom;

    ptr += sprintf(ptr, "{\"type\":\"GeometryCollection\",");
    if (srs) ptr += asgeojson_srs_buf(ptr, srs);
    if (ngeoms && bbox) ptr += asgeojson_bbox_buf(ptr, bbox, GEOS_getWKBOutputDims(col) == 3, precision);
    ptr += sprintf(ptr, "\"geometries\":[");

    for (i=0; i<ngeoms; i++)
    {
        if (i) ptr += sprintf(ptr, ",");
        subgeom = (GEOSGeom ) GEOSGetGeometryN(col, i);
        ptr += asgeojson_geom_buf(subgeom, ptr, NULL, precision);
    }

    ptr += sprintf(ptr, "]}");

    return (ptr - output);
}
示例#13
0
static size_t
asgeojson_collection_buf(const LWCOLLECTION *col, char *srs, char *output, GBOX *bbox, int precision)
{
	int i;
	char *ptr=output;
	LWGEOM *subgeom;

	ptr += sprintf(ptr, "{\"type\":\"GeometryCollection\",");
	if (srs) ptr += asgeojson_srs_buf(ptr, srs);
	if (col->ngeoms && bbox) ptr += asgeojson_bbox_buf(ptr, bbox, FLAGS_GET_Z(col->flags), precision);
	ptr += sprintf(ptr, "\"geometries\":[");

	for (i=0; i<col->ngeoms; i++)
	{
		if (i) ptr += sprintf(ptr, ",");
		subgeom = col->geoms[i];
		ptr += asgeojson_geom_buf(subgeom, ptr, NULL, precision);
	}

	ptr += sprintf(ptr, "]}");

	return (ptr - output);
}