2011-11-03 16:20:39 +00:00
|
|
|
/**********************************************************************
|
|
|
|
*
|
|
|
|
* PostGIS - Spatial Types for PostgreSQL
|
|
|
|
* http://postgis.refractions.net
|
|
|
|
*
|
|
|
|
* Copyright (C) 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 "CUnit/Basic.h"
|
|
|
|
#include "cu_tester.h"
|
|
|
|
|
|
|
|
#include "liblwgeom.h"
|
|
|
|
#include "liblwgeom_internal.h"
|
|
|
|
|
|
|
|
static void test_lwline_split_by_point_to(void)
|
|
|
|
{
|
2011-11-03 17:09:17 +00:00
|
|
|
#if POSTGIS_GEOS_VERSION >= 33
|
2011-11-03 16:20:39 +00:00
|
|
|
LWLINE *line;
|
|
|
|
LWPOINT *point;
|
|
|
|
LWMLINE *coll;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Because i don't trust that much prior tests... ;) */
|
|
|
|
cu_error_msg_reset();
|
|
|
|
|
|
|
|
coll = lwmline_construct_empty(SRID_UNKNOWN, 0, 0);
|
|
|
|
CU_ASSERT_EQUAL(coll->ngeoms, 0);
|
|
|
|
|
|
|
|
line = lwgeom_as_lwline(lwgeom_from_wkt("LINESTRING(0 0,5 5, 10 0))",
|
|
|
|
LW_PARSER_CHECK_NONE));
|
|
|
|
CU_ASSERT(line != NULL);
|
|
|
|
|
|
|
|
point = lwgeom_as_lwpoint(lwgeom_from_wkt(
|
|
|
|
"POINT(0 0)",
|
|
|
|
LW_PARSER_CHECK_NONE));
|
|
|
|
ret = lwline_split_by_point_to(line, point, coll);
|
|
|
|
CU_ASSERT_EQUAL(ret, 1);
|
|
|
|
CU_ASSERT_EQUAL(coll->ngeoms, 0);
|
2012-02-07 19:42:49 +00:00
|
|
|
lwpoint_free(point);
|
2011-11-03 16:20:39 +00:00
|
|
|
|
|
|
|
point = lwgeom_as_lwpoint(lwgeom_from_wkt(
|
|
|
|
"POINT(10 0)",
|
|
|
|
LW_PARSER_CHECK_NONE));
|
|
|
|
ret = lwline_split_by_point_to(line, point, coll);
|
|
|
|
CU_ASSERT_EQUAL(ret, 1);
|
|
|
|
CU_ASSERT_EQUAL(coll->ngeoms, 0);
|
2012-02-07 19:42:49 +00:00
|
|
|
lwpoint_free(point);
|
2011-11-03 16:20:39 +00:00
|
|
|
|
|
|
|
point = lwgeom_as_lwpoint(lwgeom_from_wkt(
|
|
|
|
"POINT(5 0)",
|
|
|
|
LW_PARSER_CHECK_NONE));
|
|
|
|
ret = lwline_split_by_point_to(line, point, coll);
|
|
|
|
CU_ASSERT_EQUAL(ret, 0);
|
|
|
|
CU_ASSERT_EQUAL(coll->ngeoms, 0);
|
2012-02-07 19:42:49 +00:00
|
|
|
lwpoint_free(point);
|
2011-11-03 16:20:39 +00:00
|
|
|
|
|
|
|
point = lwgeom_as_lwpoint(lwgeom_from_wkt(
|
|
|
|
"POINT(5 5)",
|
|
|
|
LW_PARSER_CHECK_NONE));
|
|
|
|
ret = lwline_split_by_point_to(line, point, coll);
|
|
|
|
CU_ASSERT_EQUAL(ret, 2);
|
|
|
|
CU_ASSERT_EQUAL(coll->ngeoms, 2);
|
2012-02-07 19:42:49 +00:00
|
|
|
lwpoint_free(point);
|
2011-11-03 16:20:39 +00:00
|
|
|
|
|
|
|
point = lwgeom_as_lwpoint(lwgeom_from_wkt(
|
|
|
|
"POINT(2 2)",
|
|
|
|
LW_PARSER_CHECK_NONE));
|
|
|
|
ret = lwline_split_by_point_to(line, point, coll);
|
|
|
|
CU_ASSERT_EQUAL(ret, 2);
|
|
|
|
CU_ASSERT_EQUAL(coll->ngeoms, 4);
|
2012-02-07 19:42:49 +00:00
|
|
|
lwpoint_free(point);
|
2011-11-03 16:20:39 +00:00
|
|
|
|
2012-02-07 19:42:49 +00:00
|
|
|
lwcollection_free(coll);
|
|
|
|
lwline_free(line);
|
2011-11-03 16:20:39 +00:00
|
|
|
|
2011-11-03 17:09:17 +00:00
|
|
|
#endif /* POSTGIS_GEOS_VERSION >= 33 */
|
2011-11-03 16:20:39 +00:00
|
|
|
}
|
|
|
|
|
2011-11-08 08:55:09 +00:00
|
|
|
static void test_lwgeom_split(void)
|
|
|
|
{
|
|
|
|
LWGEOM *geom, *blade, *ret;
|
2011-11-21 14:59:36 +00:00
|
|
|
char *wkt, *in_wkt;
|
2011-11-08 08:55:09 +00:00
|
|
|
|
|
|
|
geom = lwgeom_from_wkt(
|
|
|
|
"MULTILINESTRING((-5 -2,0 0),(0 0,10 10))",
|
|
|
|
LW_PARSER_CHECK_NONE);
|
|
|
|
CU_ASSERT(geom != NULL);
|
2011-11-21 14:59:36 +00:00
|
|
|
blade = lwgeom_from_wkt(
|
2011-11-08 08:55:09 +00:00
|
|
|
"POINT(0 0)",
|
2011-11-21 14:59:36 +00:00
|
|
|
LW_PARSER_CHECK_NONE);
|
2011-11-08 08:55:09 +00:00
|
|
|
CU_ASSERT(blade != NULL);
|
|
|
|
ret = lwgeom_split(geom, blade);
|
|
|
|
CU_ASSERT(ret != NULL);
|
2011-11-21 14:59:36 +00:00
|
|
|
wkt = lwgeom_to_ewkt(ret);
|
|
|
|
in_wkt = "GEOMETRYCOLLECTION(LINESTRING(-5 -2,0 0),LINESTRING(0 0,10 10))";
|
|
|
|
if (strcmp(in_wkt, wkt))
|
|
|
|
fprintf(stderr, "\nExp: %s\nObt: %s\n", in_wkt, wkt);
|
|
|
|
CU_ASSERT_STRING_EQUAL(wkt, in_wkt);
|
2011-11-08 08:55:09 +00:00
|
|
|
lwfree(wkt);
|
2011-11-21 14:59:36 +00:00
|
|
|
lwgeom_free(ret);
|
|
|
|
lwgeom_free(geom);
|
|
|
|
lwgeom_free(blade);
|
|
|
|
|
|
|
|
/* See #1311 */
|
|
|
|
geom = lwgeom_from_wkt(
|
|
|
|
"LINESTRING(0 0,10 0,20 4,0 3)",
|
|
|
|
LW_PARSER_CHECK_NONE);
|
|
|
|
CU_ASSERT(geom != NULL);
|
|
|
|
blade = lwgeom_from_wkt("POINT(10 0)", LW_PARSER_CHECK_NONE);
|
|
|
|
ret = lwgeom_split(geom, blade);
|
|
|
|
CU_ASSERT(ret != NULL);
|
|
|
|
wkt = lwgeom_to_ewkt(ret);
|
|
|
|
in_wkt = "GEOMETRYCOLLECTION(LINESTRING(0 0,10 0),LINESTRING(10 0,20 4,0 3))";
|
|
|
|
if (strcmp(in_wkt, wkt))
|
|
|
|
fprintf(stderr, "\nExp: %s\nObt: %s\n", in_wkt, wkt);
|
|
|
|
CU_ASSERT_STRING_EQUAL(wkt, in_wkt);
|
|
|
|
lwfree(wkt);
|
|
|
|
lwgeom_free(ret);
|
|
|
|
lwgeom_free(geom);
|
|
|
|
lwgeom_free(blade);
|
2011-11-08 08:55:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-03 16:20:39 +00:00
|
|
|
/*
|
|
|
|
** Used by test harness to register the tests in this file.
|
|
|
|
*/
|
|
|
|
CU_TestInfo split_tests[] =
|
|
|
|
{
|
|
|
|
PG_TEST(test_lwline_split_by_point_to),
|
2011-11-08 08:55:09 +00:00
|
|
|
PG_TEST(test_lwgeom_split),
|
2011-11-03 16:20:39 +00:00
|
|
|
CU_TEST_INFO_NULL
|
|
|
|
};
|
|
|
|
CU_SuiteInfo split_suite = {"split", NULL, NULL, split_tests};
|