PostGIS  2.1.10dev-r@@SVN_REVISION@@
lwgeom_geos_relatematch.c
Go to the documentation of this file.
1 /**********************************************************************
2  * $Id: lwgeom_geos.c 5258 2010-02-17 21:02:49Z strk $
3  *
4  * PostGIS - Spatial Types for PostgreSQL
5  * http://postgis.net
6  *
7  * Copyright (C) 2010 Sandro Santilli <strk@keybit.net>
8  *
9  * This is free software; you can redistribute and/or modify it under
10  * the terms of the GNU General Public Licence. See the COPYING file.
11  *
12  **********************************************************************
13  *
14  * ST_RelateMatch
15  *
16  * DE9 Intersection Matrix pattern matching
17  *
18  * Developed by Sandro Santilli (strk@keybit.net) for Faunalia
19  * (http://www.faunalia.it) with funding from Regione Toscana - Sistema
20  * Informativo per la Gestione del Territorio e dell' Ambiente
21  * [RT-SIGTA]". For the project: "Sviluppo strumenti software per il
22  * trattamento di dati geografici basati su QuantumGIS e Postgis (CIG
23  * 0494241492)"
24  *
25  **********************************************************************/
26 
27 #include "postgres.h"
28 #include "fmgr.h"
29 #include "funcapi.h"
30 
31 #include "../postgis_config.h"
32 #include "lwgeom_geos.h"
33 #include "lwgeom_pg.h"
34 
35 #include <string.h>
36 #include <assert.h>
37 
38 /* #define POSTGIS_DEBUG_LEVEL 4 */
39 
40 Datum ST_RelateMatch(PG_FUNCTION_ARGS);
42 Datum ST_RelateMatch(PG_FUNCTION_ARGS)
43 {
44 #if POSTGIS_GEOS_VERSION < 33
45  lwerror("The GEOS version this postgis binary "
46  "was compiled against (%d) doesn't support "
47  "'ST_RelateMatch' function (3.3.0+ required)",
49  PG_RETURN_NULL();
50 #else /* POSTGIS_GEOS_VERSION >= 33 */
51 
52  char *mat, *pat;
53  text *mat_text, *pat_text;
54  int result;
55 
56  /* Read the arguments */
57  mat_text = (PG_GETARG_TEXT_P(0));
58  pat_text = (PG_GETARG_TEXT_P(1));
59 
60  /* Convert from text to cstring */
61  mat = text2cstring(mat_text);
62  pat = text2cstring(pat_text);
63 
64  initGEOS(lwnotice, lwgeom_geos_error);
65 
66  result = GEOSRelatePatternMatch(mat, pat);
67  if (result == 2)
68  {
69  lwfree(mat); lwfree(pat);
70  lwerror("GEOSRelatePatternMatch: %s", lwgeom_geos_errmsg);
71  PG_RETURN_NULL();
72  }
73 
74  lwfree(mat); lwfree(pat);
75  PG_RETURN_BOOL(result);
76 
77 #endif /* POSTGIS_GEOS_VERSION >= 33 */
78 
79 }
80 
#define POSTGIS_GEOS_VERSION
Definition: sqldefines.h:10
void lwfree(void *mem)
Definition: lwutil.c:190
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
PG_FUNCTION_INFO_V1(ST_RelateMatch)
char ** result
Definition: liblwgeom.h:218
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:54
void lwgeom_geos_error(const char *fmt,...)
char * text2cstring(const text *textptr)
Datum ST_RelateMatch(PG_FUNCTION_ARGS)