PostGIS  2.2.8dev-r@@SVN_REVISION@@
lwgeom_sqlmm.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  * Copyright 2001-2006 Refractions Research Inc.
6  *
7  * This is free software; you can redistribute and/or modify it under
8  * the terms of the GNU General Public Licence. See the COPYING file.
9  *
10  **********************************************************************/
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <stdarg.h>
15 #include <string.h>
16 #include <math.h>
17 
18 #include "postgres.h"
19 #include "fmgr.h"
20 
21 #include "../postgis_config.h"
22 #include "liblwgeom.h"
23 #include "lwgeom_pg.h"
24 
25 
26 Datum LWGEOM_has_arc(PG_FUNCTION_ARGS);
27 Datum LWGEOM_curve_segmentize(PG_FUNCTION_ARGS);
28 Datum LWGEOM_line_desegmentize(PG_FUNCTION_ARGS);
29 
30 
31 
32 /*******************************************************************************
33  * Begin PG_FUNCTIONs
34  ******************************************************************************/
35 
37 Datum LWGEOM_has_arc(PG_FUNCTION_ARGS)
38 {
39  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
40  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
41  uint32 result = lwgeom_has_arc(lwgeom);
42  lwgeom_free(lwgeom);
43  PG_RETURN_BOOL(result == 1);
44 }
45 
46 /*
47  * Converts any curve segments of the geometry into a linear approximation.
48  * Curve centers are determined by projecting the defining points into the 2d
49  * plane. Z and M values are assigned by linear interpolation between
50  * defining points.
51  */
53 Datum LWGEOM_curve_segmentize(PG_FUNCTION_ARGS)
54 {
55  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
56  int32 perQuad = PG_GETARG_INT32(1);
57  GSERIALIZED *ret;
58  LWGEOM *igeom = NULL, *ogeom = NULL;
59 
60  POSTGIS_DEBUG(2, "LWGEOM_curve_segmentize called.");
61 
62  if (perQuad < 0)
63  {
64  elog(ERROR, "2nd argument must be positive.");
65  PG_RETURN_NULL();
66  }
67 
68  POSTGIS_DEBUGF(3, "perQuad = %d", perQuad);
69 
70  igeom = lwgeom_from_gserialized(geom);
71  ogeom = lwgeom_stroke(igeom, perQuad);
72  lwgeom_free(igeom);
73 
74  if (ogeom == NULL)
75  PG_RETURN_NULL();
76 
77  ret = geometry_serialize(ogeom);
78  lwgeom_free(ogeom);
79  PG_FREE_IF_COPY(geom, 0);
80  PG_RETURN_POINTER(ret);
81 }
82 
84 Datum LWGEOM_line_desegmentize(PG_FUNCTION_ARGS)
85 {
86  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
87  GSERIALIZED *ret;
88  LWGEOM *igeom = NULL, *ogeom = NULL;
89 
90  POSTGIS_DEBUG(2, "LWGEOM_line_desegmentize.");
91 
92  igeom = lwgeom_from_gserialized(geom);
93  ogeom = lwgeom_unstroke(igeom);
94  lwgeom_free(igeom);
95 
96  if (ogeom == NULL)
97  {
98  PG_FREE_IF_COPY(geom, 0);
99  PG_RETURN_NULL();
100  }
101 
102  ret = geometry_serialize(ogeom);
103  lwgeom_free(ogeom);
104  PG_FREE_IF_COPY(geom, 0);
105  PG_RETURN_POINTER(ret);
106 }
107 
108 /*******************************************************************************
109  * End PG_FUNCTIONs
110  ******************************************************************************/
LWGEOM * lwgeom_stroke(const LWGEOM *geom, uint32_t perQuad)
Definition: lwstroke.c:446
unsigned int int32
Definition: shpopen.c:273
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
int lwgeom_has_arc(const LWGEOM *geom)
Definition: lwstroke.c:41
Datum LWGEOM_has_arc(PG_FUNCTION_ARGS)
Definition: lwgeom_sqlmm.c:37
Datum LWGEOM_curve_segmentize(PG_FUNCTION_ARGS)
Definition: lwgeom_sqlmm.c:53
Datum LWGEOM_line_desegmentize(PG_FUNCTION_ARGS)
Definition: lwgeom_sqlmm.c:84
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
PG_FUNCTION_INFO_V1(LWGEOM_has_arc)
LWGEOM * lwgeom_unstroke(const LWGEOM *geom)
Definition: lwstroke.c:842
This library is the generic geometry handling section of PostGIS.