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"
103 GSERIALIZED *geom = PG_GETARG_GSERIALIZED_HEADER(0);
105 PG_FREE_IF_COPY(geom,0);
106 PG_RETURN_INT32(srid);
114 int32_t srid = PG_GETARG_INT32(1);
116 PG_RETURN_POINTER(g);
127 static int maxtyplen = 20;
129 gser = PG_GETARG_GSERIALIZED_HEADER(0);
130 text_ob = palloc0(VARHDRSZ + maxtyplen);
131 result = VARDATA(text_ob);
138 strcpy(
result,
"MULTIPOINT");
140 strcpy(
result,
"LINESTRING");
142 strcpy(
result,
"CIRCULARSTRING");
144 strcpy(
result,
"COMPOUNDCURVE");
146 strcpy(
result,
"MULTILINESTRING");
148 strcpy(
result,
"MULTICURVE");
152 strcpy(
result,
"TRIANGLE");
154 strcpy(
result,
"CURVEPOLYGON");
156 strcpy(
result,
"MULTIPOLYGON");
158 strcpy(
result,
"MULTISURFACE");
160 strcpy(
result,
"GEOMETRYCOLLECTION");
162 strcpy(
result,
"POLYHEDRALSURFACE");
171 SET_VARSIZE(text_ob, strlen(
result) + VARHDRSZ);
173 PG_FREE_IF_COPY(gser, 0);
175 PG_RETURN_TEXT_P(text_ob);
184 "ST_MultiLineString",
186 "ST_GeometryCollection",
192 "ST_PolyhedralSurface",
204 gser = PG_GETARG_GSERIALIZED_HEADER(0);
209 PG_FREE_IF_COPY(gser, 0);
210 PG_RETURN_TEXT_P(type_text);
231 PG_FREE_IF_COPY(geom, 0);
237 PG_RETURN_INT32(
count);
260 ret = col ? col->
ngeoms : 1;
289 PG_FREE_IF_COPY(geom, 0);
290 PG_RETURN_INT32(ret);
305 PG_FREE_IF_COPY(geom, 0);
306 elog(ERROR,
"ST_NumPatches only supports TIN and PolyhedralSurface geometries");
312 PG_FREE_IF_COPY(geom, 0);
313 PG_RETURN_INT32(ret);
367 subgeom = coll->
geoms[idx];
378 int32 idx = PG_GETARG_INT32(1);
388 if (subgeom == lwgeom)
391 PG_FREE_IF_COPY(geom, 0);
392 PG_RETURN_POINTER(geom);
399 result = geometry_serialize(subgeom);
401 PG_FREE_IF_COPY(geom, 0);
402 PG_RETURN_POINTER(
result);
412 int32 idx = PG_GETARG_INT32(1);
418 PG_FREE_IF_COPY(geom, 0);
419 elog(ERROR,
"ST_PatchN only supports TIN and PolyhedralSurface geometries");
429 if (subgeom == lwgeom)
430 PG_RETURN_POINTER(geom);
436 result = geometry_serialize(subgeom);
438 PG_FREE_IF_COPY(geom, 0);
439 PG_RETURN_POINTER(
result);
456 PG_FREE_IF_COPY(geom, 0);
460 elog(NOTICE,
"Could not compute geometry dimensions");
464 PG_RETURN_INT32(dimension);
498 extring = poly->
rings[0];
522 if ( triangle->
bbox )
537 PG_FREE_IF_COPY(geom, 0);
538 PG_RETURN_POINTER(
result);
587 elog(ERROR,
"%s unsupported ring type %d", __func__,
type);
591 PG_FREE_IF_COPY(geom, 0);
618 POSTGIS_DEBUG(2,
"LWGEOM_interiorringn_polygon called.");
620 wanted_index = PG_GETARG_INT32(1);
621 if ( wanted_index < 1 )
626 geom = PG_GETARG_GSERIALIZED_P(0);
631 PG_FREE_IF_COPY(geom, 0);
639 PG_FREE_IF_COPY(geom, 0);
651 PG_FREE_IF_COPY(geom, 0);
655 ring = poly->
rings[wanted_index];
678 PG_FREE_IF_COPY(geom, 0);
683 result = geometry_serialize(curvepoly->
rings[wanted_index]);
687 PG_FREE_IF_COPY(geom, 0);
688 PG_RETURN_POINTER(
result);
700 int where = PG_GETARG_INT32(1);
715 where = where +
count + 1;
732 PG_FREE_IF_COPY(geom, 0);
751 lwpgerror(
"Argument to ST_X() must have type POINT");
757 PG_RETURN_FLOAT8(pt.
x);
771 lwpgerror(
"Argument to ST_Y() must have type POINT");
777 PG_RETURN_FLOAT8(pt.
y);
792 lwpgerror(
"Argument to ST_Z() must have type POINT");
798 PG_RETURN_FLOAT8(pt.
z);
812 lwpgerror(
"Argument to ST_M() must have type POINT");
818 PG_RETURN_FLOAT8(pt.
m);
840 ret = geometry_serialize(lwpoint);
845 PG_FREE_IF_COPY(geom, 0);
846 PG_RETURN_POINTER(ret);
873 PG_FREE_IF_COPY(geom, 0);
891 text *wkttext = PG_GETARG_TEXT_P(0);
892 char *wkt = text_to_cstring(wkttext);
897 POSTGIS_DEBUG(2,
"LWGEOM_from_text");
898 POSTGIS_DEBUGF(3,
"wkt: [%s]", wkt);
901 PG_PARSER_ERROR(lwg_parser_result);
903 lwgeom = lwg_parser_result.
geom;
907 elog(WARNING,
"OGC WKT expected, EWKT provided - use GeomFromEWKT() for this");
911 if ( PG_NARGS() > 1 )
914 geom_result = geometry_serialize(lwgeom);
917 PG_RETURN_POINTER(geom_result);
932 bytea *bytea_wkb = PG_GETARG_BYTEA_P(0);
936 uint8_t *wkb = (uint8_t*)VARDATA(bytea_wkb);
940 lwpgerror(
"Unable to parse WKB");
942 geom = geometry_serialize(lwgeom);
944 PG_FREE_IF_COPY(bytea_wkb, 0);
948 elog(WARNING,
"OGC WKB expected, EWKB provided - use GeometryFromEWKB() for this");
951 if ( PG_NARGS() > 1 )
953 srid = PG_GETARG_INT32(1);
958 PG_RETURN_POINTER(geom);
969 if (PG_NARGS() > 1) dbl_dig_for_wkt = PG_GETARG_INT32(1);
987 geom = PG_GETARG_GSERIALIZED_P(0);
992 if ( (PG_NARGS()>1) && (!PG_ARGISNULL(1)) )
994 text *wkb_endian = PG_GETARG_TEXT_P(1);
996 if ( ! strncmp(VARDATA(wkb_endian),
"xdr", 3) ||
997 ! strncmp(VARDATA(wkb_endian),
"XDR", 3) )
1027 PG_FREE_IF_COPY(geom, 0);
1028 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.
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_is_unitary(const LWGEOM *geom)
Determine whether a Geometry is a bag of sub-geometries.
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...
int lwgeom_has_rings(const LWGEOM *geom)
Is this a type that has rings enclosing an area, but is not a collection of areas?...
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_has_patches(const LWGEOM *geom)
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)
#define POLYHEDRALSURFACETYPE
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
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 int32 lwgeom_count_geometries(LWGEOM *lwgeom, bool patches_as_geometries)
static LWGEOM * lwgeom_extract_geometry_n(LWGEOM *lwgeom, int32 idx, bool patches_as_geometries)
static char * stTypeName[]
Datum LWGEOM_numpatches(PG_FUNCTION_ARGS)
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_patchn(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.