PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
lwgeom_debug.c
Go to the documentation of this file.
1/**********************************************************************
2 *
3 * PostGIS - Spatial Types for PostgreSQL
4 * http://postgis.net
5 *
6 * PostGIS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * PostGIS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with PostGIS. If not, see <http://www.gnu.org/licenses/>.
18 *
19 **********************************************************************
20 *
21 * Copyright (C) 2004 Refractions Research Inc.
22 *
23 **********************************************************************/
24
25
26#include "lwgeom_log.h"
27#include "liblwgeom.h"
28
29#include <stdio.h>
30#include <string.h>
31
32/* Place to hold the ZM string used in other summaries */
33static char tflags[6];
34
35static char *
37{
38 int flagno = 0;
39 if ( FLAGS_GET_Z(lwg->flags) ) tflags[flagno++] = 'Z';
40 if ( FLAGS_GET_M(lwg->flags) ) tflags[flagno++] = 'M';
41 if ( FLAGS_GET_BBOX(lwg->flags) ) tflags[flagno++] = 'B';
42 if ( FLAGS_GET_GEODETIC(lwg->flags) ) tflags[flagno++] = 'G';
43 if ( lwg->srid != SRID_UNKNOWN ) tflags[flagno++] = 'S';
44 tflags[flagno] = '\0';
45
46 LWDEBUGF(4, "Flags: %s - returning %p", lwg->flags, tflags);
47
48 return tflags;
49}
50
51/*
52 * Returns an allocated string containing summary for the LWGEOM object
53 */
54static char *
55lwpoint_summary(LWPOINT *point, int offset)
56{
57 char *result;
58 char *pad="";
59 char *zmflags = lwgeom_flagchars((LWGEOM*)point);
60 size_t sz = 128+offset;
61
62 result = (char *)lwalloc(sz);
63
64 snprintf(result, sz, "%*.s%s[%s]",
65 offset, pad, lwtype_name(point->type),
66 zmflags);
67 return result;
68}
69
70static char *
71lwline_summary(LWLINE *line, int offset)
72{
73 char *result;
74 char *pad="";
75 char *zmflags = lwgeom_flagchars((LWGEOM*)line);
76 size_t sz = 128+offset;
77
78 result = (char *)lwalloc(sz);
79
80 snprintf(result, sz, "%*.s%s[%s] with %d points",
81 offset, pad, lwtype_name(line->type),
82 zmflags,
83 line->points->npoints);
84 return result;
85}
86
87
88static char *
90{
91 size_t size = 128;
92 char *result;
93 char *tmp;
94 uint32_t i;
95 static char *nl = "\n";
96 char *pad="";
97 char *zmflags = lwgeom_flagchars((LWGEOM*)col);
98
99 LWDEBUG(2, "lwcollection_summary called");
100
101 result = (char *)lwalloc(size);
102
103 snprintf(result, size, "%*.s%s[%s] with %d element%s",
104 offset, pad, lwtype_name(col->type),
105 zmflags,
106 col->ngeoms,
107 col->ngeoms ?
108 ( col->ngeoms > 1 ? "s:\n" : ":\n")
109 : "s");
110
111 for (i=0; i<col->ngeoms; i++)
112 {
113 tmp = lwgeom_summary(col->geoms[i], offset+2);
114 size += strlen(tmp)+1;
115 result = lwrealloc(result, size);
116
117 LWDEBUGF(4, "Reallocated %d bytes for result", size);
118 if ( i > 0 ) strcat(result,nl);
119
120 strcat(result, tmp);
121 lwfree(tmp);
122 }
123
124 LWDEBUG(3, "lwcollection_summary returning");
125
126 return result;
127}
128
129static char *
130lwpoly_summary(LWPOLY *poly, int offset)
131{
132 char tmp[256];
133 size_t size = 64*(poly->nrings+1)+128;
134 char *result;
135 uint32_t i;
136 char *pad="";
137 static char *nl = "\n";
138 char *zmflags = lwgeom_flagchars((LWGEOM*)poly);
139
140 LWDEBUG(2, "lwpoly_summary called");
141
142 result = (char *)lwalloc(size);
143
144 snprintf(result, size, "%*.s%s[%s] with %i ring%s",
145 offset, pad, lwtype_name(poly->type),
146 zmflags,
147 poly->nrings,
148 poly->nrings ?
149 ( poly->nrings > 1 ? "s:\n" : ":\n")
150 : "s");
151
152 for (i=0; i<poly->nrings; i++)
153 {
154 snprintf(tmp, sizeof(tmp), "%s ring %i has %i points",
155 pad, i, poly->rings[i]->npoints);
156 if ( i > 0 ) strcat(result,nl);
157 strcat(result,tmp);
158 }
159
160 LWDEBUG(3, "lwpoly_summary returning");
161
162 return result;
163}
164
165char *
166lwgeom_summary(const LWGEOM *lwgeom, int offset)
167{
168 char *result;
169
170 switch (lwgeom->type)
171 {
172 case POINTTYPE:
173 return lwpoint_summary((LWPOINT *)lwgeom, offset);
174
175 case CIRCSTRINGTYPE:
176 case TRIANGLETYPE:
177 case LINETYPE:
178 return lwline_summary((LWLINE *)lwgeom, offset);
179
180 case POLYGONTYPE:
181 return lwpoly_summary((LWPOLY *)lwgeom, offset);
182
183 case TINTYPE:
184 case MULTISURFACETYPE:
185 case MULTICURVETYPE:
186 case CURVEPOLYTYPE:
187 case COMPOUNDTYPE:
188 case MULTIPOINTTYPE:
189 case MULTILINETYPE:
190 case MULTIPOLYGONTYPE:
191 case COLLECTIONTYPE:
192 return lwcollection_summary((LWCOLLECTION *)lwgeom, offset);
193 default:
194 result = (char *)lwalloc(256);
195 snprintf(result, 256, "Object is of unknown type: %d",
196 lwgeom->type);
197 return result;
198 }
199
200 return NULL;
201}
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition cu_print.c:267
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition lwutil.c:216
#define COLLECTIONTYPE
Definition liblwgeom.h:108
#define COMPOUNDTYPE
Definition liblwgeom.h:110
void * lwrealloc(void *mem, size_t size)
Definition lwutil.c:242
#define CURVEPOLYTYPE
Definition liblwgeom.h:111
#define MULTILINETYPE
Definition liblwgeom.h:106
#define MULTISURFACETYPE
Definition liblwgeom.h:113
#define LINETYPE
Definition liblwgeom.h:103
#define FLAGS_GET_BBOX(flags)
Definition liblwgeom.h:167
#define MULTIPOINTTYPE
Definition liblwgeom.h:105
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition liblwgeom.h:102
#define FLAGS_GET_Z(flags)
Definition liblwgeom.h:165
void * lwalloc(size_t size)
Definition lwutil.c:227
#define TINTYPE
Definition liblwgeom.h:116
#define MULTIPOLYGONTYPE
Definition liblwgeom.h:107
void lwfree(void *mem)
Definition lwutil.c:248
#define POLYGONTYPE
Definition liblwgeom.h:104
#define CIRCSTRINGTYPE
Definition liblwgeom.h:109
#define FLAGS_GET_M(flags)
Definition liblwgeom.h:166
#define MULTICURVETYPE
Definition liblwgeom.h:112
#define TRIANGLETYPE
Definition liblwgeom.h:115
#define SRID_UNKNOWN
Unknown SRID value.
Definition liblwgeom.h:215
#define FLAGS_GET_GEODETIC(flags)
Definition liblwgeom.h:168
This library is the generic geometry handling section of PostGIS.
static char tflags[6]
static char * lwgeom_flagchars(LWGEOM *lwg)
char * lwgeom_summary(const LWGEOM *lwgeom, int offset)
static char * lwpoint_summary(LWPOINT *point, int offset)
static char * lwpoly_summary(LWPOLY *poly, int offset)
static char * lwcollection_summary(LWCOLLECTION *col, int offset)
static char * lwline_summary(LWLINE *line, int offset)
#define LWDEBUG(level, msg)
Definition lwgeom_log.h:101
#define LWDEBUGF(level, msg,...)
Definition lwgeom_log.h:106
uint32_t ngeoms
Definition liblwgeom.h:580
uint8_t type
Definition liblwgeom.h:578
LWGEOM ** geoms
Definition liblwgeom.h:575
uint8_t type
Definition liblwgeom.h:462
int32_t srid
Definition liblwgeom.h:460
lwflags_t flags
Definition liblwgeom.h:461
POINTARRAY * points
Definition liblwgeom.h:483
uint8_t type
Definition liblwgeom.h:486
uint8_t type
Definition liblwgeom.h:474
POINTARRAY ** rings
Definition liblwgeom.h:519
uint8_t type
Definition liblwgeom.h:522
uint32_t nrings
Definition liblwgeom.h:524
uint32_t npoints
Definition liblwgeom.h:427