PostGIS  2.5.0dev-r@@SVN_REVISION@@
LWGEOM* lwgeom_from_gserialized ( const GSERIALIZED g)

Allocate a new LWGEOM from a GSERIALIZED.

The resulting LWGEOM will have coordinates that are double aligned and suitable for direct reading using getPoint2d_p_ro

Definition at line 1526 of file g_serialized.c.

References LWGEOM::bbox, GSERIALIZED::data, GSERIALIZED::flags, LWGEOM::flags, FLAGS_GET_BBOX, genraster::g_size, gbox_copy(), gbox_serialized_size(), gserialized_get_srid(), gserialized_get_type(), gserialized_read_gbox_p(), if(), LW_SUCCESS, LWDEBUGF, lwerror(), lwgeom_calculate_gbox(), lwgeom_from_gserialized_buffer(), lwgeom_needs_bbox(), lwgeom_set_srid(), lwtype_name(), and LWGEOM::type.

Referenced by ARRAY2LWGEOM(), boundary(), BOX2D_construct(), BOX3D_combine(), BOX3D_construct(), centroid(), CircTreePIP(), contains(), coveredby(), covers(), errorIfGeometryCollection(), geobuf_agg_transfn(), geography_area(), geography_as_geojson(), geography_as_gml(), geography_as_kml(), geography_as_svg(), geography_azimuth(), geography_centroid(), geography_covers(), geography_distance_cache_tolerance(), geography_distance_knn(), geography_distance_uncached(), geography_dwithin(), geography_dwithin_uncached(), geography_from_geometry(), geography_length(), geography_out(), geography_perimeter(), geography_project(), geography_segmentize(), geography_send(), geography_tree_distance(), geometry_distance_spheroid(), geometry_from_geography(), geometry_to_path(), geometry_to_point(), geometry_to_polygon(), geos_difference(), geos_geomunion(), geos_intersection(), geos_intersects(), gserialized_distance_nd(), gserialized_get_gbox_p(), gserialized_to_string(), intersects3d_dwithin(), issimple(), isvalid(), linemerge(), LWGEOM_addBBOX(), LWGEOM_addpoint(), LWGEOM_affine(), LWGEOM_angle(), LWGEOM_area_polygon(), LWGEOM_asBinary(), LWGEOM_asEncodedPolyline(), LWGEOM_asEWKT(), LWGEOM_asGeoJson(), LWGEOM_asGML(), LWGEOM_asHEXEWKB(), LWGEOM_asKML(), LWGEOM_asSVG(), LWGEOM_asText(), LWGEOM_asX3D(), LWGEOM_azimuth(), LWGEOM_closestpoint(), LWGEOM_closestpoint3d(), LWGEOM_collect(), LWGEOM_collect_garray(), LWGEOM_curve_segmentize(), LWGEOM_dfullywithin(), LWGEOM_dfullywithin3d(), LWGEOM_dimension(), LWGEOM_dump(), LWGEOM_dump_rings(), LWGEOM_dumppoints(), LWGEOM_dwithin(), LWGEOM_dwithin3d(), LWGEOM_endpoint_linestring(), LWGEOM_envelope(), LWGEOM_expand(), LWGEOM_exteriorring_polygon(), LWGEOM_force_2d(), LWGEOM_force_3dm(), LWGEOM_force_3dz(), LWGEOM_force_4d(), LWGEOM_force_clockwise_poly(), LWGEOM_force_collection(), LWGEOM_force_curve(), LWGEOM_force_multi(), LWGEOM_force_sfs(), LWGEOM_geometryn_collection(), LWGEOM_has_arc(), LWGEOM_inside_circle_point(), LWGEOM_interiorringn_polygon(), LWGEOM_isclosed(), LWGEOM_isempty(), LWGEOM_length2d_ellipsoid(), LWGEOM_length2d_linestring(), LWGEOM_length_ellipsoid_linestring(), LWGEOM_length_linestring(), LWGEOM_line_desegmentize(), LWGEOM_line_from_mpoint(), LWGEOM_line_interpolate_point(), LWGEOM_line_locate_point(), LWGEOM_line_substring(), LWGEOM_locate_between_m(), LWGEOM_longestline2d(), LWGEOM_longestline3d(), LWGEOM_longitude_shift(), LWGEOM_m_point(), LWGEOM_makeline(), LWGEOM_makeline_garray(), LWGEOM_makepoly(), LWGEOM_maxdistance2d_linestring(), LWGEOM_maxdistance3d(), LWGEOM_mindistance2d(), LWGEOM_mindistance3d(), LWGEOM_noop(), LWGEOM_npoints(), LWGEOM_nrings(), LWGEOM_numgeometries_collection(), LWGEOM_numinteriorrings_polygon(), LWGEOM_numpoints_linestring(), LWGEOM_out(), lwgeom_over_gserialized(), LWGEOM_perimeter2d_poly(), LWGEOM_perimeter_poly(), LWGEOM_pointn_linestring(), LWGEOM_removepoint(), LWGEOM_reverse(), LWGEOM_same(), LWGEOM_segmentize2d(), LWGEOM_SetEffectiveArea(), LWGEOM_setpoint_linestring(), LWGEOM_shortestline2d(), LWGEOM_shortestline3d(), LWGEOM_simplify2d(), LWGEOM_snaptogrid(), LWGEOM_snaptogrid_pointoff(), LWGEOM_startpoint_linestring(), LWGEOM_summary(), LWGEOM_to_BOX(), LWGEOM_to_BOX2D(), LWGEOM_to_BOX3D(), LWGEOM_to_latlon(), LWGEOM_to_text(), LWGEOM_x_point(), LWGEOM_y_point(), LWGEOM_z_point(), mvt_agg_transfn(), optimistic_overlap(), pip_short_circuit(), POSTGIS2GEOS(), POSTGIS2SFCGALGeometry(), POSTGIS2SFCGALPreparedGeometry(), RASTER_asRaster(), RASTER_clip(), RASTER_nearestValue(), RASTER_setPixelValuesGeomval(), read_lwgeom_from_partition(), sfcgal_is_solid(), sfcgal_make_solid(), ST_AddMeasure(), ST_AsMVTGeom(), ST_BoundingDiagonal(), ST_BuildArea(), ST_CleanGeometry(), ST_ClipByBox2d(), ST_ClosestPointOfApproach(), ST_ClusterKMeans(), ST_CollectionExtract(), ST_CollectionHomogenize(), ST_CPAWithin(), ST_CurveToLine(), ST_DelaunayTriangles(), ST_DistanceCPA(), ST_FlipCoordinates(), ST_GeneratePoints(), ST_GeoHash(), ST_GeometricMedian(), ST_InterpolatePoint(), ST_IsPolygonCCW(), ST_IsPolygonCW(), ST_IsValidTrajectory(), ST_LineCrossingDirection(), ST_LocateAlong(), ST_LocateBetween(), ST_LocateBetweenElevations(), ST_MakeValid(), ST_MinimumBoundingCircle(), ST_MinimumBoundingRadius(), ST_Node(), ST_Normalize(), ST_OffsetCurve(), ST_Points(), ST_RemoveRepeatedPoints(), ST_Scale(), ST_SharedPaths(), ST_Snap(), ST_Split(), ST_Subdivide(), ST_SwapOrdinates(), ST_UnaryUnion(), ST_Voronoi(), ST_WrapX(), symdifference(), test_lwgeom_from_gserialized(), test_on_gser_lwgeom_count_vertices(), transform(), transform_geom(), TWKBFromLWGEOM(), TWKBFromLWGEOMArray(), and WKBFromLWGEOM().

