26 #include "utils/geo_decls.h" 28 #include "../postgis_config.h" 31 #include "lwgeom_pg.h" 51 POSTGIS_DEBUG(2,
"point_to_geometry called");
53 if ( PG_ARGISNULL(0) )
56 point = PG_GETARG_POINT_P(0);
65 PG_RETURN_POINTER(geom);
79 POSTGIS_DEBUG(2,
"geometry_to_point called");
81 if ( PG_ARGISNULL(0) )
84 geom = PG_GETARG_GSERIALIZED_P(0);
87 elog(ERROR,
"geometry_to_point only accepts Points");
101 PG_FREE_IF_COPY(geom,0);
103 PG_RETURN_POINT_P(point);
118 POSTGIS_DEBUG(2,
"geometry_to_path called");
120 if ( PG_ARGISNULL(0) )
123 geom = PG_GETARG_GSERIALIZED_P(0);
126 elog(ERROR,
"geometry_to_path only accepts LineStrings");
134 size = offsetof(PATH, p[0]) +
sizeof(path->p[0]) * pa->
npoints;
135 path = (PATH*)palloc(size);
136 SET_VARSIZE(path, size);
141 for ( i = 0; i < pa->
npoints; i++ )
144 (path->p[i]).
x = pt->
x;
145 (path->p[i]).y = pt->
y;
149 PG_FREE_IF_COPY(geom,0);
151 PG_RETURN_PATH_P(path);
166 POSTGIS_DEBUG(2,
"path_to_geometry called");
168 if ( PG_ARGISNULL(0) )
171 path = PG_GETARG_PATH_P(0);
177 for ( i = 0; i < path->npts; i++ )
188 PG_RETURN_POINTER(geom);
203 POSTGIS_DEBUG(2,
"geometry_to_polygon called");
205 if ( PG_ARGISNULL(0) )
208 geom = PG_GETARG_GSERIALIZED_P(0);
211 elog(ERROR,
"geometry_to_polygon only accepts Polygons");
218 pa = lwpoly->
rings[0];
220 size = offsetof(POLYGON, p[0]) +
sizeof(polygon->p[0]) * pa->
npoints;
221 polygon = (POLYGON*)palloc0(size);
222 SET_VARSIZE(polygon, size);
227 polygon->boundbox.low.x = gbox.
xmin;
228 polygon->boundbox.low.y = gbox.
ymin;
229 polygon->boundbox.high.x = gbox.
xmax;
230 polygon->boundbox.high.y = gbox.
ymax;
232 for ( i = 0; i < pa->
npoints; i++ )
235 (polygon->p[i]).
x = pt->
x;
236 (polygon->p[i]).y = pt->
y;
240 PG_FREE_IF_COPY(geom,0);
242 PG_RETURN_POLYGON_P(polygon);
255 int i = 0, unclosed = 0;
257 POSTGIS_DEBUG(2,
"polygon_to_geometry called");
259 if ( PG_ARGISNULL(0) )
262 polygon = PG_GETARG_POLYGON_P(0);
268 if ( memcmp( polygon->p, polygon->p + polygon->npts - 1,
sizeof(
Point) ) )
275 for ( i = 0; i < (polygon->npts+unclosed); i++ )
278 p = polygon->p[i % polygon->npts];
290 PG_RETURN_POINTER(geom);
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
Datum path_to_geometry(PG_FUNCTION_ARGS)
Datum geometry_to_point(PG_FUNCTION_ARGS)
Datum point_to_geometry(PG_FUNCTION_ARGS)
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
LWPOINT * lwpoint_make2d(int srid, double x, double y)
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
void lwpoint_free(LWPOINT *pt)
void lwgeom_free(LWGEOM *geom)
void lwline_free(LWLINE *line)
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Datum geometry_to_polygon(PG_FUNCTION_ARGS)
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
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...
double lwpoint_get_x(const LWPOINT *point)
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE, then a duplicate point will not be added.
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
void lwpoly_free(LWPOLY *poly)
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
#define SRID_UNKNOWN
Unknown SRID value.
Datum polygon_to_geometry(PG_FUNCTION_ARGS)
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
PG_FUNCTION_INFO_V1(point_to_geometry)
Cast a PostgreSQL Point to a PostGIS geometry.
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
double lwpoint_get_y(const LWPOINT *point)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Datum geometry_to_path(PG_FUNCTION_ARGS)
This library is the generic geometry handling section of PostGIS.