char * pc_patch_dimensional_bytes_array_to_string(PCPATCH_DIMENSIONAL* pd) { int i; char *str; stringbuffer_t *sb = stringbuffer_create(); stringbuffer_append(sb, "{"); if ( pd->schema->ndims ) { stringbuffer_append(sb, "\"bytes\" : [\n"); for ( i = 0; i < pd->schema->ndims; i++ ) { if ( pd->bytes[i].bytes ) { PCBYTES *d = &pd->bytes[i]; if ( i ) stringbuffer_append(sb, ","); stringbuffer_append(sb, "\n { \n"); stringbuffer_aprintf(sb, " %s ", pc_bytes_to_string(d)); stringbuffer_append(sb, " }"); } } stringbuffer_append(sb, "\n]\n"); } stringbuffer_append(sb, "}\n"); str = stringbuffer_getstringcopy(sb); stringbuffer_destroy(sb); return str; }
/* takes a GEOMETRY and returns a KML representation */ char* lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix) { stringbuffer_t *sb; int rv; char *kml; /* Can't do anything with empty */ if( lwgeom_is_empty(geom) ) return NULL; sb = stringbuffer_create(); rv = lwgeom_to_kml2_sb(geom, precision, prefix, sb); if ( rv == LW_FAILURE ) { stringbuffer_destroy(sb); return NULL; } kml = stringbuffer_getstringcopy(sb); stringbuffer_destroy(sb); return kml; }
char * pc_point_to_string(const PCPOINT *pt) { /* { "pcid":1, "values":[<dim1>, <dim2>, <dim3>, <dim4>] }*/ stringbuffer_t *sb = stringbuffer_create(); char *str; int i; stringbuffer_aprintf(sb, "{\"pcid\":%d,\"pt\":[", pt->schema->pcid); for ( i = 0; i < pt->schema->ndims; i++ ) { double d; if ( ! pc_point_get_double_by_index(pt, i, &d) ) { pcerror("pc_point_to_string: unable to read double at position %d", i); } if ( i ) { stringbuffer_append(sb, ","); } stringbuffer_aprintf(sb, "%g", d); } stringbuffer_append(sb, "]}"); str = stringbuffer_getstringcopy(sb); stringbuffer_destroy(sb); return str; }
/** Convert a PCSCHEMA to a human-readable JSON string */ char * pc_schema_to_json(const PCSCHEMA *pcs) { int i; char *str; stringbuffer_t *sb = stringbuffer_create(); stringbuffer_append(sb, "{"); if ( pcs->pcid ) stringbuffer_aprintf(sb, "\"pcid\" : %d,\n", pcs->pcid); if ( pcs->srid ) stringbuffer_aprintf(sb, "\"srid\" : %d,\n", pcs->srid); if ( pcs->compression ) stringbuffer_aprintf(sb, "\"compression\" : %d,\n", pcs->compression); if ( pcs->ndims ) { stringbuffer_append(sb, "\"dims\" : [\n"); for ( i = 0; i < pcs->ndims; i++ ) { if ( pcs->dims[i] ) { PCDIMENSION *d = pcs->dims[i]; if ( i ) stringbuffer_append(sb, ","); stringbuffer_append(sb, "\n { \n"); if ( d->name ) stringbuffer_aprintf(sb, " \"name\" : \"%s\",\n", d->name); if ( d->description ) stringbuffer_aprintf(sb, " \"description\" : \"%s\",\n", d->description); stringbuffer_aprintf(sb, " \"size\" : %d,\n", d->size); stringbuffer_aprintf(sb, " \"byteoffset\" : %d,\n", d->byteoffset); stringbuffer_aprintf(sb, " \"scale\" : %g,\n", d->scale); stringbuffer_aprintf(sb, " \"interpretation\" : \"%s\",\n", pc_interpretation_string(d->interpretation)); stringbuffer_aprintf(sb, " \"offset\" : %g,\n", d->offset); stringbuffer_aprintf(sb, " \"active\" : %d\n", d->active); stringbuffer_append(sb, " }"); } } stringbuffer_append(sb, "\n]\n"); } stringbuffer_append(sb, "}\n"); str = stringbuffer_getstringcopy(sb); stringbuffer_destroy(sb); return str; }
/** Convert a PCSCHEMA to a human-readable JSON string */ char * pc_schema_to_json(const PCSCHEMA *pcs) { int i; char *str; stringbuffer_t *sb = stringbuffer_create(); stringbuffer_append(sb, "{"); if ( pcs->pcid ) stringbuffer_aprintf(sb, "\"pcid\" : %d,\n", pcs->pcid); if ( pcs->ndims ) stringbuffer_aprintf(sb, "\"ndims\" : %d,\n", pcs->ndims); if ( pcs->srid ) stringbuffer_aprintf(sb, "\"srid\" : %d,\n", pcs->srid); if ( pcs->compression ) stringbuffer_aprintf(sb, "\"compression\" : %d,\n", pcs->compression); if ( pcs->size ) stringbuffer_aprintf(sb, "\"size\" : %zu,\n", pcs->size); if ( pcs->x_position>=0 ) stringbuffer_aprintf(sb, "\"x_position\" : %d,\n", pcs->x_position); if ( pcs->y_position >=0) stringbuffer_aprintf(sb, "\"y_position\" : %d,\n", pcs->y_position); if ( pcs->namehash->entrycount ) stringbuffer_aprintf(sb, "\"namehash->entrycount\" : %d,\n", pcs->namehash->entrycount); if ( pcs->ndims ) { stringbuffer_append(sb, "\"dims\" : [\n"); for ( i = 0; i < pcs->ndims; i++ ) { stringbuffer_append(sb,pc_dimension_to_json(pcs->dims[i] ) ); } stringbuffer_append(sb, "\n]\n"); } stringbuffer_append(sb, "}\n"); str = stringbuffer_getstringcopy(sb); stringbuffer_destroy(sb); return str; }
/** * 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; }
/**@brief * Convert a PCSDIMENSION to a human-readable JSON string * @param the PCDIMENSION we want to print * @return q pointer to the string buff describing the object * */ char * pc_dimension_to_json(const PCDIMENSION *d) { int i; char *str; stringbuffer_t *sb = stringbuffer_create(); stringbuffer_append(sb, "{"); if ( d ) { if ( i ) stringbuffer_append(sb, ","); stringbuffer_append(sb, "\n { \n"); if ( d->name ) stringbuffer_aprintf(sb, " \"name\" : \"%s\",\n", d->name); if ( d->description ) stringbuffer_aprintf(sb, " \"description\" : \"%s\",\n", d->description); stringbuffer_aprintf(sb, " \"size\" : %d,\n", d->size); stringbuffer_aprintf(sb, " \"byteoffset\" : %d,\n", d->byteoffset); stringbuffer_aprintf(sb, " \"scale\" : %g,\n", d->scale); stringbuffer_aprintf(sb, " \"interpretation\" : \"%s\",\n", pc_interpretation_string(d->interpretation)); stringbuffer_aprintf(sb, " \"offset\" : %g,\n", d->offset); stringbuffer_aprintf(sb, " \"active\" : %d\n", d->active); stringbuffer_append(sb, " }"); } stringbuffer_append(sb, "}\n"); str = stringbuffer_getstringcopy(sb); stringbuffer_destroy(sb); return str; }