PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ lwtype_from_wkb_state()

static void lwtype_from_wkb_state ( wkb_parse_state s,
uint32_t  wkb_type 
)
static

Take in an unknown kind of wkb type number and ensure it comes out as an extended WKB type number (with Z/M/SRID flags masked onto the high bits).

Definition at line 140 of file lwin_wkb.c.

References CIRCSTRINGTYPE, COLLECTIONTYPE, COMPOUNDTYPE, CURVEPOLYTYPE, wkb_parse_state::has_m, wkb_parse_state::has_srid, wkb_parse_state::has_z, LINETYPE, LW_FALSE, LW_TRUE, LWDEBUG, LWDEBUGF, lwerror(), wkb_parse_state::lwtype, lwtype_name(), MULTICURVETYPE, MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, MULTISURFACETYPE, POINTTYPE, POLYGONTYPE, POLYHEDRALSURFACETYPE, TINTYPE, TRIANGLETYPE, WKB_CIRCULARSTRING_TYPE, WKB_COMPOUNDCURVE_TYPE, WKB_CURVE_TYPE, WKB_CURVEPOLYGON_TYPE, WKB_GEOMETRYCOLLECTION_TYPE, WKB_LINESTRING_TYPE, WKB_MULTICURVE_TYPE, WKB_MULTILINESTRING_TYPE, WKB_MULTIPOINT_TYPE, WKB_MULTIPOLYGON_TYPE, WKB_MULTISURFACE_TYPE, WKB_POINT_TYPE, WKB_POLYGON_TYPE, WKB_POLYHEDRALSURFACE_TYPE, WKB_SURFACE_TYPE, WKB_TIN_TYPE, WKB_TRIANGLE_TYPE, WKBMOFFSET, WKBSRIDFLAG, and WKBZOFFSET.

Referenced by lwgeom_from_wkb_state().

