33 #include "access/gist.h"
34 #include "access/itup.h"
37 #include "utils/builtins.h"
38 #include "utils/elog.h"
40 #include "../postgis_config.h"
44 #include "lwgeom_pg.h"
99 GSERIALIZED *geom = PG_GETARG_GSERIALIZED_HEADER(0);
101 PG_FREE_IF_COPY(geom,0);
102 PG_RETURN_INT32(srid);
110 int32_t srid = PG_GETARG_INT32(1);
112 PG_RETURN_POINTER(g);
123 static int maxtyplen = 20;
125 gser = PG_GETARG_GSERIALIZED_HEADER(0);
126 text_ob = palloc0(VARHDRSZ + maxtyplen);
127 result = VARDATA(text_ob);
134 strcpy(
result,
"MULTIPOINT");
136 strcpy(
result,
"LINESTRING");
138 strcpy(
result,
"CIRCULARSTRING");
140 strcpy(
result,
"COMPOUNDCURVE");
142 strcpy(
result,
"MULTILINESTRING");
144 strcpy(
result,
"MULTICURVE");
148 strcpy(
result,
"TRIANGLE");
150 strcpy(
result,
"CURVEPOLYGON");
152 strcpy(
result,
"MULTIPOLYGON");
154 strcpy(
result,
"MULTISURFACE");
156 strcpy(
result,
"GEOMETRYCOLLECTION");
158 strcpy(
result,
"POLYHEDRALSURFACE");
167 SET_VARSIZE(text_ob, strlen(
result) + VARHDRSZ);
169 PG_FREE_IF_COPY(gser, 0);
171 PG_RETURN_TEXT_P(text_ob);
180 "ST_MultiLineString",
182 "ST_GeometryCollection",
188 "ST_PolyhedralSurface",
200 gser = PG_GETARG_GSERIALIZED_HEADER(0);
205 PG_FREE_IF_COPY(gser, 0);
206 PG_RETURN_TEXT_P(type_text);
227 PG_FREE_IF_COPY(geom, 0);
233 PG_RETURN_INT32(
count);
254 PG_FREE_IF_COPY(geom, 0);
255 PG_RETURN_INT32(ret);
269 POSTGIS_DEBUG(2,
"LWGEOM_geometryn_collection called.");
273 idx = PG_GETARG_INT32(1);
286 if ( idx == 0 ) PG_RETURN_POINTER(geom);
292 if ( idx < 0 ) PG_RETURN_NULL();
293 if ( idx >= (
int32) coll->
ngeoms ) PG_RETURN_NULL();
295 subgeom = coll->
geoms[idx];
301 result = geometry_serialize(subgeom);
304 PG_FREE_IF_COPY(geom, 0);
306 PG_RETURN_POINTER(
result);
324 PG_FREE_IF_COPY(geom, 0);
328 elog(NOTICE,
"Could not compute geometry dimensions");
332 PG_RETURN_INT32(dimension);
352 POSTGIS_DEBUG(2,
"LWGEOM_exteriorring_polygon called.");
375 extring = poly->
rings[0];
399 if ( triangle->
bbox )
414 PG_FREE_IF_COPY(geom, 0);
415 PG_RETURN_POINTER(
result);
451 PG_FREE_IF_COPY(geom, 0);
479 POSTGIS_DEBUG(2,
"LWGEOM_interiorringn_polygon called.");
481 wanted_index = PG_GETARG_INT32(1);
482 if ( wanted_index < 1 )
487 geom = PG_GETARG_GSERIALIZED_P(0);
492 PG_FREE_IF_COPY(geom, 0);
500 PG_FREE_IF_COPY(geom, 0);
512 PG_FREE_IF_COPY(geom, 0);
516 ring = poly->
rings[wanted_index];
539 PG_FREE_IF_COPY(geom, 0);
544 result = geometry_serialize(curvepoly->
rings[wanted_index]);
548 PG_FREE_IF_COPY(geom, 0);
549 PG_RETURN_POINTER(
result);
561 int where = PG_GETARG_INT32(1);
576 where = where +
count + 1;
593 PG_FREE_IF_COPY(geom, 0);
612 lwpgerror(
"Argument to ST_X() must have type POINT");
618 PG_RETURN_FLOAT8(pt.
x);
632 lwpgerror(
"Argument to ST_Y() must have type POINT");
638 PG_RETURN_FLOAT8(pt.
y);
653 lwpgerror(
"Argument to ST_Z() must have type POINT");
659 PG_RETURN_FLOAT8(pt.
z);
673 lwpgerror(
"Argument to ST_M() must have type POINT");
679 PG_RETURN_FLOAT8(pt.
m);
701 ret = geometry_serialize(lwpoint);
706 PG_FREE_IF_COPY(geom, 0);
707 PG_RETURN_POINTER(ret);
734 PG_FREE_IF_COPY(geom, 0);
752 text *wkttext = PG_GETARG_TEXT_P(0);
753 char *wkt = text_to_cstring(wkttext);
758 POSTGIS_DEBUG(2,
"LWGEOM_from_text");
759 POSTGIS_DEBUGF(3,
"wkt: [%s]", wkt);
762 PG_PARSER_ERROR(lwg_parser_result);
764 lwgeom = lwg_parser_result.
geom;
768 elog(WARNING,
"OGC WKT expected, EWKT provided - use GeomFromEWKT() for this");
772 if ( PG_NARGS() > 1 )
775 geom_result = geometry_serialize(lwgeom);
778 PG_RETURN_POINTER(geom_result);
793 bytea *bytea_wkb = PG_GETARG_BYTEA_P(0);
797 uint8_t *wkb = (uint8_t*)VARDATA(bytea_wkb);
801 lwpgerror(
"Unable to parse WKB");
803 geom = geometry_serialize(lwgeom);
805 PG_FREE_IF_COPY(bytea_wkb, 0);
809 elog(WARNING,
"OGC WKB expected, EWKB provided - use GeometryFromEWKB() for this");
812 if ( PG_NARGS() > 1 )
814 srid = PG_GETARG_INT32(1);
819 PG_RETURN_POINTER(geom);
830 if (PG_NARGS() > 1) dbl_dig_for_wkt = PG_GETARG_INT32(1);
848 geom = PG_GETARG_GSERIALIZED_P(0);
853 if ( (PG_NARGS()>1) && (!PG_ARGISNULL(1)) )
855 text *wkb_endian = PG_GETARG_TEXT_P(1);
857 if ( ! strncmp(VARDATA(wkb_endian),
"xdr", 3) ||
858 ! strncmp(VARDATA(wkb_endian),
"XDR", 3) )
888 PG_FREE_IF_COPY(geom, 0);
889 PG_RETURN_BOOL(closed);
char result[OUT_DOUBLE_BUFFER_SIZE]
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox)
Calculate box (x/y) and add values to gbox.
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
int gserialized_has_m(const GSERIALIZED *g)
Check if a GSERIALIZED has an M ordinate.
int gserialized_peek_first_point(const GSERIALIZED *g, POINT4D *out_point)
Pull the first point values of a GSERIALIZED.
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
void gserialized_set_srid(GSERIALIZED *g, int32_t srid)
Write the SRID into the serialized form (it is packed into three bytes so this is a handy function).
int gserialized_has_z(const GSERIALIZED *g)
Check if a GSERIALIZED has a Z ordinate.
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
int lwgeom_is_closed(const LWGEOM *geom)
Return true or false depending on whether a geometry is a linear feature that closes on itself.
#define LW_PARSER_CHECK_ALL
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
int lwgeom_startpoint(const LWGEOM *lwgeom, POINT4D *pt)
void lwgeom_set_srid(LWGEOM *geom, int32_t srid)
Set the SRID on an LWGEOM For collections, only the parent gets an SRID, all the children get SRID_UN...
void lwgeom_free(LWGEOM *geom)
LWPOINT * lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, uint32_t where)
void lwline_release(LWLINE *lwline)
int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags)
Parse a WKT geometry string into an LWGEOM structure.
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
LWTRIANGLE * lwgeom_as_lwtriangle(const LWGEOM *lwgeom)
uint32_t lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
int lwgeom_dimension(const LWGEOM *geom)
For an LWGEOM, returns 0 for points, 1 for lines, 2 for polygons, 3 for volume, and the max dimension...
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
#define POLYHEDRALSURFACETYPE
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
void lwcollection_free(LWCOLLECTION *col)
void * lwalloc(size_t size)
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
void lwpoly_free(LWPOLY *poly)
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
#define SRID_UNKNOWN
Unknown SRID value.
LWGEOM * lwgeom_from_wkb(const uint8_t *wkb, const size_t wkb_size, const char check)
WKB inputs must have a declared size, to prevent malformed WKB from reading off the end of the memory...
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
lwvarlena_t * lwgeom_to_wkb_varlena(const LWGEOM *geom, uint8_t variant)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
LWLINE * lwline_construct_empty(int32_t srid, char hasz, char hasm)
void lwgeom_parser_result_free(LWGEOM_PARSER_RESULT *parser_result)
LWPOINT * lwcompound_get_endpoint(const LWCOMPOUND *lwcmp)
LWPOINT * lwpoint_make(int32_t srid, int hasz, int hasm, const POINT4D *p)
lwvarlena_t * lwgeom_to_wkt_varlena(const LWGEOM *geom, uint8_t variant, int precision)
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
This library is the generic geometry handling section of PostGIS.
#define OUT_DEFAULT_DECIMAL_DIGITS
Datum LWGEOM_asBinary(PG_FUNCTION_ARGS)
Datum LWGEOM_exteriorring_polygon(PG_FUNCTION_ARGS)
Datum LWGEOM_from_WKB(PG_FUNCTION_ARGS)
Datum LWGEOM_dimension(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(LWGEOM_get_srid)
Datum LWGEOM_get_srid(PG_FUNCTION_ARGS)
Datum LWGEOM_isclosed(PG_FUNCTION_ARGS)
Datum LWGEOM_asText(PG_FUNCTION_ARGS)
static char * stTypeName[]
Datum LWGEOM_endpoint_linestring(PG_FUNCTION_ARGS)
Datum LWGEOM_startpoint_linestring(PG_FUNCTION_ARGS)
Datum LWGEOM_from_text(PG_FUNCTION_ARGS)
Datum LWGEOM_pointn_linestring(PG_FUNCTION_ARGS)
Datum LWGEOM_numpoints_linestring(PG_FUNCTION_ARGS)
Datum LWGEOM_geometryn_collection(PG_FUNCTION_ARGS)
Datum geometry_geometrytype(PG_FUNCTION_ARGS)
Datum LWGEOM_x_point(PG_FUNCTION_ARGS)
Datum LWGEOM_interiorringn_polygon(PG_FUNCTION_ARGS)
Datum LWGEOM_y_point(PG_FUNCTION_ARGS)
Datum LWGEOM_m_point(PG_FUNCTION_ARGS)
Datum LWGEOM_numinteriorrings_polygon(PG_FUNCTION_ARGS)
Datum LWGEOM_numgeometries_collection(PG_FUNCTION_ARGS)
Datum LWGEOM_getTYPE(PG_FUNCTION_ARGS)
Datum LWGEOM_set_srid(PG_FUNCTION_ARGS)
Datum LWGEOM_z_point(PG_FUNCTION_ARGS)
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM.