25
25
The Initial Developer of the Original Code is Alessandro Furieri
27
Portions created by the Initial Developer are Copyright (C) 2008-2013
27
Portions created by the Initial Developer are Copyright (C) 2008-2015
28
28
the Initial Developer. All Rights Reserved.
30
30
Alternatively, the contents of this file may be used under the terms of
1670
SPATIALITE_DECLARE int
1671
sanitize_geometry_column (sqlite3 * sqlite, const char *table, const char *geom,
1672
const char *tmp_table, const char *report_path,
1673
int *n_invalids, int *n_repaired, int *n_discarded,
1674
int *n_failures, char **err_msg)
1671
sanitize_geometry_column_common (const void *p_cache, sqlite3 * sqlite,
1672
const char *table, const char *geom,
1673
const char *tmp_table, const char *report_path,
1674
int *n_invalids, int *n_repaired,
1675
int *n_discarded, int *n_failures,
1678
#ifdef ENABLE_LWGEOM /* only if LWGEOM is enabled */
1676
1680
/* attempts to repair invalid Geometries from a Geometry Column */
1705
1709
if (!check_table_column (sqlite, table, geom, >ype, &srid))
1707
spatialite_e ("sanitize_geometry_column error: <%s>\n"
1711
spatialite_e ("sanitize_geometry_column error: <%s><%s>\n"
1708
1712
"Not defined in \"geometry_columns\"", table, geom);
1709
1713
if (err_msg != NULL)
1979
1983
/* checking a geometry for validity */
1980
gaiaResetGeosMsg ();
1981
if (!gaiaIsValid (geom))
1985
if (p_cache != NULL)
1987
gaiaResetGeosMsg_r (p_cache);
1988
valret = gaiaIsValid_r (p_cache, geom);
1992
gaiaResetGeosMsg ();
1993
valret = gaiaIsValid (geom);
1983
1997
unsigned char *blob_geom;
1984
1998
int blob_sz_geom;
2395
2409
free_sanitize_report (report);
2413
#endif /* end LWGEOM conditional */
2401
2418
SPATIALITE_DECLARE int
2402
sanitize_all_geometry_columns (sqlite3 * sqlite,
2403
const char *tmp_prefix,
2404
const char *output_dir, int *x_not_repaired,
2419
sanitize_geometry_column (sqlite3 * sqlite, const char *table, const char *geom,
2420
const char *tmp_table, const char *report_path,
2421
int *n_invalids, int *n_repaired, int *n_discarded,
2422
int *n_failures, char **err_msg)
2424
return sanitize_geometry_column_common (NULL, sqlite, table, geom,
2425
tmp_table, report_path, n_invalids,
2426
n_repaired, n_discarded, n_failures,
2430
SPATIALITE_DECLARE int
2431
sanitize_geometry_column_r (const void *p_cache, sqlite3 * sqlite,
2432
const char *table, const char *geom,
2433
const char *tmp_table, const char *report_path,
2434
int *n_invalids, int *n_repaired, int *n_discarded,
2435
int *n_failures, char **err_msg)
2437
return sanitize_geometry_column_common (p_cache, sqlite, table, geom,
2438
tmp_table, report_path, n_invalids,
2439
n_repaired, n_discarded, n_failures,
2444
sanitize_all_geometry_columns_common (const void *p_cache, sqlite3 * sqlite,
2445
const char *tmp_prefix,
2446
const char *output_dir,
2447
int *x_not_repaired, char **err_msg)
2407
2449
/* attempts to repair invalid Geometries from all Geometry Columns */
2408
2450
const char *sql;
2566
2608
report = sqlite3_mprintf ("%s/lyr_%04d.html", output_dir, i);
2568
2610
sqlite3_mprintf ("%s%s_%s", tmp_prefix, table, geom);
2570
sanitize_geometry_column (sqlite, table, geom, tmp_table,
2571
report, &n_invalids, &n_repaired,
2572
&n_discarded, &n_failures,
2611
if (p_cache != NULL)
2613
sanitize_geometry_column_r (p_cache, sqlite, table,
2614
geom, tmp_table, report,
2615
&n_invalids, &n_repaired,
2616
&n_discarded, &n_failures,
2620
sanitize_geometry_column (sqlite, table, geom,
2622
&n_invalids, &n_repaired,
2623
&n_discarded, &n_failures,
2574
2625
sqlite3_free (report);
2575
2626
sqlite3_free (tmp_table);
2689
SPATIALITE_DECLARE int
2690
sanitize_all_geometry_columns (sqlite3 * sqlite,
2691
const char *tmp_prefix,
2692
const char *output_dir, int *x_not_repaired,
2695
return sanitize_all_geometry_columns_common (NULL, sqlite, tmp_prefix,
2696
output_dir, x_not_repaired,
2700
SPATIALITE_DECLARE int
2701
sanitize_all_geometry_columns_r (const void *p_cache, sqlite3 * sqlite,
2702
const char *tmp_prefix,
2703
const char *output_dir, int *x_not_repaired,
2706
return sanitize_all_geometry_columns_common (p_cache, sqlite, tmp_prefix,
2707
output_dir, x_not_repaired,
2638
2711
#else /* LIBXML2 isn't enabled */
2640
2713
SPATIALITE_DECLARE int
2664
2737
SPATIALITE_DECLARE int
2738
sanitize_all_geometry_columns_r (const void *p_cache, sqlite3 * sqlite,
2739
const char *tmp_prefix,
2740
const char *output_dir, int *x_not_repaired,
2743
/* LWGEOM isn't enabled: always returning an error */
2745
const char *msg = "Sorry ... libspatialite was built disabling LWGEOM\n"
2746
"and is thus unable to support MakeValid";
2748
/* silencing stupid compiler warnings */
2749
if (p_cache == NULL || sqlite == NULL || tmp_prefix == NULL
2750
|| output_dir == NULL || x_not_repaired == NULL)
2753
if (err_msg == NULL)
2756
*err_msg = malloc (len + 1);
2757
strcpy (*err_msg, msg);
2761
SPATIALITE_DECLARE int
2665
2762
sanitize_geometry_column (sqlite3 * sqlite, const char *table, const char *geom,
2666
2763
const char *tmp_table, const char *report_path,
2667
2764
int *n_invalids, int *n_repaired, int *n_discarded,
2787
SPATIALITE_DECLARE int
2788
sanitize_geometry_column_r (const void *p_cache, sqlite3 * sqlite,
2789
const char *table, const char *geom,
2790
const char *tmp_table, const char *report_path,
2791
int *n_invalids, int *n_repaired, int *n_discarded,
2792
int *n_failures, char **err_msg)
2794
/* LWGEOM isn't enabled: always returning an error */
2796
const char *msg = "Sorry ... libspatialite was built disabling LWGEOM\n"
2797
"and is thus unable to support MakeValid";
2799
/* silencing stupid compiler warnings */
2800
if (p_cache == NULL || sqlite == NULL || table == NULL || geom == NULL
2801
|| tmp_table == NULL || report_path == NULL || n_invalids == NULL
2802
|| n_repaired == NULL || n_discarded == NULL || n_failures == NULL)
2806
if (err_msg == NULL)
2809
*err_msg = malloc (len + 1);
2810
strcpy (*err_msg, msg);
2690
2814
#endif /* end LWGEOM conditionals */
2773
2897
report->last = r;
2776
SPATIALITE_DECLARE int
2777
check_geometry_column (sqlite3 * sqlite, const char *table, const char *geom,
2778
const char *report_path, int *n_rows, int *n_invalids,
2901
check_geometry_column_common (const void *p_cache, sqlite3 * sqlite,
2902
const char *table, const char *geom,
2903
const char *report_path, int *n_rows,
2904
int *n_invalids, char **err_msg)
2781
2906
/* checks a Geometry Column for validity */
3011
3136
const char *error;
3012
3137
const char *warning;
3013
3138
const char *extra;
3014
gaiaResetGeosMsg ();
3015
valid = gaiaIsValid (geom);
3016
error = gaiaGetGeosErrorMsg ();
3017
warning = gaiaGetGeosWarningMsg ();
3018
extra = gaiaGetGeosAuxErrorMsg ();
3139
if (p_cache != NULL)
3141
gaiaResetGeosMsg_r (p_cache);
3142
valid = gaiaIsValid_r (p_cache, geom);
3143
error = gaiaGetGeosErrorMsg_r (p_cache);
3144
warning = gaiaGetGeosWarningMsg_r (p_cache);
3145
extra = gaiaGetGeosAuxErrorMsg_r (p_cache);
3149
gaiaResetGeosMsg ();
3150
valid = gaiaIsValid (geom);
3151
error = gaiaGetGeosErrorMsg ();
3152
warning = gaiaGetGeosWarningMsg ();
3153
extra = gaiaGetGeosAuxErrorMsg ();
3019
3155
if (!valid || error || warning)
3020
3156
addMessageToValidityReport (report, rowid, valid,
3021
3157
error, warning, extra);
3284
3420
SPATIALITE_DECLARE int
3285
check_all_geometry_columns (sqlite3 * sqlite,
3286
const char *output_dir, int *x_invalids,
3421
check_geometry_column (sqlite3 * sqlite, const char *table, const char *geom,
3422
const char *report_path, int *n_rows, int *n_invalids,
3425
return check_geometry_column_common (NULL, sqlite, table, geom, report_path,
3426
n_rows, n_invalids, err_msg);
3429
SPATIALITE_DECLARE int
3430
check_geometry_column_r (const void *p_cache, sqlite3 * sqlite,
3431
const char *table, const char *geom,
3432
const char *report_path, int *n_rows, int *n_invalids,
3435
return check_geometry_column_common (p_cache, sqlite, table, geom,
3436
report_path, n_rows, n_invalids,
3441
check_all_geometry_columns_common (const void *p_cache, sqlite3 * sqlite,
3442
const char *output_dir, int *x_invalids,
3289
3445
/* checks all Geometry Columns for validity */
3290
3446
const char *sql;
3432
3588
const char *table = results[(i * columns) + 0];
3433
3589
const char *geom = results[(i * columns) + 1];
3434
3590
report = sqlite3_mprintf ("%s/lyr_%04d.html", output_dir, i);
3436
check_geometry_column (sqlite, table, geom, report, &n_rows,
3437
&n_invalids, err_msg);
3591
if (p_cache != NULL)
3593
check_geometry_column_r (p_cache, sqlite, table, geom,
3594
report, &n_rows, &n_invalids,
3598
check_geometry_column (sqlite, table, geom, report,
3599
&n_rows, &n_invalids, err_msg);
3438
3600
sqlite3_free (report);
3440
3602
"\t\t\t<tr><td align=\"center\"><a href=\"./lyr_%04d.html\">show</a></td>",
3637
SPATIALITE_DECLARE int
3638
check_all_geometry_columns (sqlite3 * sqlite,
3639
const char *output_dir, int *x_invalids,
3642
return check_all_geometry_columns_common (NULL, sqlite, output_dir,
3643
x_invalids, err_msg);
3646
SPATIALITE_DECLARE int
3647
check_all_geometry_columns_r (const void *p_cache, sqlite3 * sqlite,
3648
const char *output_dir, int *x_invalids,
3651
return check_all_geometry_columns_common (p_cache, sqlite, output_dir,
3652
x_invalids, err_msg);
3499
3678
SPATIALITE_DECLARE int
3679
check_all_geometry_columns_r (const void *p_cache, sqlite3 * sqlite,
3680
const char *output_dir, int *x_invalids,
3683
/* GEOS isn't enabled: always returning an error */
3685
const char *msg = "Sorry ... libspatialite was built disabling LWGEOM\n"
3686
"and is thus unable to support IsValid";
3687
/* silencing stupid compiler warnings */
3688
if (p_cache == NULL || sqlite == NULL || output_dir == NULL
3689
|| x_invalids == NULL)
3692
if (err_msg == NULL)
3695
*err_msg = malloc (len + 1);
3696
strcpy (*err_msg, msg);
3700
SPATIALITE_DECLARE int
3500
3701
check_geometry_column (sqlite3 * sqlite,
3501
3702
const char *table,
3502
3703
const char *geom,
3511
3712
/* silencing stupid compiler warnings */
3512
3713
if (sqlite == NULL || table == NULL || geom == NULL ||
3513
||report_path == NULL || n_rows == NULL || n_invalids == NULL)
3714
report_path == NULL || n_rows == NULL || n_invalids == NULL)
3717
if (err_msg == NULL)
3720
*err_msg = malloc (len + 1);
3721
strcpy (*err_msg, msg);
3725
SPATIALITE_DECLARE int
3726
check_geometry_column_r (const void *p_cache, sqlite3 * sqlite,
3729
const char *report_path,
3730
int *n_rows, int *n_invalids, char **err_msg)
3732
/* GEOS isn't enabled: always returning an error */
3734
const char *msg = "Sorry ... libspatialite was built disabling GEOS\n"
3735
"and is thus unable to support IsValid";
3737
/* silencing stupid compiler warnings */
3738
if (p_cache == NULL || sqlite == NULL || table == NULL || geom == NULL ||
3739
report_path == NULL || n_rows == NULL || n_invalids == NULL)
3516
3742
if (err_msg == NULL)