]> granicus.if.org Git - postgis/commitdiff
Use GEOS compiler and linker flags for liblwgeom, add lwgeom_geos_noop and cunit...
authorSandro Santilli <strk@keybit.net>
Sat, 6 Aug 2011 09:47:01 +0000 (09:47 +0000)
committerSandro Santilli <strk@keybit.net>
Sat, 6 Aug 2011 09:47:01 +0000 (09:47 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@7698 b70326c6-7e19-0410-871a-916f4a2858ee

configure.ac
liblwgeom/Makefile.in
liblwgeom/cunit/Makefile.in
liblwgeom/cunit/cu_geos.c [new file with mode: 0644]
liblwgeom/cunit/cu_tester.c
liblwgeom/lwgeom_geos.c
liblwgeom/lwgeom_geos.h

index 0aebf05b4eb7a90390bad68973d1f994b00f21e4..9a679c6b364c3636ede957238f9d2150bbd1f81b 100644 (file)
@@ -496,6 +496,8 @@ fi
 dnl Extract the linker and include flags 
 GEOS_LDFLAGS=`$GEOSCONFIG --ldflags`
 GEOS_CPPFLAGS=-I`$GEOSCONFIG --includes`
+AC_SUBST([GEOS_LDFLAGS])
+AC_SUBST([GEOS_CPPFLAGS])
 
 dnl Ensure that we can parse geos_c.h
 CPPFLAGS_SAVE="$CPPFLAGS"
index 525c1e633864243a9dcfda16748e2cdfa35e6856..bd3eef91a2f82c68a8b653557e0fc74e78ded7e1 100644 (file)
 # *
 # **********************************************************************
 
-CC=@CC@
-CFLAGS=@CFLAGS@ @PICFLAGS@ @WARNFLAGS@ 
-NUMERICFLAGS=@NUMERICFLAGS@
+CC = @CC@
+CFLAGS = @CFLAGS@ @PICFLAGS@ @WARNFLAGS@ @GEOS_CPPFLAGS@
+LDFLAGS = @GEOS_LDFLAGS@ -lgeos_c
+NUMERICFLAGS = @NUMERICFLAGS@
 
 YACC=@YACC@
 LEX=@LEX@
index 51824f5edfecbc262d709b7eb4312267f7b4a080..990601952f9585f3cbf94301b66f47a62e3efc05 100644 (file)
@@ -11,7 +11,8 @@
 # **********************************************************************
 
 CC=@CC@
-CFLAGS=@CFLAGS@ @WARNFLAGS@
+CFLAGS=@CFLAGS@ @WARNFLAGS@ @GEOS_CPPFLAGS@
+LDFLAGS = @GEOS_LDFLAGS@ -lgeos_c
 
 CUNIT_LDFLAGS=@CUNIT_LDFLAGS@
 CUNIT_CPPFLAGS=@CUNIT_CPPFLAGS@ -I..
@@ -23,6 +24,7 @@ OBJS= \
        cu_misc.o \
        cu_ptarray.o \
        cu_geodetic.o \
+       cu_geos.o \
        cu_measures.o \
        cu_libgeom.o \
        cu_surface.o \
@@ -55,7 +57,7 @@ endif
 
 # Build the main unit test executable
 cu_tester: ../liblwgeom.a $(OBJS)
-       $(CC) -o $@ $(OBJS) ../liblwgeom.a -lm $(CUNIT_LDFLAGS)
+       $(CC) -o $@ $(OBJS) ../liblwgeom.a -lm $(CUNIT_LDFLAGS) $(LDFLAGS)
 
 # Command to build each of the .o files
 $(OBJS): %.o: %.c
diff --git a/liblwgeom/cunit/cu_geos.c b/liblwgeom/cunit/cu_geos.c
new file mode 100644 (file)
index 0000000..9278221
--- /dev/null
@@ -0,0 +1,77 @@
+/**********************************************************************
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.refractions.net
+ *
+ * Copyright 2011 Sandro Santilli <strk@keybit.net>
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU General Public Licence. See the COPYING file.
+ *
+ **********************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "CUnit/Basic.h"
+
+#include "lwgeom_geos.h"
+#include "cu_tester.h"
+
+static void test_geos_noop(void)
+{
+       int i;
+
+       char *ewkt[] =
+       {
+               "POINT(0 0.2)",
+               "LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
+               "MULTIPOINT(0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9)",
+               "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
+               "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
+               "POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
+               "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
+               "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))",
+               "SRID=100000;POLYGON((-1 -1 3,-1 2.5 3,2 2 3,2 -1 3,-1 -1 3),(0 0 3,0 1 3,1 1 3,1 0 3,0 0 3),(-0.5 -0.5 3,-0.5 -0.4 3,-0.4 -0.4 3,-0.4 -0.5 3,-0.5 -0.5 3))",
+               "SRID=4326;MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)),((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)))",
+               "SRID=4326;GEOMETRYCOLLECTION(POINT(0 1),POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0)),MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))))",
+       };
+
+
+       for ( i = 0; i < (sizeof ewkt/sizeof(char *)); i++ )
+       {
+               LWGEOM *geom_in, *geom_out;
+               char *in_ewkt;
+               char *out_ewkt;
+
+               in_ewkt = ewkt[i];
+               geom_in = lwgeom_from_ewkt(in_ewkt, PARSER_CHECK_NONE);
+               geom_out = lwgeom_geos_noop(geom_in);
+               if ( ! geom_out ) {
+                       fprintf(stderr, "\nNull return from lwgeom_geos_noop with wkt:   %s\n", in_ewkt);
+                       lwgeom_free(geom_in);
+                       continue;
+               }
+               out_ewkt = lwgeom_to_ewkt(geom_out, PARSER_CHECK_NONE);
+               if (strcmp(in_ewkt, out_ewkt))
+                       fprintf(stderr, "\nExp:   %s\nObt:  %s\n", in_ewkt, out_ewkt);
+               CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
+               lwfree(out_ewkt);
+               lwgeom_free(geom_out);
+               lwgeom_free(geom_in);
+       }
+
+
+}
+
+
+/*
+** Used by test harness to register the tests in this file.
+*/
+CU_TestInfo geos_tests[] =
+{
+       PG_TEST(test_geos_noop),
+       CU_TEST_INFO_NULL
+};
+CU_SuiteInfo geos_suite = {"GEOS",  NULL,  NULL, geos_tests};
+
index 8934b270174dd5de168af1602386f6999e6adf56..647930facdbaa78d5291e875627324d6f4dc18c1 100644 (file)
@@ -29,6 +29,7 @@ extern CU_SuiteInfo wkb_in_suite;
 extern CU_SuiteInfo libgeom_suite;
 extern CU_SuiteInfo surface_suite;
 extern CU_SuiteInfo geodetic_suite;
+extern CU_SuiteInfo geos_suite;
 extern CU_SuiteInfo homogenize_suite;
 extern CU_SuiteInfo out_gml_suite;
 extern CU_SuiteInfo out_kml_suite;
@@ -58,6 +59,7 @@ int main(int argc, char *argv[])
                libgeom_suite,
                surface_suite,
                geodetic_suite,
+               geos_suite,
                homogenize_suite,
                out_gml_suite,
                out_kml_suite,
index 11d24f72a70b21dd2262b71aa0e89e0ab3951a80..d2701004298169039a13ebbed5ee14acb1a391e6 100644 (file)
@@ -936,3 +936,28 @@ lwgeom_buildarea(LWGEOM *geom)
 
        return geom_out;
 }
