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);
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Datum point_to_geometry(PG_FUNCTION_ARGS)
Datum geometry_to_path(PG_FUNCTION_ARGS)
Datum geometry_to_polygon(PG_FUNCTION_ARGS)
Datum geometry_to_point(PG_FUNCTION_ARGS)
Datum path_to_geometry(PG_FUNCTION_ARGS)
Datum polygon_to_geometry(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(point_to_geometry)
Cast a PostgreSQL Point to a PostGIS geometry.
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
LWPOINT * lwpoint_make2d(int srid, double x, double y)
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
void lwpoint_free(LWPOINT *pt)
void lwgeom_free(LWGEOM *geom)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
double lwpoint_get_x(const LWPOINT *point)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
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...
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,...
void lwpoly_free(LWPOLY *poly)
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
#define SRID_UNKNOWN
Unknown SRID value.
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
void lwline_free(LWLINE *line)
double lwpoint_get_y(const LWPOINT *point)
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
This library is the generic geometry handling section of PostGIS.
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)