PostGIS  2.2.7dev-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  * Copyright (C) 2010 Sandro Santilli <strk@keybit.net>
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU General Public Licence. See the COPYING file.
10  *
11  **********************************************************************
12  *
13  * ST_RelateMatch
14  *
15  * DE9 Intersection Matrix pattern matching
16  *
17  * Developed by Sandro Santilli (strk@keybit.net) for Faunalia
18  * (http://www.faunalia.it) with funding from Regione Toscana - Sistema
19  * Informativo per la Gestione del Territorio e dell' Ambiente
20  * [RT-SIGTA]". For the project: "Sviluppo strumenti software per il
21  * trattamento di dati geografici basati su QuantumGIS e Postgis (CIG
22  * 0494241492)"
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 #if POSTGIS_GEOS_VERSION < 33
44  lwpgerror("The GEOS version this postgis binary "
45  "was compiled against (%d) doesn't support "
46  "'ST_RelateMatch' function (3.3.0+ required)",
48  PG_RETURN_NULL();
49 #else /* POSTGIS_GEOS_VERSION >= 33 */
50 
51  char *mat, *pat;
52  text *mat_text, *pat_text;
53  int result;
54 
55  /* Read the arguments */
56  mat_text = (PG_GETARG_TEXT_P(0));
57  pat_text = (PG_GETARG_TEXT_P(1));
58 
59  /* Convert from text to cstring */
60  mat = text2cstring(mat_text);
61  pat = text2cstring(pat_text);
62 
63  initGEOS(lwpgnotice, lwgeom_geos_error);
64 
65  result = GEOSRelatePatternMatch(mat, pat);
66  if (result == 2)
67  {
68  lwfree(mat); lwfree(pat);
69  lwpgerror("GEOSRelatePatternMatch: %s", lwgeom_geos_errmsg);
70  PG_RETURN_NULL();
71  }
72 
73  lwfree(mat); lwfree(pat);
74  PG_RETURN_BOOL(result);
75 
76 #endif /* POSTGIS_GEOS_VERSION >= 33 */
77 
78 }
79 
#define POSTGIS_GEOS_VERSION
Definition: sqldefines.h:10
void lwfree(void *mem)
Definition: lwutil.c:214
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)