PostGIS  2.4.9dev-r@@SVN_REVISION@@
lwgeom_geos_relatematch.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * PostGIS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * PostGIS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with PostGIS. If not, see <http://www.gnu.org/licenses/>.
18  *
19  **********************************************************************
20  *
21  * Copyright (C) 2010 Sandro Santilli <strk@kbt.io>
22  *
23  **********************************************************************/
24 
25 
26 #include "postgres.h"
27 #include "fmgr.h"
28 #include "funcapi.h"
29 
30 #include "../postgis_config.h"
31 #include "lwgeom_geos.h"
32 #include "lwgeom_pg.h"
33 
34 #include <string.h>
35 #include <assert.h>
36 
37 /* #define POSTGIS_DEBUG_LEVEL 4 */
38 
39 Datum ST_RelateMatch(PG_FUNCTION_ARGS);
41 Datum ST_RelateMatch(PG_FUNCTION_ARGS)
42 {
43  char *mat, *pat;
44  text *mat_text, *pat_text;
45  int result;
46 
47  /* Read the arguments */
48  mat_text = (PG_GETARG_TEXT_P(0));
49  pat_text = (PG_GETARG_TEXT_P(1));
50 
51  /* Convert from text to cstring */
52  mat = text2cstring(mat_text);
53  pat = text2cstring(pat_text);
54 
55  initGEOS(lwpgnotice, lwgeom_geos_error);
56 
57  result = GEOSRelatePatternMatch(mat, pat);
58  if (result == 2)
59  {
60  lwfree(mat); lwfree(pat);
61  lwpgerror("GEOSRelatePatternMatch: %s", lwgeom_geos_errmsg);
62  PG_RETURN_NULL();
63  }
64 
65  lwfree(mat); lwfree(pat);
66  PG_RETURN_BOOL(result);
67 }
68 
void lwfree(void *mem)
Definition: lwutil.c:244
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
PG_FUNCTION_INFO_V1(ST_RelateMatch)
void lwgeom_geos_error(const char *fmt,...)
char * text2cstring(const text *textptr)
Datum ST_RelateMatch(PG_FUNCTION_ARGS)