From: Sandro Santilli Date: Sat, 6 Aug 2011 09:47:01 +0000 (+0000) Subject: Use GEOS compiler and linker flags for liblwgeom, add lwgeom_geos_noop and cunit... X-Git-Tag: 2.0.0alpha1~1149 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5a9d3c5db2093bb26f97f161f4ede1100987a81c;p=postgis Use GEOS compiler and linker flags for liblwgeom, add lwgeom_geos_noop and cunit test for it (to confirm linking works, and it does) [RT-SIGTA] git-svn-id: http://svn.osgeo.org/postgis/trunk@7698 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/configure.ac b/configure.ac index 0aebf05b4..9a679c6b3 100644 --- a/configure.ac +++ b/configure.ac @@ -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" diff --git a/liblwgeom/Makefile.in b/liblwgeom/Makefile.in index 525c1e633..bd3eef91a 100644 --- a/liblwgeom/Makefile.in +++ b/liblwgeom/Makefile.in @@ -10,9 +10,10 @@ # * # ********************************************************************** -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@ diff --git a/liblwgeom/cunit/Makefile.in b/liblwgeom/cunit/Makefile.in index 51824f5ed..990601952 100644 --- a/liblwgeom/cunit/Makefile.in +++ b/liblwgeom/cunit/Makefile.in @@ -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 index 000000000..9278221c2 --- /dev/null +++ b/liblwgeom/cunit/cu_geos.c @@ -0,0 +1,77 @@ +/********************************************************************** + * + * PostGIS - Spatial Types for PostgreSQL + * http://postgis.refractions.net + * + * Copyright 2011 Sandro Santilli + * + * 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 +#include +#include +#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}; + diff --git a/liblwgeom/cunit/cu_tester.c b/liblwgeom/cunit/cu_tester.c index 8934b2701..647930fac 100644 --- a/liblwgeom/cunit/cu_tester.c +++ b/liblwgeom/cunit/cu_tester.c @@ -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, diff --git a/liblwgeom/lwgeom_geos.c b/liblwgeom/lwgeom_geos.c index 11d24f72a..d27010042 100644 --- a/liblwgeom/lwgeom_geos.c +++ b/liblwgeom/lwgeom_geos.c @@ -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; + +} diff --git a/liblwgeom/lwgeom_geos.h b/liblwgeom/lwgeom_geos.h index eaa820464..3571de1fd 100644 --- a/liblwgeom/lwgeom_geos.h +++ b/liblwgeom/lwgeom_geos.h @@ -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) ;