PostGIS  2.2.7dev-r@@SVN_REVISION@@
lwgeom_debug.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * Copyright (C) 2004 Refractions Research Inc.
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU General Public Licence. See the COPYING file.
10  *
11  **********************************************************************/
12 
13 #include "lwgeom_log.h"
14 #include "liblwgeom.h"
15 
16 #include <stdio.h>
17 #include <string.h>
18 
19 /* Place to hold the ZM string used in other summaries */
20 static char tflags[6];
21 
22 static char *
24 {
25  int flagno = 0;
26  if ( FLAGS_GET_Z(lwg->flags) ) tflags[flagno++] = 'Z';
27  if ( FLAGS_GET_M(lwg->flags) ) tflags[flagno++] = 'M';
28  if ( FLAGS_GET_BBOX(lwg->flags) ) tflags[flagno++] = 'B';
29  if ( FLAGS_GET_GEODETIC(lwg->flags) ) tflags[flagno++] = 'G';
30  if ( lwg->srid != SRID_UNKNOWN ) tflags[flagno++] = 'S';
31  tflags[flagno] = '\0';
32 
33  LWDEBUGF(4, "Flags: %s - returning %p", lwg->flags, tflags);
34 
35  return tflags;
36 }
37 
38 /*
39  * Returns an alloced string containing summary for the LWGEOM object
40  */
41 static char *
42 lwpoint_summary(LWPOINT *point, int offset)
43 {
44  char *result;
45  char *pad="";
46  char *zmflags = lwgeom_flagchars((LWGEOM*)point);
47 
48  result = (char *)lwalloc(128+offset);
49 
50  sprintf(result, "%*.s%s[%s]",
51  offset, pad, lwtype_name(point->type),
52  zmflags);
53  return result;
54 }
55 
56 static char *
57 lwline_summary(LWLINE *line, int offset)
58 {
59  char *result;
60  char *pad="";
61  char *zmflags = lwgeom_flagchars((LWGEOM*)line);
62 
63  result = (char *)lwalloc(128+offset);
64 
65  sprintf(result, "%*.s%s[%s] with %d points",
66  offset, pad, lwtype_name(line->type),
67  zmflags,
68  line->points->npoints);
69  return result;
70 }
71 
72 
73 static char *
75 {
76  size_t size = 128;
77  char *result;
78  char *tmp;
79  int i;
80  static char *nl = "\n";
81  char *pad="";
82  char *zmflags = lwgeom_flagchars((LWGEOM*)col);
83 
84  LWDEBUG(2, "lwcollection_summary called");
85 
86  result = (char *)lwalloc(size);
87 
88  sprintf(result, "%*.s%s[%s] with %d elements\n",
89  offset, pad, lwtype_name(col->type),
90  zmflags,
91  col->ngeoms);
92 
93  for (i=0; i<col->ngeoms; i++)
94  {
95  tmp = lwgeom_summary(col->geoms[i], offset+2);
96  size += strlen(tmp)+1;
97  result = lwrealloc(result, size);
98 
99  LWDEBUGF(4, "Reallocated %d bytes for result", size);
100  if ( i > 0 ) strcat(result,nl);
101 
102  strcat(result, tmp);
103  lwfree(tmp);
104  }
105 
106  LWDEBUG(3, "lwcollection_summary returning");
107 
108  return result;
109 }
110 
111 static char *
112 lwpoly_summary(LWPOLY *poly, int offset)
113 {
114  char tmp[256];
115  size_t size = 64*(poly->nrings+1)+128;
116  char *result;
117  int i;
118  char *pad="";
119  static char *nl = "\n";
120  char *zmflags = lwgeom_flagchars((LWGEOM*)poly);
121 
122  LWDEBUG(2, "lwpoly_summary called");
123 
124  result = (char *)lwalloc(size);
125 
126  sprintf(result, "%*.s%s[%s] with %i rings\n",
127  offset, pad, lwtype_name(poly->type),
128  zmflags,
129  poly->nrings);
130 
131  for (i=0; i<poly->nrings; i++)
132  {
133  sprintf(tmp,"%s ring %i has %i points",
134  pad, i, poly->rings[i]->npoints);
135  if ( i > 0 ) strcat(result,nl);
136  strcat(result,tmp);
137  }
138 
139  LWDEBUG(3, "lwpoly_summary returning");
140 
141  return result;
142 }
143 
144 char *
145 lwgeom_summary(const LWGEOM *lwgeom, int offset)
146 {
147  char *result;
148 
149  switch (lwgeom->type)
150  {
151  case POINTTYPE:
152  return lwpoint_summary((LWPOINT *)lwgeom, offset);
153 
154  case CIRCSTRINGTYPE:
155  case TRIANGLETYPE:
156  case LINETYPE:
157  return lwline_summary((LWLINE *)lwgeom, offset);
158 
159  case POLYGONTYPE:
160  return lwpoly_summary((LWPOLY *)lwgeom, offset);
161 
162  case TINTYPE:
163  case MULTISURFACETYPE:
164  case MULTICURVETYPE:
165  case CURVEPOLYTYPE:
166  case COMPOUNDTYPE:
167  case MULTIPOINTTYPE:
168  case MULTILINETYPE:
169  case MULTIPOLYGONTYPE:
170  case COLLECTIONTYPE:
171  return lwcollection_summary((LWCOLLECTION *)lwgeom, offset);
172  default:
173  result = (char *)lwalloc(256);
174  sprintf(result, "Object is of unknown type: %d",
175  lwgeom->type);
176  return result;
177  }
178 
179  return NULL;
180 }
#define LINETYPE
Definition: liblwgeom.h:71
uint8_t type
Definition: liblwgeom.h:402
static char * lwline_summary(LWLINE *line, int offset)
Definition: lwgeom_debug.c:57
#define MULTICURVETYPE
Definition: liblwgeom.h:80
uint8_t type
Definition: liblwgeom.h:391
void lwfree(void *mem)
Definition: lwutil.c:214
int npoints
Definition: liblwgeom.h:355
uint8_t type
Definition: liblwgeom.h:487
#define FLAGS_GET_GEODETIC(flags)
Definition: liblwgeom.h:127
#define POLYGONTYPE
Definition: liblwgeom.h:72
uint8_t flags
Definition: liblwgeom.h:381
char * lwgeom_summary(const LWGEOM *lwgeom, int offset)
Definition: lwgeom_debug.c:145
#define CURVEPOLYTYPE
Definition: liblwgeom.h:79
#define COMPOUNDTYPE
Definition: liblwgeom.h:78
#define MULTIPOINTTYPE
Definition: liblwgeom.h:73
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
#define TRIANGLETYPE
Definition: liblwgeom.h:83
static char * lwpoint_summary(LWPOINT *point, int offset)
Definition: lwgeom_debug.c:42
static char tflags[6]
Definition: lwgeom_debug.c:20
int32_t srid
Definition: liblwgeom.h:383
static char * lwgeom_flagchars(LWGEOM *lwg)
Definition: lwgeom_debug.c:23
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:188
#define FLAGS_GET_BBOX(flags)
Definition: liblwgeom.h:126
uint8_t type
Definition: liblwgeom.h:435
LWGEOM ** geoms
Definition: liblwgeom.h:493
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:172
#define TINTYPE
Definition: liblwgeom.h:84
POINTARRAY ** rings
Definition: liblwgeom.h:441
static char * lwpoly_summary(LWPOLY *poly, int offset)
Definition: lwgeom_debug.c:112
int nrings
Definition: liblwgeom.h:439
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:124
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:75
#define MULTISURFACETYPE
Definition: liblwgeom.h:81
static char * lwcollection_summary(LWCOLLECTION *col, int offset)
Definition: lwgeom_debug.c:74
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:207
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:125
uint8_t type
Definition: liblwgeom.h:380
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:77
void * lwalloc(size_t size)
Definition: lwutil.c:199
#define MULTILINETYPE
Definition: liblwgeom.h:74
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
#define COLLECTIONTYPE
Definition: liblwgeom.h:76
This library is the generic geometry handling section of PostGIS.
POINTARRAY * points
Definition: liblwgeom.h:406