141 {
142  uint32_t wkb_simple_type;
143 
144  LWDEBUG(4, "Entered function");
145 
146  s->has_z = LW_FALSE;
147  s->has_m = LW_FALSE;
148  s->has_srid = LW_FALSE;
149 
150  /* If any of the higher bits are set, this is probably an extended type. */
151  if( wkb_type & 0xF0000000 )
152  {
153  if( wkb_type & WKBZOFFSET ) s->has_z = LW_TRUE;
154  if( wkb_type & WKBMOFFSET ) s->has_m = LW_TRUE;
155  if( wkb_type & WKBSRIDFLAG ) s->has_srid = LW_TRUE;
156  LWDEBUGF(4, "Extended type: has_z=%d has_m=%d has_srid=%d", s->has_z, s->has_m, s->has_srid);
157  }
158 
159  /* Mask off the flags */
160  wkb_type = wkb_type & 0x0FFFFFFF;
161  /* Strip out just the type number (1-12) from the ISO number (eg 3001-3012) */
162  wkb_simple_type = wkb_type % 1000;
163 
164  /* Extract the Z/M information from ISO style numbers */
165  if( wkb_type >= 3000 && wkb_type < 4000 )
166  {
167  s->has_z = LW_TRUE;
168  s->has_m = LW_TRUE;
169  }
170  else if ( wkb_type >= 2000 && wkb_type < 3000 )
171  {
172  s->has_m = LW_TRUE;
173  }
174  else if ( wkb_type >= 1000 && wkb_type < 2000 )
175  {
176  s->has_z = LW_TRUE;
177  }
178 
179  switch (wkb_simple_type)
180  {
181  case WKB_POINT_TYPE:
182  s->lwtype = POINTTYPE;
183  break;
184  case WKB_LINESTRING_TYPE:
185  s->lwtype = LINETYPE;
186  break;
187  case WKB_POLYGON_TYPE:
188  s->lwtype = POLYGONTYPE;
189  break;
190  case WKB_MULTIPOINT_TYPE:
191  s->lwtype = MULTIPOINTTYPE;
192  break;
194  s->lwtype = MULTILINETYPE;
195  break;
198  break;
200  s->lwtype = COLLECTIONTYPE;
201  break;
203  s->lwtype = CIRCSTRINGTYPE;
204  break;
206  s->lwtype = COMPOUNDTYPE;
207  break;
209  s->lwtype = CURVEPOLYTYPE;
210  break;
211  case WKB_MULTICURVE_TYPE:
212  s->lwtype = MULTICURVETYPE;
213  break;
216  break;
219  break;
220  case WKB_TIN_TYPE:
221  s->lwtype = TINTYPE;
222  break;
223  case WKB_TRIANGLE_TYPE:
224  s->lwtype = TRIANGLETYPE;
225  break;
226 
227  /* PostGIS 1.5 emits 13, 14 for CurvePolygon, MultiCurve */
228  /* These numbers aren't SQL/MM (numbers currently only */
229  /* go up to 12. We can handle the old data here (for now??) */
230  /* converting them into the lwtypes that are intended. */
231  case WKB_CURVE_TYPE:
232  s->lwtype = CURVEPOLYTYPE;
233  break;
234  case WKB_SURFACE_TYPE:
235  s->lwtype = MULTICURVETYPE;
236  break;
237 
238  default: /* Error! */
239  lwerror("Unknown WKB type (%d)! Full WKB type number was (%d).", wkb_simple_type, wkb_type);
240  break;
241  }
242 
243  LWDEBUGF(4,"Got lwtype %s (%u)", lwtype_name(s->lwtype), s->lwtype);
244 
245  return;
246 }
#define WKB_SURFACE_TYPE
#define LINETYPE
Definition: liblwgeom.h:85
#define WKBMOFFSET
Definition: liblwgeom.h:107
#define MULTICURVETYPE
Definition: liblwgeom.h:94
#define WKB_COMPOUNDCURVE_TYPE
#define WKB_POLYHEDRALSURFACE_TYPE
uint32_t lwtype
Definition: lwin_wkb.c:42
#define POLYGONTYPE
Definition: liblwgeom.h:86
#define CURVEPOLYTYPE
Definition: liblwgeom.h:93
#define WKB_TRIANGLE_TYPE
#define COMPOUNDTYPE
Definition: liblwgeom.h:92
#define MULTIPOINTTYPE
Definition: liblwgeom.h:87
#define WKB_MULTISURFACE_TYPE
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
#define TRIANGLETYPE
Definition: liblwgeom.h:97
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:96
#define WKB_MULTICURVE_TYPE
unsigned int uint32_t
Definition: uthash.h:78
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
#define WKBZOFFSET
Flags applied in EWKB to indicate Z/M dimensions and presence/absence of SRID and bounding boxes...
Definition: liblwgeom.h:106
#define WKB_POLYGON_TYPE
#define LW_FALSE
Definition: liblwgeom.h:76
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
#define TINTYPE
Definition: liblwgeom.h:98
#define WKBSRIDFLAG
Definition: liblwgeom.h:108
#define WKB_POINT_TYPE
Well-Known Binary (WKB) Geometry Types.
#define WKB_LINESTRING_TYPE
#define WKB_CIRCULARSTRING_TYPE
#define WKB_MULTIPOLYGON_TYPE
#define WKB_CURVEPOLYGON_TYPE
#define WKB_MULTILINESTRING_TYPE
#define WKB_TIN_TYPE
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:89
#define WKB_CURVE_TYPE
#define MULTISURFACETYPE
Definition: liblwgeom.h:95
#define WKB_MULTIPOINT_TYPE
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:91
#define MULTILINETYPE
Definition: liblwgeom.h:88
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
#define COLLECTIONTYPE
Definition: liblwgeom.h:90
#define WKB_GEOMETRYCOLLECTION_TYPE
Here is the call graph for this function:
Here is the caller graph for this function: