Skip to content

Commit 8003f8b

Browse files
committed
WL#10927: gis::Unary_functor based Ellipsoidal ST_ISVALID
Changes in this commit - Create Unary_functor based gis::Is_valid for boost::geometry::is_valid - Create gis::is_valid interface for calling gis::Is_valid - Unittest for gis::is_valid - Rewrite Item_func_isvalid::val_int in style of Item_func_spatial_relation::val_int, using gis::is_valid. - MTR tests. Change-Id: Id525fa8c7561518f7d260febc6e5d335d2b357fc
1 parent d0dd257 commit 8003f8b

11 files changed

+909
-62
lines changed

mysql-test/suite/gis/r/spatial_utility_function_isvalid.result

Lines changed: 88 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ INSERT INTO gis_geometrycollection VALUES
3737
(114,ST_GEOMFROMTEXT(@star_lines_near_vertical)),
3838
(115,ST_GEOMFROMTEXT(@star_collection_elems)),
3939
(116,ST_GEOMFROMTEXT(@star_collection_multilinestr));
40-
# Checking the integrity of the above create/insert statements
41-
# 17 rows.
40+
# Checking the integrity of the above create/insert statements
41+
# 17 rows.
4242
SELECT count(ST_ASTEXT(g) != 'NULL') FROM gis_geometrycollection;
4343
count(ST_ASTEXT(g) != 'NULL')
4444
17
@@ -380,25 +380,31 @@ ERROR 22003: SRID value is out of range in 'st_geomfromtext'
380380
SELECT ST_ISVALID(ST_GEOMFROMTEXT(@star_all_points,-1));
381381
ERROR 22003: SRID value is out of range in 'st_geomfromtext'
382382
SELECT ST_ISVALID(ST_GEOMFROMTEXT(@star_lines_near_vertical,4236));
383-
ERROR 22S00: st_isvalid(MULTILINESTRING) has not been implemented for geographic spatial reference systems.
383+
ST_ISVALID(ST_GEOMFROMTEXT(@star_lines_near_vertical,4236))
384+
1
385+
SELECT ST_ISVALID(ST_GEOMFROMTEXT(@star_elem_vertical,4294967295));
386+
ERROR SR001: There's no spatial reference system with SRID 4294967295.
384387
SELECT ST_ISVALID(ST_GEOMFROMTEXT(@star_of_elems,4294967297));
385388
ERROR 22003: SRID value is out of range in 'st_geomfromtext'
386389
SELECT ST_ISVALID(ST_GEOMFROMTEXT(@star_collection_elems,4294967295000));
387390
ERROR 22003: SRID value is out of range in 'st_geomfromtext'
388-
SELECT ST_ISVALID(0x000000000200000000000000000000000000000000);
389-
ERROR HY000: Geometry byte string must be little endian.
390-
SELECT ST_ISVALID(0x010100000001000000010100000000000000000000);
391-
ERROR HY000: Geometry byte string must be little endian.
392-
SELECT ST_ISVALID(0x010100000002000000000000000000000000000000);
393-
ERROR HY000: Geometry byte string must be little endian.
391+
SELECT ST_ISVALID( x'e6100000010100000000000000000000000000000000000000');
392+
ST_ISVALID( x'e6100000010100000000000000000000000000000000000000')
393+
1
394+
SELECT ST_ISVALID( x'e6100000020000000100000000000000000000000000000000');
395+
ERROR 22023: Invalid GIS data provided to function st_isvalid.
396+
SELECT ST_ISVALID( x'00000000000001000001010000000000000000000000000000');
397+
ERROR 22023: Invalid GIS data provided to function st_isvalid.
398+
SELECT ST_ISVALID( x'e6100000060100000000000000000000000000000000000000');
399+
ERROR 22023: Invalid GIS data provided to function st_isvalid.
394400
SELECT ST_ISVALID(0x000000000600000001000000000200000002000000);
395-
ERROR HY000: Geometry byte string must be little endian.
401+
ERROR 22023: Invalid GIS data provided to function st_isvalid.
396402
SELECT ST_ISVALID(0x000000000200000001000000050000000000000000);
397-
ERROR HY000: Geometry byte string must be little endian.
403+
ERROR 22023: Invalid GIS data provided to function st_isvalid.
398404
SELECT ST_ISVALID(0x010300000002000000010300000002000000050000);
399-
ERROR HY000: Geometry byte string must be little endian.
405+
ERROR SR001: There's no spatial reference system with SRID 769.
400406
SELECT ST_ISVALID(0x010400000002000000010100000000000000000000);
401-
ERROR HY000: Geometry byte string must be little endian.
407+
ERROR SR001: There's no spatial reference system with SRID 1025.
402408
# Clean up
403409
DROP TABLE gis_geometrycollection;
404410
########################################################################
@@ -430,19 +436,80 @@ ST_ISVALID(ST_GEOMFROMTEXT('POINT(0 0)', 0))
430436
SELECT ST_ISVALID(ST_GEOMFROMTEXT('POINT(0 0)', 2000));
431437
ST_ISVALID(ST_GEOMFROMTEXT('POINT(0 0)', 2000))
432438
1
433-
# Geographic SRS (should fail)
439+
# Geographic SRS (shall pass)
434440
SELECT ST_ISVALID(ST_GEOMFROMTEXT('POINT(0 0)', 4326));
435-
ERROR 22S00: st_isvalid(POINT) has not been implemented for geographic spatial reference systems.
441+
ST_ISVALID(ST_GEOMFROMTEXT('POINT(0 0)', 4326))
442+
1
436443
# Unparseable SRS definition (should fail)
437444
INSERT INTO mysql.st_spatial_reference_systems(id, catalog_id, name,
438445
organization, organization_coordsys_id, definition, description)
439446
VALUES (2000001, 1, 'TEST2000001', 'Foo', 2000001, 'FOOBAR', '');
440447
SELECT ST_ISVALID(ST_GEOMFROMTEXT('POINT(0 0)', 2000001));
441448
ERROR SR002: Can't parse the spatial reference system definition of SRID 2000001.
442449
DELETE FROM mysql.st_spatial_reference_systems WHERE id = 2000001;
443-
#
444-
# WL#11096 Don't do Cartesian computations on geographic geometries
445-
#
446-
# Assume SRID 10 is not defined.
447-
DO ST_ISVALID(x'0A000000010100000000000000000000000000000000000000');
448-
ERROR SR001: There's no spatial reference system with SRID 10.
450+
# Verify that ST_IsValid() returns NULL if at least one of its parameters
451+
# is NULL
452+
SELECT ST_ISVALID(NULL);
453+
ST_ISVALID(NULL)
454+
NULL
455+
# Verify that ST_IsValid() doesn't return NULL if its arguments are not
456+
# NULL
457+
SELECT ST_ISVALID(ST_GEOMFROMTEXT('POINT(0 0)',4053));
458+
ST_ISVALID(ST_GEOMFROMTEXT('POINT(0 0)',4053))
459+
1
460+
# Verify that ST_IsValid() returns ER_GIS_INVALID_DATA error if geometry
461+
# argument is not syntactically well-formed geometry
462+
DO ST_ISVALID(X'FF');
463+
ERROR 22023: Invalid GIS data provided to function st_isvalid.
464+
# Verify that ST_IsValid() returns 1 with empty geometry input
465+
SELECT ST_ISVALID( ST_GEOMFROMTEXT('GEOMETRYCOLLECTION EMPTY','4326'));
466+
ST_ISVALID( ST_GEOMFROMTEXT('GEOMETRYCOLLECTION EMPTY','4326'))
467+
1
468+
# Verify that ST_IsValid() returns 1 if the input is geometrically valid
469+
SELECT ST_ISVALID( ST_GEOMFROMTEXT('POINT(1 1)',4053));
470+
ST_ISVALID( ST_GEOMFROMTEXT('POINT(1 1)',4053))
471+
1
472+
SELECT ST_ISVALID( ST_GEOMFROMTEXT('POINT(1 1)'));
473+
ST_ISVALID( ST_GEOMFROMTEXT('POINT(1 1)'))
474+
1
475+
SELECT ST_ISVALID( ST_GEOMFROMTEXT('POINT(1 1)',4326));
476+
ST_ISVALID( ST_GEOMFROMTEXT('POINT(1 1)',4326))
477+
1
478+
SELECT ST_ISVALID( ST_GEOMFROMTEXT('POLYGON((0 0,0 1,1 1,1 0,0 0),(0.25 0.25,0.75 0.25, 0.25 0.75, 0.25 0.25))',4053));
479+
ST_ISVALID( ST_GEOMFROMTEXT('POLYGON((0 0,0 1,1 1,1 0,0 0),(0.25 0.25,0.75 0.25, 0.25 0.75, 0.25 0.25))',4053))
480+
1
481+
SELECT ST_ISVALID( ST_GEOMFROMTEXT('POLYGON((0 0,0 1,1 1,1 0,0 0),(0.25 0.25,0.75 0.25, 0.25 0.75, 0.25 0.25))',4326));
482+
ST_ISVALID( ST_GEOMFROMTEXT('POLYGON((0 0,0 1,1 1,1 0,0 0),(0.25 0.25,0.75 0.25, 0.25 0.75, 0.25 0.25))',4326))
483+
1
484+
# Verify that ST_IsValid() returns 0 if input is geometrically invalid
485+
SELECT ST_ISVALID( ST_GEOMFROMTEXT('POLYGON((0 0,0 1,1 1,1 0,0 0),(0.25 0.25,1.75 0.25, 0.25 0.75, 0.25 0.25))',4053));
486+
ST_ISVALID( ST_GEOMFROMTEXT('POLYGON((0 0,0 1,1 1,1 0,0 0),(0.25 0.25,1.75 0.25, 0.25 0.75, 0.25 0.25))',4053))
487+
0
488+
SELECT ST_ISVALID( ST_GEOMFROMTEXT('POLYGON((0 0,0 1,1 1,1 0,0 0),(0.25 0.25,1.75 0.25, 0.25 0.75, 0.25 0.25))',4326));
489+
ST_ISVALID( ST_GEOMFROMTEXT('POLYGON((0 0,0 1,1 1,1 0,0 0),(0.25 0.25,1.75 0.25, 0.25 0.75, 0.25 0.25))',4326))
490+
0
491+
# Verify that ST_IsValid() returns ER_LONGITUDE_OUT_OF_RANGE error with a
492+
# geometry in a geographic SRS and a longitude value is not in the range
493+
# (-180,180]
494+
DO ST_ISVALID(X'D50F0000010100000000000000000070400000000000000000');
495+
ERROR 22S02: Longitude 256.000000 is out of range in function st_isvalid. It must be within (-180.000000, 180.000000].
496+
# Verify that ST_IsValid() returns ER_LATITUDE_OUT_OF_RANGE error with a
497+
# geometry in geographic SRS and a latitude value is not in the range
498+
# [-90,90]
499+
DO ST_ISVALID(X'D50F0000010100000000000000000000000000000000008040');
500+
ERROR 22S03: Latitude 512.000000 is out of range in function st_isvalid. It must be within [-90.000000, 90.000000].
501+
# If a multipoint is made up of valid points it should be valid.
502+
SELECT ST_ISVALID(ST_GEOMFROMTEXT('multipoint((0 0),(1 1))',4053 )) AS RESULT;
503+
RESULT
504+
1
505+
SELECT ST_IsValid(ST_GeomFromText('MULTIPOLYGON(((9 11,14 84,43 54,9 11)),((-144
506+
-58,-142 -6,-4 -70,-144 -58)))', '4326', 'axis-order=long-lat')) AS RESULT;
507+
RESULT
508+
1
509+
SELECT ST_ISVALID(ST_GEOMFROMTEXT('GEOMETRYCOLLECTION(POLYGON((0 0,0 1,1 1,1 0,0 0),(0.25 0.25,0.75 0.25, 0.25 0.75, 0.25 0.25)),POINT(1 1))',4053)) as result;
510+
result
511+
1
512+
SELECT ST_IsValid(ST_GeomFromText('GEOMETRYCOLLECTION(MULTIPOLYGON(((9 11,14 84,43 54,9 11)),((-144
513+
-58,-142 -6,-4 -70,-144 -58))), point( 1 1))', '4326', 'axis-order=long-lat')) AS RESULT;
514+
RESULT
515+
1

mysql-test/suite/gis/t/spatial_utility_function_isvalid.test

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ INSERT INTO gis_geometrycollection VALUES
6363
(116,ST_GEOMFROMTEXT(@star_collection_multilinestr));
6464
--enable_warnings
6565

66-
--echo # Checking the integrity of the above create/insert statements
66+
--echo # Checking the integrity of the above create/insert statements
6767

68-
--echo # 17 rows.
68+
--echo # 17 rows.
6969
SELECT count(ST_ASTEXT(g) != 'NULL') FROM gis_geometrycollection;
7070

7171
--echo #####################################################################################
@@ -352,34 +352,40 @@ SELECT ST_ISVALID(ST_GEOMFROMTEXT(@star_center,-1024));
352352
--error ER_DATA_OUT_OF_RANGE
353353
SELECT ST_ISVALID(ST_GEOMFROMTEXT(@star_all_points,-1));
354354

355-
--error ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
356355
SELECT ST_ISVALID(ST_GEOMFROMTEXT(@star_lines_near_vertical,4236));
357356

357+
--error ER_SRS_NOT_FOUND
358+
SELECT ST_ISVALID(ST_GEOMFROMTEXT(@star_elem_vertical,4294967295));
359+
358360
--error ER_DATA_OUT_OF_RANGE
359361
SELECT ST_ISVALID(ST_GEOMFROMTEXT(@star_of_elems,4294967297));
360362

361363
--error ER_DATA_OUT_OF_RANGE
362364
SELECT ST_ISVALID(ST_GEOMFROMTEXT(@star_collection_elems,4294967295000));
363365

364-
--error ER_GIS_DATA_WRONG_ENDIANESS
365-
SELECT ST_ISVALID(0x000000000200000000000000000000000000000000);
366+
# This is an example of a working wkb, first the SRID, specification it is
367+
# littleendian, and is a point with coordinates (0,0)
368+
SELECT ST_ISVALID( x'e6100000010100000000000000000000000000000000000000');
369+
370+
--error ER_GIS_INVALID_DATA
371+
SELECT ST_ISVALID( x'e6100000020000000100000000000000000000000000000000');
366372

367-
--error ER_GIS_DATA_WRONG_ENDIANESS
368-
SELECT ST_ISVALID(0x010100000001000000010100000000000000000000);
373+
--error ER_GIS_INVALID_DATA
374+
SELECT ST_ISVALID( x'00000000000001000001010000000000000000000000000000');
369375

370-
--error ER_GIS_DATA_WRONG_ENDIANESS
371-
SELECT ST_ISVALID(0x010100000002000000000000000000000000000000);
376+
--error ER_GIS_INVALID_DATA
377+
SELECT ST_ISVALID( x'e6100000060100000000000000000000000000000000000000');
372378

373-
--error ER_GIS_DATA_WRONG_ENDIANESS
379+
--error ER_GIS_INVALID_DATA
374380
SELECT ST_ISVALID(0x000000000600000001000000000200000002000000);
375381

376-
--error ER_GIS_DATA_WRONG_ENDIANESS
382+
--error ER_GIS_INVALID_DATA
377383
SELECT ST_ISVALID(0x000000000200000001000000050000000000000000);
378384

379-
--error ER_GIS_DATA_WRONG_ENDIANESS
385+
--error ER_SRS_NOT_FOUND
380386
SELECT ST_ISVALID(0x010300000002000000010300000002000000050000);
381387

382-
--error ER_GIS_DATA_WRONG_ENDIANESS
388+
--error ER_SRS_NOT_FOUND
383389
SELECT ST_ISVALID(0x010400000002000000010100000000000000000000);
384390

385391
--echo # Clean up
@@ -407,8 +413,7 @@ SELECT ST_ISVALID(ST_GEOMFROMTEXT('POINT(0 0)', 0));
407413
--echo # Projected SRS (should pass)
408414
SELECT ST_ISVALID(ST_GEOMFROMTEXT('POINT(0 0)', 2000));
409415

410-
--echo # Geographic SRS (should fail)
411-
--error ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
416+
--echo # Geographic SRS (shall pass)
412417
SELECT ST_ISVALID(ST_GEOMFROMTEXT('POINT(0 0)', 4326));
413418

414419
--echo # Unparseable SRS definition (should fail)
@@ -420,10 +425,41 @@ VALUES (2000001, 1, 'TEST2000001', 'Foo', 2000001, 'FOOBAR', '');
420425
SELECT ST_ISVALID(ST_GEOMFROMTEXT('POINT(0 0)', 2000001));
421426
DELETE FROM mysql.st_spatial_reference_systems WHERE id = 2000001;
422427

423-
--echo #
424-
--echo # WL#11096 Don't do Cartesian computations on geographic geometries
425-
--echo #
426-
427-
--echo # Assume SRID 10 is not defined.
428-
--error ER_SRS_NOT_FOUND
429-
DO ST_ISVALID(x'0A000000010100000000000000000000000000000000000000');
428+
--echo # Verify that ST_IsValid() returns NULL if at least one of its parameters
429+
--echo # is NULL
430+
SELECT ST_ISVALID(NULL);
431+
--echo # Verify that ST_IsValid() doesn't return NULL if its arguments are not
432+
--echo # NULL
433+
SELECT ST_ISVALID(ST_GEOMFROMTEXT('POINT(0 0)',4053));
434+
--echo # Verify that ST_IsValid() returns ER_GIS_INVALID_DATA error if geometry
435+
--echo # argument is not syntactically well-formed geometry
436+
--error ER_GIS_INVALID_DATA
437+
DO ST_ISVALID(X'FF');
438+
--echo # Verify that ST_IsValid() returns 1 with empty geometry input
439+
SELECT ST_ISVALID( ST_GEOMFROMTEXT('GEOMETRYCOLLECTION EMPTY','4326'));
440+
--echo # Verify that ST_IsValid() returns 1 if the input is geometrically valid
441+
SELECT ST_ISVALID( ST_GEOMFROMTEXT('POINT(1 1)',4053));
442+
SELECT ST_ISVALID( ST_GEOMFROMTEXT('POINT(1 1)'));
443+
SELECT ST_ISVALID( ST_GEOMFROMTEXT('POINT(1 1)',4326));
444+
SELECT ST_ISVALID( ST_GEOMFROMTEXT('POLYGON((0 0,0 1,1 1,1 0,0 0),(0.25 0.25,0.75 0.25, 0.25 0.75, 0.25 0.25))',4053));
445+
SELECT ST_ISVALID( ST_GEOMFROMTEXT('POLYGON((0 0,0 1,1 1,1 0,0 0),(0.25 0.25,0.75 0.25, 0.25 0.75, 0.25 0.25))',4326));
446+
--echo # Verify that ST_IsValid() returns 0 if input is geometrically invalid
447+
SELECT ST_ISVALID( ST_GEOMFROMTEXT('POLYGON((0 0,0 1,1 1,1 0,0 0),(0.25 0.25,1.75 0.25, 0.25 0.75, 0.25 0.25))',4053));
448+
SELECT ST_ISVALID( ST_GEOMFROMTEXT('POLYGON((0 0,0 1,1 1,1 0,0 0),(0.25 0.25,1.75 0.25, 0.25 0.75, 0.25 0.25))',4326));
449+
--echo # Verify that ST_IsValid() returns ER_LONGITUDE_OUT_OF_RANGE error with a
450+
--echo # geometry in a geographic SRS and a longitude value is not in the range
451+
--echo # (-180,180]
452+
--error ER_LONGITUDE_OUT_OF_RANGE
453+
DO ST_ISVALID(X'D50F0000010100000000000000000070400000000000000000');
454+
--echo # Verify that ST_IsValid() returns ER_LATITUDE_OUT_OF_RANGE error with a
455+
--echo # geometry in geographic SRS and a latitude value is not in the range
456+
--echo # [-90,90]
457+
--error ER_LATITUDE_OUT_OF_RANGE
458+
DO ST_ISVALID(X'D50F0000010100000000000000000000000000000000008040');
459+
--echo # If a multipoint is made up of valid points it should be valid.
460+
SELECT ST_ISVALID(ST_GEOMFROMTEXT('multipoint((0 0),(1 1))',4053 )) AS RESULT;
461+
SELECT ST_IsValid(ST_GeomFromText('MULTIPOLYGON(((9 11,14 84,43 54,9 11)),((-144
462+
-58,-142 -6,-4 -70,-144 -58)))', '4326', 'axis-order=long-lat')) AS RESULT;
463+
SELECT ST_ISVALID(ST_GEOMFROMTEXT('GEOMETRYCOLLECTION(POLYGON((0 0,0 1,1 1,1 0,0 0),(0.25 0.25,0.75 0.25, 0.25 0.75, 0.25 0.25)),POINT(1 1))',4053)) as result;
464+
SELECT ST_IsValid(ST_GeomFromText('GEOMETRYCOLLECTION(MULTIPOLYGON(((9 11,14 84,43 54,9 11)),((-144
465+
-58,-142 -6,-4 -70,-144 -58))), point( 1 1))', '4326', 'axis-order=long-lat')) AS RESULT;

sql/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ SET(SQL_GIS_SOURCES
211211
gis/geometries.cc
212212
gis/intersects.cc
213213
gis/is_simple.cc
214+
gis/is_valid.cc
214215
gis/length.cc
215216
gis/mbr_utils.cc
216217
gis/overlaps.cc

sql/gis/is_valid.cc

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
//
3+
// This program is free software; you can redistribute it and/or modify it under
4+
// the terms of the GNU General Public License as published by the Free Software
5+
// Foundation; version 2 of the License.
6+
//
7+
// This program is distributed in the hope that it will be useful, but WITHOUT
8+
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9+
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10+
// details.
11+
//
12+
// You should have received a copy of the GNU General Public License along with
13+
// this program; if not, write to the Free Software Foundation, 51 Franklin
14+
// Street, Suite 500, Boston, MA 02110-1335 USA.
15+
16+
///@file
17+
///
18+
/// This file implements the Is_valid functor and is_valid function.
19+
20+
#include "is_valid.h"
21+
#include "is_valid_functor.h"
22+
23+
#include <algorithm> // all_of
24+
#include <limits>
25+
26+
#include <boost/geometry.hpp> // boost::geometry::is_simple
27+
28+
#include "my_inttypes.h" // MYF
29+
#include "my_sys.h" // my_error
30+
#include "mysqld_error.h" // Error codes
31+
#include "sql/dd/types/spatial_reference_system.h" // dd::Spatial_reference_system
32+
#include "sql/gis/geometries.h"
33+
#include "sql/gis/geometries_traits.h"
34+
#include "sql/sql_exception_handler.h" // handle_gis_exception
35+
36+
namespace bg = boost::geometry;
37+
38+
namespace gis {
39+
Is_valid::Is_valid(double semi_major, double semi_minor)
40+
: m_geographic_ll_la_aa_strategy(
41+
bg::srs::spheroid<double>(semi_major, semi_minor)) {}
42+
43+
bool Is_valid::operator()(const Geometry &g) const { return apply(*this, g); }
44+
45+
bool Is_valid::eval(const Cartesian_point &g) const { return bg::is_valid(g); }
46+
bool Is_valid::eval(const Cartesian_linestring &g) const {
47+
return bg::is_valid(g);
48+
}
49+
bool Is_valid::eval(const Cartesian_polygon &g) const {
50+
return bg::is_valid(g);
51+
}
52+
bool Is_valid::eval(const Cartesian_multipoint &g) const {
53+
return bg::is_valid(g);
54+
}
55+
bool Is_valid::eval(const Cartesian_multilinestring &g) const {
56+
return bg::is_valid(g);
57+
}
58+
bool Is_valid::eval(const Cartesian_multipolygon &g) const {
59+
return bg::is_valid(g);
60+
}
61+
bool Is_valid::eval(const Cartesian_geometrycollection &g) const {
62+
return std::all_of(g.begin(), g.end(),
63+
[this](const Geometry *a) { return apply(*this, *a); });
64+
}
65+
66+
bool Is_valid::eval(const Geographic_point &g) const { return bg::is_valid(g); }
67+
bool Is_valid::eval(const Geographic_linestring &g) const {
68+
return bg::is_valid(g, m_geographic_ll_la_aa_strategy);
69+
}
70+
bool Is_valid::eval(const Geographic_polygon &g) const {
71+
return bg::is_valid(g, m_geographic_ll_la_aa_strategy);
72+
}
73+
bool Is_valid::eval(const Geographic_multipoint &g) const {
74+
return bg::is_valid(g, m_geographic_ll_la_aa_strategy);
75+
}
76+
bool Is_valid::eval(const Geographic_multilinestring &g) const {
77+
return bg::is_valid(g, m_geographic_ll_la_aa_strategy);
78+
}
79+
bool Is_valid::eval(const Geographic_multipolygon &g) const {
80+
return bg::is_valid(g, m_geographic_ll_la_aa_strategy);
81+
}
82+
bool Is_valid::eval(const Geographic_geometrycollection &g) const {
83+
return std::all_of(g.begin(), g.end(),
84+
[this](const Geometry *a) { return apply(*this, *a); });
85+
}
86+
87+
bool is_valid(const dd::Spatial_reference_system *srs, const Geometry *g,
88+
const char *func_name, bool *is_valid) noexcept {
89+
try {
90+
DBUG_ASSERT(srs == nullptr ||
91+
((srs->is_cartesian() &&
92+
g->coordinate_system() == Coordinate_system::kCartesian) ||
93+
(srs->is_geographic() &&
94+
g->coordinate_system() == Coordinate_system::kGeographic)));
95+
if (g->is_empty()) {
96+
*is_valid = true;
97+
return false;
98+
}
99+
double smajor = 0.0;
100+
double sminor = 0.0;
101+
if (srs != nullptr) {
102+
smajor = srs->semi_major_axis();
103+
sminor = srs->semi_minor_axis();
104+
}
105+
Is_valid is_valid_functor(smajor, sminor);
106+
*is_valid = is_valid_functor(*g);
107+
return false;
108+
} catch (...) {
109+
handle_gis_exception(func_name);
110+
return true;
111+
}
112+
}
113+
} // namespace gis

0 commit comments

Comments
 (0)