From e4d3fc1f9b5cea54281b602e0a5879c0ef044332 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Wed, 24 Feb 2010 13:50:22 +0000 Subject: [PATCH] Add support from SRID= block on EWKT git-svn-id: http://svn.osgeo.org/postgis/trunk@5334 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/cunit/cu_wkt.c | 5 ++++- liblwgeom/liblwgeom.h | 8 +++++++- liblwgeom/lwgeom.c | 9 +++++++++ liblwgeom/lwout_wkt.c | 5 +++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/liblwgeom/cunit/cu_wkt.c b/liblwgeom/cunit/cu_wkt.c index 2b38fb4e1..bd830b043 100644 --- a/liblwgeom/cunit/cu_wkt.c +++ b/liblwgeom/cunit/cu_wkt.c @@ -67,12 +67,15 @@ static void test_wkt_point(void) CU_ASSERT_STRING_EQUAL(cu_wkt("POINT(100 100)",WKT_ISO), "POINT(100 100)"); CU_ASSERT_STRING_EQUAL(cu_wkt("POINT(100 100)",WKT_EXTENDED), "POINT(100 100)"); CU_ASSERT_STRING_EQUAL(cu_wkt("POINT(100 100)",WKT_SFSQL), "POINT(100 100)"); -// printf("%s\n",cu_wkt("POINT(100 100)",WKT_SFSQL)); CU_ASSERT_STRING_EQUAL(cu_wkt("POINT(100.1 100 12 12)",WKT_ISO), "POINTZM(100.1 100 12 12)"); CU_ASSERT_STRING_EQUAL(cu_wkt("POINT(100.1 100 12 12)",WKT_EXTENDED), "POINT(100.1 100 12 12)"); CU_ASSERT_STRING_EQUAL(cu_wkt("POINT(100.1 100 12 12)",WKT_SFSQL), "POINT(100.1 100)"); + CU_ASSERT_STRING_EQUAL(cu_wkt("SRID=100;POINT(100.1 100 12 12)",WKT_SFSQL), "POINT(100.1 100)"); + CU_ASSERT_STRING_EQUAL(cu_wkt("SRID=100;POINT(100.1 100 12 12)",WKT_EXTENDED), "SRID=100;POINT(100.1 100 12 12)"); +// printf("%s\n",cu_wkt("SRID=100;POINT(100.1 100 12 12)",WKT_EXTENDED)); + } static void test_wkt_linestring(void) diff --git a/liblwgeom/liblwgeom.h b/liblwgeom/liblwgeom.h index 20035595b..8d84ca10a 100644 --- a/liblwgeom/liblwgeom.h +++ b/liblwgeom/liblwgeom.h @@ -1264,7 +1264,13 @@ extern int lwgeom_count_vertices(LWGEOM *geom); extern int32 lwgeom_npoints(uchar *serialized); /** -* Return true of false depending on whether a geometry is an "empty" +* Return true or false depending on whether a geometry has +* a valid SRID set. +*/ +extern int lwgeom_has_srid(const LWGEOM *geom); + +/** +* Return true or false depending on whether a geometry is an "empty" * geometry (no vertices members) */ extern int lwgeom_is_empty(const LWGEOM *geom); diff --git a/liblwgeom/lwgeom.c b/liblwgeom/lwgeom.c index 93687c43d..08f691933 100644 --- a/liblwgeom/lwgeom.c +++ b/liblwgeom/lwgeom.c @@ -1133,6 +1133,15 @@ int lwgeom_is_empty(const LWGEOM *geom) return result; } +int lwgeom_has_srid(const LWGEOM *geom) +{ + if( (int)(geom->SRID) > 0 ) + return LW_TRUE; + + return LW_FALSE; +} + + static int lwcollection_dimensionality(LWCOLLECTION *col) { int i; diff --git a/liblwgeom/lwout_wkt.c b/liblwgeom/lwout_wkt.c index 158a21621..355021ebc 100644 --- a/liblwgeom/lwout_wkt.c +++ b/liblwgeom/lwout_wkt.c @@ -529,6 +529,11 @@ char *lwgeom_to_wkt(const LWGEOM *geom, int precision, uchar variant) if( geom == NULL ) return NULL; sb = stringbuffer_create(); + /* Extended mode starts with an "SRID=" section for geoms that have one */ + if( (variant & WKT_EXTENDED) && lwgeom_has_srid(geom) ) + { + stringbuffer_vasbappend(sb, "SRID=%d;", geom->SRID); + } lwgeom_to_wkt_sb(geom, sb, precision, variant); if( stringbuffer_getstring(sb) == NULL ) { -- 2.40.0