+
+LWGEOM*
+lwgeom_geos_noop(LWGEOM* geom_in)
+{
+       GEOSGeometry *geosgeom;
+       LWGEOM* geom_out;
+
+       int is3d = FLAGS_GET_Z(geom_in->flags);
+
+       initGEOS(lwnotice, lwgeom_geos_error);
+       geosgeom = LWGEOM2GEOS(geom_in);
+       if ( ! geosgeom ) {
+               lwerror("Geometry could not be converted to GEOS: %s",
+                       lwgeom_geos_errmsg);
+               return NULL;
+       }
+       geom_out = GEOS2LWGEOM(geosgeom, is3d);
+       GEOSGeom_destroy(geosgeom);
+       if ( ! geom_out ) {
+               lwerror("GEOS Geometry could not be converted to LWGEOM: %s",
+                       lwgeom_geos_errmsg);
+       }
+       return geom_out;
+       
+}
index eaa8204648f5615464848104090fe0a416b736ae..3571de1fd074dd05afd82d687b76fa7943e3d620 100644 (file)
@@ -25,6 +25,7 @@ LWGEOM *lwgeom_difference(LWGEOM *geom1, LWGEOM *geom2) ;
 LWGEOM *lwgeom_symdifference(LWGEOM* geom1, LWGEOM* geom2) ;
 LWGEOM* lwgeom_union(LWGEOM *geom1, LWGEOM *geom2) ;
 LWGEOM* lwgeom_buildarea(LWGEOM *geom) ;
+LWGEOM* lwgeom_geos_noop(LWGEOM *geom) ;