1527 {
1528  uint8_t g_flags = 0;
1529  int32_t g_srid = 0;
1530  uint32_t g_type = 0;
1531  uint8_t *data_ptr = NULL;
1532  LWGEOM *lwgeom = NULL;
1533  GBOX bbox;
1534  size_t g_size = 0;
1535 
1536  assert(g);
1537 
1538  g_srid = gserialized_get_srid(g);
1539  g_flags = g->flags;
1540  g_type = gserialized_get_type(g);
1541  LWDEBUGF(4, "Got type %d (%s), srid=%d", g_type, lwtype_name(g_type), g_srid);
1542 
1543  data_ptr = (uint8_t*)g->data;
1544  if ( FLAGS_GET_BBOX(g_flags) )
1545  data_ptr += gbox_serialized_size(g_flags);
1546 
1547  lwgeom = lwgeom_from_gserialized_buffer(data_ptr, g_flags, &g_size);
1548 
1549  if ( ! lwgeom )
1550  lwerror("lwgeom_from_gserialized: unable create geometry"); /* Ooops! */
1551 
1552  lwgeom->type = g_type;
1553  lwgeom->flags = g_flags;
1554 
1555  if ( gserialized_read_gbox_p(g, &bbox) == LW_SUCCESS )
1556  {
1557  lwgeom->bbox = gbox_copy(&bbox);
1558  }
1559  else if ( lwgeom_needs_bbox(lwgeom) && (lwgeom_calculate_gbox(lwgeom, &bbox) == LW_SUCCESS) )
1560  {
1561  lwgeom->bbox = gbox_copy(&bbox);
1562  }
1563  else
1564  {
1565  lwgeom->bbox = NULL;
1566  }
1567 
1568  lwgeom_set_srid(lwgeom, g_srid);
1569 
1570  return lwgeom;
1571 }
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:433
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
Definition: g_serialized.c:86
int gserialized_read_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Pull a GBOX from the header of a GSERIALIZED, if one is available.
Definition: g_serialized.c:413
GBOX * bbox
Definition: liblwgeom.h:397
uint8_t data[1]
Definition: liblwgeom.h:383
uint8_t flags
Definition: liblwgeom.h:396
#define LW_SUCCESS
Definition: liblwgeom.h:79
unsigned int uint32_t
Definition: uthash.h:78
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...
Definition: lwgeom.c:739
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
#define FLAGS_GET_BBOX(flags)
Definition: liblwgeom.h:141
static LWGEOM * lwgeom_from_gserialized_buffer(uint8_t *data_ptr, uint8_t g_flags, size_t *g_size)
uint8_t type
Definition: liblwgeom.h:395
tuple g_size
Definition: genraster.py:41
void lwgeom_set_srid(LWGEOM *geom, int srid)
Set the SRID on an LWGEOM For collections, only the parent gets an SRID, all the children get SRID_UN...
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
unsigned char uint8_t
Definition: uthash.h:79
int lwgeom_needs_bbox(const LWGEOM *geom)
Check whether or not a lwgeom is big enough to warrant a bounding box.
Definition: lwgeom.c:1190
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:99
if(!(yy_init))
Definition: lwin_wkt_lex.c:888
size_t gbox_serialized_size(uint8_t flags)
Return the number of bytes necessary to hold a GBOX of this dimension in serialized form...
Definition: g_box.c:446
uint8_t flags
Definition: liblwgeom.h:382

Here is the call graph for this function: