Check-in [eaf8c35bda]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:supporting RTTOPO 1.1 new API
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: eaf8c35bda4b55ca59c91bdcf0e288697d7a76ad
User & Date: sandro 2016-11-04 11:08:48
Context
2016-11-07
10:58
adding testcases for NoFace/Polygonize - RTTOPO 1.1 check-in: b3a91f678f user: sandro tags: trunk
2016-11-04
11:08
supporting RTTOPO 1.1 new API check-in: eaf8c35bda user: sandro tags: trunk
2016-10-17
08:21
initial implementation of VirtualRouting check-in: ec084cb63b user: sandro tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to configure.

18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518

else
  as_fn_error $? "cannot find librttopo.h, bailing out" "$LINENO" 5
fi

done

	  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing rtgeom_make_valid" >&5
$as_echo_n "checking for library containing rtgeom_make_valid... " >&6; }
if ${ac_cv_search_rtgeom_make_valid+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_func_search_save_LIBS=$LIBS
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
#ifdef __cplusplus
extern "C"
#endif
char rtgeom_make_valid ();
int
main ()
{
return rtgeom_make_valid ();
  ;
  return 0;
}
_ACEOF
for ac_lib in '' rttopo; do
  if test -z "$ac_lib"; then
    ac_res="none required"
  else
    ac_res=-l$ac_lib
    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
  fi
  if ac_fn_c_try_link "$LINENO"; then :
  ac_cv_search_rtgeom_make_valid=$ac_res
fi
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext
  if ${ac_cv_search_rtgeom_make_valid+:} false; then :
  break
fi
done
if ${ac_cv_search_rtgeom_make_valid+:} false; then :

else
  ac_cv_search_rtgeom_make_valid=no
fi
rm conftest.$ac_ext
LIBS=$ac_func_search_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_rtgeom_make_valid" >&5
$as_echo "$ac_cv_search_rtgeom_make_valid" >&6; }
ac_res=$ac_cv_search_rtgeom_make_valid
if test "$ac_res" != no; then :
  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"

else
  as_fn_error $? "'librttopo' is required but it doesn't seem to be installed on this system. You may need to try re-running configure with a --disable-rttopo parameter." "$LINENO" 5
fi

	  $as_echo "#define ENABLE_RTTOPO 1" >>confdefs.h

  fi
else
  $as_echo "#define OMIT_GEOS 1" >>confdefs.h







|
|
|












|



|












|



|



|


|




|
|
|




|







18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518

else
  as_fn_error $? "cannot find librttopo.h, bailing out" "$LINENO" 5
fi

done

	  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing rtt_AddLineNoFace" >&5
$as_echo_n "checking for library containing rtt_AddLineNoFace... " >&6; }
if ${ac_cv_search_rtt_AddLineNoFace+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_func_search_save_LIBS=$LIBS
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
#ifdef __cplusplus
extern "C"
#endif
char rtt_AddLineNoFace ();
int
main ()
{
return rtt_AddLineNoFace ();
  ;
  return 0;
}
_ACEOF
for ac_lib in '' rttopo; do
  if test -z "$ac_lib"; then
    ac_res="none required"
  else
    ac_res=-l$ac_lib
    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
  fi
  if ac_fn_c_try_link "$LINENO"; then :
  ac_cv_search_rtt_AddLineNoFace=$ac_res
fi
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext
  if ${ac_cv_search_rtt_AddLineNoFace+:} false; then :
  break
fi
done
if ${ac_cv_search_rtt_AddLineNoFace+:} false; then :

else
  ac_cv_search_rtt_AddLineNoFace=no
fi
rm conftest.$ac_ext
LIBS=$ac_func_search_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_rtt_AddLineNoFace" >&5
$as_echo "$ac_cv_search_rtt_AddLineNoFace" >&6; }
ac_res=$ac_cv_search_rtt_AddLineNoFace
if test "$ac_res" != no; then :
  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"

else
  as_fn_error $? "'librttopo' (>= v.1.1.0) is required but it doesn't seem to be installed on this system. You may need to try re-running configure with a --disable-rttopo parameter." "$LINENO" 5
fi

	  $as_echo "#define ENABLE_RTTOPO 1" >>confdefs.h

  fi
else
  $as_echo "#define OMIT_GEOS 1" >>confdefs.h

Changes to configure.ac.

353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
  #   --enable-rttopo
  #
  AC_ARG_ENABLE(rttopo, [AS_HELP_STRING(
	  [--enable-rttopo], [enables RTTOPO support [default=no]])],
	  [], [enable_rttopo=no])
  if test x"$enable_rttopo" != "xno"; then
	  AC_CHECK_HEADERS(librttopo.h,, [AC_MSG_ERROR([cannot find librttopo.h, bailing out])])
	  AC_SEARCH_LIBS(rtgeom_make_valid,rttopo,,AC_MSG_ERROR(['librttopo' is required but it doesn't seem to be installed on this system. You may need to try re-running configure with a --disable-rttopo parameter.]))
	  AC_DEFINE(ENABLE_RTTOPO)
  fi
else
  AC_DEFINE(OMIT_GEOS)
fi

#-----------------------------------------------------------------------







|







353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
  #   --enable-rttopo
  #
  AC_ARG_ENABLE(rttopo, [AS_HELP_STRING(
	  [--enable-rttopo], [enables RTTOPO support [default=no]])],
	  [], [enable_rttopo=no])
  if test x"$enable_rttopo" != "xno"; then
	  AC_CHECK_HEADERS(librttopo.h,, [AC_MSG_ERROR([cannot find librttopo.h, bailing out])])
	  AC_SEARCH_LIBS(rtt_AddLineNoFace,rttopo,,AC_MSG_ERROR(['librttopo' (>= v.1.1.0) is required but it doesn't seem to be installed on this system. You may need to try re-running configure with a --disable-rttopo parameter.]))
	  AC_DEFINE(ENABLE_RTTOPO)
  fi
else
  AC_DEFINE(OMIT_GEOS)
fi

#-----------------------------------------------------------------------

Changes to src/gaiageo/gg_rttopo.c.

1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192


1193
1194
1195
1196
1197
1198
1199
	  gaia = NULL;
	  break;
      };

    return gaia;
}

static gaiaGeomCollPtr
fromRTGeom (const RTCTX * ctx, const RTGEOM * rtgeom, const int dimension_model,
	    const int declared_type)
{
/* converting a RTGEOM Geometry into a GAIA Geometry */
    gaiaGeomCollPtr gaia = NULL;



    if (rtgeom == NULL)
	return NULL;
    if (rtgeom_is_empty (ctx, rtgeom))
	return NULL;

    if (dimension_model == GAIA_XY_Z)







|
|




>
>







1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
	  gaia = NULL;
	  break;
      };

    return gaia;
}

SPATIALITE_PRIVATE void *
fromRTGeom (const void * pctx, const void * prtgeom, const int dimension_model,
	    const int declared_type)
{
/* converting a RTGEOM Geometry into a GAIA Geometry */
    gaiaGeomCollPtr gaia = NULL;
    const RTCTX * ctx = (const RTCTX *)pctx;
    const RTGEOM * rtgeom = (const RTGEOM *)prtgeom;

    if (rtgeom == NULL)
	return NULL;
    if (rtgeom_is_empty (ctx, rtgeom))
	return NULL;

    if (dimension_model == GAIA_XY_Z)

Changes to src/headers/spatialite/gaia_topology.h.

564
565
566
567
568
569
570



















571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589































590
591
592
593
594
595
596
...
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637






























638
639
640
641
642
643
644
...
655
656
657
658
659
660
661
662
663
664
665
666




































667
668
669
670
671
672
673

 \sa gaiaTopologyFromDBMS
 */
    GAIATOPO_DECLARE sqlite3_int64
	gaiaTopoGeo_AddPoint (GaiaTopologyAccessorPtr ptr, gaiaPointPtr pt,
			      double tolerance);




















/**
 Adds a Linestring to an existing Topology and possibly splitting Edges/Faces.

 \param ptr pointer to the Topology Accessor Object.
 \param ln pointer to the Linestring Geometry.
 \param tolerance approximation factor.
 \param edge_ids on success will point to an array of Edge IDs
 \param ids_count on success will report the number of Edge IDs in the
 above array

 \return 1 on success; 0 on failure.

 \sa gaiaTopologyFromDBMS
 */
    GAIATOPO_DECLARE int
	gaiaTopoGeo_AddLineString (GaiaTopologyAccessorPtr ptr,
				   gaiaLinestringPtr pt, double tolerance,
				   sqlite3_int64 ** edge_ids, int *ids_count);
































/**
 Adds a Polygon to an existing Topology and possibly splitting Edges/Faces.

 \param ptr pointer to the Topology Accessor Object.
 \param pg pointer to the Polygon Geometry.
 \param tolerance approximation factor.
 \param face_ids on success will point to an array of Face IDs
................................................................................
 and/or Polygon Rings will be split into simpler Lines having a length
 not exceeding this threshold. If both line_max_points and max_legth
 are set as the same time the first condition occurring will cause
 a new Line to be started. 

 \return 1 on success; -1 on failure (will raise an exception).

 \sa gaiaTopologyFromDBMS
 */
    GAIATOPO_DECLARE int
	gaiaTopoGeo_FromGeoTable (GaiaTopologyAccessorPtr ptr,
				  const char *db_prefix, const char *table,
				  const char *column, double tolerance,
				  int line_max_points, double max_length);































/**
 Populates a Topology by importing a whole GeoTable - Extended mode

 \param ptr pointer to the Topology Accessor Object.
 \param sql_in an SQL statement (SELECT) returning input features
 \param sql_out a second SQL statement (INSERT INTO) intended to
 store failing features references into the "dustbin" table.
................................................................................
 a new Line to be started. 

 \return 0 if all input features were succesfully importer, or a
 positive number (total count of failing features raising an exception
 and referenced by the "dustbin" table); -1 if some unexpected
 error occurred.

 \sa gaiaTopologyFromDBMS
 */
    GAIATOPO_DECLARE int
	gaiaTopoGeo_FromGeoTableExtended (GaiaTopologyAccessorPtr ptr,
					  const char *sql_in,




































					  const char *sql_out,
					  const char *sql_in2, double tolerance,
					  int line_max_points,
					  double max_length);

/**
 Creates a temporary table containing a validation report for a given TopoGeo.







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>












|


|



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
...
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
...
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789

 \sa gaiaTopologyFromDBMS
 */
    GAIATOPO_DECLARE sqlite3_int64
	gaiaTopoGeo_AddPoint (GaiaTopologyAccessorPtr ptr, gaiaPointPtr pt,
			      double tolerance);

/**
 Adds a Linestring to an existing Topology without determining generated faces..

 \param ptr pointer to the Topology Accessor Object.
 \param ln pointer to the Linestring Geometry.
 \param tolerance approximation factor.
 \param edge_ids on success will point to an array of Edge IDs
 \param ids_count on success will report the number of Edge IDs in the
 above array

 \return 1 on success; 0 on failure.

 \sa gaiaTopologyFromDBMS, gaiaTopoGeo_AddLineStringNoFace
 */
    GAIATOPO_DECLARE int
	gaiaTopoGeo_AddLineString (GaiaTopologyAccessorPtr ptr,
				   gaiaLinestringPtr pt, double tolerance,
				   sqlite3_int64 ** edge_ids, int *ids_count);

/**
 Adds a Linestring to an existing Topology and possibly splitting Edges/Faces.

 \param ptr pointer to the Topology Accessor Object.
 \param ln pointer to the Linestring Geometry.
 \param tolerance approximation factor.
 \param edge_ids on success will point to an array of Edge IDs
 \param ids_count on success will report the number of Edge IDs in the
 above array

 \return 1 on success; 0 on failure.

 \sa gaiaTopologyFromDBMS, gaiaTopoGeo_AddLineString, gaiaTopoGeo_Polygonize
 */
    GAIATOPO_DECLARE int
	gaiaTopoGeo_AddLineStringNoFace (GaiaTopologyAccessorPtr ptr,
				   gaiaLinestringPtr pt, double tolerance,
				   sqlite3_int64 ** edge_ids, int *ids_count);

/**
 Determine and register all topology faces.

 \param ptr pointer to the Topology Accessor Object.

 \return 1 on success; 0 on failure.

 \sa gaiaTopologyFromDBMS, gaiaTopoGeo_AddLineStringNoFace, 
 gaiaTopoGeo_FromGeoTableNoFace, FromGeoTableNoFaceExt
 */
    GAIATOPO_DECLARE int
	gaiaTopoGeo_Polygonize (GaiaTopologyAccessorPtr ptr);

/**
 Snap Geometry to Topology.

 \param ptr pointer to the Topology Accessor Object.
 \param geom pointer to the input Geometry.
 \param tolerance approximation factor.
 \param iterate if non zero, allows snapping to more than a single 
 vertex, iteratively
 \param remove_vertices if non zero, makes an initial pass removing
 vertices within tolerance

 \return pointer to the snapped Geometry; NULL on failure.

 \sa gaiaTopologyFromDBMS
 */
    GAIATOPO_DECLARE gaiaGeomCollPtr
	gaiaTopoSnap (GaiaTopologyAccessorPtr ptr, gaiaGeomCollPtr geom, double tolerance, int iterate, int remove_vertices);

/**
 Adds a Polygon to an existing Topology and possibly splitting Edges/Faces.

 \param ptr pointer to the Topology Accessor Object.
 \param pg pointer to the Polygon Geometry.
 \param tolerance approximation factor.
 \param face_ids on success will point to an array of Face IDs
................................................................................
 and/or Polygon Rings will be split into simpler Lines having a length
 not exceeding this threshold. If both line_max_points and max_legth
 are set as the same time the first condition occurring will cause
 a new Line to be started. 

 \return 1 on success; -1 on failure (will raise an exception).

 \sa gaiaTopologyFromDBMS, gaiaTopoGeo_FromGeoTableNoFace
 */
    GAIATOPO_DECLARE int
	gaiaTopoGeo_FromGeoTable (GaiaTopologyAccessorPtr ptr,
				  const char *db_prefix, const char *table,
				  const char *column, double tolerance,
				  int line_max_points, double max_length);

/**
 Populates a Topology by importing a whole GeoTable without 
 determining generated faces

 \param ptr pointer to the Topology Accessor Object.
 \param db-prefix prefix of the DB containing the input GeoTable.
 If NULL the "main" DB will be intended by default.
 \param table name of the input GeoTable.
 \param column name of the input Geometry Column.
 Could be NULL is the input table has just a single Geometry Column.
 \param tolerance approximation factor.
 \param line_max_points if set to a positive number all input Linestrings
 and/or Polygon Rings will be split into simpler Linestrings having no more 
 than this maximum number of points. 
 \param max_length if set to a positive value all input Linestrings 
 and/or Polygon Rings will be split into simpler Lines having a length
 not exceeding this threshold. If both line_max_points and max_legth
 are set as the same time the first condition occurring will cause
 a new Line to be started. 

 \return 1 on success; -1 on failure (will raise an exception).

 \sa gaiaTopologyFromDBMS, gaiaTopoGeo_FromGeoTable, gaiaTopoGeo_Polygonize
 */
    GAIATOPO_DECLARE int
	gaiaTopoGeo_FromGeoTableNoFace (GaiaTopologyAccessorPtr ptr,
				  const char *db_prefix, const char *table,
				  const char *column, double tolerance,
				  int line_max_points, double max_length);

/**
 Populates a Topology by importing a whole GeoTable - Extended mode

 \param ptr pointer to the Topology Accessor Object.
 \param sql_in an SQL statement (SELECT) returning input features
 \param sql_out a second SQL statement (INSERT INTO) intended to
 store failing features references into the "dustbin" table.
................................................................................
 a new Line to be started. 

 \return 0 if all input features were succesfully importer, or a
 positive number (total count of failing features raising an exception
 and referenced by the "dustbin" table); -1 if some unexpected
 error occurred.

 \sa gaiaTopologyFromDBMS, gaiaTopoGeo_FromGeoTableNoFaceExtended
 */
    GAIATOPO_DECLARE int
	gaiaTopoGeo_FromGeoTableExtended (GaiaTopologyAccessorPtr ptr,
					  const char *sql_in,
					  const char *sql_out,
					  const char *sql_in2, double tolerance,
					  int line_max_points,
					  double max_length);

/**
 Populates a Topology by importing a whole GeoTable without 
 determining generated faces - Extended mode

 \param ptr pointer to the Topology Accessor Object.
 \param sql_in an SQL statement (SELECT) returning input features
 \param sql_out a second SQL statement (INSERT INTO) intended to
 store failing features references into the "dustbin" table.
 \param sql_in2 an SQL statement (SELECT) returning a single input 
 feature (used for retrying to insert a failing feature)
 \param tolerance approximation factor.
 \param line_max_points if set to a positive number all input Linestrings
 and/or Polygon Rings will be split into simpler Linestrings having no more 
 than this maximum number of points. 
 \param max_length if set to a positive value all input Linestrings 
 and/or Polygon Rings will be split into simpler Lines having a length
 not exceeding this threshold. If both line_max_points and max_legth
 are set as the same time the first condition occurring will cause
 a new Line to be started. 

 \return 0 if all input features were succesfully importer, or a
 positive number (total count of failing features raising an exception
 and referenced by the "dustbin" table); -1 if some unexpected
 error occurred.

 \sa gaiaTopologyFromDBMS, gaiaTopoGeo_FromGeoTableExtended, 
 gaiaTopoGeo_Polygonize
 */
    GAIATOPO_DECLARE int
	gaiaTopoGeo_FromGeoTableNoFaceExtended (GaiaTopologyAccessorPtr ptr,
					  const char *sql_in,
					  const char *sql_out,
					  const char *sql_in2, double tolerance,
					  int line_max_points,
					  double max_length);

/**
 Creates a temporary table containing a validation report for a given TopoGeo.

Changes to src/headers/spatialite_private.h.

720
721
722
723
724
725
726


727
728
729
730
731
732
733
...
807
808
809
810
811
812
813








814
815
816
817




818
819
820
821












822
823
824
825
826
827
828
    SPATIALITE_PRIVATE int gaiaAuxClonerExecute (const void *cloner);

    SPATIALITE_PRIVATE int gaia_matrix_to_arrays (const unsigned char *blob,
						  int blob_sz, double *E,
						  double *N, double *Z);

/* Topology SQL functions */


    SPATIALITE_PRIVATE void fnctaux_GetLastTopologyException (const void
							      *context,
							      int argc,
							      const void *argv);

    SPATIALITE_PRIVATE void fnctaux_CreateTopology (const void *context,
						    int argc, const void *argv);
................................................................................
    SPATIALITE_PRIVATE void fnctaux_TopoGeo_AddPoint (const void *context,
						      int argc,
						      const void *argv);

    SPATIALITE_PRIVATE void fnctaux_TopoGeo_AddLineString (const void *context,
							   int argc,
							   const void *argv);









    SPATIALITE_PRIVATE void fnctaux_TopoGeo_FromGeoTable (const void *context,
							  int argc,
							  const void *argv);





    SPATIALITE_PRIVATE void fnctaux_TopoGeo_FromGeoTableExt (const void
							     *context, int argc,
							     const void *argv);













    SPATIALITE_PRIVATE void fnctaux_TopoGeo_ToGeoTable (const void *context,
							int argc,
							const void *argv);

    SPATIALITE_PRIVATE void fnctaux_TopoGeo_ToGeoTableGeneralize (const void
								  *context,







>
>







 







>
>
>
>
>
>
>
>




>
>
>
>




>
>
>
>
>
>
>
>
>
>
>
>







720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
...
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
    SPATIALITE_PRIVATE int gaiaAuxClonerExecute (const void *cloner);

    SPATIALITE_PRIVATE int gaia_matrix_to_arrays (const unsigned char *blob,
						  int blob_sz, double *E,
						  double *N, double *Z);

/* Topology SQL functions */
	SPATIALITE_PRIVATE void * fromRTGeom (const void * ctx, const void * rtgeom, const int dimension_model, const int declared_type);
	
    SPATIALITE_PRIVATE void fnctaux_GetLastTopologyException (const void
							      *context,
							      int argc,
							      const void *argv);

    SPATIALITE_PRIVATE void fnctaux_CreateTopology (const void *context,
						    int argc, const void *argv);
................................................................................
    SPATIALITE_PRIVATE void fnctaux_TopoGeo_AddPoint (const void *context,
						      int argc,
						      const void *argv);

    SPATIALITE_PRIVATE void fnctaux_TopoGeo_AddLineString (const void *context,
							   int argc,
							   const void *argv);

    SPATIALITE_PRIVATE void fnctaux_TopoGeo_AddLineStringNoFace (const void *context,
							   int argc,
							   const void *argv);

    SPATIALITE_PRIVATE void fnctaux_TopoGeo_Polygonize (const void *context,
							   int argc,
							   const void *argv);

    SPATIALITE_PRIVATE void fnctaux_TopoGeo_FromGeoTable (const void *context,
							  int argc,
							  const void *argv);

    SPATIALITE_PRIVATE void fnctaux_TopoGeo_FromGeoTableNoFace (const void *context,
							  int argc,
							  const void *argv);

    SPATIALITE_PRIVATE void fnctaux_TopoGeo_FromGeoTableExt (const void
							     *context, int argc,
							     const void *argv);

    SPATIALITE_PRIVATE void fnctaux_TopoGeo_FromGeoTableNoFaceExt (const void
							     *context, int argc,
							     const void *argv);

    SPATIALITE_PRIVATE void fnctaux_Polygonize (const void
							     *context, int argc,
							     const void *argv);

    SPATIALITE_PRIVATE void fnctaux_TopoSnap (const void
							     *context, int argc,
							     const void *argv);

    SPATIALITE_PRIVATE void fnctaux_TopoGeo_ToGeoTable (const void *context,
							int argc,
							const void *argv);

    SPATIALITE_PRIVATE void fnctaux_TopoGeo_ToGeoTableGeneralize (const void
								  *context,

Changes to src/spatialite/spatialite.c.

35413
35414
35415
35416
35417
35418
35419







35420
35421
35422
35423
35424
35425
35426







35427
35428
35429
35430
35431
35432
35433





















35434
35435
35436
35437
35438
35439
35440
.....
39037
39038
39039
39040
39041
39042
39043



39044
39045
39046
39047
39048
39049






39050
39051
39052
39053
39054
39055












39056
39057
39058
39059
39060
39061
39062

static void
fnct_TopoGeo_AddLineString (sqlite3_context * context, int argc,
			    sqlite3_value ** argv)
{
    fnctaux_TopoGeo_AddLineString (context, argc, argv);
}








static void
fnct_TopoGeo_FromGeoTable (sqlite3_context * context, int argc,
			   sqlite3_value ** argv)
{
    fnctaux_TopoGeo_FromGeoTable (context, argc, argv);
}








static void
fnct_TopoGeo_FromGeoTableExt (sqlite3_context * context, int argc,
			      sqlite3_value ** argv)
{
    fnctaux_TopoGeo_FromGeoTableExt (context, argc, argv);
}






















static void
fnct_TopoGeo_ToGeoTable (sqlite3_context * context, int argc,
			 sqlite3_value ** argv)
{
    fnctaux_TopoGeo_ToGeoTable (context, argc, argv);
}
................................................................................
				      fnct_GetFaceByPoint, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_AddPoint", 3,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_AddPoint, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_AddLineString", 3,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_AddLineString, 0, 0, 0);



	  sqlite3_create_function_v2 (db, "TopoGeo_FromGeoTable", 5,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_FromGeoTable, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_FromGeoTable", 7,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_FromGeoTable, 0, 0, 0);






	  sqlite3_create_function_v2 (db, "TopoGeo_FromGeoTableExt", 7,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_FromGeoTableExt, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_FromGeoTableExt", 9,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_FromGeoTableExt, 0, 0, 0);












	  sqlite3_create_function_v2 (db, "TopoGeo_ToGeoTable", 5,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_ToGeoTable, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_ToGeoTable", 6,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_ToGeoTable, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_ToGeoTableGeneralize", 6,







>
>
>
>
>
>
>







>
>
>
>
>
>
>







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>






>
>
>
>
>
>






>
>
>
>
>
>
>
>
>
>
>
>







35413
35414
35415
35416
35417
35418
35419
35420
35421
35422
35423
35424
35425
35426
35427
35428
35429
35430
35431
35432
35433
35434
35435
35436
35437
35438
35439
35440
35441
35442
35443
35444
35445
35446
35447
35448
35449
35450
35451
35452
35453
35454
35455
35456
35457
35458
35459
35460
35461
35462
35463
35464
35465
35466
35467
35468
35469
35470
35471
35472
35473
35474
35475
.....
39072
39073
39074
39075
39076
39077
39078
39079
39080
39081
39082
39083
39084
39085
39086
39087
39088
39089
39090
39091
39092
39093
39094
39095
39096
39097
39098
39099
39100
39101
39102
39103
39104
39105
39106
39107
39108
39109
39110
39111
39112
39113
39114
39115
39116
39117
39118

static void
fnct_TopoGeo_AddLineString (sqlite3_context * context, int argc,
			    sqlite3_value ** argv)
{
    fnctaux_TopoGeo_AddLineString (context, argc, argv);
}

static void
fnct_TopoGeo_AddLineStringNoFace (sqlite3_context * context, int argc,
			    sqlite3_value ** argv)
{
    fnctaux_TopoGeo_AddLineStringNoFace (context, argc, argv);
}

static void
fnct_TopoGeo_FromGeoTable (sqlite3_context * context, int argc,
			   sqlite3_value ** argv)
{
    fnctaux_TopoGeo_FromGeoTable (context, argc, argv);
}

static void
fnct_TopoGeo_FromGeoTableNoFace (sqlite3_context * context, int argc,
			   sqlite3_value ** argv)
{
    fnctaux_TopoGeo_FromGeoTableNoFace (context, argc, argv);
}

static void
fnct_TopoGeo_FromGeoTableExt (sqlite3_context * context, int argc,
			      sqlite3_value ** argv)
{
    fnctaux_TopoGeo_FromGeoTableExt (context, argc, argv);
}

static void
fnct_TopoGeo_FromGeoTableNoFaceExt (sqlite3_context * context, int argc,
			      sqlite3_value ** argv)
{
    fnctaux_TopoGeo_FromGeoTableNoFaceExt (context, argc, argv);
}

static void
fnct_TopoGeo_Polygonize (sqlite3_context * context, int argc,
			      sqlite3_value ** argv)
{
    fnctaux_TopoGeo_Polygonize (context, argc, argv);
}

static void
fnct_TopoSnap (sqlite3_context * context, int argc,
			      sqlite3_value ** argv)
{
    fnctaux_TopoSnap (context, argc, argv);
}

static void
fnct_TopoGeo_ToGeoTable (sqlite3_context * context, int argc,
			 sqlite3_value ** argv)
{
    fnctaux_TopoGeo_ToGeoTable (context, argc, argv);
}
................................................................................
				      fnct_GetFaceByPoint, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_AddPoint", 3,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_AddPoint, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_AddLineString", 3,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_AddLineString, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_AddLineStringNoFace", 3,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_AddLineStringNoFace, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_FromGeoTable", 5,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_FromGeoTable, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_FromGeoTable", 7,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_FromGeoTable, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_FromGeoTableNoFace", 5,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_FromGeoTableNoFace, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_FromGeoTableNoFace", 7,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_FromGeoTableNoFace, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_FromGeoTableExt", 7,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_FromGeoTableExt, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_FromGeoTableExt", 9,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_FromGeoTableExt, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_FromGeoTableNoFaceExt", 7,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_FromGeoTableNoFaceExt, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_FromGeoTableNoFaceExt", 9,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_FromGeoTableNoFaceExt, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_Polygonize", 1,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_Polygonize, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "ST_TopoSnap", 5,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoSnap, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_ToGeoTable", 5,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_ToGeoTable, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_ToGeoTable", 6,
				      SQLITE_UTF8 | SQLITE_DETERMINISTIC, cache,
				      fnct_TopoGeo_ToGeoTable, 0, 0, 0);
	  sqlite3_create_function_v2 (db, "TopoGeo_ToGeoTableGeneralize", 6,

Changes to src/spatialite/virtualfdo.c.

1823
1824
1825
1826
1827
1828
1829



1830
1831
1832
1833
1834
1835
1836
1837
		*(p_vt->Format + i) = FDO_OGR_NONE;
		*(p_vt->CoordDimensions + i) = GAIA_XY;
	    }
	  for (i = 1; i <= n_rows; i++)
	    {
		col_name = results[(i * n_columns) + 0];
		type = atoi (results[(i * n_columns) + 1]);



		srid = atoi (results[(i * n_columns) + 2]);
		format = results[(i * n_columns) + 3];
		coord_dimension = atoi (results[(i * n_columns) + 4]);
		len = strlen (col_name);
		*(p_vt->GeoColumn + (i - 1)) = sqlite3_malloc (len + 1);
		strcpy (*(p_vt->GeoColumn + (i - 1)), col_name);
		*(p_vt->GeoType + (i - 1)) = type;
		*(p_vt->Srid + (i - 1)) = srid;







>
>
>
|







1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
		*(p_vt->Format + i) = FDO_OGR_NONE;
		*(p_vt->CoordDimensions + i) = GAIA_XY;
	    }
	  for (i = 1; i <= n_rows; i++)
	    {
		col_name = results[(i * n_columns) + 0];
		type = atoi (results[(i * n_columns) + 1]);
		if (results[(i * n_columns) + 2] == NULL)
		    srid = -1;
		else
		    srid = atoi (results[(i * n_columns) + 2]);
		format = results[(i * n_columns) + 3];
		coord_dimension = atoi (results[(i * n_columns) + 4]);
		len = strlen (col_name);
		*(p_vt->GeoColumn + (i - 1)) = sqlite3_malloc (len + 1);
		strcpy (*(p_vt->GeoColumn + (i - 1)), col_name);
		*(p_vt->GeoType + (i - 1)) = type;
		*(p_vt->Srid + (i - 1)) = srid;

Changes to src/spatialite/virtualrouting.c.

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

83
84


85
86
87
88
89
90
91
...
205
206
207
208
209
210
211

212
213
214
215
216
217
218
...
223
224
225
226
227
228
229

230
231
232
233
234
235
236
...
282
283
284
285
286
287
288

289
290
291
292
293










































294
295
296
297
298
299
300
...
582
583
584
585
586
587
588


589
590
591
592
593
594
595
...
596
597
598
599
600
601
602

603
604
605
606
607
608
609
....
1186
1187
1188
1189
1190
1191
1192


1193
1194
1195
1196
1197
1198
1199
....
1205
1206
1207
1208
1209
1210
1211

1212
1213
1214
1215
1216
1217
1218
....
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233

1234
1235
1236
1237
1238
1239
1240
1241
1242

1243
1244
1245
1246

1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298

1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324



1325
















1326
1327
1328
1329

1330
1331

1332

1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356

1357
1358
1359
1360
1361
1362
1363
....
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385

1386
1387
1388
1389
1390
1391
1392
....
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403

1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417












1418
1419
1420
1421
1422
1423
1424
....
1425
1426
1427
1428
1429
1430
1431




1432

1433
1434
1435
1436











1437
1438


1439
1440
1441



1442
1443





1444

1445
1446
1447
1448

1449
1450
























1451





1452




1453
1454
1455
1456
1457
1458




















1459


















1460
1461


1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482




1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496

1497
1498
1499
1500
1501
1502
1503
1504
1505



1506
1507
1508
1509
1510
1511
1512
....
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
























































































































1614
1615
1616
1617
1618
1619
1620
....
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657

1658
1659





1660
1661
1662




1663
1664
1665
1666
1667
1668
1669
....
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687











1688
1689
1690
1691
1692
1693
1694
....
1724
1725
1726
1727
1728
1729
1730


1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741


1742
1743
1744
1745
1746
1747
1748
1749
1750
1751













1752
1753
1754
1755
1756
1757
1758
1759
....
1862
1863
1864
1865
1866
1867
1868

1869


1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
....
2448
2449
2450
2451
2452
2453
2454

2455
2456
2457
2458
2459
2460


2461
2462
2463
2464
2465
2466
2467
2468
....
2547
2548
2549
2550
2551
2552
2553


2554
2555
2556
2557
2558
2559
2560
....
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778



2779
2780


























2781
2782
2783
2784
2785
2786
2787
....
2789
2790
2791
2792
2793
2794
2795










































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































2796
2797
2798
2799
2800
2801
2802
....
3765
3766
3767
3768
3769
3770
3771












3772
3773
3774
3775
3776
3777
3778
....
4001
4002
4003
4004
4005
4006
4007


4008
4009
4010
4011
4012
4013
4014
....
4042
4043
4044
4045
4046
4047
4048



































































































































4049
4050
4051
4052
4053
4054
4055
....
4063
4064
4065
4066
4067
4068
4069


4070
4071
4072
4073
4074
4075
4076
....
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127


4128
4129
4130
4131

4132
4133
4134
4135
4136
4137
4138
....
4165
4166
4167
4168
4169
4170
4171



4172
4173
4174
4175
4176
4177
4178
4179
....
4207
4208
4209
4210
4211
4212
4213


4214
4215
4216
4217
4218
4219
4220
....
4377
4378
4379
4380
4381
4382
4383



4384
4385
4386
4387
4388
4389
4390

static struct sqlite3_module my_route_module;

#define VROUTE_DIJKSTRA_ALGORITHM	1
#define VROUTE_A_STAR_ALGORITHM	2

#define VROUTE_ROUTING_SOLUTION	0xdd
#define VROUTE_RANGE_SOLUTION		0xbb
#define VROUTE_TSP_SOLUTION		0xee

#define VROUTE_SHORTEST_PATH_FULL		0x70
#define VROUTE_SHORTEST_PATH_NO_ARCS	0x71
#define VROUTE_SHORTEST_PATH_NO_GEOMS	0x72
#define VROUTE_SHORTEST_PATH_SIMPLE		0x73

#define VROUTE_SHORTEST_PATH			0x91
#define VROUTE_TSP_NN					0x92


#define VROUTE_INVALID_SRID	-1234



#ifdef _WIN32
#define strcasecmp	_stricmp
#endif /* not WIN32 */

/******************************************************************************
/
................................................................................
typedef struct ShortestPathSolutionStruct
{
/* a shortest path solution */
    ArcSolutionPtr FirstArc;
    ArcSolutionPtr LastArc;
    RouteNodePtr From;
    RouteNodePtr To;

    RowSolutionPtr First;
    RowSolutionPtr Last;
    RowNodeSolutionPtr FirstNode;
    RowNodeSolutionPtr LastNode;
    RowNodeSolutionPtr CurrentNodeRow;
    double TotalCost;
    gaiaGeomCollPtr Geometry;
................................................................................
typedef struct ResultsetRowStruct
{
/* a row into the resultset */
    int RouteNum;
    int RouteRow;
    RouteNodePtr From;
    RouteNodePtr To;

    RowSolutionPtr linkRef;
    double TotalCost;
    gaiaGeomCollPtr Geometry;
    struct ResultsetRowStruct *Next;

} ResultsetRow;
typedef ResultsetRow *ResultsetRowPtr;
................................................................................
/* TSP helper struct */
    unsigned char Mode;
    double TotalCost;
    RouteNodePtr From;
    int Count;
    RouteNodePtr *To;
    char *Found;

    ShortestPathSolutionPtr First;
    ShortestPathSolutionPtr Last;
} TspTargets;
typedef TspTargets *TspTargetsPtr;











































/******************************************************************************
/
/ Dijkstra and A* common structs
/
******************************************************************************/

typedef struct RoutingNode
................................................................................
    pN = solution->FirstNode;
    while (pN)
      {
	  pNn = pN->Next;
	  free (pN);
	  pN = pNn;
      }


    if (solution->Geometry)
	gaiaFreeGeomColl (solution->Geometry);
    free (solution);
}

static ShortestPathSolutionPtr
alloc_solution (void)
................................................................................
{
/* allocates and initializes the current solution */
    ShortestPathSolutionPtr p = malloc (sizeof (ShortestPathSolution));
    p->FirstArc = NULL;
    p->LastArc = NULL;
    p->From = NULL;
    p->To = NULL;

    p->First = NULL;
    p->Last = NULL;
    p->FirstNode = NULL;
    p->LastNode = NULL;
    p->CurrentNodeRow = NULL;
    p->TotalCost = 0.0;
    p->Geometry = NULL;
................................................................................
	  int route_row = 0;
	  RowSolutionPtr pA;
	  ResultsetRowPtr row = malloc (sizeof (ResultsetRow));
	  row->RouteNum = route_num;
	  row->RouteRow = route_row++;
	  row->From = pS->From;
	  row->To = pS->To;


	  row->linkRef = NULL;
	  row->TotalCost = pS->TotalCost;
	  row->Geometry = pS->Geometry;
	  row->Next = NULL;
	  if (multiSolution->FirstRow == NULL)
	      multiSolution->FirstRow = row;
	  if (multiSolution->LastRow != NULL)
................................................................................
	    {
		/* inserting Route's traversed Arcs */
		row = malloc (sizeof (ResultsetRow));
		row->RouteNum = route_num;
		row->RouteRow = route_row++;
		row->From = NULL;
		row->To = NULL;

		row->linkRef = pA;
		row->TotalCost = 0.0;
		row->Geometry = NULL;
		row->Next = NULL;
		if (multiSolution->FirstRow == NULL)
		    multiSolution->FirstRow = row;
		if (multiSolution->LastRow != NULL)
................................................................................
	    }
	  route_num++;
	  pS = pS->Next;
      }
}

static void
aux_build_tsp (MultiSolutionPtr multiSolution, ShortestPathSolutionPtr pStart,
	       ShortestPathSolutionPtr pStop, int *route_num, int *route_row,
	       gaiaLinestringPtr tsp_path, int *point_index, int start)
{
/* helper function: formatting the TSP resultset */

    ResultsetRowPtr row;
    ShortestPathSolutionPtr pS = pStart;
    while (pS != NULL)
      {
	  /* inserting the Route Header */
	  RowSolutionPtr pA;
	  *route_row = 0;
	  row = malloc (sizeof (ResultsetRow));
	  row->RouteNum = *route_num;

	  row->RouteRow = *route_row;
	  *route_row += 1;
	  row->From = pS->From;
	  row->To = pS->To;

	  row->linkRef = NULL;
	  row->TotalCost = pS->TotalCost;
	  row->Geometry = pS->Geometry;
	  row->Next = NULL;
	  if (multiSolution->FirstRow == NULL)
	      multiSolution->FirstRow = row;
	  if (multiSolution->LastRow != NULL)
	      multiSolution->LastRow->Next = row;
	  multiSolution->LastRow = row;
	  /* adding the Geometry to the multiSolution list */
	  if (multiSolution->FirstGeom == NULL)
	      multiSolution->FirstGeom = pS->Geometry;
	  if (multiSolution->LastGeom != NULL)
	      multiSolution->LastGeom->Next = pS->Geometry;
	  multiSolution->LastGeom = pS->Geometry;
	  /* removing Geometry ownership form Solution */
	  pS->Geometry = NULL;

	  /* copying points into the TSP geometry */
	  if (tsp_path != NULL && row->Geometry != NULL)
	    {
		gaiaLinestringPtr ln = row->Geometry->FirstLinestring;
		if (ln != NULL)
		  {
		      int base;
		      int iv;
		      if (pS == pStart && start)
			  base = 0;
		      else
			  base = 1;
		      for (iv = base; iv < ln->Points; iv++)
			{
			    double x;
			    double y;
			    int pt = *point_index;
			    *point_index += 1;
			    gaiaGetPoint (ln->Coords, iv, &x, &y);
			    gaiaSetPoint (tsp_path->Coords, pt, x, y);
			}
		  }
	    }

	  pA = pS->First;
	  while (pA != NULL)
	    {
		/* inserting Route's traversed Arcs */
		row = malloc (sizeof (ResultsetRow));
		row->RouteNum = *route_num;
		row->RouteRow = *route_row;
		*route_row += 1;
		row->From = NULL;
		row->To = NULL;

		row->linkRef = pA;
		row->TotalCost = 0.0;
		row->Geometry = NULL;
		row->Next = NULL;
		if (multiSolution->FirstRow == NULL)
		    multiSolution->FirstRow = row;
		if (multiSolution->LastRow != NULL)
		    multiSolution->LastRow->Next = row;
		multiSolution->LastRow = row;
		/* adding the Arc to the multiSolution list */
		if (multiSolution->FirstArc == NULL)
		    multiSolution->FirstArc = pA;
		if (multiSolution->LastArc != NULL)
		    multiSolution->LastArc->Next = pA;
		multiSolution->LastArc = pA;
		pA = pA->Next;
	    }
	  *route_num += 1;
	  /* removing Arcs ownership form Solution */
	  pS->First = NULL;
	  pS->Last = NULL;
	  pS = pS->Next;
	  if (pS == pStop)
	      break;
      }
}




















static void
build_tsp_solution (MultiSolutionPtr multiSolution, TspTargetsPtr targets)
{
/* formatting the TSP resultset */

    ShortestPathSolutionPtr pS;
    ResultsetRowPtr row;

    int i;

    int unreachable = 0;
    int route_row = 0;
    int route_num = 0;
    int points = 0;
    gaiaLinestringPtr tsp_path = NULL;
    int srid = -1;
    int iv = 0;

/* checking for unreacheable targets */
    for (i = 0; i < targets->Count; i++)
      {
	  RouteNodePtr to = *(targets->To + i);
	  if (to == NULL)
	      continue;
	  if (*(targets->Found + i) != 'Y')
	      unreachable = 1;
      }

/* inserting the TSP Header */
    row = malloc (sizeof (ResultsetRow));
    row->RouteNum = route_num++;
    row->RouteRow = route_row++;
    row->From = targets->From;
    row->To = targets->From;

    row->linkRef = NULL;
    if (unreachable)
	row->TotalCost = 0.0;
    else
	row->TotalCost = targets->TotalCost;
    row->Geometry = NULL;
    row->Next = NULL;
................................................................................
		RouteNodePtr to = *(targets->To + i);
		if (to == NULL)
		    continue;
		if (*(targets->Found + i) != 'Y')
		  {
		      /* unreacheable target */
		      row = malloc (sizeof (ResultsetRow));
		      row->RouteNum = 0;
		      row->RouteRow = route_row++;
		      row->From = to;
		      row->To = to;

		      row->linkRef = NULL;
		      row->TotalCost = 0.0;
		      row->Geometry = NULL;
		      row->Next = NULL;
		      if (multiSolution->FirstRow == NULL)
			  multiSolution->FirstRow = row;
		      if (multiSolution->LastRow != NULL)
................................................................................
		      multiSolution->LastRow = row;
		  }
	    }
	  return;
      }

/* creating the TSP geometry */
    pS = targets->First;
    while (pS != NULL)
      {

	  gaiaGeomCollPtr geom = pS->Geometry;
	  if (geom != NULL)
	    {
		srid = geom->Srid;
		gaiaLinestringPtr ln = geom->FirstLinestring;
		if (ln != NULL)
		  {
		      if (pS == targets->First)
			  points += ln->Points;
		      else
			  points += ln->Points - 1;
		  }
	    }
	  pS = pS->Next;












      }
    if (points >= 2)
      {
	  row->Geometry = gaiaAllocGeomColl ();
	  row->Geometry->Srid = srid;
	  tsp_path = gaiaAddLinestringToGeomColl (row->Geometry, points);
	  /* adding the Geometry to the multiSolution list */
................................................................................
	  if (multiSolution->FirstGeom == NULL)
	      multiSolution->FirstGeom = row->Geometry;
	  if (multiSolution->LastGeom != NULL)
	      multiSolution->LastGeom->Next = row->Geometry;
	  multiSolution->LastGeom = row->Geometry;
      }





    if (multiSolution->From == targets->From)

      {
	  /* TSP solution already is in its right seguence */
	  aux_build_tsp (multiSolution, targets->First, NULL, &route_num,
			 &route_row, tsp_path, &iv, 1);











      }
    else


      {
	  /* reordering the TSP solution */
	  ShortestPathSolutionPtr pStart = NULL;



	  pS = targets->First;
	  while (pS != NULL)





	    {

		if (pS->From == multiSolution->From)
		  {
		      /* this one is the real TSP start node */
		      pStart = pS;

		      break;
		  }
























		pS = pS->Next;





	    }




	  if (pStart == NULL)
	      return;
	  aux_build_tsp (multiSolution, pStart, NULL, &route_num, &route_row,
			 tsp_path, &iv, 1);
	  aux_build_tsp (multiSolution, targets->First, pStart, &route_num,
			 &route_row, tsp_path, &iv, 0);




















      }


















}



static ShortestPathSolutionPtr
add2multiSolution (MultiSolutionPtr multiSolution, RouteNodePtr pfrom,
		   RouteNodePtr pto, RouteArcPtr * shortest_path, int cnt)
{
/* adding a route solution to a multiple destinations request */
    int i;
    ShortestPathSolutionPtr solution = alloc_solution ();
    solution->From = pfrom;
    solution->To = pto;
    if (multiSolution->First == NULL)
	multiSolution->First = solution;
    if (multiSolution->Last != NULL)
	multiSolution->Last->Next = solution;
    multiSolution->Last = solution;
    return solution;
    if (cnt > 0)
      {
	  /* building the solution */
	  for (i = 0; i < cnt; i++)
	      add_arc_to_solution (solution, shortest_path[i]);
      }




    return solution;
}

static ShortestPathSolutionPtr
add2tspSolution (TspTargetsPtr targets, RouteNodePtr pfrom,
		 RouteNodePtr pto, RouteArcPtr * shortest_path, int cnt)
{
/* adding a route solution to a TSP request */
    int i;
    ShortestPathSolutionPtr solution = alloc_solution ();
    solution->From = pfrom;
    solution->To = pto;
    if (targets->First == NULL)
	targets->First = solution;

    if (targets->Last != NULL)
	targets->Last->Next = solution;
    targets->Last = solution;
    return solution;
    if (cnt > 0)
      {
	  /* building the solution */
	  for (i = 0; i < cnt; i++)
	      add_arc_to_solution (solution, shortest_path[i]);



      }
    return solution;
}

static RouteNodePtr
check_multiTo (RoutingNodePtr node, RoutingMultiDestPtr multiple)
{
................................................................................
		      /* inserting an Arc into the solution */
		      result[k] = n->Arc;
		      n = n->PreviousNode;
		      k--;
		  }
		solution =
		    add2multiSolution (multiSolution, multiSolution->From,
				       destination, result, cnt);
		build_solution (handle, options, graph, solution, result, cnt);
		/* testing for end (all destinations already reached) */
		if (end_multiTo (multiSolution->MultiTo))
		    break;
























































































































	    }
	  n->Inspected = 1;
	  for (i = 0; i < n->DimTo; i++)
	    {
		p_to = *(n->To + i);
		p_link = *(n->Link + i);
		if (p_to->Inspected == 0)
................................................................................
    routing_heap_free (heap);
}

static void
destroy_tsp_targets (TspTargetsPtr targets)
{
/* memory cleanup; destroying a TSP helper struct */
    ShortestPathSolutionPtr pS;
    ShortestPathSolutionPtr pSn;

    if (targets == NULL)
	return;
    if (targets->To != NULL)
	free (targets->To);
    if (targets->Found != NULL)
	free (targets->Found);
    pS = targets->First;
    while (pS != NULL)

      {
	  pSn = pS->Next;





	  delete_solution (pS);
	  pS = pSn;
      }




    free (targets);
}

static TspTargetsPtr
randomize_targets (sqlite3 * handle, RoutingPtr graph,
		   MultiSolutionPtr multiSolution)
{
................................................................................
    int n_columns;
    const char *value = NULL;
    char **results;
    int from;
    TspTargetsPtr targets = malloc (sizeof (TspTargets));
    targets->Mode = multiSolution->Mode;
    targets->TotalCost = 0.0;
    targets->First = NULL;
    targets->Last = NULL;
    targets->Count = multiSolution->MultiTo->Items;
    targets->To = malloc (sizeof (RouteNodePtr *) * targets->Count);
    targets->Found = malloc (sizeof (char) * targets->Count);












    sql =
	sqlite3_mprintf ("SELECT %d, Random() AS rnd\n",
			 multiSolution->From->InternalIndex);
    for (i = 0; i < multiSolution->MultiTo->Items; i++)
      {
	  RouteNodePtr p_to = *(multiSolution->MultiTo->To + i);
................................................................................
      {
	  targets->From = multiSolution->From;
	  for (i = 0; i < multiSolution->MultiTo->Items; i++)
	    {
		RouteNodePtr p_to = *(multiSolution->MultiTo->To + i);
		*(targets->To + i) = p_to;
		*(targets->Found + i) = 'N';


	    }
      }
    else
      {
	  int j = 0;
	  targets->From = graph->Nodes + from;
	  *(targets->To + j++) = multiSolution->From;
	  for (i = 0; i < multiSolution->MultiTo->Items; i++)
	    {
		RouteNodePtr p_to = *(multiSolution->MultiTo->To + i);
		*(targets->Found + i) = 'N';


		if (p_to == targets->From)
		    continue;
		*(targets->To + j++) = p_to;
	    }
      }

    return targets;

  illegal:
    destroy_tsp_targets (targets);













    return NULL;
}

static RouteNodePtr
check_TspTo (RoutingNodePtr node, TspTargetsPtr targets)
{
/* testing TSP destinations */
    int i;
................................................................................
		while (n->PreviousNode != NULL)
		  {
		      /* inserting an Arc into the solution */
		      result[k] = n->Arc;
		      n = n->PreviousNode;
		      k--;
		  }

		solution =


		    add2tspSolution (targets, origin, destination, result, cnt);
		build_solution (handle, options, graph, solution, result, cnt);
		targets->TotalCost += solution->TotalCost;

		/* testing for end (all destinations already reached) */
		if (last_route)
		    break;
		if (end_TspTo (targets))
		  {
		      /* determining the final route so to close the circular trip */
		      last_route = 1;
		  }

		/* restarting from the current target */
		from = to;
		for (i = 0; i < e->Dim; i++)
		  {
................................................................................
    int i;
    const char *prev = str;
    const char *ptr = str;

/* populating a linked list */
    while (1)
      {

	  if (*ptr == '\0')
	    {
		item = vroute_parse_multiple_item (prev, ptr);
		addMultiCandidate (list, item);
		break;
	    }


	  if (*ptr == delimiter)
	    {
		item = vroute_parse_multiple_item (prev, ptr);
		addMultiCandidate (list, item);
		ptr++;
		prev = ptr;
		continue;
	    }
................................................................................
	  free (pN);
	  pN = pNn;
      }
    pR = multiSolution->FirstRow;
    while (pR != NULL)
      {
	  pRn = pR->Next;


	  free (pR);
	  pR = pRn;
      }
    pA = multiSolution->FirstArc;
    while (pA != NULL)
      {
	  pAn = pA->Next;
................................................................................
    ShortestPathSolutionPtr solution;
    RouteNodePtr to = findSingleTo (multiSolution->MultiTo);
    if (to == NULL)
	return;
    shortest_path =
	astar_shortest_path (routing, graph->Nodes, multiSolution->From,
			     to, graph->AStarHeuristicCoeff, &cnt);
    solution =
	add2multiSolution (multiSolution, multiSolution->From, to,
			   shortest_path, cnt);
    build_solution (handle, options, graph, solution, shortest_path, cnt);
    build_multi_solution (multiSolution);
}

static void
tsp_nn_solve (sqlite3 * handle, int options, RoutingPtr graph,
	      RoutingNodesPtr routing, MultiSolutionPtr multiSolution)
{
/* computing a Dijkstra TSP NN Solution */
    TspTargetsPtr targets = randomize_targets (handle, graph, multiSolution);
    if (targets == NULL)
	return;
    dijkstra_tsp_nn (handle, options, graph, routing, targets);
    build_tsp_solution (multiSolution, targets);
    destroy_tsp_targets (targets);
}

static void
dijkstra_multi_solve (sqlite3 * handle, int options, RoutingPtr graph,
		      RoutingNodesPtr routing, MultiSolutionPtr multiSolution)
{
/* computing a Dijkstra Shortest Path multiSolution */



    dijkstra_multi_shortest_path (handle, options, graph, routing,
				  multiSolution);


























    build_multi_solution (multiSolution);
}

static void
dijkstra_within_cost_range (RoutingNodesPtr routing,
			    MultiSolutionPtr multiSolution, int srid)
{
................................................................................
    int cnt;
    RoutingNodePtr *range_nodes =
	dijkstra_range_analysis (routing, multiSolution->From,
				 multiSolution->MaxCost,
				 &cnt);
    build_range_solution (multiSolution, range_nodes, cnt, srid);
}











































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































static void
network_free (RoutingPtr p)
{
/* memory cleanup; freeing any allocation for the network struct */
    RouteNodePtr pN;
    int i;
................................................................................
		  {
		      tsp_nn_solve (net->db, net->currentOptions, net->graph,
				    net->routing, cursor->pVtab->multiSolution);
		      cursor->pVtab->multiSolution->CurrentRowId = 0;
		      cursor->pVtab->multiSolution->CurrentRow =
			  cursor->pVtab->multiSolution->FirstRow;
		  }












	    }
	  else
	    {
		cursor->pVtab->multiSolution->Mode = VROUTE_ROUTING_SOLUTION;
		if (net->currentAlgorithm == VROUTE_A_STAR_ALGORITHM)
		    astar_solve (net->db, net->currentOptions, net->graph,
				 net->routing, cursor->pVtab->multiSolution);
................................................................................
					   SQLITE_TRANSIENT);
		  }
		else if (column == 1)
		  {
		      /* the current Request type */
		      if (net->currentRequest == VROUTE_TSP_NN)
			  algorithm = "TSP NN";


		      else
			  algorithm = "Shortest Path";
		      sqlite3_result_text (pContext, algorithm,
					   strlen (algorithm),
					   SQLITE_TRANSIENT);
		  }
		else if (column == 2)
................................................................................
				   cursor->pVtab->currentDelimiter);
		      sqlite3_result_text (pContext, delimiter,
					   strlen (delimiter),
					   SQLITE_TRANSIENT);
		  }
		else
		    sqlite3_result_null (pContext);



































































































































		return SQLITE_OK;
	    }
	  if (row->linkRef == NULL)
	    {
		/* special case: this one is the solution summary */
		if (column == 0)
		  {
................................................................................
					   SQLITE_TRANSIENT);
		  }
		if (column == 1)
		  {
		      /* the current Request type */
		      if (net->currentRequest == VROUTE_TSP_NN)
			  algorithm = "TSP NN";


		      else
			  algorithm = "Shortest Path";
		      sqlite3_result_text (pContext, algorithm,
					   strlen (algorithm),
					   SQLITE_TRANSIENT);
		  }
		if (column == 2)
................................................................................
		      sqlite3_result_int (pContext, row->RouteRow);
		  }
		if (column == 6)
		  {
		      /* role of this row */
		      if (cursor->pVtab->multiSolution->Mode ==
			  VROUTE_TSP_SOLUTION && row->RouteNum == 0)
			{
			    if (row->RouteRow == 0)
				role = "TSP Solution";
			    else


				role = "Unreachable City";
			}
		      else
			  role = "Route";

		      sqlite3_result_text (pContext, role, strlen (role),
					   SQLITE_TRANSIENT);
		  }
		if (row->From == NULL || row->To == NULL)
		  {
		      /* empty [uninitialized] solution */
		      if (column > 0)
................................................................................
					       SQLITE_STATIC);
		      else
			  sqlite3_result_int64 (pContext, row->To->Id);
		  }
		if (column == 10)
		  {
		      /* the Cost column */



		      sqlite3_result_double (pContext, row->TotalCost);
		  }
		if (column == 11)
		  {
		      /* the Geometry column */
		      if (!(row->Geometry))
			  sqlite3_result_null (pContext);
		      else
................................................................................
					   SQLITE_TRANSIENT);
		  }
		if (column == 1)
		  {
		      /* the current Request type */
		      if (net->currentRequest == VROUTE_TSP_NN)
			  algorithm = "TSP NN";


		      else
			  algorithm = "Shortest Path";
		      sqlite3_result_text (pContext, algorithm,
					   strlen (algorithm),
					   SQLITE_TRANSIENT);
		  }
		if (column == 2)
................................................................................
			    const unsigned char *request =
				sqlite3_value_text (argv[3]);
			    if (strcasecmp ((char *) request, "TSP") == 0)
				p_vtab->currentRequest = VROUTE_TSP_NN;
			    else if (strcasecmp
				     ((char *) request, "TSP NN") == 0)
				p_vtab->currentRequest = VROUTE_TSP_NN;



			    else if (strcasecmp
				     ((char *) request, "SHORTEST PATH") == 0)
				p_vtab->currentRequest = VROUTE_SHORTEST_PATH;
			}
		      if (sqlite3_value_type (argv[4]) == SQLITE_TEXT)
			{
			    const unsigned char *options =







|









>


>
>







 







>







 







>







 







>
|
|



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>







 







>







 







>
>







 







>







 







|
|
|

|
>

<
|
|
|
<
<
|
|
>
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
<
<
|
|
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




>


>

>






|

|













|
|
>







 







|
|


>







 







|
<

>







|





<
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
|
>

<
<
<
>
>
>
>
>
>
>
>
>
>
>
|
<
>
>
|
<
<
>
>
>
|
<
>
>
>
>
>
|
>
|
|
<
<
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
|
>
>
>
>
|
<
<
<
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>


|


<









|
|
|
|
|
|
>
>
>
>




|
<




|
|
|
<
>
|
<
<
<
<
|
<
<
<
>
>
>







 







|




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<
<
<






|
|
>

<
>
>
>
>
>
|
<
|
>
>
>
>







 







<
<



>
>
>
>
>
>
>
>
>
>
>







 







>
>











>
>





<



|
>
>
>
>
>
>
>
>
>
>
>
>
>
|







 







>
|
>
>
|








|







 







>






>
>
|







 







>
>







 







<
|
<




<
<
<
<
<
<
<
<
<
<
<
<
<





>
>
>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>







 







>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>







 







<
<
|
|
>
>
|
<
|
|
>







 







>
>
>
|







 







>
>







 







>
>
>







66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
...
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
...
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
...
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
...
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
...
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
....
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
....
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
....
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289

1290
1291
1292


1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374



1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
....
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
....
1470
1471
1472
1473
1474
1475
1476
1477

1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492

1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
....
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525



1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537

1538
1539
1540


1541
1542
1543
1544

1545
1546
1547
1548
1549
1550
1551
1552
1553


1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592





1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640

1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664

1665
1666
1667
1668
1669
1670
1671

1672
1673




1674



1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
....
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
....
1932
1933
1934
1935
1936
1937
1938



1939
1940
1941
1942
1943
1944
1945
1946
1947
1948

1949
1950
1951
1952
1953
1954

1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
....
1973
1974
1975
1976
1977
1978
1979


1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
....
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056

2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
....
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
....
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
....
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
....
3077
3078
3079
3080
3081
3082
3083

3084

3085
3086
3087
3088













3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
....
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
....
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
....
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
....
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
....
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
....
5706
5707
5708
5709
5710
5711
5712


5713
5714
5715
5716
5717

5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
....
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
....
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
....
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987

static struct sqlite3_module my_route_module;

#define VROUTE_DIJKSTRA_ALGORITHM	1
#define VROUTE_A_STAR_ALGORITHM	2

#define VROUTE_ROUTING_SOLUTION	0xdd
#define VROUTE_RANGE_SOLUTION	0xbb
#define VROUTE_TSP_SOLUTION		0xee

#define VROUTE_SHORTEST_PATH_FULL		0x70
#define VROUTE_SHORTEST_PATH_NO_ARCS	0x71
#define VROUTE_SHORTEST_PATH_NO_GEOMS	0x72
#define VROUTE_SHORTEST_PATH_SIMPLE		0x73

#define VROUTE_SHORTEST_PATH			0x91
#define VROUTE_TSP_NN					0x92
#define VROUTE_TSP_GA					0x93

#define VROUTE_INVALID_SRID	-1234

#define	VROUTE_TSP_GA_MAX_ITERATIONS	512

#ifdef _WIN32
#define strcasecmp	_stricmp
#endif /* not WIN32 */

/******************************************************************************
/
................................................................................
typedef struct ShortestPathSolutionStruct
{
/* a shortest path solution */
    ArcSolutionPtr FirstArc;
    ArcSolutionPtr LastArc;
    RouteNodePtr From;
    RouteNodePtr To;
    char *Undefined;
    RowSolutionPtr First;
    RowSolutionPtr Last;
    RowNodeSolutionPtr FirstNode;
    RowNodeSolutionPtr LastNode;
    RowNodeSolutionPtr CurrentNodeRow;
    double TotalCost;
    gaiaGeomCollPtr Geometry;
................................................................................
typedef struct ResultsetRowStruct
{
/* a row into the resultset */
    int RouteNum;
    int RouteRow;
    RouteNodePtr From;
    RouteNodePtr To;
    char *Undefined;
    RowSolutionPtr linkRef;
    double TotalCost;
    gaiaGeomCollPtr Geometry;
    struct ResultsetRowStruct *Next;

} ResultsetRow;
typedef ResultsetRow *ResultsetRowPtr;
................................................................................
/* TSP helper struct */
    unsigned char Mode;
    double TotalCost;
    RouteNodePtr From;
    int Count;
    RouteNodePtr *To;
    char *Found;
    double *Costs;
    ShortestPathSolutionPtr *Solutions;
    ShortestPathSolutionPtr LastSolution;
} TspTargets;
typedef TspTargets *TspTargetsPtr;

typedef struct TspGaSubDistanceStruct
{
/* a cache sub-item for storing TSP GA costs */
    RouteNodePtr CityTo;
    double Cost;
} TspGaSubDistance;
typedef TspGaSubDistance *TspGaSubDistancePtr;

typedef struct TspGaDistanceStruct
{
/* a cache item for storing TSP GA costs */
    RouteNodePtr CityFrom;
    int Cities;
    TspGaSubDistancePtr *Distances;
    int NearestIndex;
} TspGaDistance;
typedef TspGaDistance *TspGaDistancePtr;

typedef struct TspGaSolutionStruct
{
/* TSP GA solution struct */
    int Cities;
    RouteNodePtr *CitiesFrom;
    RouteNodePtr *CitiesTo;
    double *Costs;
    double TotalCost;
} TspGaSolution;
typedef TspGaSolution *TspGaSolutionPtr;

typedef struct TspGaPopulationStruct
{
/* TSP GA helper struct */
    int Count;
    int Cities;
    TspGaSolutionPtr *Solutions;
    TspGaSolutionPtr *Offsprings;
    TspGaDistancePtr *Distances;
    char *RandomSolutionsSql;
    char *RandomIntervalSql;
} TspGaPopulation;
typedef TspGaPopulation *TspGaPopulationPtr;

/******************************************************************************
/
/ Dijkstra and A* common structs
/
******************************************************************************/

typedef struct RoutingNode
................................................................................
    pN = solution->FirstNode;
    while (pN)
      {
	  pNn = pN->Next;
	  free (pN);
	  pN = pNn;
      }
    if (solution->Undefined != NULL)
	free (solution->Undefined);
    if (solution->Geometry)
	gaiaFreeGeomColl (solution->Geometry);
    free (solution);
}

static ShortestPathSolutionPtr
alloc_solution (void)
................................................................................
{
/* allocates and initializes the current solution */
    ShortestPathSolutionPtr p = malloc (sizeof (ShortestPathSolution));
    p->FirstArc = NULL;
    p->LastArc = NULL;
    p->From = NULL;
    p->To = NULL;
    p->Undefined = NULL;
    p->First = NULL;
    p->Last = NULL;
    p->FirstNode = NULL;
    p->LastNode = NULL;
    p->CurrentNodeRow = NULL;
    p->TotalCost = 0.0;
    p->Geometry = NULL;
................................................................................
	  int route_row = 0;
	  RowSolutionPtr pA;
	  ResultsetRowPtr row = malloc (sizeof (ResultsetRow));
	  row->RouteNum = route_num;
	  row->RouteRow = route_row++;
	  row->From = pS->From;
	  row->To = pS->To;
	  row->Undefined = pS->Undefined;
	  pS->Undefined = NULL;
	  row->linkRef = NULL;
	  row->TotalCost = pS->TotalCost;
	  row->Geometry = pS->Geometry;
	  row->Next = NULL;
	  if (multiSolution->FirstRow == NULL)
	      multiSolution->FirstRow = row;
	  if (multiSolution->LastRow != NULL)
................................................................................
	    {
		/* inserting Route's traversed Arcs */
		row = malloc (sizeof (ResultsetRow));
		row->RouteNum = route_num;
		row->RouteRow = route_row++;
		row->From = NULL;
		row->To = NULL;
		row->Undefined = NULL;
		row->linkRef = pA;
		row->TotalCost = 0.0;
		row->Geometry = NULL;
		row->Next = NULL;
		if (multiSolution->FirstRow == NULL)
		    multiSolution->FirstRow = row;
		if (multiSolution->LastRow != NULL)
................................................................................
	    }
	  route_num++;
	  pS = pS->Next;
      }
}

static void
aux_tsp_add_solution (MultiSolutionPtr multiSolution,
		      ShortestPathSolutionPtr pS, int *route_num,
		      gaiaLinestringPtr tsp_path, int *point_index, int mode)
{
/* helper function: adding a solutiont into the TSP resultset */
    RowSolutionPtr pA;
    ResultsetRowPtr row;

    int route_row = 0;

/* inserting the Route Header */


    row = malloc (sizeof (ResultsetRow));
    row->RouteNum = *route_num;
    *route_num += 1;
    row->RouteRow = route_row;
    route_row += 1;
    row->From = pS->From;
    row->To = pS->To;
    row->Undefined = NULL;
    row->linkRef = NULL;
    row->TotalCost = pS->TotalCost;
    row->Geometry = pS->Geometry;
    row->Next = NULL;
    if (multiSolution->FirstRow == NULL)
	multiSolution->FirstRow = row;
    if (multiSolution->LastRow != NULL)
	multiSolution->LastRow->Next = row;
    multiSolution->LastRow = row;
    /* adding the Geometry to the multiSolution list */
    if (multiSolution->FirstGeom == NULL)
	multiSolution->FirstGeom = pS->Geometry;
    if (multiSolution->LastGeom != NULL)
	multiSolution->LastGeom->Next = pS->Geometry;
    multiSolution->LastGeom = pS->Geometry;
    /* removing Geometry ownership form Solution */
    pS->Geometry = NULL;

    /* copying points into the TSP geometry */
    if (tsp_path != NULL && row->Geometry != NULL)
      {
	  gaiaLinestringPtr ln = row->Geometry->FirstLinestring;
	  if (ln != NULL)
	    {
		int base;
		int iv;
		if (!mode)
		    base = 0;
		else
		    base = 1;
		for (iv = base; iv < ln->Points; iv++)
		  {
		      double x;
		      double y;
		      int pt = *point_index;
		      *point_index += 1;
		      gaiaGetPoint (ln->Coords, iv, &x, &y);
		      gaiaSetPoint (tsp_path->Coords, pt, x, y);
		  }
	    }
      }

    pA = pS->First;
    while (pA != NULL)
      {
	  /* inserting Route's traversed Arcs */
	  row = malloc (sizeof (ResultsetRow));
	  row->RouteNum = *route_num;
	  row->RouteRow = route_row;
	  route_row += 1;
	  row->From = NULL;
	  row->To = NULL;
	  row->Undefined = NULL;
	  row->linkRef = pA;
	  row->TotalCost = 0.0;
	  row->Geometry = NULL;
	  row->Next = NULL;
	  if (multiSolution->FirstRow == NULL)
	      multiSolution->FirstRow = row;
	  if (multiSolution->LastRow != NULL)
	      multiSolution->LastRow->Next = row;
	  multiSolution->LastRow = row;
	  /* adding the Arc to the multiSolution list */
	  if (multiSolution->FirstArc == NULL)
	      multiSolution->FirstArc = pA;
	  if (multiSolution->LastArc != NULL)
	      multiSolution->LastArc->Next = pA;
	  multiSolution->LastArc = pA;
	  pA = pA->Next;
      }
    route_num += 1;
    /* removing Arcs ownership form Solution */
    pS->First = NULL;
    pS->Last = NULL;



}

static void
aux_build_tsp (MultiSolutionPtr multiSolution, TspTargetsPtr targets,
	       int route_num, gaiaLinestringPtr tsp_path)
{
/* helper function: formatting the TSP resultset */
    int point_index = 0;
    int i;
    for (i = 0; i < targets->Count; i++)
      {
	  /* adding all City to City solutions */
	  ShortestPathSolutionPtr pS = *(targets->Solutions + i);
	  aux_tsp_add_solution (multiSolution, pS, &route_num, tsp_path,
				&point_index, i);
      }
    /* adding the final trip closing the circular path */
    aux_tsp_add_solution (multiSolution, targets->LastSolution, &route_num,
			  tsp_path, &point_index, targets->Count);

}

static void
build_tsp_solution (MultiSolutionPtr multiSolution, TspTargetsPtr targets)
{
/* formatting the TSP resultset */
    ShortestPathSolutionPtr *oldS;
    ShortestPathSolutionPtr pS;
    ResultsetRowPtr row;
    RouteNodePtr from;
    int i;
    int k;
    int unreachable = 0;
    int route_row = 0;
    int route_num = 0;
    int points = 0;
    gaiaLinestringPtr tsp_path = NULL;
    int srid = -1;
    int found;

/* checking for undefined or unreacheable targets */
    for (i = 0; i < targets->Count; i++)
      {
	  RouteNodePtr to = *(targets->To + i);
	  if (to == NULL)
	      continue;
	  if (*(targets->Found + i) != 'Y')
	      unreachable = 1;
      }

/* inserting the TSP Header */
    row = malloc (sizeof (ResultsetRow));
    row->RouteNum = route_num++;
    row->RouteRow = route_row++;
    row->From = multiSolution->From;
    row->To = multiSolution->From;
    row->Undefined = NULL;
    row->linkRef = NULL;
    if (unreachable)
	row->TotalCost = 0.0;
    else
	row->TotalCost = targets->TotalCost;
    row->Geometry = NULL;
    row->Next = NULL;
................................................................................
		RouteNodePtr to = *(targets->To + i);
		if (to == NULL)
		    continue;
		if (*(targets->Found + i) != 'Y')
		  {
		      /* unreacheable target */
		      row = malloc (sizeof (ResultsetRow));
		      row->RouteNum = route_num++;
		      row->RouteRow = 0;
		      row->From = to;
		      row->To = to;
		      row->Undefined = NULL;
		      row->linkRef = NULL;
		      row->TotalCost = 0.0;
		      row->Geometry = NULL;
		      row->Next = NULL;
		      if (multiSolution->FirstRow == NULL)
			  multiSolution->FirstRow = row;
		      if (multiSolution->LastRow != NULL)
................................................................................
		      multiSolution->LastRow = row;
		  }
	    }
	  return;
      }

/* creating the TSP geometry */
    for (i = 0; i < targets->Count; i++)

      {
	  pS = *(targets->Solutions + i);
	  gaiaGeomCollPtr geom = pS->Geometry;
	  if (geom != NULL)
	    {
		srid = geom->Srid;
		gaiaLinestringPtr ln = geom->FirstLinestring;
		if (ln != NULL)
		  {
		      if (i == 0)
			  points += ln->Points;
		      else
			  points += ln->Points - 1;
		  }
	    }

      }
    if (targets->LastSolution != NULL)
      {
	  gaiaGeomCollPtr geom = targets->LastSolution->Geometry;
	  if (geom != NULL)
	    {
		gaiaLinestringPtr ln = geom->FirstLinestring;
		if (ln != NULL)
		  {
		      points += ln->Points - 1;
		  }
	    }
      }
    if (points >= 2)
      {
	  row->Geometry = gaiaAllocGeomColl ();
	  row->Geometry->Srid = srid;
	  tsp_path = gaiaAddLinestringToGeomColl (row->Geometry, points);
	  /* adding the Geometry to the multiSolution list */
................................................................................
	  if (multiSolution->FirstGeom == NULL)
	      multiSolution->FirstGeom = row->Geometry;
	  if (multiSolution->LastGeom != NULL)
	      multiSolution->LastGeom->Next = row->Geometry;
	  multiSolution->LastGeom = row->Geometry;
      }

    /* reordering the TSP solution */
    oldS = targets->Solutions;
    targets->Solutions =
	malloc (sizeof (ShortestPathSolutionPtr) * targets->Count);
    from = multiSolution->From;
    for (k = 0; k < targets->Count; k++)
      {



	  /* building the right sequence */
	  found = 0;
	  for (i = 0; i < targets->Count; i++)
	    {
		pS = *(oldS + i);
		if (pS->From == from)
		  {
		      *(targets->Solutions + k) = pS;
		      from = pS->To;
		      found = 1;
		      break;
		  }

	    }
	  if (!found)
	    {


		if (targets->LastSolution->From == from)
		  {
		      *(targets->Solutions + k) = targets->LastSolution;
		      from = targets->LastSolution->To;

		  }
	    }
      }
    /* adjusting the last route so to close a circular path */
    for (i = 0; i < targets->Count; i++)
      {
	  pS = *(oldS + i);
	  if (pS->From == from)
	    {


		targets->LastSolution = pS;
		break;
	    }
      }
    free (oldS);
    aux_build_tsp (multiSolution, targets, route_num, tsp_path);
}

static void
build_tsp_illegal_solution (MultiSolutionPtr multiSolution,
			    TspTargetsPtr targets)
{
/* formatting the TSP resultset - undefined targets */
    ResultsetRowPtr row;
    int i;
    int route_num = 0;

/* inserting the TSP Header */
    row = malloc (sizeof (ResultsetRow));
    row->RouteNum = route_num++;
    row->RouteRow = 0;
    row->From = multiSolution->From;
    row->To = multiSolution->From;
    row->Undefined = NULL;
    row->linkRef = NULL;
    row->TotalCost = 0.0;
    row->Geometry = NULL;
    row->Next = NULL;
    if (multiSolution->FirstRow == NULL)
	multiSolution->FirstRow = row;
    if (multiSolution->LastRow != NULL)
	multiSolution->LastRow->Next = row;
    multiSolution->LastRow = row;

    for (i = 0; i < targets->Count; i++)
      {
	  RouteNodePtr to = *(targets->To + i);
	  const char *code = *(multiSolution->MultiTo->Codes + i);
	  if (to == NULL)





	    {
		/* unknown target */
		int len;
		row = malloc (sizeof (ResultsetRow));
		row->RouteNum = route_num++;
		row->RouteRow = 0;
		row->From = to;
		row->To = to;
		len = strlen (code);
		row->Undefined = malloc (len + 1);
		strcpy (row->Undefined, code);
		row->linkRef = NULL;
		row->TotalCost = 0.0;
		row->Geometry = NULL;
		row->Next = NULL;
		if (multiSolution->FirstRow == NULL)
		    multiSolution->FirstRow = row;
		if (multiSolution->LastRow != NULL)
		    multiSolution->LastRow->Next = row;
		multiSolution->LastRow = row;
	    }
	  if (*(targets->Found + i) != 'Y')
	    {
		/* unreachable target */
		row = malloc (sizeof (ResultsetRow));
		row->RouteNum = route_num++;
		row->RouteRow = 0;
		row->From = to;
		row->To = to;
		row->Undefined = NULL;
		row->linkRef = NULL;
		row->TotalCost = 0.0;
		row->Geometry = NULL;
		row->Next = NULL;
		if (multiSolution->FirstRow == NULL)
		    multiSolution->FirstRow = row;
		if (multiSolution->LastRow != NULL)
		    multiSolution->LastRow->Next = row;
		multiSolution->LastRow = row;
	    }
      }
}

static ShortestPathSolutionPtr
add2multiSolution (MultiSolutionPtr multiSolution, RouteNodePtr pfrom,
		   RouteNodePtr pto)
{
/* adding a route solution to a multiple destinations request */

    ShortestPathSolutionPtr solution = alloc_solution ();
    solution->From = pfrom;
    solution->To = pto;
    if (multiSolution->First == NULL)
	multiSolution->First = solution;
    if (multiSolution->Last != NULL)
	multiSolution->Last->Next = solution;
    multiSolution->Last = solution;
    return solution;
}

static ShortestPathSolutionPtr
add2tspLastSolution (TspTargetsPtr targets, RouteNodePtr from, RouteNodePtr to)
{
/* adding the last route solution to a TSP request */
    ShortestPathSolutionPtr solution = alloc_solution ();
    solution->From = from;
    solution->To = to;
    targets->LastSolution = solution;
    return solution;
}

static ShortestPathSolutionPtr
add2tspSolution (TspTargetsPtr targets, RouteNodePtr from, RouteNodePtr to)

{
/* adding a route solution to a TSP request */
    int i;
    ShortestPathSolutionPtr solution = alloc_solution ();
    solution->From = from;
    solution->To = to;
    for (i = 0; i < targets->Count; i++)

      {
	  if (*(targets->To + i) == to)




	    {



		*(targets->Solutions + i) = solution;
		break;
	    }
      }
    return solution;
}

static RouteNodePtr
check_multiTo (RoutingNodePtr node, RoutingMultiDestPtr multiple)
{
................................................................................
		      /* inserting an Arc into the solution */
		      result[k] = n->Arc;
		      n = n->PreviousNode;
		      k--;
		  }
		solution =
		    add2multiSolution (multiSolution, multiSolution->From,
				       destination);
		build_solution (handle, options, graph, solution, result, cnt);
		/* testing for end (all destinations already reached) */
		if (end_multiTo (multiSolution->MultiTo))
		    break;
	    }
	  n->Inspected = 1;
	  for (i = 0; i < n->DimTo; i++)
	    {
		p_to = *(n->To + i);
		p_link = *(n->Link + i);
		if (p_to->Inspected == 0)
		  {
		      if (p_to->Distance == DBL_MAX)
			{
			    /* queuing a new node into the heap */
			    p_to->Distance = n->Distance + p_link->Cost;
			    p_to->PreviousNode = n;
			    p_to->Arc = p_link;
			    dijkstra_enqueue (heap, p_to);
			}
		      else if (p_to->Distance > n->Distance + p_link->Cost)
			{
			    /* updating an already inserted node */
			    p_to->Distance = n->Distance + p_link->Cost;
			    p_to->PreviousNode = n;
			    p_to->Arc = p_link;
			}
		  }
	    }
      }
    routing_heap_free (heap);
}

static RouteNodePtr
check_targets (RoutingNodePtr node, TspTargetsPtr targets)
{
/* testing targets */
    int i;
    for (i = 0; i < targets->Count; i++)
      {
	  RouteNodePtr to = *(targets->To + i);
	  if (to == NULL)
	      continue;
	  if (*(targets->Found + i) == 'Y')
	      continue;
	  if (node->Id == to->InternalIndex)
	    {
		*(targets->Found + i) = 'Y';
		return to;
	    }
      }
    return NULL;
}

static void
update_targets (TspTargetsPtr targets, RouteNodePtr destination, double cost,
		int *stop)
{
/* tupdating targets */
    int i;
    *stop = 1;
    for (i = 0; i < targets->Count; i++)
      {
	  RouteNodePtr to = *(targets->To + i);
	  if (to == NULL)
	      continue;
	  if (to == destination)
	      *(targets->Costs + i) = cost;
	  if (*(targets->Found + i) == 'Y')
	      continue;
	  *stop = 0;
      }
}


static void
dijkstra_targets_solve (RoutingNodesPtr e, TspTargetsPtr targets)
{
/* Shortest Path (multiple destinations) for TSP GA */
    int from;
    int i;
    RouteNodePtr destination;
    RoutingNodePtr n;
    RoutingNodePtr p_to;
    RouteArcPtr p_link;
    RoutingHeapPtr heap;
/* setting From */
    from = targets->From->InternalIndex;
/* initializing the heap */
    heap = routing_heap_init (e->DimLink);
/* initializing the graph */
    for (i = 0; i < e->Dim; i++)
      {
	  n = e->Nodes + i;
	  n->PreviousNode = NULL;
	  n->Arc = NULL;
	  n->Inspected = 0;
	  n->Distance = DBL_MAX;
      }
/* queuing the From node into the heap */
    e->Nodes[from].Distance = 0.0;
    dijkstra_enqueue (heap, e->Nodes + from);
    while (heap->Count > 0)
      {
	  /* Dijsktra loop */
	  n = routing_dequeue (heap);
	  destination = check_targets (n, targets);
	  if (destination != NULL)
	    {
		/* reached one of the targets */
		int stop = 0;
		double totalCost = 0.0;
		int to = destination->InternalIndex;
		n = e->Nodes + to;
		while (n->PreviousNode != NULL)
		  {
		      /* computing the total Cost */
		      totalCost += n->Arc->Cost;
		      n = n->PreviousNode;
		  }
		/* updating targets */
		update_targets (targets, destination, totalCost, &stop);
		if (stop)
		    break;
	    }
	  n->Inspected = 1;
	  for (i = 0; i < n->DimTo; i++)
	    {
		p_to = *(n->To + i);
		p_link = *(n->Link + i);
		if (p_to->Inspected == 0)
................................................................................
    routing_heap_free (heap);
}

static void
destroy_tsp_targets (TspTargetsPtr targets)
{
/* memory cleanup; destroying a TSP helper struct */



    if (targets == NULL)
	return;
    if (targets->To != NULL)
	free (targets->To);
    if (targets->Found != NULL)
	free (targets->Found);
    if (targets->Costs != NULL)
	free (targets->Costs);
    if (targets->Solutions != NULL)
      {

	  int i;
	  for (i = 0; i < targets->Count; i++)
	    {
		ShortestPathSolutionPtr pS = *(targets->Solutions + i);
		if (pS != NULL)
		    delete_solution (pS);

	    }
	  free (targets->Solutions);
      }
    if (targets->LastSolution != NULL)
	delete_solution (targets->LastSolution);
    free (targets);
}

static TspTargetsPtr
randomize_targets (sqlite3 * handle, RoutingPtr graph,
		   MultiSolutionPtr multiSolution)
{
................................................................................
    int n_columns;
    const char *value = NULL;
    char **results;
    int from;
    TspTargetsPtr targets = malloc (sizeof (TspTargets));
    targets->Mode = multiSolution->Mode;
    targets->TotalCost = 0.0;


    targets->Count = multiSolution->MultiTo->Items;
    targets->To = malloc (sizeof (RouteNodePtr *) * targets->Count);
    targets->Found = malloc (sizeof (char) * targets->Count);
    targets->Costs = malloc (sizeof (double) * targets->Count);
    targets->Solutions =
	malloc (sizeof (ShortestPathSolutionPtr) * targets->Count);
    targets->LastSolution = NULL;
    for (i = 0; i < targets->Count; i++)
      {
	  *(targets->To + i) = NULL;
	  *(targets->Found + i) = 'N';
	  *(targets->Costs + i) = DBL_MAX;
	  *(targets->Solutions + i) = NULL;
      }

    sql =
	sqlite3_mprintf ("SELECT %d, Random() AS rnd\n",
			 multiSolution->From->InternalIndex);
    for (i = 0; i < multiSolution->MultiTo->Items; i++)
      {
	  RouteNodePtr p_to = *(multiSolution->MultiTo->To + i);
................................................................................
      {
	  targets->From = multiSolution->From;
	  for (i = 0; i < multiSolution->MultiTo->Items; i++)
	    {
		RouteNodePtr p_to = *(multiSolution->MultiTo->To + i);
		*(targets->To + i) = p_to;
		*(targets->Found + i) = 'N';
		*(targets->Costs + i) = DBL_MAX;
		*(targets->Solutions + i) = NULL;
	    }
      }
    else
      {
	  int j = 0;
	  targets->From = graph->Nodes + from;
	  *(targets->To + j++) = multiSolution->From;
	  for (i = 0; i < multiSolution->MultiTo->Items; i++)
	    {
		RouteNodePtr p_to = *(multiSolution->MultiTo->To + i);
		*(targets->Found + i) = 'N';
		*(targets->Costs + i) = DBL_MAX;
		*(targets->Solutions + i) = NULL;
		if (p_to == targets->From)
		    continue;
		*(targets->To + j++) = p_to;
	    }
      }

    return targets;

  illegal:
    for (i = 0; i < targets->Count; i++)
      {
	  *(targets->To + i) = NULL;
	  *(targets->Found + i) = 'N';
	  *(targets->Costs + i) = DBL_MAX;
	  *(targets->Solutions + i) = NULL;
      }
    for (i = 0; i < multiSolution->MultiTo->Items; i++)
      {
	  RouteNodePtr p_to = *(multiSolution->MultiTo->To + i);
	  if (p_to == NULL)
	      continue;
	  *(targets->To + i) = p_to;
      }
    return targets;
}

static RouteNodePtr
check_TspTo (RoutingNodePtr node, TspTargetsPtr targets)
{
/* testing TSP destinations */
    int i;
................................................................................
		while (n->PreviousNode != NULL)
		  {
		      /* inserting an Arc into the solution */
		      result[k] = n->Arc;
		      n = n->PreviousNode;
		      k--;
		  }
		if (last_route)
		    solution =
			add2tspLastSolution (targets, origin, destination);
		else
		    solution = add2tspSolution (targets, origin, destination);
		build_solution (handle, options, graph, solution, result, cnt);
		targets->TotalCost += solution->TotalCost;

		/* testing for end (all destinations already reached) */
		if (last_route)
		    break;
		if (end_TspTo (targets))
		  {
		      /* determining the final route so to close the circular path */
		      last_route = 1;
		  }

		/* restarting from the current target */
		from = to;
		for (i = 0; i < e->Dim; i++)
		  {
................................................................................
    int i;
    const char *prev = str;
    const char *ptr = str;

/* populating a linked list */
    while (1)
      {
	  int whitespace = 0;
	  if (*ptr == '\0')
	    {
		item = vroute_parse_multiple_item (prev, ptr);
		addMultiCandidate (list, item);
		break;
	    }
	  if (*ptr == ' ' || *ptr == '\t' || *ptr == '\n' || *ptr == '\r')
	      whitespace = 1;
	  if (*ptr == delimiter || whitespace)
	    {
		item = vroute_parse_multiple_item (prev, ptr);
		addMultiCandidate (list, item);
		ptr++;
		prev = ptr;
		continue;
	    }
................................................................................
	  free (pN);
	  pN = pNn;
      }
    pR = multiSolution->FirstRow;
    while (pR != NULL)
      {
	  pRn = pR->Next;
	  if (pR->Undefined != NULL)
	      free (pR->Undefined);
	  free (pR);
	  pR = pRn;
      }
    pA = multiSolution->FirstArc;
    while (pA != NULL)
      {
	  pAn = pA->Next;
................................................................................
    ShortestPathSolutionPtr solution;
    RouteNodePtr to = findSingleTo (multiSolution->MultiTo);
    if (to == NULL)
	return;
    shortest_path =
	astar_shortest_path (routing, graph->Nodes, multiSolution->From,
			     to, graph->AStarHeuristicCoeff, &cnt);

    solution = add2multiSolution (multiSolution, multiSolution->From, to);

    build_solution (handle, options, graph, solution, shortest_path, cnt);
    build_multi_solution (multiSolution);
}














static void
dijkstra_multi_solve (sqlite3 * handle, int options, RoutingPtr graph,
		      RoutingNodesPtr routing, MultiSolutionPtr multiSolution)
{
/* computing a Dijkstra Shortest Path multiSolution */
    int i;
    RoutingMultiDestPtr multiple = multiSolution->MultiTo;

    dijkstra_multi_shortest_path (handle, options, graph, routing,
				  multiSolution);
/* testing if there are undefined or unresolved destinations */
    for (i = 0; i < multiple->Items; i++)
      {
	  int len;
	  ShortestPathSolutionPtr row;
	  RouteNodePtr to = *(multiple->To + i);
	  const char *code = *(multiple->Codes + i);
	  if (to == NULL)
	    {
		row =
		    add2multiSolution (multiSolution, multiSolution->From,
				       NULL);
		len = strlen (code);
		row->Undefined = malloc (len + 1);
		strcpy (row->Undefined, code);
		continue;
	    }
	  if (*(multiple->Found + i) != 'Y')
	    {
		row =
		    add2multiSolution (multiSolution, multiSolution->From, to);
		len = strlen (code);
		row->Undefined = malloc (len + 1);
		strcpy (row->Undefined, code);
	    }
      }
    build_multi_solution (multiSolution);
}

static void
dijkstra_within_cost_range (RoutingNodesPtr routing,
			    MultiSolutionPtr multiSolution, int srid)
{
................................................................................
    int cnt;
    RoutingNodePtr *range_nodes =
	dijkstra_range_analysis (routing, multiSolution->From,
				 multiSolution->MaxCost,
				 &cnt);
    build_range_solution (multiSolution, range_nodes, cnt, srid);
}

static void
tsp_nn_solve (sqlite3 * handle, int options, RoutingPtr graph,
	      RoutingNodesPtr routing, MultiSolutionPtr multiSolution)
{
/* computing a Dijkstra TSP NN Solution */
    int i;
    TspTargetsPtr targets = randomize_targets (handle, graph, multiSolution);
    for (i = 0; i < targets->Count; i++)
      {
	  /* checking for undefined targets */
	  if (*(targets->To + i) == NULL)
	      goto illegal;
      }
    dijkstra_tsp_nn (handle, options, graph, routing, targets);
    build_tsp_solution (multiSolution, targets);
    destroy_tsp_targets (targets);
    return;

  illegal:
    build_tsp_illegal_solution (multiSolution, targets);
    destroy_tsp_targets (targets);
}

static void
tsp_ga_random_solutions_sql (TspGaPopulationPtr ga)
{
/* building the Solutions randomizing SQL query */
    int i;
    char *sql;
    char *prev_sql;

    for (i = 0; i < ga->Count; i++)
      {
	  if (i == 0)
	      sql = sqlite3_mprintf ("SELECT %d, Random() AS rnd\n", i);
	  else
	    {
		prev_sql = sql;
		sql =
		    sqlite3_mprintf ("%sUNION\nSELECT %d, Random() AS rnd\n",
				     prev_sql, i);
		sqlite3_free (prev_sql);
	    }
      }
    prev_sql = sql;
    sql = sqlite3_mprintf ("%sORDER BY rnd LIMIT 2", prev_sql);
    sqlite3_free (prev_sql);
    ga->RandomSolutionsSql = sql;
}

static void
tsp_ga_random_interval_sql (TspGaPopulationPtr ga)
{
/* building the Interval randomizing SQL query */
    int i;
    char *sql;
    char *prev_sql;

    for (i = 0; i < ga->Cities; i++)
      {
	  if (i == 0)
	      sql = sqlite3_mprintf ("SELECT %d, Random() AS rnd\n", i);
	  else
	    {
		prev_sql = sql;
		sql =
		    sqlite3_mprintf ("%sUNION\nSELECT %d, Random() AS rnd\n",
				     prev_sql, i);
		sqlite3_free (prev_sql);
	    }
      }
    prev_sql = sql;
    sql = sqlite3_mprintf ("%sORDER BY rnd LIMIT 2", prev_sql);
    sqlite3_free (prev_sql);
    ga->RandomIntervalSql = sql;
}

static TspGaDistancePtr
alloc_tsp_ga_distances (TspTargetsPtr targets)
{
/* allocating a TSP GA distances struct */
    int i;
    TspGaDistancePtr dist = malloc (sizeof (TspGaDistance));
    dist->Cities = targets->Count;
    dist->CityFrom = targets->From;
    dist->Distances = malloc (sizeof (TspGaSubDistancePtr) * dist->Cities);
    for (i = 0; i < dist->Cities; i++)
      {
	  TspGaSubDistancePtr sub = malloc (sizeof (TspGaSubDistance));
	  double cost = *(targets->Costs + i);
	  sub->CityTo = *(targets->To + i);
	  sub->Cost = cost;
	  *(dist->Distances + i) = sub;
      }
    dist->NearestIndex = -1;
    return dist;
}

static void
destroy_tsp_ga_distances (TspGaDistancePtr dist)
{
/* freeing a TSP GA distance struct */
    if (dist == NULL)
	return;
    if (dist->Distances != NULL)
      {
	  int i;
	  for (i = 0; i < dist->Cities; i++)
	    {
		TspGaSubDistancePtr sub = *(dist->Distances + i);
		if (sub != NULL)
		    free (sub);
	    }
	  free (dist->Distances);
      }
    free (dist);
}

static TspGaPopulationPtr
build_tsp_ga_population (int count)
{
/* creating a TSP GA Population */
    int i;
    TspGaPopulationPtr ga = malloc (sizeof (TspGaPopulation));
    ga->Count = count;
    ga->Cities = count;
    ga->Solutions = malloc (sizeof (TspGaSolutionPtr) * count);
    ga->Offsprings = malloc (sizeof (TspGaSolutionPtr) * count);
    for (i = 0; i < count; i++)
      {
	  *(ga->Offsprings + i) = NULL;
	  *(ga->Solutions + i) = NULL;
      }
    ga->Distances = malloc (sizeof (TspGaDistancePtr) * count);
    for (i = 0; i < count; i++)
	*(ga->Distances + i) = NULL;
    ga->RandomSolutionsSql = NULL;
    tsp_ga_random_solutions_sql (ga);
    ga->RandomIntervalSql = NULL;
    tsp_ga_random_interval_sql (ga);
    return ga;
}

static void
destroy_tsp_ga_solution (TspGaSolutionPtr solution)
{
/* memory cleanup: destroyng a GA Solution */
    if (solution == NULL)
	return;
    if (solution->CitiesFrom != NULL)
	free (solution->CitiesFrom);
    if (solution->CitiesTo != NULL)
	free (solution->CitiesTo);
    if (solution->Costs != NULL)
	free (solution->Costs);
    free (solution);
}

static void
free_tsp_ga_offsprings (TspGaPopulationPtr ga)
{
/* memory cleanup; freeing GA Offsprings */
    int i;
    if (ga == NULL)
	return;

    for (i = 0; i < ga->Count; i++)
      {
	  if (*(ga->Offsprings + i) != NULL)
	      destroy_tsp_ga_solution (*(ga->Offsprings + i));
	  *(ga->Offsprings + i) = NULL;
      }
}

static void
destroy_tsp_ga_population (TspGaPopulationPtr ga)
{
/* memory cleanup; destroyng a GA Population */
    int i;
    if (ga == NULL)
	return;

    for (i = 0; i < ga->Count; i++)
	destroy_tsp_ga_solution (*(ga->Solutions + i));
    free (ga->Solutions);
    free_tsp_ga_offsprings (ga);
    free (ga->Offsprings);
    if (ga->Distances != NULL)
      {
	  for (i = 0; i < ga->Cities; i++)
	    {
		TspGaDistancePtr dist = *(ga->Distances + i);
		if (dist != NULL)
		    destroy_tsp_ga_distances (dist);
	    }
      }
    free (ga->Distances);
    if (ga->RandomSolutionsSql != NULL)
	sqlite3_free (ga->RandomSolutionsSql);
    if (ga->RandomIntervalSql != NULL)
	sqlite3_free (ga->RandomIntervalSql);
    free (ga);
}

static int
cmp_dist_from (const void *p1, const void *p2)
{
/* compares FROM distances [for BSEARCH] */
    TspGaDistancePtr pD1 = (TspGaDistancePtr) p1;
    TspGaDistancePtr pD2 = *((TspGaDistancePtr *) p2);
    RouteNodePtr pN1 = pD1->CityFrom;
    RouteNodePtr pN2 = pD2->CityFrom;
    if (pN1 == pN2)
	return 0;
    if (pN1 > pN2)
	return 1;
    return -1;
}

static TspGaDistancePtr
tsp_ga_find_from_distance (TspGaPopulationPtr ga, RouteNodePtr from)
{
/* searching the main FROM distance */
    TspGaDistancePtr *ret;
    TspGaDistance dist;
    dist.CityFrom = from;
    ret =
	bsearch (&dist, ga->Distances, ga->Cities, sizeof (TspGaDistancePtr),
		 cmp_dist_from);
    if (ret == NULL)
	return NULL;
    return *ret;
}

static int
cmp_dist_to (const void *p1, const void *p2)
{
/* compares TO distances [for BSEARCH] */
    TspGaSubDistancePtr pD1 = (TspGaSubDistancePtr) p1;
    TspGaSubDistancePtr pD2 = *((TspGaSubDistancePtr *) p2);
    RouteNodePtr pN1 = pD1->CityTo;
    RouteNodePtr pN2 = pD2->CityTo;
    if (pN1 == pN2)
	return 0;
    if (pN1 > pN2)
	return 1;
    return -1;
}

static TspGaSubDistancePtr
tsp_ga_find_to_distance (TspGaDistancePtr dist, RouteNodePtr to)
{
/* searching the main FROM distance */
    TspGaSubDistancePtr *ret;
    TspGaSubDistance sub;
    sub.CityTo = to;
    ret =
	bsearch (&sub, dist->Distances, dist->Cities,
		 sizeof (TspGaSubDistancePtr), cmp_dist_to);
    if (ret == NULL)
	return NULL;
    return *ret;
}

static double
tsp_ga_find_distance (TspGaPopulationPtr ga, RouteNodePtr from, RouteNodePtr to)
{
/* searching a cached distance */
    TspGaSubDistancePtr sub;
    TspGaDistancePtr dist = tsp_ga_find_from_distance (ga, from);
    if (dist == NULL)
	return DBL_MAX;

    sub = tsp_ga_find_to_distance (dist, to);
    if (sub != NULL)
	return sub->Cost;
    return DBL_MAX;
}

static void
tsp_ga_random_solutions (sqlite3 * handle, TspGaPopulationPtr ga, int *index1,
			 int *index2)
{
/* fetching two random TSP GA solutions */
    int i;
    int ret;
    int n_rows;
    int n_columns;
    const char *value = NULL;
    char **results;

    *index1 = -1;
    *index2 = -1;

    ret =
	sqlite3_get_table (handle, ga->RandomSolutionsSql, &results, &n_rows,
			   &n_columns, NULL);
    if (ret != SQLITE_OK)
	return;
    if (n_rows >= 1)
      {
	  for (i = 1; i <= n_rows; i++)
	    {
		value = results[(i * n_columns) + 0];
		if (i == 1)
		    *index1 = atoi (value);
		else
		    *index2 = atoi (value);
	    }
      }
    sqlite3_free_table (results);
}

static void
tsp_ga_random_interval (sqlite3 * handle, TspGaPopulationPtr ga, int *index1,
			int *index2)
{
/* fetching a random TSP GA interval */
    int i;
    int ret;
    int n_rows;
    int n_columns;
    const char *value = NULL;
    char **results;

    *index1 = -1;
    *index2 = -1;

    ret =
	sqlite3_get_table (handle, ga->RandomIntervalSql, &results, &n_rows,
			   &n_columns, NULL);
    if (ret != SQLITE_OK)
	return;
    if (n_rows >= 1)
      {
	  for (i = 1; i <= n_rows; i++)
	    {
		value = results[(i * n_columns) + 0];
		if (i == 1)
		    *index1 = atoi (value);
		else
		    *index2 = atoi (value);
	    }
      }
    sqlite3_free_table (results);
}

static void
tps_ga_chromosome_update (TspGaSolutionPtr chromosome, RouteNodePtr from,
			  RouteNodePtr to, double cost)
{
/* updating a chromosome (missing distance) */
    int j;
    for (j = 0; j < chromosome->Cities; j++)
      {
	  RouteNodePtr n1 = *(chromosome->CitiesFrom + j);
	  RouteNodePtr n2 = *(chromosome->CitiesTo + j);
	  if (n1 == from && n2 == to)
	      *(chromosome->Costs + j) = cost;
      }
}

static void
tsp_ga_random_mutation (sqlite3 * handle, TspGaPopulationPtr ga,
			TspGaSolutionPtr mutant)
{
/* introducing a random mutation */
    RouteNodePtr mutation;
    int j;
    int idx1;
    int idx2;

/* applying a random mutation */
    tsp_ga_random_interval (handle, ga, &idx1, &idx2);
    mutation = *(mutant->CitiesFrom + idx1);
    *(mutant->CitiesFrom + idx1) = *(mutant->CitiesFrom + idx2);
    *(mutant->CitiesFrom + idx2) = mutation;

/* adjusting From/To */
    for (j = 1; j < mutant->Cities; j++)
      {
	  RouteNodePtr pFrom = *(mutant->CitiesFrom + j);
	  *(mutant->CitiesTo + j - 1) = pFrom;
      }
    *(mutant->CitiesTo + mutant->Cities - 1) = *(mutant->CitiesFrom + 0);

/* adjusting Costs */
    mutant->TotalCost = 0.0;
    for (j = 0; j < mutant->Cities; j++)
      {
	  RouteNodePtr pFrom = *(mutant->CitiesFrom + j);
	  RouteNodePtr pTo = *(mutant->CitiesTo + j);
	  double cost = tsp_ga_find_distance (ga, pFrom, pTo);
	  tps_ga_chromosome_update (mutant, pFrom, pTo, cost);
	  *(mutant->Costs + j) = cost;
	  mutant->TotalCost += cost;
      }
}

static TspGaSolutionPtr
tsp_ga_clone_solution (TspGaPopulationPtr ga, TspGaSolutionPtr original)
{
/* cloning a TSP GA solution */
    int j;
    TspGaSolutionPtr clone;
    if (original == NULL)
	return NULL;

    clone = malloc (sizeof (TspGaSolution));
    clone->Cities = original->Cities;
    clone->CitiesFrom = malloc (sizeof (RouteNodePtr) * ga->Cities);
    clone->CitiesTo = malloc (sizeof (RouteNodePtr) * ga->Cities);
    clone->Costs = malloc (sizeof (double) * ga->Cities);
    for (j = 0; j < ga->Cities; j++)
      {
	  *(clone->CitiesFrom + j) = *(original->CitiesFrom + j);
	  *(clone->CitiesTo + j) = *(original->CitiesTo + j);
	  *(clone->Costs + j) = *(original->Costs + j);
      }
    clone->TotalCost = 0.0;
    return clone;
}

static TspGaSolutionPtr
tsp_ga_crossover (sqlite3 * handle, TspGaPopulationPtr ga, int mutation1,
		  int mutation2)
{
/* creating a Crossover solution */
    int j;
    int idx1;
    int idx2;
    TspGaSolutionPtr hybrid;
    TspGaSolutionPtr parent1 = NULL;
    TspGaSolutionPtr parent2 = NULL;

/* randomly choosing two parents */
    tsp_ga_random_solutions (handle, ga, &idx1, &idx2);
    if (idx1 >= 0 && idx1 < ga->Count)
	parent1 = tsp_ga_clone_solution (ga, *(ga->Solutions + idx1));
    if (idx2 >= 0 && idx2 < ga->Count)
	parent2 = tsp_ga_clone_solution (ga, *(ga->Solutions + idx2));
    if (parent1 == NULL || parent2 == NULL)
	goto stop;

    if (mutation1)
	tsp_ga_random_mutation (handle, ga, parent1);
    if (mutation2)
	tsp_ga_random_mutation (handle, ga, parent2);

/* creating an empty hybrid */
    hybrid = malloc (sizeof (TspGaSolution));
    hybrid->Cities = ga->Cities;
    hybrid->CitiesFrom = malloc (sizeof (RouteNodePtr) * ga->Cities);
    hybrid->CitiesTo = malloc (sizeof (RouteNodePtr) * ga->Cities);
    hybrid->Costs = malloc (sizeof (double) * ga->Cities);
    for (j = 0; j < ga->Cities; j++)
      {
	  *(hybrid->CitiesFrom + j) = NULL;
	  *(hybrid->CitiesTo + j) = NULL;
	  *(hybrid->Costs + j) = DBL_MAX;
      }
    hybrid->TotalCost = 0.0;

/* step #1: inheritance from the fist parent */
    tsp_ga_random_interval (handle, ga, &idx1, &idx2);
    if (idx1 < idx2)
      {
	  for (j = idx1; j <= idx2; j++)
	      *(hybrid->CitiesFrom + j) = *(parent1->CitiesFrom + j);
      }
    else
      {
	  for (j = idx2; j <= idx1; j++)
	      *(hybrid->CitiesFrom + j) = *(parent1->CitiesFrom + j);
      }

/* step #2: inheritance from the second parent */
    for (j = 0; j < parent2->Cities; j++)
      {
	  RouteNodePtr p2From = *(parent2->CitiesFrom + j);
	  int k;
	  int found = 0;
	  if (p2From == NULL)
	      continue;
	  for (k = 0; k < hybrid->Cities; k++)
	    {
		RouteNodePtr p1From = *(hybrid->CitiesFrom + k);
		if (p1From == NULL)
		    continue;
		if (p1From == p2From)
		  {
		      /* already present: skipping */
		      found = 1;
		      break;
		  }
	    }
	  if (found)
	      continue;
	  for (k = 0; k < hybrid->Cities; k++)
	    {
		if (*(hybrid->CitiesFrom + k) == NULL
		    && *(hybrid->CitiesTo + k) == NULL
		    && *(hybrid->Costs + k) == DBL_MAX)
		  {
		      /* found an empty slot: inserting */
		      *(hybrid->CitiesFrom + k) = p2From;
		      break;
		  }
	    }
      }
    destroy_tsp_ga_solution (parent1);
    destroy_tsp_ga_solution (parent2);

/* adjusting From/To */
    for (j = 1; j < hybrid->Cities; j++)
      {
	  RouteNodePtr p1From = *(hybrid->CitiesFrom + j);
	  *(hybrid->CitiesTo + j - 1) = p1From;
      }
    *(hybrid->CitiesTo + hybrid->Cities - 1) = *(hybrid->CitiesFrom + 0);

/* retrieving cached costs */
    for (j = 0; j < hybrid->Cities; j++)
      {
	  RouteNodePtr pFrom = *(hybrid->CitiesFrom + j);
	  RouteNodePtr pTo = *(hybrid->CitiesTo + j);
	  double cost = tsp_ga_find_distance (ga, pFrom, pTo);
	  tps_ga_chromosome_update (hybrid, pFrom, pTo, cost);
	  hybrid->TotalCost += cost;
      }
    return hybrid;

  stop:
    if (parent1 != NULL)
	destroy_tsp_ga_solution (parent1);
    if (parent2 != NULL)
	destroy_tsp_ga_solution (parent2);
    return NULL;
}

static void
evalTspGaFitness (TspGaPopulationPtr ga)
{
/* evaluating the comparative fitness of parents and offsprings */
    int j;
    int i;
    int index;
    int already_defined = 0;

    for (j = 0; j < ga->Count; j++)
      {
	  /* evaluating an offsprings */
	  double max_cost = 0.0;
	  TspGaSolutionPtr hybrid = *(ga->Offsprings + j);

	  for (i = 0; i < ga->Count; i++)
	    {
		/* searching the worst parent */
		TspGaSolutionPtr old = *(ga->Solutions + i);
		if (old->TotalCost > max_cost)
		  {
		      max_cost = old->TotalCost;
		      index = i;
		  }
		if (old->TotalCost == hybrid->TotalCost)
		    already_defined = 1;
	    }
	  if (max_cost > hybrid->TotalCost && !already_defined)
	    {
		/* inserting the new hybrid by replacing the worst parent */
		TspGaSolutionPtr kill = *(ga->Solutions + index);
		*(ga->Solutions + index) = hybrid;
		*(ga->Offsprings + j) = NULL;
		destroy_tsp_ga_solution (kill);
	    }
      }
}

static MultiSolutionPtr
tsp_ga_compute_route (sqlite3 * handle, int options, RouteNodePtr origin,
		      RouteNodePtr destination, RoutingPtr graph,
		      RoutingNodesPtr routing)
{
/* computing a route from City to City */
    RoutingMultiDestPtr to = NULL;
    MultiSolutionPtr ms = alloc_multiSolution ();
    ms->From = origin;
    to = malloc (sizeof (RoutingMultiDest));
    ms->MultiTo = to;
    to->CodeNode = graph->NodeCode;
    to->Found = malloc (sizeof (char));
    to->To = malloc (sizeof (RouteNodePtr));
    *(to->Found + 0) = 'N';
    *(to->To + 0) = destination;
    to->Items = 1;
    to->Next = 0;
    if (graph->NodeCode)
      {
	  int len = strlen (destination->Code);
	  to->Ids = NULL;
	  to->Codes = malloc (sizeof (char *));
	  *(to->Codes + 0) = malloc (len + 1);
	  strcpy (*(to->Codes + 0), destination->Code);
      }
    else
      {
	  to->Ids = malloc (sizeof (sqlite3_int64));
	  to->Codes = NULL;
	  *(to->Ids + 0) = destination->Id;
      }

    dijkstra_multi_shortest_path (handle, options, graph, routing, ms);
    return (ms);
}

static void
completing_tsp_ga_solution (sqlite3 * handle, int options, RouteNodePtr origin,
			    RouteNodePtr destination, RoutingPtr graph,
			    RoutingNodesPtr routing, TspTargetsPtr targets,
			    int j)
{
/* completing a TSP GA solution */
    ShortestPathSolutionPtr solution;
    MultiSolutionPtr result =
	tsp_ga_compute_route (handle, options, origin, destination, graph,
			      routing);

    solution = result->First;
    while (solution != NULL)
      {
	  RowSolutionPtr old;
	  ShortestPathSolutionPtr newSolution = alloc_solution ();
	  newSolution->From = origin;
	  newSolution->To = destination;
	  newSolution->TotalCost += solution->TotalCost;
	  targets->TotalCost += solution->TotalCost;
	  newSolution->Geometry = solution->Geometry;
	  solution->Geometry = NULL;
	  if (j < 0)
	      targets->LastSolution = newSolution;
	  else
	      *(targets->Solutions + j) = newSolution;
	  old = solution->First;
	  while (old != NULL)
	    {
		/* inserts an Arc into the Shortest Path solution */
		RowSolutionPtr p = malloc (sizeof (RowSolution));
		p->Arc = old->Arc;
		p->Name = old->Name;
		old->Name = NULL;
		p->Next = NULL;
		if (!(newSolution->First))
		    newSolution->First = p;
		if (newSolution->Last)
		    newSolution->Last->Next = p;
		newSolution->Last = p;
		old = old->Next;
	    }
	  solution = solution->Next;
      }
    delete_multiSolution (result);
}

static void
set_tsp_ga_targets (sqlite3 * handle, int options, RoutingPtr graph,
		    RoutingNodesPtr routing, TspGaSolutionPtr bestSolution,
		    TspTargetsPtr targets)
{
/* preparing TSP GA targets (best solution found) */
    int j;
    RouteNodePtr from;
    RouteNodePtr to;

    for (j = 0; j < targets->Count; j++)
      {
	  from = *(bestSolution->CitiesFrom + j);
	  to = *(bestSolution->CitiesTo + j);
	  completing_tsp_ga_solution (handle, options, from, to,
				      graph, routing, targets, j);
	  *(targets->To + j) = to;
	  *(targets->Found + j) = 'Y';
      }
    /* this is the final City closing the circular path */
    from = *(bestSolution->CitiesFrom + targets->Count);
    to = *(bestSolution->CitiesTo + targets->Count);
    completing_tsp_ga_solution (handle, options, from, to, graph,
				routing, targets, -1);
}

static TspTargetsPtr
build_tsp_ga_solution_targets (int count, RouteNodePtr from)
{
/* creating and initializing the TSP helper struct - final solution */
    int i;
    TspTargetsPtr targets = malloc (sizeof (TspTargets));
    targets->Mode = VROUTE_TSP_SOLUTION;
    targets->TotalCost = 0.0;
    targets->Count = count;
    targets->To = malloc (sizeof (RouteNodePtr *) * targets->Count);
    targets->Found = malloc (sizeof (char) * targets->Count);
    targets->Costs = malloc (sizeof (double) * targets->Count);
    targets->Solutions =
	malloc (sizeof (ShortestPathSolutionPtr) * targets->Count);
    targets->LastSolution = NULL;
    targets->From = from;
    for (i = 0; i < targets->Count; i++)
      {
	  *(targets->To + i) = NULL;
	  *(targets->Found + i) = 'N';
	  *(targets->Costs + i) = DBL_MAX;
	  *(targets->Solutions + i) = NULL;
      }
    return targets;
}

static TspTargetsPtr
tsp_ga_permuted_targets (RouteNodePtr from, RoutingMultiDestPtr multi,
			 int index)
{
/* initializing the TSP helper struct - permuted */
    int i;
    TspTargetsPtr targets = malloc (sizeof (TspTargets));
    targets->Mode = VROUTE_ROUTING_SOLUTION;
    targets->TotalCost = 0.0;
    targets->Count = multi->Items;
    targets->To = malloc (sizeof (RouteNodePtr *) * targets->Count);
    targets->Found = malloc (sizeof (char) * targets->Count);
    targets->Costs = malloc (sizeof (double) * targets->Count);
    targets->Solutions =
	malloc (sizeof (ShortestPathSolutionPtr) * targets->Count);
    targets->LastSolution = NULL;
    if (index < 0)
      {
	  /* no permutation */
	  targets->From = from;
	  for (i = 0; i < targets->Count; i++)
	    {
		*(targets->To + i) = *(multi->To + i);
		*(targets->Found + i) = 'N';
		*(targets->Costs + i) = DBL_MAX;
		*(targets->Solutions + i) = NULL;
	    }
      }
    else
      {
	  /* permuting */
	  targets->From = *(multi->To + index);
	  for (i = 0; i < targets->Count; i++)
	    {
		if (i == index)
		  {
		      *(targets->To + i) = from;
		      *(targets->Found + i) = 'N';
		      *(targets->Costs + i) = DBL_MAX;
		      *(targets->Solutions + i) = NULL;
		  }
		else
		  {
		      *(targets->To + i) = *(multi->To + i);
		      *(targets->Found + i) = 'N';
		      *(targets->Costs + i) = DBL_MAX;
		      *(targets->Solutions + i) = NULL;
		  }
	    }
      }
    return targets;
}

static int
build_tsp_nn_solution (TspGaPopulationPtr ga, TspTargetsPtr targets, int index)
{
/* building a TSP NN solution */
    int j;
    int i;
    RouteNodePtr origin;
    TspGaDistancePtr dist;
    TspGaSubDistancePtr sub;
    RouteNodePtr destination;
    double cost;
    TspGaSolutionPtr solution = malloc (sizeof (TspGaSolution));
    solution->Cities = targets->Count + 1;
    solution->CitiesFrom = malloc (sizeof (RouteNodePtr) * solution->Cities);
    solution->CitiesTo = malloc (sizeof (RouteNodePtr) * solution->Cities);
    solution->Costs = malloc (sizeof (double) * solution->Cities);
    solution->TotalCost = 0.0;

    origin = targets->From;
    for (j = 0; j < targets->Count; j++)
      {
	  /* searching the nearest City */
	  dist = tsp_ga_find_from_distance (ga, origin);
	  if (dist == NULL)
	      return 0;
	  destination = NULL;
	  cost = DBL_MAX;

	  sub = *(dist->Distances + dist->NearestIndex);
	  destination = sub->CityTo;
	  cost = sub->Cost;
	  /* excluding the last City (should be a closed circuit) */
	  if (destination == targets->From)
	      destination = NULL;
	  if (destination != NULL)
	    {
		for (i = 0; i < targets->Count; i++)
		  {
		      /* checking if this City was already reached */
		      RouteNodePtr city = *(targets->To + i);
		      if (city == destination)
			{
			    if (*(targets->Found + i) == 'Y')
				destination = NULL;
			    else
				*(targets->Found + i) = 'Y';
			    break;
			}
		  }
	    }
	  if (destination == NULL)
	    {
		/* searching for an alternative destination */
		double min = DBL_MAX;
		int ind = -1;
		int k;
		for (k = 0; k < dist->Cities; k++)
		  {
		      sub = *(dist->Distances + k);
		      RouteNodePtr city = sub->CityTo;
		      /* excluding the last City (should be a closed circuit) */
		      if (city == targets->From)
			  continue;
		      for (i = 0; i < targets->Count; i++)
			{
			    RouteNodePtr city2 = *(targets->To + i);
			    if (*(targets->Found + i) == 'Y')
				continue;
			    if (city == city2)
			      {
				  if (sub->Cost < min)
				    {
					min = sub->Cost;
					ind = k;
				    }
			      }
			}
		  }
		if (ind >= 0)
		  {
		      sub = *(dist->Distances + ind);
		      destination = sub->CityTo;
		      cost = min;
		      for (i = 0; i < targets->Count; i++)
			{
			    RouteNodePtr city = *(targets->To + i);
			    if (city == destination)
			      {
				  *(targets->Found + i) = 'Y';
				  break;
			      }
			}
		  }
	    }
	  if (destination == NULL)
	      return 0;
	  *(solution->CitiesFrom + j) = origin;
	  *(solution->CitiesTo + j) = destination;
	  *(solution->Costs + j) = cost;
	  solution->TotalCost += cost;
	  origin = destination;
      }

/* returning to FROM so to close the circular path */
    destination = targets->From;
    for (i = 0; i < ga->Cities; i++)
      {
	  TspGaDistancePtr d = *(ga->Distances + i);
	  if (d->CityFrom == origin)
	    {
		int k;
		dist = *(ga->Distances + i);
		for (k = 0; k < dist->Cities; k++)
		  {
		      sub = *(dist->Distances + k);
		      RouteNodePtr city = sub->CityTo;
		      if (city == destination)
			{
			    cost = sub->Cost;
			    *(solution->CitiesFrom + targets->Count) = origin;
			    *(solution->CitiesTo + targets->Count) =
				destination;
			    *(solution->Costs + targets->Count) = cost;
			    solution->TotalCost += cost;
			}
		  }
	    }
      }

/* inserting into the GA population */
    *(ga->Solutions + index) = solution;
    return 1;
}

static int
cmp_nodes_addr (const void *p1, const void *p2)
{
/* compares two nodes  by addr [for QSORT] */
    TspGaDistancePtr pD1 = *((TspGaDistancePtr *) p1);
    TspGaDistancePtr pD2 = *((TspGaDistancePtr *) p2);
    RouteNodePtr pN1 = pD1->CityFrom;
    RouteNodePtr pN2 = pD2->CityFrom;
    if (pN1 == pN2)
	return 0;
    if (pN1 > pN2)
	return 1;
    return -1;
}

static int
cmp_dist_addr (const void *p1, const void *p2)
{
/* compares two nodes  by addr [for QSORT] */
    TspGaSubDistancePtr pD1 = *((TspGaSubDistancePtr *) p1);
    TspGaSubDistancePtr pD2 = *((TspGaSubDistancePtr *) p2);
    RouteNodePtr pN1 = pD1->CityTo;
    RouteNodePtr pN2 = pD2->CityTo;
    if (pN1 == pN2)
	return 0;
    if (pN1 > pN2)
	return 1;
    return -1;
}

static void
tsp_ga_sort_distances (TspGaPopulationPtr ga)
{
/* sorting Distances/Costs by Node addr */
    int i;
    qsort (ga->Distances, ga->Cities, sizeof (RouteNodePtr), cmp_nodes_addr);
    for (i = 0; i < ga->Cities; i++)
      {
	  TspGaDistancePtr dist = *(ga->Distances + i);
	  qsort (dist->Distances, dist->Cities, sizeof (TspGaSubDistancePtr),
		 cmp_dist_addr);
      }
    for (i = 0; i < ga->Cities; i++)
      {
	  int k;
	  int index = -1;
	  double min = DBL_MAX;
	  TspGaDistancePtr dist = *(ga->Distances + i);
	  for (k = 0; k < dist->Cities; k++)
	    {
		TspGaSubDistancePtr sub = *(dist->Distances + k);
		if (sub->Cost < min)
		  {
		      min = sub->Cost;
		      index = k;
		  }
	    }
	  if (index >= 0)
	      dist->NearestIndex = index;
      }
}

static void
tsp_ga_solve (sqlite3 * handle, int options, RoutingPtr graph,
	      RoutingNodesPtr routing, MultiSolutionPtr multiSolution)
{
/* computing a Dijkstra TSP GA Solution */
    int i;
    int j;
    double min;
    TspGaSolutionPtr bestSolution;
    int count = 0;
    int max_iterations = VROUTE_TSP_GA_MAX_ITERATIONS;
    TspGaPopulationPtr ga = NULL;
    RoutingMultiDestPtr multi;
    TspTargetsPtr targets;
    TspGaDistancePtr dist;

    if (multiSolution == NULL)
	return;
    multi = multiSolution->MultiTo;
    if (multi == NULL)
	return;

/* initialinzing the TSP GA helper struct */
    ga = build_tsp_ga_population (multi->Items + 1);

    for (i = -1; i < multi->Items; i++)
      {
	  /* determining all City-to-City distances (costs) */
	  targets = tsp_ga_permuted_targets (multiSolution->From, multi, i);
	  for (j = 0; j < targets->Count; j++)
	    {
		/* checking for undefined targets */
		if (*(targets->To + j) == NULL)
		  {
		      int k;
		      for (k = 0; k < targets->Count; k++)
			{
			    /* maskinkg unreachable targets */
			    *(targets->Found + k) = 'Y';
			}
		      build_tsp_illegal_solution (multiSolution, targets);
		      destroy_tsp_targets (targets);
		      goto invalid;
		  }
	    }
	  dijkstra_targets_solve (routing, targets);
	  for (j = 0; j < targets->Count; j++)
	    {
		/* checking for unreachable targets */
		if (*(targets->Found + j) != 'Y')
		  {
		      build_tsp_illegal_solution (multiSolution, targets);
		      destroy_tsp_targets (targets);
		      goto invalid;
		  }
	    }
	  /* inserting the distances/costs into the helper struct */
	  dist = alloc_tsp_ga_distances (targets);
	  *(ga->Distances + i + 1) = dist;
	  destroy_tsp_targets (targets);
      }
    tsp_ga_sort_distances (ga);

    for (i = -1; i < multi->Items; i++)
      {
	  /* initializing GA using permuted NN solutions */
	  int ret;
	  targets = tsp_ga_permuted_targets (multiSolution->From, multi, i);
	  ret = build_tsp_nn_solution (ga, targets, i + 1);
	  destroy_tsp_targets (targets);
	  if (!ret)
	      goto invalid;
      }

    while (max_iterations >= 0)
      {
	  /* sexual reproduction and darwinian selection */
	  for (i = 0; i < ga->Count; i++)
	    {
		/* Genetic loop - with mutations */
		TspGaSolutionPtr hybrid;
		int mutation1 = 0;
		int mutation2 = 0;
		count++;
		if (count % 13 == 0)
		  {
		      /* introducing a random mutation on parent #1 */
		      mutation1 = 1;
		  }
		if (count % 16 == 0)
		  {
		      /* introducing a random mutation on parent #2 */
		      mutation2 = 1;
		  }
		hybrid = tsp_ga_crossover (handle, ga, mutation1, mutation2);
		*(ga->Offsprings + i) = hybrid;
	    }
	  evalTspGaFitness (ga);
	  free_tsp_ga_offsprings (ga);
	  max_iterations--;
      }

/* building the TSP GA solution */
    min = DBL_MAX;
    bestSolution = NULL;
    for (i = 0; i < ga->Count; i++)
      {
	  /* searching the best solution */
	  TspGaSolutionPtr old = *(ga->Solutions + i);
	  if (old == NULL)
	      continue;
	  if (old->TotalCost < min)
	    {
		min = old->TotalCost;
		bestSolution = old;
	    }
      }
    if (bestSolution != NULL)
      {
	  targets =
	      build_tsp_ga_solution_targets (multiSolution->MultiTo->Items,
					     multiSolution->From);
	  set_tsp_ga_targets (handle, options, graph, routing, bestSolution,
			      targets);
	  build_tsp_solution (multiSolution, targets);
	  destroy_tsp_targets (targets);
      }
    destroy_tsp_ga_population (ga);
    return;

  invalid:
    destroy_tsp_ga_population (ga);
}

static void
network_free (RoutingPtr p)
{
/* memory cleanup; freeing any allocation for the network struct */
    RouteNodePtr pN;
    int i;
................................................................................
		  {
		      tsp_nn_solve (net->db, net->currentOptions, net->graph,
				    net->routing, cursor->pVtab->multiSolution);
		      cursor->pVtab->multiSolution->CurrentRowId = 0;
		      cursor->pVtab->multiSolution->CurrentRow =
			  cursor->pVtab->multiSolution->FirstRow;
		  }
	    }
	  else if (net->currentRequest == VROUTE_TSP_GA)
	    {
		cursor->pVtab->multiSolution->Mode = VROUTE_TSP_SOLUTION;
		if (net->currentAlgorithm == VROUTE_DIJKSTRA_ALGORITHM)
		  {
		      tsp_ga_solve (net->db, net->currentOptions, net->graph,
				    net->routing, cursor->pVtab->multiSolution);
		      cursor->pVtab->multiSolution->CurrentRowId = 0;
		      cursor->pVtab->multiSolution->CurrentRow =
			  cursor->pVtab->multiSolution->FirstRow;
		  }
	    }
	  else
	    {
		cursor->pVtab->multiSolution->Mode = VROUTE_ROUTING_SOLUTION;
		if (net->currentAlgorithm == VROUTE_A_STAR_ALGORITHM)
		    astar_solve (net->db, net->currentOptions, net->graph,
				 net->routing, cursor->pVtab->multiSolution);
................................................................................
					   SQLITE_TRANSIENT);
		  }
		else if (column == 1)
		  {
		      /* the current Request type */
		      if (net->currentRequest == VROUTE_TSP_NN)
			  algorithm = "TSP NN";
		      else if (net->currentRequest == VROUTE_TSP_GA)
			  algorithm = "TSP GA";
		      else
			  algorithm = "Shortest Path";
		      sqlite3_result_text (pContext, algorithm,
					   strlen (algorithm),
					   SQLITE_TRANSIENT);
		  }
		else if (column == 2)
................................................................................
				   cursor->pVtab->currentDelimiter);
		      sqlite3_result_text (pContext, delimiter,
					   strlen (delimiter),
					   SQLITE_TRANSIENT);
		  }
		else
		    sqlite3_result_null (pContext);
		return SQLITE_OK;
	    }
	  if (row->Undefined != NULL)
	    {
		/* special case: there is an undefined destination */
		if (column == 0)
		  {
		      /* the currently used Algorithm */
		      if (net->currentAlgorithm == VROUTE_A_STAR_ALGORITHM)
			  algorithm = "A*";
		      else
			  algorithm = "Dijkstra";
		      sqlite3_result_text (pContext, algorithm,
					   strlen (algorithm),
					   SQLITE_TRANSIENT);
		  }
		if (column == 1)
		  {
		      /* the current Request type */
		      if (net->currentRequest == VROUTE_TSP_NN)
			  algorithm = "TSP NN";
		      else if (net->currentRequest == VROUTE_TSP_GA)
			  algorithm = "TSP GA";
		      else
			  algorithm = "Shortest Path";
		      sqlite3_result_text (pContext, algorithm,
					   strlen (algorithm),
					   SQLITE_TRANSIENT);
		  }
		if (column == 2)
		  {
		      /* the currently set Options */
		      if (net->currentOptions == VROUTE_SHORTEST_PATH_SIMPLE)
			  algorithm = "Simple";
		      else if (net->currentOptions ==
			       VROUTE_SHORTEST_PATH_NO_ARCS)
			  algorithm = "No Arcs";
		      else if (net->currentOptions ==
			       VROUTE_SHORTEST_PATH_NO_GEOMS)
			  algorithm = "No Geometries";
		      else
			  algorithm = "Full";
		      sqlite3_result_text (pContext, algorithm,
					   strlen (algorithm),
					   SQLITE_TRANSIENT);
		  }
		if (column == 3)
		  {
		      /* the currently set delimiter char */
		      if (isprint (cursor->pVtab->currentDelimiter))
			  sprintf (delimiter, "%c [dec=%d, hex=%02x]",
				   cursor->pVtab->currentDelimiter,
				   cursor->pVtab->currentDelimiter,
				   cursor->pVtab->currentDelimiter);
		      else
			  sprintf (delimiter, "[dec=%d, hex=%02x]",
				   cursor->pVtab->currentDelimiter,
				   cursor->pVtab->currentDelimiter);
		      sqlite3_result_text (pContext, delimiter,
					   strlen (delimiter),
					   SQLITE_TRANSIENT);
		  }
		if (column == 4)
		  {
		      /* the RouteNum column */
		      sqlite3_result_int (pContext, row->RouteNum);
		  }
		if (column == 5)
		  {
		      /* the RouteRow column */
		      sqlite3_result_int (pContext, row->RouteRow);
		  }
		if (column == 6)
		  {
		      /* role of this row */
		      if (row->To != NULL)
			  role = "Unreachable NodeTo";
		      else
			  role = "Undefined NodeTo";
		      sqlite3_result_text (pContext, role, strlen (role),
					   SQLITE_TRANSIENT);
		  }
		if (column == 7)
		  {
		      /* the ArcRowId column */
		      sqlite3_result_null (pContext);
		  }
		if (column == 8)
		  {
		      /* the NodeFrom column */
		      if (row->From == NULL)
			{
			    sqlite3_result_text (pContext,
						 row->Undefined,
						 strlen (row->Undefined),
						 SQLITE_STATIC);
			}
		      else
			{
			    if (node_code)
				sqlite3_result_text (pContext,
						     row->From->Code,
						     strlen (row->From->Code),
						     SQLITE_STATIC);
			    else
				sqlite3_result_int64 (pContext, row->From->Id);
			}
		  }
		if (column == 9)
		  {
		      /* the NodeTo column */
		      sqlite3_result_text (pContext,
					   row->Undefined,
					   strlen (row->Undefined),
					   SQLITE_STATIC);
		  }
		if (column == 10)
		  {
		      /* the Cost column */
		      sqlite3_result_null (pContext);
		  }
		if (column == 11)
		  {
		      /* the Geometry column */
		      sqlite3_result_null (pContext);
		  }
		if (column == 12)
		  {
		      /* the [optional] Name column */
		      sqlite3_result_null (pContext);
		  }
		return SQLITE_OK;
	    }
	  if (row->linkRef == NULL)
	    {
		/* special case: this one is the solution summary */
		if (column == 0)
		  {
................................................................................
					   SQLITE_TRANSIENT);
		  }
		if (column == 1)
		  {
		      /* the current Request type */
		      if (net->currentRequest == VROUTE_TSP_NN)
			  algorithm = "TSP NN";
		      else if (net->currentRequest == VROUTE_TSP_GA)
			  algorithm = "TSP GA";
		      else
			  algorithm = "Shortest Path";
		      sqlite3_result_text (pContext, algorithm,
					   strlen (algorithm),
					   SQLITE_TRANSIENT);
		  }
		if (column == 2)
................................................................................
		      sqlite3_result_int (pContext, row->RouteRow);
		  }
		if (column == 6)
		  {
		      /* role of this row */
		      if (cursor->pVtab->multiSolution->Mode ==
			  VROUTE_TSP_SOLUTION && row->RouteNum == 0)


			  role = "TSP Solution";
		      else
			{
			    if (row->From == row->To)
				role = "Unreachable NodeTo";

			    else
				role = "Route";
			}
		      sqlite3_result_text (pContext, role, strlen (role),
					   SQLITE_TRANSIENT);
		  }
		if (row->From == NULL || row->To == NULL)
		  {
		      /* empty [uninitialized] solution */
		      if (column > 0)
................................................................................
					       SQLITE_STATIC);
		      else
			  sqlite3_result_int64 (pContext, row->To->Id);
		  }
		if (column == 10)
		  {
		      /* the Cost column */
		      if (row->RouteNum != 0 && (row->From == row->To))
			  sqlite3_result_null (pContext);
		      else
			  sqlite3_result_double (pContext, row->TotalCost);
		  }
		if (column == 11)
		  {
		      /* the Geometry column */
		      if (!(row->Geometry))
			  sqlite3_result_null (pContext);
		      else
................................................................................
					   SQLITE_TRANSIENT);
		  }
		if (column == 1)
		  {
		      /* the current Request type */
		      if (net->currentRequest == VROUTE_TSP_NN)
			  algorithm = "TSP NN";
		      else if (net->currentRequest == VROUTE_TSP_GA)
			  algorithm = "TSP GA";
		      else
			  algorithm = "Shortest Path";
		      sqlite3_result_text (pContext, algorithm,
					   strlen (algorithm),
					   SQLITE_TRANSIENT);
		  }
		if (column == 2)
................................................................................
			    const unsigned char *request =
				sqlite3_value_text (argv[3]);
			    if (strcasecmp ((char *) request, "TSP") == 0)
				p_vtab->currentRequest = VROUTE_TSP_NN;
			    else if (strcasecmp
				     ((char *) request, "TSP NN") == 0)
				p_vtab->currentRequest = VROUTE_TSP_NN;
			    else if (strcasecmp
				     ((char *) request, "TSP GA") == 0)
				p_vtab->currentRequest = VROUTE_TSP_GA;
			    else if (strcasecmp
				     ((char *) request, "SHORTEST PATH") == 0)
				p_vtab->currentRequest = VROUTE_SHORTEST_PATH;
			}
		      if (sqlite3_value_type (argv[4]) == SQLITE_TEXT)
			{
			    const unsigned char *options =

Changes to src/topology/gaia_auxtopo.c.

5307
5308
5309
5310
5311
5312
5313















































































































5314
5315
5316
5317
5318
5319
5320
....
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
....
5699
5700
5701
5702
5703
5704
5705





5706
5707

5708
5709
5710
5711
5712
5713
5714
....
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737





5738
5739

5740
5741
5742
5743
5744
5745
5746
....
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
....
5857
5858
5859
5860
5861
5862
5863

























































































































5864
5865
5866
5867
5868
5869
5870
....
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
....
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
....
6150
6151
6152
6153
6154
6155
6156
6157


















































































































6158
6159
6160
6161
6162
6163
6164
....
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
	  *edge_ids = ids;
	  *ids_count = nedges;
	  ret = 1;
	  rtfree (ctx, edgeids);
      }
    return ret;
}
















































































































GAIATOPO_DECLARE int
gaiaTopoGeo_AddPolygon (GaiaTopologyAccessorPtr accessor, gaiaPolygonPtr pg,
			double tolerance, sqlite3_int64 ** face_ids,
			int *ids_count)
{
/* RTT wrapper - AddPolygon */
................................................................................
      }
    return result;
}

TOPOLOGY_PRIVATE int
auxtopo_insert_into_topology (GaiaTopologyAccessorPtr accessor,
			      gaiaGeomCollPtr geom, double tolerance,
			      int line_max_points, double max_length)
{
/* processing all individual geometry items */
    gaiaPointPtr pt;
    gaiaLinestringPtr ln;
    gaiaGeomCollPtr g;
    gaiaGeomCollPtr split = NULL;
    gaiaGeomCollPtr pg_rings;
................................................................................
	  else
	      g = geom;
      }
    ln = g->FirstLinestring;
    while (ln != NULL)
      {
	  /* looping on Linestrings items */





	  if (gaiaTopoGeo_AddLineString
	      (accessor, ln, tolerance, &ids, &ids_count) == 0)

	      return 0;
	  if (ids != NULL)
	      free (ids);
	  ln = ln->Next;
      }
    if (split != NULL)
	gaiaFreeGeomColl (split);
................................................................................
    pg_rings = do_linearize (geom);
    if (pg_rings != NULL)
      {
	  if (line_max_points <= 0 && max_length <= 0.0)
	      g = pg_rings;
	  else
	    {
		/* subdividng Linestrings */
		split =
		    gaiaTopoGeo_SubdivideLines (pg_rings, line_max_points,
						max_length);
		if (split != NULL)
		    g = split;
		else
		    g = pg_rings;
	    }
	  ln = g->FirstLinestring;
	  while (ln != NULL)
	    {
		/* looping on Linestrings items */





		if (gaiaTopoGeo_AddLineString
		    (accessor, ln, tolerance, &ids, &ids_count) == 0)

		    return 0;
		if (ids != NULL)
		    free (ids);
		ln = ln->Next;
	    }
	  gaiaFreeGeomColl (pg_rings);
	  if (split != NULL)
................................................................................
		      gaiaGeomCollPtr geom =
			  gaiaFromSpatiaLiteBlobWkbEx (blob, blob_sz, gpkg_mode,
						       gpkg_amphibious);
		      if (geom != NULL)
			{
			    if (!auxtopo_insert_into_topology
				(accessor, geom, tolerance, line_max_points,
				 max_length))
			      {
				  gaiaFreeGeomColl (geom);
				  goto error;
			      }
			    gaiaFreeGeomColl (geom);
			}
		      else
................................................................................
		    sqlite3_mprintf ("TopoGeo_FromGeoTable error: \"%s\"",
				     sqlite3_errmsg (topo->db_handle));
		gaiatopo_set_last_error_msg (accessor, msg);
		sqlite3_free (msg);
		goto error;
	    }
      }


























































































































    sqlite3_finalize (stmt);
    return 1;

  error:
    if (stmt != NULL)
	sqlite3_finalize (stmt);
................................................................................

static int
do_FromGeoTableExtended_block (GaiaTopologyAccessorPtr accessor,
			       sqlite3_stmt * stmt, sqlite3_stmt * stmt_dustbin,
			       double tolerance, int line_max_points,
			       double max_length, sqlite3_int64 start,
			       sqlite3_int64 * last, sqlite3_int64 * invalid,
			       int *dustbin_count, sqlite3_int64 * dustbin_row)
{
/* attempting to import a whole block of input features */
    struct gaia_topology *topo = (struct gaia_topology *) accessor;
    int ret;
    int gpkg_amphibious = 0;
    int gpkg_mode = 0;
    int totcnt = 0;
................................................................................
			  gaiaFromSpatiaLiteBlobWkbEx (blob, blob_sz, gpkg_mode,
						       gpkg_amphibious);
		      if (geom != NULL)
			{
			    gaiatopo_reset_last_error_msg (accessor);
			    if (!auxtopo_insert_into_topology
				(accessor, geom, tolerance, line_max_points,
				 max_length))
			      {
				  char *msg;
				  const char *rt_msg =
				      gaiaGetRtTopoErrorMsg (topo->cache);
				  if (rt_msg == NULL)
				      msg =
					  sqlite3_mprintf
................................................................................
    while (1)
      {
	  /* main loop: attempting to import a block of features */
	  ret =
	      do_FromGeoTableExtended_block (accessor, stmt, stmt_dustbin,
					     tolerance, line_max_points,
					     max_length, start, &last, &invalid,
					     &dustbin_count, &dustbin_row);


















































































































	  if (ret < 0)		/* some unexpected error occurred */
	      goto error;
	  if (ret > 1)
	    {
		/* eof */
		break;
	    }
................................................................................
	    {
		/* found a failing feature; recovering */
		ret =
		    do_FromGeoTableExtended_block (accessor, stmt, stmt_dustbin,
						   tolerance, line_max_points,
						   max_length, start, &last,
						   &invalid, &dustbin_count,
						   &dustbin_row);
		if (ret != 1)
		    goto error;
		start = invalid;
		invalid = -1;
		dustbin_row = -1;
		continue;
	    }







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>
>
>
>
>
|
|
>







 







|












>
>
>
>
>
|
|
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







|







 







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
....
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
....
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
....
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
....
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
....
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
....
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
....
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
....
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
....
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
	  *edge_ids = ids;
	  *ids_count = nedges;
	  ret = 1;
	  rtfree (ctx, edgeids);
      }
    return ret;
}

GAIATOPO_DECLARE int
gaiaTopoGeo_AddLineStringNoFace (GaiaTopologyAccessorPtr accessor,
			   gaiaLinestringPtr ln, double tolerance,
			   sqlite3_int64 ** edge_ids, int *ids_count)
{
/* RTT wrapper - AddLinestring NO FACE */
    const RTCTX *ctx = NULL;
    struct splite_internal_cache *cache = NULL;
    int ret = 0;
    RTT_ELEMID *edgeids;
    int nedges;
    int i;
    sqlite3_int64 *ids;
    RTLINE *rt_line;
    struct gaia_topology *topo = (struct gaia_topology *) accessor;
    if (topo == NULL)
	return 0;

    cache = (struct splite_internal_cache *) topo->cache;
    if (cache == NULL)
	return 0;
    if (cache->magic1 != SPATIALITE_CACHE_MAGIC1
	|| cache->magic2 != SPATIALITE_CACHE_MAGIC2)
	return 0;
    ctx = cache->RTTOPO_handle;
    if (ctx == NULL)
	return 0;

    rt_line =
	gaia_convert_linestring_to_rtline (ctx, ln, topo->srid, topo->has_z);

    gaiaResetRtTopoMsg (cache);
    edgeids =
	rtt_AddLineNoFace ((RTT_TOPOLOGY *) (topo->rtt_topology), rt_line, tolerance,
		     &nedges);

    rtline_free (ctx, rt_line);
    if (edgeids != NULL)
      {
	  ids = malloc (sizeof (sqlite3_int64) * nedges);
	  for (i = 0; i < nedges; i++)
	      ids[i] = edgeids[i];
	  *edge_ids = ids;
	  *ids_count = nedges;
	  ret = 1;
	  rtfree (ctx, edgeids);
      }
    return ret;
}

GAIATOPO_DECLARE int
gaiaTopoGeo_Polygonize (GaiaTopologyAccessorPtr accessor)
{
/* RTT wrapper - Determine and register all topology faces */
    const RTCTX *ctx = NULL;
    struct splite_internal_cache *cache = NULL;
    struct gaia_topology *topo = (struct gaia_topology *) accessor;
    if (topo == NULL)
	return 0;

    cache = (struct splite_internal_cache *) topo->cache;
    if (cache == NULL)
	return 0;
    if (cache->magic1 != SPATIALITE_CACHE_MAGIC1
	|| cache->magic2 != SPATIALITE_CACHE_MAGIC2)
	return 0;
    ctx = cache->RTTOPO_handle;
    if (ctx == NULL)
	return 0;

    gaiaResetRtTopoMsg (cache);
    rtt_Polygonize ((RTT_TOPOLOGY *) (topo->rtt_topology));
    return 1;
}

GAIATOPO_DECLARE gaiaGeomCollPtr
gaiaTopoSnap (GaiaTopologyAccessorPtr accessor, gaiaGeomCollPtr geom, double tolerance, int iterate, int remove_vertices)
{
/* RTT wrapper - TopoSnap */
    const RTCTX *ctx = NULL;
    struct splite_internal_cache *cache = NULL;
    RTGEOM *input = NULL;
    RTGEOM *result = NULL;
    gaiaGeomCollPtr output;
    struct gaia_topology *topo = (struct gaia_topology *) accessor;
    if (topo == NULL)
	return 0;

    cache = (struct splite_internal_cache *) topo->cache;
    if (cache == NULL)
	return NULL;
    if (cache->magic1 != SPATIALITE_CACHE_MAGIC1
	|| cache->magic2 != SPATIALITE_CACHE_MAGIC2)
	return NULL;
    ctx = cache->RTTOPO_handle;
    if (ctx == NULL)
	return NULL;
    if (!geom)
	return NULL;

    result = rtt_tpsnap ((RTT_TOPOLOGY *) (topo->rtt_topology), input, tolerance, iterate, remove_vertices);
    if (result == NULL)
	return NULL;

/* converting the result as a Gaia Geometry */
	output = fromRTGeom (ctx, result, geom->DimensionModel, geom->DeclaredType);
	output->Srid = geom->Srid;
    rtgeom_free (ctx, result);
    return geom;
}

GAIATOPO_DECLARE int
gaiaTopoGeo_AddPolygon (GaiaTopologyAccessorPtr accessor, gaiaPolygonPtr pg,
			double tolerance, sqlite3_int64 ** face_ids,
			int *ids_count)
{
/* RTT wrapper - AddPolygon */
................................................................................
      }
    return result;
}

TOPOLOGY_PRIVATE int
auxtopo_insert_into_topology (GaiaTopologyAccessorPtr accessor,
			      gaiaGeomCollPtr geom, double tolerance,
			      int line_max_points, double max_length, int mode)
{
/* processing all individual geometry items */
    gaiaPointPtr pt;
    gaiaLinestringPtr ln;
    gaiaGeomCollPtr g;
    gaiaGeomCollPtr split = NULL;
    gaiaGeomCollPtr pg_rings;
................................................................................
	  else
	      g = geom;
      }
    ln = g->FirstLinestring;
    while (ln != NULL)
      {
	  /* looping on Linestrings items */
	  int ret;
	  if (mode == GAIA_MODE_TOPO_NO_FACE)
	  ret =gaiaTopoGeo_AddLineStringNoFace
	      (accessor, ln, tolerance, &ids, &ids_count);
	  else
	  ret = gaiaTopoGeo_AddLineString
	      (accessor, ln, tolerance, &ids, &ids_count);
	  if (ret == 0)
	      return 0;
	  if (ids != NULL)
	      free (ids);
	  ln = ln->Next;
      }
    if (split != NULL)
	gaiaFreeGeomColl (split);
................................................................................
    pg_rings = do_linearize (geom);
    if (pg_rings != NULL)
      {
	  if (line_max_points <= 0 && max_length <= 0.0)
	      g = pg_rings;
	  else
	    {
		/* subdividing Linestrings */
		split =
		    gaiaTopoGeo_SubdivideLines (pg_rings, line_max_points,
						max_length);
		if (split != NULL)
		    g = split;
		else
		    g = pg_rings;
	    }
	  ln = g->FirstLinestring;
	  while (ln != NULL)
	    {
		/* looping on Linestrings items */
		int ret;
		if (mode == GAIA_MODE_TOPO_NO_FACE)
		ret = gaiaTopoGeo_AddLineStringNoFace
		    (accessor, ln, tolerance, &ids, &ids_count);
		else
		ret = gaiaTopoGeo_AddLineString
		    (accessor, ln, tolerance, &ids, &ids_count);
		if (ret == 0)
		    return 0;
		if (ids != NULL)
		    free (ids);
		ln = ln->Next;
	    }
	  gaiaFreeGeomColl (pg_rings);
	  if (split != NULL)
................................................................................
		      gaiaGeomCollPtr geom =
			  gaiaFromSpatiaLiteBlobWkbEx (blob, blob_sz, gpkg_mode,
						       gpkg_amphibious);
		      if (geom != NULL)
			{
			    if (!auxtopo_insert_into_topology
				(accessor, geom, tolerance, line_max_points,
				 max_length, GAIA_MODE_TOPO_FACE))
			      {
				  gaiaFreeGeomColl (geom);
				  goto error;
			      }
			    gaiaFreeGeomColl (geom);
			}
		      else
................................................................................
		    sqlite3_mprintf ("TopoGeo_FromGeoTable error: \"%s\"",
				     sqlite3_errmsg (topo->db_handle));
		gaiatopo_set_last_error_msg (accessor, msg);
		sqlite3_free (msg);
		goto error;
	    }
      }

    sqlite3_finalize (stmt);
    return 1;

  error:
    if (stmt != NULL)
	sqlite3_finalize (stmt);
    return 0;
}

GAIATOPO_DECLARE int
gaiaTopoGeo_FromGeoTableNoFace (GaiaTopologyAccessorPtr accessor,
			  const char *db_prefix, const char *table,
			  const char *column, double tolerance,
			  int line_max_points, double max_length)
{
/* attempting to import a whole GeoTable into a Topology-Geometry
/  without determining generated faces */
    struct gaia_topology *topo = (struct gaia_topology *) accessor;
    sqlite3_stmt *stmt = NULL;
    int ret;
    char *sql;
    char *xprefix;
    char *xtable;
    char *xcolumn;
    int gpkg_amphibious = 0;
    int gpkg_mode = 0;

    if (topo == NULL)
	return 0;
    if (topo->cache != NULL)
      {
	  struct splite_internal_cache *cache =
	      (struct splite_internal_cache *) (topo->cache);
	  gpkg_amphibious = cache->gpkg_amphibious_mode;
	  gpkg_mode = cache->gpkg_mode;
      }

/* building the SQL statement */
    xprefix = gaiaDoubleQuotedSql (db_prefix);
    xtable = gaiaDoubleQuotedSql (table);
    xcolumn = gaiaDoubleQuotedSql (column);
    sql =
	sqlite3_mprintf ("SELECT \"%s\" FROM \"%s\".\"%s\"", xcolumn,
			 xprefix, xtable);
    free (xprefix);
    free (xtable);
    free (xcolumn);
    ret = sqlite3_prepare_v2 (topo->db_handle, sql, strlen (sql), &stmt, NULL);
    sqlite3_free (sql);
    if (ret != SQLITE_OK)
      {
	  char *msg = sqlite3_mprintf ("TopoGeo_FromGeoTableNoFace error: \"%s\"",
				       sqlite3_errmsg (topo->db_handle));
	  gaiatopo_set_last_error_msg (accessor, msg);
	  sqlite3_free (msg);
	  goto error;
      }

/* setting up the prepared statement */
    sqlite3_reset (stmt);
    sqlite3_clear_bindings (stmt);

    while (1)
      {
	  /* scrolling the result set rows */
	  ret = sqlite3_step (stmt);
	  if (ret == SQLITE_DONE)
	      break;		/* end of result set */
	  if (ret == SQLITE_ROW)
	    {
		if (sqlite3_column_type (stmt, 0) == SQLITE_NULL)
		    continue;
		if (sqlite3_column_type (stmt, 0) == SQLITE_BLOB)
		  {
		      const unsigned char *blob = sqlite3_column_blob (stmt, 0);
		      int blob_sz = sqlite3_column_bytes (stmt, 0);
		      gaiaGeomCollPtr geom =
			  gaiaFromSpatiaLiteBlobWkbEx (blob, blob_sz, gpkg_mode,
						       gpkg_amphibious);
		      if (geom != NULL)
			{
			    if (!auxtopo_insert_into_topology
				(accessor, geom, tolerance, line_max_points,
				 max_length, GAIA_MODE_TOPO_NO_FACE))
			      {
				  gaiaFreeGeomColl (geom);
				  goto error;
			      }
			    gaiaFreeGeomColl (geom);
			}
		      else
			{
			    char *msg =
				sqlite3_mprintf
				("TopoGeo_FromGeoTableNoFace error: Invalid Geometry");
			    gaiatopo_set_last_error_msg (accessor, msg);
			    sqlite3_free (msg);
			    goto error;
			}
		  }
		else
		  {
		      char *msg =
			  sqlite3_mprintf
			  ("TopoGeo_FromGeoTableNoFace error: not a BLOB value");
		      gaiatopo_set_last_error_msg (accessor, msg);
		      sqlite3_free (msg);
		      goto error;
		  }
	    }
	  else
	    {
		char *msg =
		    sqlite3_mprintf ("TopoGeo_FromGeoTableNoFace error: \"%s\"",
				     sqlite3_errmsg (topo->db_handle));
		gaiatopo_set_last_error_msg (accessor, msg);
		sqlite3_free (msg);
		goto error;
	    }
      }

    sqlite3_finalize (stmt);
    return 1;

  error:
    if (stmt != NULL)
	sqlite3_finalize (stmt);
................................................................................

static int
do_FromGeoTableExtended_block (GaiaTopologyAccessorPtr accessor,
			       sqlite3_stmt * stmt, sqlite3_stmt * stmt_dustbin,
			       double tolerance, int line_max_points,
			       double max_length, sqlite3_int64 start,
			       sqlite3_int64 * last, sqlite3_int64 * invalid,
			       int *dustbin_count, sqlite3_int64 * dustbin_row, int mode)
{
/* attempting to import a whole block of input features */
    struct gaia_topology *topo = (struct gaia_topology *) accessor;
    int ret;
    int gpkg_amphibious = 0;
    int gpkg_mode = 0;
    int totcnt = 0;
................................................................................
			  gaiaFromSpatiaLiteBlobWkbEx (blob, blob_sz, gpkg_mode,
						       gpkg_amphibious);
		      if (geom != NULL)
			{
			    gaiatopo_reset_last_error_msg (accessor);
			    if (!auxtopo_insert_into_topology
				(accessor, geom, tolerance, line_max_points,
				 max_length, mode))
			      {
				  char *msg;
				  const char *rt_msg =
				      gaiaGetRtTopoErrorMsg (topo->cache);
				  if (rt_msg == NULL)
				      msg =
					  sqlite3_mprintf
................................................................................
    while (1)
      {
	  /* main loop: attempting to import a block of features */
	  ret =
	      do_FromGeoTableExtended_block (accessor, stmt, stmt_dustbin,
					     tolerance, line_max_points,
					     max_length, start, &last, &invalid,
					     &dustbin_count, &dustbin_row, GAIA_MODE_TOPO_FACE);
	  if (ret < 0)		/* some unexpected error occurred */
	      goto error;
	  if (ret > 1)
	    {
		/* eof */
		break;
	    }
	  if (ret == 0)
	    {
		/* found a failing feature; recovering */
		ret =
		    do_FromGeoTableExtended_block (accessor, stmt, stmt_dustbin,
						   tolerance, line_max_points,
						   max_length, start, &last,
						   &invalid, &dustbin_count,
						   &dustbin_row, GAIA_MODE_TOPO_FACE);
		if (ret != 1)
		    goto error;
		start = invalid;
		invalid = -1;
		dustbin_row = -1;
		continue;
	    }
	  start = last;
	  invalid = -1;
	  dustbin_row = -1;
      }

    sqlite3_finalize (stmt);
    sqlite3_finalize (stmt_dustbin);
    sqlite3_finalize (stmt_retry);
    return dustbin_count;

  error:
    if (stmt != NULL)
	sqlite3_finalize (stmt);
    if (stmt_dustbin != NULL)
	sqlite3_finalize (stmt_dustbin);
    return -1;
}

GAIATOPO_DECLARE int
gaiaTopoGeo_FromGeoTableNoFaceExtended (GaiaTopologyAccessorPtr accessor,
				  const char *sql_in, const char *sql_out,
				  const char *sql_in2, double tolerance,
				  int line_max_points, double max_length)
{
/* attempting to import a whole GeoTable into a Topology-Geometry 
/  without determining generated faces - Extended mode */
    struct gaia_topology *topo = (struct gaia_topology *) accessor;
    sqlite3_stmt *stmt = NULL;
    sqlite3_stmt *stmt_dustbin = NULL;
    sqlite3_stmt *stmt_retry = NULL;
    int ret;
    int dustbin_count = 0;
    sqlite3_int64 start = -1;
    sqlite3_int64 last;
    sqlite3_int64 invalid = -1;
    sqlite3_int64 dustbin_row = -1;

    if (topo == NULL)
	return 0;
    if (sql_in == NULL)
	return 0;
    if (sql_out == NULL)
	return 0;

/* building the SQL statement */
    ret =
	sqlite3_prepare_v2 (topo->db_handle, sql_in, strlen (sql_in), &stmt,
			    NULL);
    if (ret != SQLITE_OK)
      {
	  char *msg = sqlite3_mprintf ("TopoGeo_FromGeoTableNoFaceExt error: \"%s\"",
				       sqlite3_errmsg (topo->db_handle));
	  gaiatopo_set_last_error_msg (accessor, msg);
	  sqlite3_free (msg);
	  goto error;
      }

/* building the SQL dustbin statement */
    ret =
	sqlite3_prepare_v2 (topo->db_handle, sql_out, strlen (sql_out),
			    &stmt_dustbin, NULL);
    if (ret != SQLITE_OK)
      {
	  char *msg = sqlite3_mprintf ("TopoGeo_FromGeoTableNoFaceExt error: \"%s\"",
				       sqlite3_errmsg (topo->db_handle));
	  gaiatopo_set_last_error_msg (accessor, msg);
	  sqlite3_free (msg);
	  goto error;
      }

/* building the SQL retry statement */
    ret =
	sqlite3_prepare_v2 (topo->db_handle, sql_in2, strlen (sql_in2),
			    &stmt_retry, NULL);
    if (ret != SQLITE_OK)
      {
	  char *msg = sqlite3_mprintf ("TopoGeo_FromGeoTableNoFaceExt error: \"%s\"",
				       sqlite3_errmsg (topo->db_handle));
	  gaiatopo_set_last_error_msg (accessor, msg);
	  sqlite3_free (msg);
	  goto error;
      }

    while (1)
      {
	  /* main loop: attempting to import a block of features */
	  ret =
	      do_FromGeoTableExtended_block (accessor, stmt, stmt_dustbin,
					     tolerance, line_max_points,
					     max_length, start, &last, &invalid,
					     &dustbin_count, &dustbin_row, GAIA_MODE_TOPO_NO_FACE);
	  if (ret < 0)		/* some unexpected error occurred */
	      goto error;
	  if (ret > 1)
	    {
		/* eof */
		break;
	    }
................................................................................
	    {
		/* found a failing feature; recovering */
		ret =
		    do_FromGeoTableExtended_block (accessor, stmt, stmt_dustbin,
						   tolerance, line_max_points,
						   max_length, start, &last,
						   &invalid, &dustbin_count,
						   &dustbin_row, GAIA_MODE_TOPO_NO_FACE);
		if (ret != 1)
		    goto error;
		start = invalid;
		invalid = -1;
		dustbin_row = -1;
		continue;
	    }

Changes to src/topology/gaia_topology.c.

2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
....
3183
3184
3185
3186
3187
3188
3189











































































































































































































































































































































































3190
3191
3192
3193
3194
3195
3196
....
3527
3528
3529
3530
3531
3532
3533












































































































































































3534
3535
3536
3537
3538
3539
3540
....
4151
4152
4153
4154
4155
4156
4157








































































































































































































































































4158
4159
4160
4161
4162
4163
4164
    topo = (struct gaia_topology *) accessor;
    if (!check_empty_topology (topo))
	goto not_empty;
    if (!check_matching_srid_dims (accessor, geom->Srid, geom->DimensionModel))
	goto invalid_geom;

    start_topo_savepoint (sqlite, cache);
    ret = auxtopo_insert_into_topology (accessor, geom, 0.0, -1, -1);
    if (!ret)
	rollback_topo_savepoint (sqlite, cache);
    else
	release_topo_savepoint (sqlite, cache);
    if (!ret)
      {
	  msg = gaiaGetRtTopoErrorMsg (cache);
................................................................................
	gaiaFreeGeomColl (linestring);
    msg =
	"SQL/MM Spatial exception - invalid geometry (mismatching SRID or dimensions).";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;
}












































































































































































































































































































































































SPATIALITE_PRIVATE void
fnctaux_TopoGeo_SubdivideLines (const void *xcontext, int argc,
				const void *xargv)
{
/* SQL function:
/ TopoGeo_SubdivideLines ( Geometry geom, int line_max_points,
................................................................................
    start_topo_savepoint (sqlite, cache);
    ret =
	gaiaTopoGeo_FromGeoTable (accessor, db_prefix, xtable, xcolumn,
				  tolerance, line_max_points, max_length);
    if (!ret)
	rollback_topo_savepoint (sqlite, cache);
    else












































































































































































	release_topo_savepoint (sqlite, cache);
    free (xtable);
    free (xcolumn);
    if (!ret)
      {
	  msg = gaiaGetRtTopoErrorMsg (cache);
	  gaiatopo_set_last_error_msg (accessor, msg);
................................................................................
      }
    release_topo_savepoint (sqlite, cache);

    ret =
	gaiaTopoGeo_FromGeoTableExtended (accessor, sql_in, sql_out, sql_in2,
					  tolerance, line_max_points,
					  max_length);








































































































































































































































































    free (xtable);
    free (xcolumn);
    sqlite3_free (sql_in);
    sqlite3_free (sql_out);
    sqlite3_free (sql_in2);
    sqlite3_result_int (context, ret);
    return;







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
....
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
....
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
....
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
    topo = (struct gaia_topology *) accessor;
    if (!check_empty_topology (topo))
	goto not_empty;
    if (!check_matching_srid_dims (accessor, geom->Srid, geom->DimensionModel))
	goto invalid_geom;

    start_topo_savepoint (sqlite, cache);
    ret = auxtopo_insert_into_topology (accessor, geom, 0.0, -1, -1, GAIA_MODE_TOPO_FACE);
    if (!ret)
	rollback_topo_savepoint (sqlite, cache);
    else
	release_topo_savepoint (sqlite, cache);
    if (!ret)
      {
	  msg = gaiaGetRtTopoErrorMsg (cache);
................................................................................
	gaiaFreeGeomColl (linestring);
    msg =
	"SQL/MM Spatial exception - invalid geometry (mismatching SRID or dimensions).";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;
}

SPATIALITE_PRIVATE void
fnctaux_TopoGeo_AddLineStringNoFace (const void *xcontext, int argc,
			       const void *xargv)
{
/* SQL function:
/ TopoGeo_AddLineStringNoFace ( text topology-name, Geometry (multi)linestring, 
/                               double tolerance )
/
/ returns: a comma separated list of all IDs of corresponding Edges on success
/ raises an exception on failure
*/
    const char *msg;
    int ret;
    char xedge_id[64];
    sqlite3_int64 *edge_ids = NULL;
    int ids_count = 0;
    char *retlist = NULL;
    char *savelist;
    int i;
    const char *topo_name;
    unsigned char *p_blob;
    int n_bytes;
    gaiaGeomCollPtr linestring = NULL;
    gaiaLinestringPtr ln;
    double tolerance;
    int invalid = 0;
    GaiaTopologyAccessorPtr accessor = NULL;
    int gpkg_amphibious = 0;
    int gpkg_mode = 0;
    sqlite3_context *context = (sqlite3_context *) xcontext;
    sqlite3_value **argv = (sqlite3_value **) xargv;
    sqlite3 *sqlite = sqlite3_context_db_handle (context);
    struct splite_internal_cache *cache = sqlite3_user_data (context);
    GAIA_UNUSED ();		/* LCOV_EXCL_LINE */
    if (cache != NULL)
      {
	  gpkg_amphibious = cache->gpkg_amphibious_mode;
	  gpkg_mode = cache->gpkg_mode;
      }
    if (sqlite3_value_type (argv[0]) == SQLITE_NULL)
	goto null_arg;
    else if (sqlite3_value_type (argv[0]) == SQLITE_TEXT)
	topo_name = (const char *) sqlite3_value_text (argv[0]);
    else
	goto invalid_arg;
    if (sqlite3_value_type (argv[1]) == SQLITE_NULL)
	goto null_arg;
    else if (sqlite3_value_type (argv[1]) == SQLITE_BLOB)
      {
	  p_blob = (unsigned char *) sqlite3_value_blob (argv[1]);
	  n_bytes = sqlite3_value_bytes (argv[1]);
      }
    else
	goto invalid_arg;
    if (sqlite3_value_type (argv[2]) == SQLITE_NULL)
	goto null_arg;
    else if (sqlite3_value_type (argv[2]) == SQLITE_INTEGER)
      {
	  int t = sqlite3_value_int (argv[2]);
	  tolerance = t;
      }
    else if (sqlite3_value_type (argv[2]) == SQLITE_FLOAT)
	tolerance = sqlite3_value_int (argv[2]);
    else
	goto invalid_arg;

/* attempting to get a Linestring Geometry */
    linestring =
	gaiaFromSpatiaLiteBlobWkbEx (p_blob, n_bytes, gpkg_mode,
				     gpkg_amphibious);
    if (!linestring)
	goto invalid_arg;
    if (linestring->FirstPoint != NULL)
	invalid = 1;
    if (linestring->FirstPolygon != NULL)
	invalid = 1;
    if (linestring->FirstLinestring == NULL)
	invalid = 1;
    if (invalid)
	goto invalid_arg;

/* attempting to get a Topology Accessor */
    accessor = gaiaGetTopology (sqlite, cache, topo_name);
    if (accessor == NULL)
	goto no_topo;
    gaiatopo_reset_last_error_msg (accessor);
    if (!check_matching_srid_dims
	(accessor, linestring->Srid, linestring->DimensionModel))
	goto invalid_geom;

    start_topo_savepoint (sqlite, cache);
    ln = linestring->FirstLinestring;
    while (ln != NULL)
      {
	  /* looping on individual Linestrings */
	  ret =
	      gaiaTopoGeo_AddLineStringNoFace (accessor, ln, tolerance, &edge_ids,
					 &ids_count);
	  if (!ret)
	      break;
	  for (i = 0; i < ids_count; i++)
	    {
		sprintf (xedge_id, "%lld", edge_ids[i]);
		if (retlist == NULL)
		    retlist = sqlite3_mprintf ("%s", xedge_id);
		else
		  {
		      savelist = retlist;
		      retlist = sqlite3_mprintf ("%s, %s", savelist, xedge_id);
		      sqlite3_free (savelist);
		  }
	    }
	  free (edge_ids);
	  ln = ln->Next;
      }

    if (!ret)
	rollback_topo_savepoint (sqlite, cache);
    else
	release_topo_savepoint (sqlite, cache);
    gaiaFreeGeomColl (linestring);
    linestring = NULL;
    if (!ret)
      {
	  msg = gaiaGetRtTopoErrorMsg (cache);
	  gaiatopo_set_last_error_msg (accessor, msg);
	  sqlite3_result_error (context, msg, -1);
	  sqlite3_free (retlist);
	  return;
      }
    sqlite3_result_text (context, retlist, strlen (retlist), sqlite3_free);
    return;

  no_topo:
    if (linestring != NULL)
	gaiaFreeGeomColl (linestring);
    msg = "SQL/MM Spatial exception - invalid topology name.";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;

  null_arg:
    if (linestring != NULL)
	gaiaFreeGeomColl (linestring);
    msg = "SQL/MM Spatial exception - null argument.";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;

  invalid_arg:
    if (linestring != NULL)
	gaiaFreeGeomColl (linestring);
    msg = "SQL/MM Spatial exception - invalid argument.";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;

  invalid_geom:
    if (linestring != NULL)
	gaiaFreeGeomColl (linestring);
    msg =
	"SQL/MM Spatial exception - invalid geometry (mismatching SRID or dimensions).";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;
}

SPATIALITE_PRIVATE void
fnctaux_TopoGeo_Polygonize (const void *xcontext, int argc,
			       const void *xargv)
{
/* SQL function:
/ TopoGeo_Polygonize ( text topology-name )
*/
    const char *msg;
    int ret;
    const char *topo_name;
    GaiaTopologyAccessorPtr accessor = NULL;
    sqlite3_context *context = (sqlite3_context *) xcontext;
    sqlite3_value **argv = (sqlite3_value **) xargv;
    sqlite3 *sqlite = sqlite3_context_db_handle (context);
    struct splite_internal_cache *cache = sqlite3_user_data (context);
    GAIA_UNUSED ();		/* LCOV_EXCL_LINE */
    if (sqlite3_value_type (argv[0]) == SQLITE_NULL)
	goto null_arg;
    else if (sqlite3_value_type (argv[0]) == SQLITE_TEXT)
	topo_name = (const char *) sqlite3_value_text (argv[0]);
    else
	goto invalid_arg;
	
/* attempting to get a Topology Accessor */
    accessor = gaiaGetTopology (sqlite, cache, topo_name);
    if (accessor == NULL)
	goto no_topo;
    gaiatopo_reset_last_error_msg (accessor);

    start_topo_savepoint (sqlite, cache);
    ret = gaiaTopoGeo_Polygonize (accessor);

    if (!ret)
	rollback_topo_savepoint (sqlite, cache);
    else
	release_topo_savepoint (sqlite, cache);
    if (!ret)
      {
	  msg = gaiaGetRtTopoErrorMsg (cache);
	  gaiatopo_set_last_error_msg (accessor, msg);
	  sqlite3_result_error (context, msg, -1);
	  return;
      }
    sqlite3_result_null (context);
    return;

  no_topo:
    msg = "SQL/MM Spatial exception - invalid topology name.";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;

  null_arg:
    msg = "SQL/MM Spatial exception - null argument.";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;

  invalid_arg:
    msg = "SQL/MM Spatial exception - invalid argument.";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;
}

SPATIALITE_PRIVATE void
fnctaux_TopoSnap (const void *xcontext, int argc, const void *xargv)
{
/* SQL function:
/ ST_TopoSnap ( text topology-name, , Geometry geom, double tolerance,
/               int iterate, int remove_vertices )
/
/ returns: the snapped Geometry
/ raises an exception on failure
*/
    const char *msg;
    const char *topo_name;
    unsigned char *p_blob;
    int n_bytes;
    gaiaGeomCollPtr geom = NULL;
    gaiaGeomCollPtr g2;
    double tolerance;
    int iterate;
    int remove_vertices;
    GaiaTopologyAccessorPtr accessor = NULL;
    int gpkg_amphibious = 0;
    int gpkg_mode = 0;
    sqlite3_context *context = (sqlite3_context *) xcontext;
    sqlite3_value **argv = (sqlite3_value **) xargv;
    sqlite3 *sqlite = sqlite3_context_db_handle (context);
    struct splite_internal_cache *cache = sqlite3_user_data (context);
    GAIA_UNUSED ();		/* LCOV_EXCL_LINE */
    if (cache != NULL)
      {
	  gpkg_amphibious = cache->gpkg_amphibious_mode;
	  gpkg_mode = cache->gpkg_mode;
      }
    if (sqlite3_value_type (argv[0]) == SQLITE_NULL)
	goto null_arg;
    else if (sqlite3_value_type (argv[0]) == SQLITE_TEXT)
	topo_name = (const char *) sqlite3_value_text (argv[0]);
    else
	goto invalid_arg;
    if (sqlite3_value_type (argv[1]) == SQLITE_NULL)
	goto null_arg;
    else if (sqlite3_value_type (argv[1]) == SQLITE_BLOB)
      {
	  p_blob = (unsigned char *) sqlite3_value_blob (argv[1]);
	  n_bytes = sqlite3_value_bytes (argv[1]);
      }
    else
	goto invalid_arg;
    if (sqlite3_value_type (argv[2]) == SQLITE_NULL)
	goto null_arg;
    else if (sqlite3_value_type (argv[2]) == SQLITE_INTEGER)
      {
	  int t = sqlite3_value_int (argv[2]);
	  tolerance = t;
      }
    else if (sqlite3_value_type (argv[2]) == SQLITE_FLOAT)
	tolerance = sqlite3_value_int (argv[2]);
    else
	goto invalid_arg;
    if (sqlite3_value_type (argv[3]) == SQLITE_NULL)
	goto null_arg;
    else if (sqlite3_value_type (argv[3]) == SQLITE_INTEGER)
	iterate = sqlite3_value_int (argv[3]);
    else
	goto invalid_arg;
    if (sqlite3_value_type (argv[4]) == SQLITE_NULL)
	goto null_arg;
    else if (sqlite3_value_type (argv[4]) == SQLITE_INTEGER)
	remove_vertices = sqlite3_value_int (argv[4]);
    else
	goto invalid_arg;

/* attempting to get a Geometry */
    geom =
	gaiaFromSpatiaLiteBlobWkbEx (p_blob, n_bytes, gpkg_mode,
				     gpkg_amphibious);
    if (!geom)
	goto invalid_arg;

/* attempting to get a Topology Accessor */
    accessor = gaiaGetTopology (sqlite, cache, topo_name);
    if (accessor == NULL)
	goto no_topo;

    gaiatopo_reset_last_error_msg (accessor);
    g2 = gaiaTopoSnap (accessor, geom, tolerance, iterate, remove_vertices);
	gaiaFreeGeomColl (geom);
    if (g2 == NULL)
      {
	  msg = gaiaGetRtTopoErrorMsg (cache);
	  if (msg != NULL)
	    {
		gaiatopo_set_last_error_msg (accessor, msg);
		sqlite3_result_error (context, msg, -1);
		return;
	    }
	  sqlite3_result_null (context);
	  return;
      }
    gaiaToSpatiaLiteBlobWkbEx (g2, &p_blob, &n_bytes, gpkg_mode);
    gaiaFreeGeomColl (g2);
    if (p_blob == NULL)
	sqlite3_result_null (context);
    else
	sqlite3_result_blob (context, p_blob, n_bytes, free);
    return;

  no_topo:
    if (geom != NULL)
	gaiaFreeGeomColl (geom);
    msg = "SQL/MM Spatial exception - invalid topology name.";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;

  null_arg:
    if (geom != NULL)
	gaiaFreeGeomColl (geom);
    msg = "SQL/MM Spatial exception - null argument.";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;

  invalid_arg:
    if (geom != NULL)
	gaiaFreeGeomColl (geom);
    msg = "SQL/MM Spatial exception - invalid argument.";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;
}

SPATIALITE_PRIVATE void
fnctaux_TopoGeo_SubdivideLines (const void *xcontext, int argc,
				const void *xargv)
{
/* SQL function:
/ TopoGeo_SubdivideLines ( Geometry geom, int line_max_points,
................................................................................
    start_topo_savepoint (sqlite, cache);
    ret =
	gaiaTopoGeo_FromGeoTable (accessor, db_prefix, xtable, xcolumn,
				  tolerance, line_max_points, max_length);
    if (!ret)
	rollback_topo_savepoint (sqlite, cache);
    else
	release_topo_savepoint (sqlite, cache);
    free (xtable);
    free (xcolumn);
    if (!ret)
      {
	  msg = gaiaGetRtTopoErrorMsg (cache);
	  gaiatopo_set_last_error_msg (accessor, msg);
	  sqlite3_result_error (context, msg, -1);
	  return;
      }
    sqlite3_result_int (context, 1);
    return;

  no_topo:
    if (xtable != NULL)
	free (xtable);
    if (xcolumn != NULL)
	free (xcolumn);
    msg = "SQL/MM Spatial exception - invalid topology name.";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;

  no_input:
    if (xtable != NULL)
	free (xtable);
    if (xcolumn != NULL)
	free (xcolumn);
    msg = "SQL/MM Spatial exception - invalid input GeoTable.";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;

  null_arg:
    if (xtable != NULL)
	free (xtable);
    if (xcolumn != NULL)
	free (xcolumn);
    msg = "SQL/MM Spatial exception - null argument.";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;

  invalid_arg:
    if (xtable != NULL)
	free (xtable);
    if (xcolumn != NULL)
	free (xcolumn);
    msg = "SQL/MM Spatial exception - invalid argument.";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;

  invalid_geom:
    if (xtable != NULL)
	free (xtable);
    if (xcolumn != NULL)
	free (xcolumn);
    msg =
	"SQL/MM Spatial exception - invalid GeoTable (mismatching SRID or dimensions).";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;
}

SPATIALITE_PRIVATE void
fnctaux_TopoGeo_FromGeoTableNoFace (const void *xcontext, int argc, const void *xargv)
{
/* SQL function:
/ TopoGeo_FromGeoTableNoFace ( text topology-name, text db-prefix, text table,
/                        text column, double tolerance )
/ TopoGeo_FromGeoTableNoFace ( text topology-name, text db-prefix, text table,
/                        text column, double tolerance, int line_max_points,
/                        double max_length )
/
/ returns: 1 on success
/ raises an exception on failure
*/
    const char *msg;
    int ret;
    const char *topo_name;
    const char *db_prefix;
    const char *table;
    const char *column;
    char *xtable = NULL;
    char *xcolumn = NULL;
    int srid;
    int dims;
    double tolerance;
    int line_max_points = -1;
    double max_length = -1.0;
    GaiaTopologyAccessorPtr accessor = NULL;
    sqlite3_context *context = (sqlite3_context *) xcontext;
    sqlite3_value **argv = (sqlite3_value **) xargv;
    sqlite3 *sqlite = sqlite3_context_db_handle (context);
    struct splite_internal_cache *cache = sqlite3_user_data (context);
    GAIA_UNUSED ();		/* LCOV_EXCL_LINE */
    if (sqlite3_value_type (argv[0]) == SQLITE_NULL)
	goto null_arg;
    else if (sqlite3_value_type (argv[0]) == SQLITE_TEXT)
	topo_name = (const char *) sqlite3_value_text (argv[0]);
    else
	goto invalid_arg;
    if (sqlite3_value_type (argv[1]) == SQLITE_NULL)
	db_prefix = "main";
    else if (sqlite3_value_type (argv[1]) == SQLITE_TEXT)
	db_prefix = (const char *) sqlite3_value_text (argv[1]);
    else
	goto invalid_arg;
    if (sqlite3_value_type (argv[2]) == SQLITE_NULL)
	goto null_arg;
    else if (sqlite3_value_type (argv[2]) == SQLITE_TEXT)
	table = (const char *) sqlite3_value_text (argv[2]);
    else
	goto invalid_arg;
    if (sqlite3_value_type (argv[3]) == SQLITE_NULL)
	column = NULL;
    else if (sqlite3_value_type (argv[3]) == SQLITE_TEXT)
	column = (const char *) sqlite3_value_text (argv[3]);
    else
	goto invalid_arg;
    if (sqlite3_value_type (argv[4]) == SQLITE_NULL)
	goto null_arg;
    else if (sqlite3_value_type (argv[4]) == SQLITE_INTEGER)
      {
	  int t = sqlite3_value_int (argv[4]);
	  tolerance = t;
      }
    else if (sqlite3_value_type (argv[4]) == SQLITE_FLOAT)
	tolerance = sqlite3_value_int (argv[4]);
    else
	goto invalid_arg;
    if (argc >= 6)
      {
	  if (sqlite3_value_type (argv[5]) == SQLITE_INTEGER)
	      line_max_points = sqlite3_value_int (argv[5]);
	  else
	      goto invalid_arg;
      }
    if (argc >= 7)
      {
	  if (sqlite3_value_type (argv[6]) == SQLITE_INTEGER)
	    {
		int max = sqlite3_value_int (argv[6]);
		max_length = max;
	    }
	  else if (sqlite3_value_type (argv[6]) == SQLITE_FLOAT)
	      max_length = sqlite3_value_double (argv[6]);
	  else
	      goto invalid_arg;
      }

/* attempting to get a Topology Accessor */
    accessor = gaiaGetTopology (sqlite, cache, topo_name);
    if (accessor == NULL)
	goto no_topo;
    gaiatopo_reset_last_error_msg (accessor);

/* checking the input GeoTable */
    if (!check_input_geo_table
	(sqlite, db_prefix, table, column, &xtable, &xcolumn, &srid, &dims))
	goto no_input;
    if (!check_matching_srid_dims (accessor, srid, dims))
	goto invalid_geom;

    start_topo_savepoint (sqlite, cache);
    ret =
	gaiaTopoGeo_FromGeoTableNoFace (accessor, db_prefix, xtable, xcolumn,
				  tolerance, line_max_points, max_length);
    if (!ret)
	rollback_topo_savepoint (sqlite, cache);
    else
	release_topo_savepoint (sqlite, cache);
    free (xtable);
    free (xcolumn);
    if (!ret)
      {
	  msg = gaiaGetRtTopoErrorMsg (cache);
	  gaiatopo_set_last_error_msg (accessor, msg);
................................................................................
      }
    release_topo_savepoint (sqlite, cache);

    ret =
	gaiaTopoGeo_FromGeoTableExtended (accessor, sql_in, sql_out, sql_in2,
					  tolerance, line_max_points,
					  max_length);
    free (xtable);
    free (xcolumn);
    sqlite3_free (sql_in);
    sqlite3_free (sql_out);
    sqlite3_free (sql_in2);
    sqlite3_result_int (context, ret);
    return;

  no_topo:
    if (xtable != NULL)
	free (xtable);
    if (xcolumn != NULL)
	free (xcolumn);
    if (sql_in != NULL)
	sqlite3_free (sql_in);
    if (sql_out != NULL)
	sqlite3_free (sql_out);
    if (sql_in2 != NULL)
	sqlite3_free (sql_in2);
    msg = "SQL/MM Spatial exception - invalid topology name.";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;

  no_input:
    if (xtable != NULL)
	free (xtable);
    if (xcolumn != NULL)
	free (xcolumn);
    if (sql_in != NULL)
	sqlite3_free (sql_in);
    if (sql_out != NULL)
	sqlite3_free (sql_out);
    if (sql_in2 != NULL)
	sqlite3_free (sql_in2);
    msg = "SQL/MM Spatial exception - invalid input GeoTable.";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;

  null_arg:
    if (xtable != NULL)
	free (xtable);
    if (xcolumn != NULL)
	free (xcolumn);
    if (sql_in != NULL)
	sqlite3_free (sql_in);
    if (sql_out != NULL)
	sqlite3_free (sql_out);
    if (sql_in2 != NULL)
	sqlite3_free (sql_in2);
    msg = "SQL/MM Spatial exception - null argument.";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;

  invalid_arg:
    if (xtable != NULL)
	free (xtable);
    if (xcolumn != NULL)
	free (xcolumn);
    if (sql_in != NULL)
	sqlite3_free (sql_in);
    if (sql_out != NULL)
	sqlite3_free (sql_out);
    if (sql_in2 != NULL)
	sqlite3_free (sql_in2);
    msg = "SQL/MM Spatial exception - invalid argument.";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;

  invalid_geom:
    if (xtable != NULL)
	free (xtable);
    if (xcolumn != NULL)
	free (xcolumn);
    if (sql_in != NULL)
	sqlite3_free (sql_in);
    if (sql_out != NULL)
	sqlite3_free (sql_out);
    if (sql_in2 != NULL)
	sqlite3_free (sql_in2);
    msg =
	"SQL/MM Spatial exception - invalid GeoTable (mismatching SRID or dimensions).";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;

  no_dustbin_table:
    if (xtable != NULL)
	free (xtable);
    if (xcolumn != NULL)
	free (xcolumn);
    if (sql_in != NULL)
	sqlite3_free (sql_in);
    if (sql_out != NULL)
	sqlite3_free (sql_out);
    msg = "SQL/MM Spatial exception - unable to create the dustbin table.";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;

  no_dustbin_view:
    if (xtable != NULL)
	free (xtable);
    if (xcolumn != NULL)
	free (xcolumn);
    if (sql_in != NULL)
	sqlite3_free (sql_in);
    if (sql_out != NULL)
	sqlite3_free (sql_out);
    if (sql_in2 != NULL)
	sqlite3_free (sql_in2);
    msg = "SQL/MM Spatial exception - unable to create the dustbin view.";
    gaiatopo_set_last_error_msg (accessor, msg);
    sqlite3_result_error (context, msg, -1);
    return;
}

SPATIALITE_PRIVATE void
fnctaux_TopoGeo_FromGeoTableNoFaceExt (const void *xcontext, int argc,
				 const void *xargv)
{
/* SQL function:
/ TopoGeo_FromGeoTableNoFaceExt ( text topology-name, text db-prefix, 
/                                 text table, text column, double tolerance, 
/                                 text dustbin-table, text dustbin-view )
/ TopoGeo_FromGeoTableNoFaceExt ( text topology-name, text db-prefix, 
/                                 text table, text column, double tolerance, 
/                                 text dustbin-table, text dustbin-view,
/                                 int line_max_points, double max_length )
/
/ returns: 1 on success
/ raises an exception on failure
*/
    const char *msg;
    int ret;
    const char *topo_name;
    const char *db_prefix;
    const char *table;
    const char *column;
    char *xtable = NULL;
    char *xcolumn = NULL;
    int srid;
    int dims;
    double tolerance;
    const char *dustbin_table;
    const char *dustbin_view;
    int line_max_points = -1;
    double max_length = -1.0;
    char *sql_in = NULL;
    char *sql_out = NULL;
    char *sql_in2 = NULL;
    GaiaTopologyAccessorPtr accessor = NULL;
    sqlite3_context *context = (sqlite3_context *) xcontext;
    sqlite3_value **argv = (sqlite3_value **) xargv;
    sqlite3 *sqlite = sqlite3_context_db_handle (context);
    struct splite_internal_cache *cache = sqlite3_user_data (context);
    GAIA_UNUSED ();		/* LCOV_EXCL_LINE */
    if (sqlite3_value_type (argv[0]) == SQLITE_NULL)
	goto null_arg;
    else if (sqlite3_value_type (argv[0]) == SQLITE_TEXT)
	topo_name = (const char *) sqlite3_value_text (argv[0]);
    else
	goto invalid_arg;
    if (sqlite3_value_type (argv[1]) == SQLITE_NULL)
	db_prefix = "main";
    else if (sqlite3_value_type (argv[1]) == SQLITE_TEXT)
	db_prefix = (const char *) sqlite3_value_text (argv[1]);
    else
	goto invalid_arg;
    if (sqlite3_value_type (argv[2]) == SQLITE_NULL)
	goto null_arg;
    else if (sqlite3_value_type (argv[2]) == SQLITE_TEXT)
	table = (const char *) sqlite3_value_text (argv[2]);
    else
	goto invalid_arg;
    if (sqlite3_value_type (argv[3]) == SQLITE_NULL)
	column = NULL;
    else if (sqlite3_value_type (argv[3]) == SQLITE_TEXT)
	column = (const char *) sqlite3_value_text (argv[3]);
    else
	goto invalid_arg;
    if (sqlite3_value_type (argv[4]) == SQLITE_NULL)
	goto null_arg;
    else if (sqlite3_value_type (argv[4]) == SQLITE_INTEGER)
      {
	  int t = sqlite3_value_int (argv[4]);
	  tolerance = t;
      }
    else if (sqlite3_value_type (argv[4]) == SQLITE_FLOAT)
	tolerance = sqlite3_value_int (argv[4]);
    else
	goto invalid_arg;
    if (sqlite3_value_type (argv[5]) == SQLITE_NULL)
	goto null_arg;
    else if (sqlite3_value_type (argv[5]) == SQLITE_TEXT)
	dustbin_table = (const char *) sqlite3_value_text (argv[5]);
    else
	goto invalid_arg;
    if (sqlite3_value_type (argv[6]) == SQLITE_NULL)
	goto null_arg;
    else if (sqlite3_value_type (argv[6]) == SQLITE_TEXT)
	dustbin_view = (const char *) sqlite3_value_text (argv[6]);
    else
	goto invalid_arg;
    if (argc >= 8)
      {
	  if (sqlite3_value_type (argv[7]) == SQLITE_NULL)
	      goto null_arg;
	  else if (sqlite3_value_type (argv[7]) == SQLITE_INTEGER)
	      line_max_points = sqlite3_value_int (argv[8]);
	  else
	      goto invalid_arg;
      }
    if (argc >= 9)
      {
	  if (sqlite3_value_type (argv[8]) == SQLITE_NULL)
	      goto null_arg;
	  else if (sqlite3_value_type (argv[8]) == SQLITE_INTEGER)
	    {
		int max = sqlite3_value_int (argv[8]);
		max_length = max;
	    }
	  else if (sqlite3_value_type (argv[8]) == SQLITE_FLOAT)
	      max_length = sqlite3_value_double (argv[8]);
	  else
	      goto invalid_arg;
      }

/* attempting to get a Topology Accessor */
    accessor = gaiaGetTopology (sqlite, cache, topo_name);
    if (accessor == NULL)
	goto no_topo;
    gaiatopo_reset_last_error_msg (accessor);

/* checking the input GeoTable */
    if (!check_input_geo_table
	(sqlite, db_prefix, table, column, &xtable, &xcolumn, &srid, &dims))
	goto no_input;
    if (!check_matching_srid_dims (accessor, srid, dims))
	goto invalid_geom;

/* attempting to create the dustbin table and view */
    start_topo_savepoint (sqlite, cache);
    if (!create_dustbin_table (sqlite, db_prefix, xtable, dustbin_table))
      {
	  rollback_topo_savepoint (sqlite, cache);
	  goto no_dustbin_table;
      }
    if (!create_dustbin_view
	(sqlite, db_prefix, xtable, xcolumn, dustbin_table, dustbin_view,
	 &sql_in, &sql_out, &sql_in2))
      {
	  rollback_topo_savepoint (sqlite, cache);
	  goto no_dustbin_view;
      }
    release_topo_savepoint (sqlite, cache);

    ret =
	gaiaTopoGeo_FromGeoTableNoFaceExtended (accessor, sql_in, sql_out, sql_in2,
					  tolerance, line_max_points,
					  max_length);
    free (xtable);
    free (xcolumn);
    sqlite3_free (sql_in);
    sqlite3_free (sql_out);
    sqlite3_free (sql_in2);
    sqlite3_result_int (context, ret);
    return;

Changes to src/topology/topology_private.h.

55
56
57
58
59
60
61



62
63
64
65
66
67
68
...
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#define TOPOLOGY_PRIVATE
#endif
#else
#define TOPOLOGY_PRIVATE __attribute__ ((visibility("hidden")))
#endif
#endif




struct gaia_topology
{
/* a struct wrapping a Topology Accessor Object */
    const void *cache;
    sqlite3 *db_handle;
    char *topology_name;
    int srid;
................................................................................
						 gaiaGeomCollPtr geom);

TOPOLOGY_PRIVATE int auxtopo_insert_into_topology (GaiaTopologyAccessorPtr
						   accessor,
						   gaiaGeomCollPtr geom,
						   double tolerance,
						   int line_max_points,
						   double max_length);


/* prototypes for functions creating some SQL prepared statement */
TOPOLOGY_PRIVATE sqlite3_stmt
    * do_create_stmt_getNodeWithinDistance2D (GaiaTopologyAccessorPtr accessor);

TOPOLOGY_PRIVATE sqlite3_stmt







>
>
>







 







|







55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
...
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#define TOPOLOGY_PRIVATE
#endif
#else
#define TOPOLOGY_PRIVATE __attribute__ ((visibility("hidden")))
#endif
#endif

#define GAIA_MODE_TOPO_FACE		0x00
#define GAIA_MODE_TOPO_NO_FACE	0xbb

struct gaia_topology
{
/* a struct wrapping a Topology Accessor Object */
    const void *cache;
    sqlite3 *db_handle;
    char *topology_name;
    int srid;
................................................................................
						 gaiaGeomCollPtr geom);

TOPOLOGY_PRIVATE int auxtopo_insert_into_topology (GaiaTopologyAccessorPtr
						   accessor,
						   gaiaGeomCollPtr geom,
						   double tolerance,
						   int line_max_points,
						   double max_length, int mode);


/* prototypes for functions creating some SQL prepared statement */
TOPOLOGY_PRIVATE sqlite3_stmt
    * do_create_stmt_getNodeWithinDistance2D (GaiaTopologyAccessorPtr accessor);

TOPOLOGY_PRIVATE sqlite3_stmt

Changes to test/sql_stmt_cache_tests/Makefile.

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
PACKAGE_STRING = libspatialite 4.4.0-RC1
PACKAGE_TARNAME = libspatialite
PACKAGE_URL = 
PACKAGE_VERSION = 4.4.0-RC1
PATH_SEPARATOR = :
PKG_CONFIG = /usr/bin/pkg-config
PKG_CONFIG_LIBDIR = 
PKG_CONFIG_PATH = /usr/local/lib/pkgconfig
RANLIB = ranlib
SED = /usr/bin/sed
SET_MAKE = 
SHELL = /bin/sh
STRIP = strip
VERSION = 4.4.0-RC1
abs_builddir = /home/sandro/fossil/libspatialite/test/sql_stmt_cache_tests







|







187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
PACKAGE_STRING = libspatialite 4.4.0-RC1
PACKAGE_TARNAME = libspatialite
PACKAGE_URL = 
PACKAGE_VERSION = 4.4.0-RC1
PATH_SEPARATOR = :
PKG_CONFIG = /usr/bin/pkg-config
PKG_CONFIG_LIBDIR = 
PKG_CONFIG_PATH = 
RANLIB = ranlib
SED = /usr/bin/sed
SET_MAKE = 
SHELL = /bin/sh
STRIP = strip
VERSION = 4.4.0-RC1
abs_builddir = /home/sandro/fossil/libspatialite/test/sql_stmt_cache_tests

Changes to test/sql_stmt_freexl_tests/Makefile.

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
PACKAGE_STRING = libspatialite 4.4.0-RC1
PACKAGE_TARNAME = libspatialite
PACKAGE_URL = 
PACKAGE_VERSION = 4.4.0-RC1
PATH_SEPARATOR = :
PKG_CONFIG = /usr/bin/pkg-config
PKG_CONFIG_LIBDIR = 
PKG_CONFIG_PATH = /usr/local/lib/pkgconfig
RANLIB = ranlib
SED = /usr/bin/sed
SET_MAKE = 
SHELL = /bin/sh
STRIP = strip
VERSION = 4.4.0-RC1
abs_builddir = /home/sandro/fossil/libspatialite/test/sql_stmt_freexl_tests







|







187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
PACKAGE_STRING = libspatialite 4.4.0-RC1
PACKAGE_TARNAME = libspatialite
PACKAGE_URL = 
PACKAGE_VERSION = 4.4.0-RC1
PATH_SEPARATOR = :
PKG_CONFIG = /usr/bin/pkg-config
PKG_CONFIG_LIBDIR = 
PKG_CONFIG_PATH = 
RANLIB = ranlib
SED = /usr/bin/sed
SET_MAKE = 
SHELL = /bin/sh
STRIP = strip
VERSION = 4.4.0-RC1
abs_builddir = /home/sandro/fossil/libspatialite/test/sql_stmt_freexl_tests

Changes to test/sql_stmt_geosadvanced_tests/Makefile.

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
PACKAGE_STRING = libspatialite 4.4.0-RC1
PACKAGE_TARNAME = libspatialite
PACKAGE_URL = 
PACKAGE_VERSION = 4.4.0-RC1
PATH_SEPARATOR = :
PKG_CONFIG = /usr/bin/pkg-config
PKG_CONFIG_LIBDIR = 
PKG_CONFIG_PATH = /usr/local/lib/pkgconfig
RANLIB = ranlib
SED = /usr/bin/sed
SET_MAKE = 
SHELL = /bin/sh
STRIP = strip
VERSION = 4.4.0-RC1
abs_builddir = /home/sandro/fossil/libspatialite/test/sql_stmt_geosadvanced_tests







|







187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
PACKAGE_STRING = libspatialite 4.4.0-RC1
PACKAGE_TARNAME = libspatialite
PACKAGE_URL = 
PACKAGE_VERSION = 4.4.0-RC1
PATH_SEPARATOR = :
PKG_CONFIG = /usr/bin/pkg-config
PKG_CONFIG_LIBDIR = 
PKG_CONFIG_PATH = 
RANLIB = ranlib
SED = /usr/bin/sed
SET_MAKE = 
SHELL = /bin/sh
STRIP = strip
VERSION = 4.4.0-RC1
abs_builddir = /home/sandro/fossil/libspatialite/test/sql_stmt_geosadvanced_tests

Changes to test/sql_stmt_gpkgcache_tests/Makefile.

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
PACKAGE_STRING = libspatialite 4.4.0-RC1
PACKAGE_TARNAME = libspatialite
PACKAGE_URL = 
PACKAGE_VERSION = 4.4.0-RC1
PATH_SEPARATOR = :
PKG_CONFIG = /usr/bin/pkg-config
PKG_CONFIG_LIBDIR = 
PKG_CONFIG_PATH = /usr/local/lib/pkgconfig
RANLIB = ranlib
SED = /usr/bin/sed
SET_MAKE = 
SHELL = /bin/sh
STRIP = strip
VERSION = 4.4.0-RC1
abs_builddir = /home/sandro/fossil/libspatialite/test/sql_stmt_gpkgcache_tests







|







187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
PACKAGE_STRING = libspatialite 4.4.0-RC1
PACKAGE_TARNAME = libspatialite
PACKAGE_URL = 
PACKAGE_VERSION = 4.4.0-RC1
PATH_SEPARATOR = :
PKG_CONFIG = /usr/bin/pkg-config
PKG_CONFIG_LIBDIR = 
PKG_CONFIG_PATH = 
RANLIB = ranlib
SED = /usr/bin/sed
SET_MAKE = 
SHELL = /bin/sh
STRIP = strip
VERSION = 4.4.0-RC1
abs_builddir = /home/sandro/fossil/libspatialite/test/sql_stmt_gpkgcache_tests

Changes to test/sql_stmt_gpkgnocache_tests/Makefile.

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
PACKAGE_STRING = libspatialite 4.4.0-RC1
PACKAGE_TARNAME = libspatialite
PACKAGE_URL = 
PACKAGE_VERSION = 4.4.0-RC1
PATH_SEPARATOR = :
PKG_CONFIG = /usr/bin/pkg-config
PKG_CONFIG_LIBDIR = 
PKG_CONFIG_PATH = /usr/local/lib/pkgconfig
RANLIB = ranlib
SED = /usr/bin/sed
SET_MAKE = 
SHELL = /bin/sh
STRIP = strip
VERSION = 4.4.0-RC1
abs_builddir = /home/sandro/fossil/libspatialite/test/sql_stmt_gpkgnocache_tests







|







187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
PACKAGE_STRING = libspatialite 4.4.0-RC1
PACKAGE_TARNAME = libspatialite
PACKAGE_URL = 
PACKAGE_VERSION = 4.4.0-RC1
PATH_SEPARATOR = :
PKG_CONFIG = /usr/bin/pkg-config
PKG_CONFIG_LIBDIR = 
PKG_CONFIG_PATH = 
RANLIB = ranlib
SED = /usr/bin/sed
SET_MAKE = 
SHELL = /bin/sh
STRIP = strip
VERSION = 4.4.0-RC1
abs_builddir = /home/sandro/fossil/libspatialite/test/sql_stmt_gpkgnocache_tests

Changes to test/sql_stmt_nocache_tests/Makefile.

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
PACKAGE_STRING = libspatialite 4.4.0-RC1
PACKAGE_TARNAME = libspatialite
PACKAGE_URL = 
PACKAGE_VERSION = 4.4.0-RC1
PATH_SEPARATOR = :
PKG_CONFIG = /usr/bin/pkg-config
PKG_CONFIG_LIBDIR = 
PKG_CONFIG_PATH = /usr/local/lib/pkgconfig
RANLIB = ranlib
SED = /usr/bin/sed
SET_MAKE = 
SHELL = /bin/sh
STRIP = strip
VERSION = 4.4.0-RC1
abs_builddir = /home/sandro/fossil/libspatialite/test/sql_stmt_nocache_tests







|







187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
PACKAGE_STRING = libspatialite 4.4.0-RC1
PACKAGE_TARNAME = libspatialite
PACKAGE_URL = 
PACKAGE_VERSION = 4.4.0-RC1
PATH_SEPARATOR = :
PKG_CONFIG = /usr/bin/pkg-config
PKG_CONFIG_LIBDIR = 
PKG_CONFIG_PATH = 
RANLIB = ranlib
SED = /usr/bin/sed
SET_MAKE = 
SHELL = /bin/sh
STRIP = strip
VERSION = 4.4.0-RC1
abs_builddir = /home/sandro/fossil/libspatialite/test/sql_stmt_nocache_tests

Changes to test/sql_stmt_rttopo_tests/Makefile.am.

610
611
612
613
614
615
616





617
618
619
620
621
622
623
...
728
729
730
731
732
733
734

















735
736
737
738
739
740
741
...
779
780
781
782
783
784
785







































786
787
788
789
790
791
792
...
809
810
811
812
813
814
815






























816
817
818
819
820
821
822
...
997
998
999
1000
1001
1002
1003





















1004
1005
1006
1007
1008
1009
1010
	pointsnapseed11.testcase \
	pointsnapseed12.testcase \
	pointsnapseed13.testcase \
	pointsnapseed14.testcase \
	pointsnapseed15.testcase \
	pointsnapseed16.testcase \
	pointsnapseed17.testcase \





	remedgemodface1.testcase \
	remedgemodface2.testcase \
	remedgemodface3.testcase \
	remedgemodface4.testcase \
	remedgemodface5.testcase \
	remedgemodface6.testcase \
	remedgemodface7.testcase \
................................................................................
	topogeoaddline11.testcase \
	topogeoaddline12.testcase \
	topogeoaddline13.testcase \
	topogeoaddline14.testcase \
	topogeoaddline15.testcase \
	topogeoaddline16.testcase \
	topogeoaddline17.testcase \

















	topogeoclone1.testcase \
	topogeoclone2.testcase \
	topogeoclone3.testcase \
	topogeoclone4.testcase \
	topogeoclone5.testcase \
	topogeoclone6.testcase \
	topogeoclone7.testcase \
................................................................................
	topogeofromext33.testcase \
	topogeofromext34.testcase \
	topogeofromext35.testcase \
	topogeofromext36.testcase \
	topogeofromext37.testcase \
	topogeofromext38.testcase \
	topogeofromext39.testcase \







































	topogeofromtable1.testcase \
	topogeofromtable2.testcase \
	topogeofromtable3.testcase \
	topogeofromtable4.testcase \
	topogeofromtable5.testcase \
	topogeofromtable6.testcase \
	topogeofromtable7.testcase \
................................................................................
	topogeofromtable24.testcase \
	topogeofromtable25.testcase \
	topogeofromtable26.testcase \
	topogeofromtable27.testcase \
	topogeofromtable28.testcase \
	topogeofromtable29.testcase \
	topogeofromtable30.testcase \






























	topogeosplitline1.testcase \
	topogeosplitline2.testcase \
	topogeosplitline3.testcase \
	topogeosplitline4.testcase \
	topogeosplitline5.testcase \
	topogeosplitline6.testcase \
	topogeosplitline7.testcase \
................................................................................
	toponettotablegen25.testcase \
	toponettotablegen26.testcase \
	toponettotablegen27.testcase \
	toponettotablegen28.testcase \
	toponettotablegen29.testcase \
	toponettotablegen30.testcase \
	toponettotablegen31.testcase \





















	validatetopogeo1.testcase \
	validatetopogeo2.testcase \
	validatetopogeo3.testcase \
	validatetopogeo4.testcase \
	validatetopogeo5.testcase \
	validlogicalnet1.testcase \
	validlogicalnet2.testcase \







>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
...
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
...
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
...
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
....
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
	pointsnapseed11.testcase \
	pointsnapseed12.testcase \
	pointsnapseed13.testcase \
	pointsnapseed14.testcase \
	pointsnapseed15.testcase \
	pointsnapseed16.testcase \
	pointsnapseed17.testcase \
	polygonize1.testcase \
	polygonize2.testcase \
	polygonize3.testcase \
	polygonize4.testcase \
	polygonize5.testcase \
	remedgemodface1.testcase \
	remedgemodface2.testcase \
	remedgemodface3.testcase \
	remedgemodface4.testcase \
	remedgemodface5.testcase \
	remedgemodface6.testcase \
	remedgemodface7.testcase \
................................................................................
	topogeoaddline11.testcase \
	topogeoaddline12.testcase \
	topogeoaddline13.testcase \
	topogeoaddline14.testcase \
	topogeoaddline15.testcase \
	topogeoaddline16.testcase \
	topogeoaddline17.testcase \
	topogeoaddlinenf1.testcase \
	topogeoaddlinenf2.testcase \
	topogeoaddlinenf3.testcase \
	topogeoaddlinenf4.testcase \
	topogeoaddlinenf5.testcase \
	topogeoaddlinenf6.testcase \
	topogeoaddlinenf7.testcase \
	topogeoaddlinenf8.testcase \
	topogeoaddlinenf9.testcase \
	topogeoaddlinenf10.testcase \
	topogeoaddlinenf11.testcase \
	topogeoaddlinenf12.testcase \
	topogeoaddlinenf13.testcase \
	topogeoaddlinenf14.testcase \
	topogeoaddlinenf15.testcase \
	topogeoaddlinenf16.testcase \
	topogeoaddlinenf17.testcase \
	topogeoclone1.testcase \
	topogeoclone2.testcase \
	topogeoclone3.testcase \
	topogeoclone4.testcase \
	topogeoclone5.testcase \
	topogeoclone6.testcase \
	topogeoclone7.testcase \
................................................................................
	topogeofromext33.testcase \
	topogeofromext34.testcase \
	topogeofromext35.testcase \
	topogeofromext36.testcase \
	topogeofromext37.testcase \
	topogeofromext38.testcase \
	topogeofromext39.testcase \
	topogeofromextnf1.testcase \
	topogeofromextnf2.testcase \
	topogeofromextnf3.testcase \
	topogeofromextnf4.testcase \
	topogeofromextnf5.testcase \
	topogeofromextnf6.testcase \
	topogeofromextnf7.testcase \
	topogeofromextnf8.testcase \
	topogeofromextnf9.testcase \
	topogeofromextnf10.testcase \
	topogeofromextnf11.testcase \
	topogeofromextnf12.testcase \
	topogeofromextnf13.testcase \
	topogeofromextnf14.testcase \
	topogeofromextnf15.testcase \
	topogeofromextnf16.testcase \
	topogeofromextnf17.testcase \
	topogeofromextnf18.testcase \
	topogeofromextnf19.testcase \
	topogeofromextnf20.testcase \
	topogeofromextnf21.testcase \
	topogeofromextnf22.testcase \
	topogeofromextnf23.testcase \
	topogeofromextnf24.testcase \
	topogeofromextnf25.testcase \
	topogeofromextnf26.testcase \
	topogeofromextnf27.testcase \
	topogeofromextnf28.testcase \
	topogeofromextnf29.testcase \
	topogeofromextnf30.testcase \
	topogeofromextnf31.testcase \
	topogeofromextnf32.testcase \
	topogeofromextnf33.testcase \
	topogeofromextnf34.testcase \
	topogeofromextnf35.testcase \
	topogeofromextnf36.testcase \
	topogeofromextnf37.testcase \
	topogeofromextnf38.testcase \
	topogeofromextnf39.testcase \
	topogeofromtable1.testcase \
	topogeofromtable2.testcase \
	topogeofromtable3.testcase \
	topogeofromtable4.testcase \
	topogeofromtable5.testcase \
	topogeofromtable6.testcase \
	topogeofromtable7.testcase \
................................................................................
	topogeofromtable24.testcase \
	topogeofromtable25.testcase \
	topogeofromtable26.testcase \
	topogeofromtable27.testcase \
	topogeofromtable28.testcase \
	topogeofromtable29.testcase \
	topogeofromtable30.testcase \
	topogeofromtablenf1.testcase \
	topogeofromtablenf2.testcase \
	topogeofromtablenf3.testcase \
	topogeofromtablenf4.testcase \
	topogeofromtablenf5.testcase \
	topogeofromtablenf6.testcase \
	topogeofromtablenf7.testcase \
	topogeofromtablenf8.testcase \
	topogeofromtablenf9.testcase \
	topogeofromtablenf10.testcase \
	topogeofromtablenf11.testcase \
	topogeofromtablenf12.testcase \
	topogeofromtablenf13.testcase \
	topogeofromtablenf14.testcase \
	topogeofromtablenf15.testcase \
	topogeofromtablenf16.testcase \
	topogeofromtablenf17.testcase \
	topogeofromtablenf18.testcase \
	topogeofromtablenf19.testcase \
	topogeofromtablenf20.testcase \
	topogeofromtablenf21.testcase \
	topogeofromtablenf22.testcase \
	topogeofromtablenf23.testcase \
	topogeofromtablenf24.testcase \
	topogeofromtablenf25.testcase \
	topogeofromtablenf26.testcase \
	topogeofromtablenf27.testcase \
	topogeofromtablenf28.testcase \
	topogeofromtablenf29.testcase \
	topogeofromtablenf30.testcase \
	topogeosplitline1.testcase \
	topogeosplitline2.testcase \
	topogeosplitline3.testcase \
	topogeosplitline4.testcase \
	topogeosplitline5.testcase \
	topogeosplitline6.testcase \
	topogeosplitline7.testcase \
................................................................................
	toponettotablegen25.testcase \
	toponettotablegen26.testcase \
	toponettotablegen27.testcase \
	toponettotablegen28.testcase \
	toponettotablegen29.testcase \
	toponettotablegen30.testcase \
	toponettotablegen31.testcase \
	toposnap1.testcase \
	toposnap2.testcase \
	toposnap3.testcase \
	toposnap4.testcase \
	toposnap5.testcase \
	toposnap6.testcase \
	toposnap7.testcase \
	toposnap8.testcase \
	toposnap9.testcase \
	toposnap10.testcase \
	toposnap11.testcase \
	toposnap12.testcase \
	toposnap13.testcase \
	toposnap14.testcase \
	toposnap15.testcase \
	toposnap16.testcase \
	toposnap17.testcase \
	toposnap18.testcase \
	toposnap19.testcase \
	toposnap20.testcase \
	toposnap21.testcase \
	validatetopogeo1.testcase \
	validatetopogeo2.testcase \
	validatetopogeo3.testcase \
	validatetopogeo4.testcase \
	validatetopogeo5.testcase \
	validlogicalnet1.testcase \
	validlogicalnet2.testcase \

Changes to test/sql_stmt_rttopo_tests/Makefile.in.

862
863
864
865
866
867
868





869
870
871
872
873
874
875
...
980
981
982
983
984
985
986

















987
988
989
990
991
992
993
....
1031
1032
1033
1034
1035
1036
1037







































1038
1039
1040
1041
1042
1043
1044
....
1061
1062
1063
1064
1065
1066
1067






























1068
1069
1070
1071
1072
1073
1074
....
1249
1250
1251
1252
1253
1254
1255





















1256
1257
1258
1259
1260
1261
1262
	pointsnapseed11.testcase \
	pointsnapseed12.testcase \
	pointsnapseed13.testcase \
	pointsnapseed14.testcase \
	pointsnapseed15.testcase \
	pointsnapseed16.testcase \
	pointsnapseed17.testcase \





	remedgemodface1.testcase \
	remedgemodface2.testcase \
	remedgemodface3.testcase \
	remedgemodface4.testcase \
	remedgemodface5.testcase \
	remedgemodface6.testcase \
	remedgemodface7.testcase \
................................................................................
	topogeoaddline11.testcase \
	topogeoaddline12.testcase \
	topogeoaddline13.testcase \
	topogeoaddline14.testcase \
	topogeoaddline15.testcase \
	topogeoaddline16.testcase \
	topogeoaddline17.testcase \

















	topogeoclone1.testcase \
	topogeoclone2.testcase \
	topogeoclone3.testcase \
	topogeoclone4.testcase \
	topogeoclone5.testcase \
	topogeoclone6.testcase \
	topogeoclone7.testcase \
................................................................................
	topogeofromext33.testcase \
	topogeofromext34.testcase \
	topogeofromext35.testcase \
	topogeofromext36.testcase \
	topogeofromext37.testcase \
	topogeofromext38.testcase \
	topogeofromext39.testcase \







































	topogeofromtable1.testcase \
	topogeofromtable2.testcase \
	topogeofromtable3.testcase \
	topogeofromtable4.testcase \
	topogeofromtable5.testcase \
	topogeofromtable6.testcase \
	topogeofromtable7.testcase \
................................................................................
	topogeofromtable24.testcase \
	topogeofromtable25.testcase \
	topogeofromtable26.testcase \
	topogeofromtable27.testcase \
	topogeofromtable28.testcase \
	topogeofromtable29.testcase \
	topogeofromtable30.testcase \






























	topogeosplitline1.testcase \
	topogeosplitline2.testcase \
	topogeosplitline3.testcase \
	topogeosplitline4.testcase \
	topogeosplitline5.testcase \
	topogeosplitline6.testcase \
	topogeosplitline7.testcase \
................................................................................
	toponettotablegen25.testcase \
	toponettotablegen26.testcase \
	toponettotablegen27.testcase \
	toponettotablegen28.testcase \
	toponettotablegen29.testcase \
	toponettotablegen30.testcase \
	toponettotablegen31.testcase \





















	validatetopogeo1.testcase \
	validatetopogeo2.testcase \
	validatetopogeo3.testcase \
	validatetopogeo4.testcase \
	validatetopogeo5.testcase \
	validlogicalnet1.testcase \
	validlogicalnet2.testcase \







>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
...
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
....
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
....
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
....
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
	pointsnapseed11.testcase \
	pointsnapseed12.testcase \
	pointsnapseed13.testcase \
	pointsnapseed14.testcase \
	pointsnapseed15.testcase \
	pointsnapseed16.testcase \
	pointsnapseed17.testcase \
	polygonize1.testcase \
	polygonize2.testcase \
	polygonize3.testcase \
	polygonize4.testcase \
	polygonize5.testcase \
	remedgemodface1.testcase \
	remedgemodface2.testcase \
	remedgemodface3.testcase \
	remedgemodface4.testcase \
	remedgemodface5.testcase \
	remedgemodface6.testcase \
	remedgemodface7.testcase \
................................................................................
	topogeoaddline11.testcase \
	topogeoaddline12.testcase \
	topogeoaddline13.testcase \
	topogeoaddline14.testcase \
	topogeoaddline15.testcase \
	topogeoaddline16.testcase \
	topogeoaddline17.testcase \
	topogeoaddlinenf1.testcase \
	topogeoaddlinenf2.testcase \
	topogeoaddlinenf3.testcase \
	topogeoaddlinenf4.testcase \
	topogeoaddlinenf5.testcase \
	topogeoaddlinenf6.testcase \
	topogeoaddlinenf7.testcase \
	topogeoaddlinenf8.testcase \
	topogeoaddlinenf9.testcase \
	topogeoaddlinenf10.testcase \
	topogeoaddlinenf11.testcase \
	topogeoaddlinenf12.testcase \
	topogeoaddlinenf13.testcase \
	topogeoaddlinenf14.testcase \
	topogeoaddlinenf15.testcase \
	topogeoaddlinenf16.testcase \
	topogeoaddlinenf17.testcase \
	topogeoclone1.testcase \
	topogeoclone2.testcase \
	topogeoclone3.testcase \
	topogeoclone4.testcase \
	topogeoclone5.testcase \
	topogeoclone6.testcase \
	topogeoclone7.testcase \
................................................................................
	topogeofromext33.testcase \
	topogeofromext34.testcase \
	topogeofromext35.testcase \
	topogeofromext36.testcase \
	topogeofromext37.testcase \
	topogeofromext38.testcase \
	topogeofromext39.testcase \
	topogeofromextnf1.testcase \
	topogeofromextnf2.testcase \
	topogeofromextnf3.testcase \
	topogeofromextnf4.testcase \
	topogeofromextnf5.testcase \
	topogeofromextnf6.testcase \
	topogeofromextnf7.testcase \
	topogeofromextnf8.testcase \
	topogeofromextnf9.testcase \
	topogeofromextnf10.testcase \
	topogeofromextnf11.testcase \
	topogeofromextnf12.testcase \
	topogeofromextnf13.testcase \
	topogeofromextnf14.testcase \
	topogeofromextnf15.testcase \
	topogeofromextnf16.testcase \
	topogeofromextnf17.testcase \
	topogeofromextnf18.testcase \
	topogeofromextnf19.testcase \
	topogeofromextnf20.testcase \
	topogeofromextnf21.testcase \
	topogeofromextnf22.testcase \
	topogeofromextnf23.testcase \
	topogeofromextnf24.testcase \
	topogeofromextnf25.testcase \
	topogeofromextnf26.testcase \
	topogeofromextnf27.testcase \
	topogeofromextnf28.testcase \
	topogeofromextnf29.testcase \
	topogeofromextnf30.testcase \
	topogeofromextnf31.testcase \
	topogeofromextnf32.testcase \
	topogeofromextnf33.testcase \
	topogeofromextnf34.testcase \
	topogeofromextnf35.testcase \
	topogeofromextnf36.testcase \
	topogeofromextnf37.testcase \
	topogeofromextnf38.testcase \
	topogeofromextnf39.testcase \
	topogeofromtable1.testcase \
	topogeofromtable2.testcase \
	topogeofromtable3.testcase \
	topogeofromtable4.testcase \
	topogeofromtable5.testcase \
	topogeofromtable6.testcase \
	topogeofromtable7.testcase \
................................................................................
	topogeofromtable24.testcase \
	topogeofromtable25.testcase \
	topogeofromtable26.testcase \
	topogeofromtable27.testcase \
	topogeofromtable28.testcase \
	topogeofromtable29.testcase \
	topogeofromtable30.testcase \
	topogeofromtablenf1.testcase \
	topogeofromtablenf2.testcase \
	topogeofromtablenf3.testcase \
	topogeofromtablenf4.testcase \
	topogeofromtablenf5.testcase \
	topogeofromtablenf6.testcase \
	topogeofromtablenf7.testcase \
	topogeofromtablenf8.testcase \
	topogeofromtablenf9.testcase \
	topogeofromtablenf10.testcase \
	topogeofromtablenf11.testcase \
	topogeofromtablenf12.testcase \
	topogeofromtablenf13.testcase \
	topogeofromtablenf14.testcase \
	topogeofromtablenf15.testcase \
	topogeofromtablenf16.testcase \
	topogeofromtablenf17.testcase \
	topogeofromtablenf18.testcase \
	topogeofromtablenf19.testcase \
	topogeofromtablenf20.testcase \
	topogeofromtablenf21.testcase \
	topogeofromtablenf22.testcase \
	topogeofromtablenf23.testcase \
	topogeofromtablenf24.testcase \
	topogeofromtablenf25.testcase \
	topogeofromtablenf26.testcase \
	topogeofromtablenf27.testcase \
	topogeofromtablenf28.testcase \
	topogeofromtablenf29.testcase \
	topogeofromtablenf30.testcase \
	topogeosplitline1.testcase \
	topogeosplitline2.testcase \
	topogeosplitline3.testcase \
	topogeosplitline4.testcase \
	topogeosplitline5.testcase \
	topogeosplitline6.testcase \
	topogeosplitline7.testcase \
................................................................................
	toponettotablegen25.testcase \
	toponettotablegen26.testcase \
	toponettotablegen27.testcase \
	toponettotablegen28.testcase \
	toponettotablegen29.testcase \
	toponettotablegen30.testcase \
	toponettotablegen31.testcase \
	toposnap1.testcase \
	toposnap2.testcase \
	toposnap3.testcase \
	toposnap4.testcase \
	toposnap5.testcase \
	toposnap6.testcase \
	toposnap7.testcase \
	toposnap8.testcase \
	toposnap9.testcase \
	toposnap10.testcase \
	toposnap11.testcase \
	toposnap12.testcase \
	toposnap13.testcase \
	toposnap14.testcase \
	toposnap15.testcase \
	toposnap16.testcase \
	toposnap17.testcase \
	toposnap18.testcase \
	toposnap19.testcase \
	toposnap20.testcase \
	toposnap21.testcase \
	validatetopogeo1.testcase \
	validatetopogeo2.testcase \
	validatetopogeo3.testcase \
	validatetopogeo4.testcase \
	validatetopogeo5.testcase \
	validlogicalnet1.testcase \
	validlogicalnet2.testcase \

Added test/sql_stmt_rttopo_tests/polygonize1.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_Polygonize - NULL Topology
:memory: #use in-memory database
SELECT TopoGeo_Polygonize(NULL);
1 # rows (not including the header row)
1 # columns
TopoGeo_Polygonize(NULL)
SQL/MM Spatial exception - null argument.

Added test/sql_stmt_rttopo_tests/polygonize2.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_Polygonize - Int Topology
:memory: #use in-memory database
SELECT TopoGeo_Polygonize(1);
1 # rows (not including the header row)
1 # columns
TopoGeo_Polygonize(1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/polygonize3.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_Polygonize - Double Topology
:memory: #use in-memory database
SELECT TopoGeo_Polygonize(1.1);
1 # rows (not including the header row)
1 # columns
TopoGeo_Polygonize(1.1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/polygonize4.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_Polygonize - BLOB Topology
:memory: #use in-memory database
SELECT TopoGeo_Polygonize(zeroblob(4));
1 # rows (not including the header row)
1 # columns
TopoGeo_Polygonize(zeroblob(4))
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/polygonize5.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_Polygonize - Text Topology
:memory: #use in-memory database
SELECT TopoGeo_Polygonize('topoW');
1 # rows (not including the header row)
1 # columns
TopoGeo_Polygonize('topoW')
SQL/MM Spatial exception - invalid topology name.

Added test/sql_stmt_rttopo_tests/topogeoaddlinenf1.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_AddLineStringNoFace - NULL Topology
:memory: #use in-memory database
SELECT TopoGeo_AddLineStringNoFace(NULL, GeomFromText('LINESTRING(0 0, 1 1)', 4326), 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_AddLineStringNoFace(NULL, GeomFromText('LINESTRING(0 0, 1 1)', 4326), 0)
SQL/MM Spatial exception - null argument.

Added test/sql_stmt_rttopo_tests/topogeoaddlinenf10.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_AddLineStringNoFace - Double Geometry
:memory: #use in-memory database
SELECT TopoGeo_AddLineStringNoFace('topology', 1.1, 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_AddLineStringNoFace('topology', 1.1, 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeoaddlinenf11.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_AddLineStringNoFace - NULL Geometry
:memory: #use in-memory database
SELECT TopoGeo_AddLineStringNoFace('topology', NULL, 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_AddLineStringNoFace('topology', NULL, 0)
SQL/MM Spatial exception - null argument.

Added test/sql_stmt_rttopo_tests/topogeoaddlinenf12.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_AddLineStringNoFace - Text Geometry
:memory: #use in-memory database
SELECT TopoGeo_AddLineStringNoFace('topology', 'geom', 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_AddLineStringNoFace('topology', 'geom', 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeoaddlinenf13.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_AddLineStringNoFace - Invalid BLOB Geometry
:memory: #use in-memory database
SELECT TopoGeo_AddLineStringNoFace('topology', zeroblob(4), 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_AddLineStringNoFace('topology', zeroblob(4), 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeoaddlinenf14.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_AddLineStringNoFace - Point Geometry
:memory: #use in-memory database
SELECT TopoGeo_AddLineStringNoFace('topology', MakePoint(0, 1, 4326), 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_AddLineStringNoFace('topology', MakePoint(0, 1, 4326), 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeoaddlinenf15.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_AddLineStringNoFace - Polygon Geometry
:memory: #use in-memory database
SELECT TopoGeo_AddLineStringNoFace('topology', GeomFromText('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))', 4326), 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_AddLineStringNoFace('topology', GeomFromText('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))', 4326), 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeoaddlinenf16.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_AddLineStringNoFace - MULTILINESTRING Geometry
:memory: #use in-memory database
SELECT TopoGeo_AddLineStringNoFace('topology', GeomFromText('MULTILINESTRING((0 0, 1 1), (2 2, 3 3))', 4326), 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_AddLineStringNoFace('topology', GeomFromText('MULTILINESTRING((0 0, 1 1), (2 2, 3 3))', 4326), 0)
SQL/MM Spatial exception - invalid topology name.

Added test/sql_stmt_rttopo_tests/topogeoaddlinenf17.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_AddLineStringNoFace - NULL Tolerance
:memory: #use in-memory database
SELECT TopoGeo_AddLineStringNoFace('topology', MakePoint(1, 2, 4326), NULL);
1 # rows (not including the header row)
1 # columns
TopoGeo_AddLineStringNoFace('topology', MakePoint(1, 2, 4326), NULL)
SQL/MM Spatial exception - null argument.

Added test/sql_stmt_rttopo_tests/topogeoaddlinenf2.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_AddLineStringNoFace - Int Topology
:memory: #use in-memory database
SELECT TopoGeo_AddLineStringNoFace(1, GeomFromText('LINESTRING(0 0, 1 1)', 4326), 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_AddLineStringNoFace(1, GeomFromText('LINESTRING(0 0, 1 1)', 4326), 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeoaddlinenf3.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_AddLineStringNoFace - Double Topology
:memory: #use in-memory database
SELECT TopoGeo_AddLineStringNoFace(1.5, GeomFromText('LINESTRING(0 0, 1 1)', 4326), 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_AddLineStringNoFace(1.5, GeomFromText('LINESTRING(0 0, 1 1)', 4326), 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeoaddlinenf4.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_AddLineStringNoFace - Blob Topology
:memory: #use in-memory database
SELECT TopoGeo_AddLineStringNoFace(zeroblob(4), GeomFromText('LINESTRING(0 0, 1 1)', 4326), 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_AddLineStringNoFace(zeroblob(4), GeomFromText('LINESTRING(0 0, 1 1)', 4326), 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeoaddlinenf5.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_AddLineStringNoFace - Text Topology
:memory: #use in-memory database
SELECT TopoGeo_AddLineStringNoFace('topology', GeomFromText('LINESTRING(0 0, 1 1)', 4326), 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_AddLineStringNoFace('topology', GeomFromText('LINESTRING(0 0, 1 1)', 4326), 0)
SQL/MM Spatial exception - invalid topology name.

Added test/sql_stmt_rttopo_tests/topogeoaddlinenf6.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_AddLineStringNoFace - Double Tolerance
:memory: #use in-memory database
SELECT TopoGeo_AddLineStringNoFace('topology', GeomFromText('LINESTRING(0 0, 1 1)', 4326), 0.0);
1 # rows (not including the header row)
1 # columns
TopoGeo_AddLineStringNoFace('topology', GeomFromText('LINESTRING(0 0, 1 1)', 4326), 0.0)
SQL/MM Spatial exception - invalid topology name.

Added test/sql_stmt_rttopo_tests/topogeoaddlinenf7.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_AddLineStringNoFace - BLOB Tolerance
:memory: #use in-memory database
SELECT TopoGeo_AddLineStringNoFace('topology', GeomFromText('LINESTRING(0 0, 1 1)', 4326), zeroblob(4));
1 # rows (not including the header row)
1 # columns
TopoGeo_AddLineStringNoFace('topology', GeomFromText('LINESTRING(0 0, 1 1)', 4326), zeroblob(4))
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeoaddlinenf8.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_AddLineStringNoFace - Text Tolerance
:memory: #use in-memory database
SELECT TopoGeo_AddLineStringNoFace('topology', GeomFromText('LINESTRING(0 0, 1 1)', 4326), 'tol');
1 # rows (not including the header row)
1 # columns
TopoGeo_AddLineStringNoFace('topology', GeomFromText('LINESTRING(0 0, 1 1)', 4326), 'tol')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeoaddlinenf9.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_AddLineStringNoFace - Int Geometry
:memory: #use in-memory database
SELECT TopoGeo_AddLineStringNoFace('topology', -1, 1);
1 # rows (not including the header row)
1 # columns
TopoGeo_AddLineStringNoFace('topology', -1, 1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf1.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - NULL Topology
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt(NULL, NULL, 'table', NULL, 0, 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt(NULL, NULL, 'table', NULL, 0, 'dustbin', 'dustbinview')
SQL/MM Spatial exception - null argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf10.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - NULL table
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, NULL, NULL, 0, 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, NULL, NULL, 0, 'dustbin', 'dustbinview')
SQL/MM Spatial exception - null argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf11.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - INT table
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 1, NULL, 0, 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 1, NULL, 0, 'dustbin', 'dustbinview')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf12.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - Double table
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 1.2, NULL, 0, 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 1.2, NULL, 0, 'dustbin', 'dustbinview')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf13.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - BLOB table
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, zeroblob(4), NULL, 0, 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, zeroblob(4), NULL, 0, 'dustbin', 'dustbinview')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf14.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - Text Column
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', 'column', 0, 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', 'column', 0, 'dustbin', 'dustbinview')
SQL/MM Spatial exception - invalid topology name.

Added test/sql_stmt_rttopo_tests/topogeofromextnf15.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - Int Column
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', 1, 0, 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', 1, 0, 'dustbin', 'dustbinview')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf16.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - Double Column
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', 1.2, 0, 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', 1.2, 0, 'dustbin', 'dustbinview')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf17.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - BLOB Column
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', zeroblob(4), 0, 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', zeroblob(4), 0, 'dustbin', 'dustbinview')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf18.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - NULL tolerance
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, NULL, 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, NULL, 'dustbin', 'dustbinview')
SQL/MM Spatial exception - null argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf19.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - Text tolerance
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 'zero', 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 'zero', 'dustbin', 'dustbinview')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf2.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - Int Topology
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt(1, NULL, 'table', NULL, 0, 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt(1, NULL, 'table', NULL, 0, 'dustbin', 'dustbinview')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf20.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - BLOB tolerance
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, zeroblob(4), 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, zeroblob(4), 'dustbin', 'dustbinview')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf21.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - Double tolerance
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, 'dustbin', 'dustbinview')
SQL/MM Spatial exception - invalid topology name.

Added test/sql_stmt_rttopo_tests/topogeofromextnf22.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - NULL line-max-points
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview', NULL, -1);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview', NULL, -1)
SQL/MM Spatial exception - null argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf23.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - Double line-max-points
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview', 1.5, -1);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview', 1.5, -1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf24.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - Text line-max-points
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview', 'abc', -1);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview', 'abc', -1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf25.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - BLOB line-max-points
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview', zeroblob(4), -1);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview', zeroblob(4), -1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf26.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - Integer line-max-points / Integer max-length
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview', -1, -1);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview', -1, -1)
SQL/MM Spatial exception - invalid topology name.

Added test/sql_stmt_rttopo_tests/topogeofromextnf27.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - NULL max-length
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview', -1, NULL);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview', -1, NULL)
SQL/MM Spatial exception - null argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf28.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - BLOB max-length
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview', -1, zeroblob(4));
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview', -1, zeroblob(4))
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf29.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - Text max-length
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview', -1, 'abc');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview', -1, 'abc')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf3.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - Double Topology
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt(1.5, NULL, 'table', NULL, 0, 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt(1.5, NULL, 'table', NULL, 0, 'dustbin', 'dustbinview')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf30.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - Double max-length
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview', -1, 5000.0);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview', -1, 5000.0)
SQL/MM Spatial exception - invalid topology name.

Added test/sql_stmt_rttopo_tests/topogeofromextnf31.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - NULL dustbin-table
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, NULL, 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, NULL, 'dustbinview')
SQL/MM Spatial exception - null argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf32.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - INT dustbin-table
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, 1, 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, 1, 'dustbinview')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf33.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - DOUBLE dustbin-table
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, 1.2, 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, 1.2, 'dustbinview')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf34.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - DOUBLE dustbin-table
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, 1.2, 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, 1.2, 'dustbinview')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf35.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - BLOB dustbin-table
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, zeroblob(5), 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, zeroblob(5), 'dustbinview')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf36.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - NULL dustbin-view
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, 'dustbin', NULL);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, NULL, 'dustbin')
SQL/MM Spatial exception - null argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf37.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - INT dustbin-view
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, 'dustbin', 1);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, 1, 'dustbin')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf38.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - DOUBLE dustbin-view
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, 'dustbin', 1.2);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, 1.2, 'dustbin')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf39.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - BLOB dustbin-view
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, 'dustbin', zeroblob(4));
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0.001, 'dustbin', zeroblob(4))
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf4.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - Blob Topology
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt(zeroblob(4), NULL, 'table', NULL, 0, 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt(zeroblob(4), NULL, 'table', NULL, 0, 'dustbin', 'dustbinview')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf5.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - Text Topology
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', NULL, 'table', NULL, 0, 'dustbin', 'dustbinview')
SQL/MM Spatial exception - invalid topology name.

Added test/sql_stmt_rttopo_tests/topogeofromextnf6.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - TEXT prefix
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', 'a', 'table', NULL, 0, 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', 'a', 'table', NULL, 0, 'dustbin', 'dustbinview')
SQL/MM Spatial exception - invalid topology name.

Added test/sql_stmt_rttopo_tests/topogeofromextnf7.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - INT prefix
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', 1, 'table', NULL, 0, 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', 1, 'table', NULL, 0, 'dustbin', 'dustbinview')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf8.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - Double prefix
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', 1.2, 'table', NULL, 0, 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', 1.2, 'table', NULL, 0, 'dustbin', 'dustbinview')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromextnf9.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFaceExt - BLOB prefix
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFaceExt('topology', zeroblob(4), 'table', NULL, 0, 'dustbin', 'dustbinview');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFaceExt('topology', zeroblob(4), 'table', NULL, 0, 'dustbin', 'dustbinview')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf1.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - NULL Topology
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace(NULL, NULL, 'table', NULL, 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace(NULL, NULL, 'table', NULL, 0)
SQL/MM Spatial exception - null argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf10.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - NULL table
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, NULL, NULL, 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, NULL, NULL, 0)
SQL/MM Spatial exception - null argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf11.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - INT table
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 1, NULL, 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 1, NULL, 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf12.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - Double table
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 1.2, NULL, 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 1.2, NULL, 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf13.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - BLOB table
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, zeroblob(4), NULL, 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, zeroblob(4), NULL, 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf14.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - Text Column
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', 'column', 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', 'column', 0)
SQL/MM Spatial exception - invalid topology name.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf15.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - Int Column
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', 1, 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', 1, 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf16.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - Double Column
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', 1.2, 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', 1.2, 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf17.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - BLOB Column
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', zeroblob(4), 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', zeroblob(4), 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf18.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - NULL tolerance
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, NULL);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, NULL)
SQL/MM Spatial exception - null argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf19.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - Text tolerance
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 'zero');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 'zero')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf2.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - Int Topology
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace(1, NULL, 'table', NULL, 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace(1, NULL, 'table', NULL, 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf20.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - BLOB tolerance
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, zeroblob(4));
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, zeroblob(4))
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf21.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - Double tolerance
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0.001);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0.001)
SQL/MM Spatial exception - invalid topology name.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf22.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - NULL line-max-points
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0, NULL, -1);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0, NULL, -1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf23.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - Double line-max-points
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0, 1.5, -1);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0, 1.5, -1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf24.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - Text line-max-points
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0, 'abc', -1);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0, 'abc', -1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf25.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - BLOB line-max-points
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0, zeroblob(4), -1);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0, zeroblob(4), -1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf26.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - Integer line-max-points / Integer max-length
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0, -1, -1);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0, -1, -1)
SQL/MM Spatial exception - invalid topology name.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf27.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - NULL max-length
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0, -1, NULL);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0, -1, NULL)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf28.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - BLOB max-length
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0, -1, zeroblob(4));
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0, -1, zeroblob(4))
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf29.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - Text max-length
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0, -1, 'abc');
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0, -1, 'abc')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf3.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - Double Topology
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace(1.5, NULL, 'table', NULL, 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace(1.5, NULL, 'table', NULL, 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf30.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - Double max-length
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0, -1, 5000.0);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0, -1, 5000.0)
SQL/MM Spatial exception - invalid topology name.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf4.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - Blob Topology
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace(zeroblob(4), NULL, 'table', NULL, 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace(zeroblob(4), NULL, 'table', NULL, 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf5.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - Text Topology
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', NULL, 'table', NULL, 0)
SQL/MM Spatial exception - invalid topology name.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf6.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - TEXT prefix
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', 'a', 'table', NULL, 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', 'a', 'table', NULL, 0)
SQL/MM Spatial exception - invalid topology name.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf7.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - INT prefix
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', 1, 'table', NULL, 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', 1, 'table', NULL, 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf8.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - Double prefix
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', 1.2, 'table', NULL, 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', 1.2, 'table', NULL, 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/topogeofromtablenf9.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
TopoGeo_FromGeoTableNoFace - BLOB prefix
:memory: #use in-memory database
SELECT TopoGeo_FromGeoTableNoFace('topology', zeroblob(4), 'table', NULL, 0);
1 # rows (not including the header row)
1 # columns
TopoGeo_FromGeoTableNoFace('topology', zeroblob(4), 'table', NULL, 0)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/toposnap1.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - NULL Topology
:memory: #use in-memory database
SELECT ST_TopoSnap(NULL, MakePoint(1, 2, 4326), -1, 1, 1);
1 # rows (not including the header row)
1 # columns
ST_TopoSnap(NULL, MakePoint(1, 2, 4326), -1, 1, 1)
SQL/MM Spatial exception - null argument.

Added test/sql_stmt_rttopo_tests/toposnap10.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - NULL tolerance
:memory: #use in-memory database
SELECT ST_TopoSnap('topo', MakePoint(1, 2, 4326), NULL, 1, 1);
1 # rows (not including the header row)
1 # columns
ST_TopoSnap('topo', MakePoint(1, 2, 4326), NULL, 1, 1)
SQL/MM Spatial exception - null argument.

Added test/sql_stmt_rttopo_tests/toposnap11.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - Text tolerance
:memory: #use in-memory database
SELECT ST_TopoSnap('topo', MakePoint(1, 2, 4326), 'tolerance', 1, 1);
1 # rows (not including the header row)
1 # columns
ST_TopoSnap('topo', MakePoint(1, 2, 4326), 'tolerance', 1, 1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/toposnap12.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - BLOB tolerance
:memory: #use in-memory database
SELECT ST_TopoSnap('topo', MakePoint(1, 2, 4326), zeroblob(12), 1, 1);
1 # rows (not including the header row)
1 # columns
ST_TopoSnap('topo', MakePoint(1, 2, 4326), zeroblob(12), 1, 1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/toposnap13.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - NULL iterate
:memory: #use in-memory database
SELECT ST_TopoSnap('topo', MakePoint(1, 2, 4326), -1.0, NULL, 1);
1 # rows (not including the header row)
1 # columns
ST_TopoSnap('topo', MakePoint(1, 2, 4326), -1.0, NULL, 1)
SQL/MM Spatial exception - null argument.

Added test/sql_stmt_rttopo_tests/toposnap14.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - Text iterate
:memory: #use in-memory database
SELECT ST_TopoSnap('topo', MakePoint(1, 2, 4326), -1.0, 'iterate', 1);
1 # rows (not including the header row)
1 # columns
ST_TopoSnap('topo', MakePoint(1, 2, 4326), -1.0, 'iterate', 1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/toposnap15.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - DOUBLE iterate
:memory: #use in-memory database
SELECT ST_TopoSnap('topo', MakePoint(1, 2, 4326), -1.0, 1.5, 1);
1 # rows (not including the header row)
1 # columns
ST_TopoSnap('topo', MakePoint(1, 2, 4326), -1.0, 1.5, 1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/toposnap16.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - BLOB iterate
:memory: #use in-memory database
SELECT ST_TopoSnap('topo', MakePoint(1, 2, 4326), -1.0, zeroblob(4), 1);
1 # rows (not including the header row)
1 # columns
ST_TopoSnap('topo', MakePoint(1, 2, 4326), -1.0, zeroblob(4), 1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/toposnap17.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - NULL remove_vertices
:memory: #use in-memory database
SELECT ST_TopoSnap('topo', MakePoint(1, 2, 4326), -1.0, 1, NULL);
1 # rows (not including the header row)
1 # columns
ST_TopoSnap('topo', MakePoint(1, 2, 4326), -1.0, 1, NULL)
SQL/MM Spatial exception - null argument.

Added test/sql_stmt_rttopo_tests/toposnap18.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - DOUBLE remove_vertices
:memory: #use in-memory database
SELECT ST_TopoSnap('topo', MakePoint(1, 2, 4326), -1.0, 1, 1.5);
1 # rows (not including the header row)
1 # columns
ST_TopoSnap('topo', MakePoint(1, 2, 4326), -1.0, 1, 1.5)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/toposnap19.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - BLOB remove_vertices
:memory: #use in-memory database
SELECT ST_TopoSnap('topo', MakePoint(1, 2, 4326), -1.0, 1, zeroblob(4));
1 # rows (not including the header row)
1 # columns
ST_TopoSnap('topo', MakePoint(1, 2, 4326), -1.0, 1, zeroblob(4))
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/toposnap2.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - Int Topology
:memory: #use in-memory database
SELECT ST_TopoSnap(1, MakePoint(1, 2, 4326), -1, 1, 1);
1 # rows (not including the header row)
1 # columns
ST_TopoSnap(1, MakePoint(1, 2, 4326), -1, 1, 1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/toposnap20.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - non-existing topology
:memory: #use in-memory database
SELECT ST_TopoSnap('topo', MakePoint(1, 2, 4326), -1.0, 1, 1);
1 # rows (not including the header row)
1 # columns
ST_TopoSnap('topo', MakePoint(1, 2, 4326), -1.0, 1, 1)
SQL/MM Spatial exception - invalid topology name.

Added test/sql_stmt_rttopo_tests/toposnap21.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - TEXT remove_vertices
:memory: #use in-memory database
SELECT ST_TopoSnap('topo', MakePoint(1, 2, 4326), -1.0, 1, 'remove');
1 # rows (not including the header row)
1 # columns
ST_TopoSnap('topo', MakePoint(1, 2, 4326), -1.0, 1, 'remove')
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/toposnap3.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - Double Topology
:memory: #use in-memory database
SELECT ST_TopoSnap(1.5, MakePoint(1, 2, 4326), -1, 1, 1);
1 # rows (not including the header row)
1 # columns
ST_TopoSnap(1.5, MakePoint(1, 2, 4326), -1, 1, 1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/toposnap4.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - BLOB Topology
:memory: #use in-memory database
SELECT ST_TopoSnap(zeroblob(10), MakePoint(1, 2, 4326), -1, 1, 1);
1 # rows (not including the header row)
1 # columns
ST_TopoSnap(zeroblob(10), MakePoint(1, 2, 4326), -1, 1, 1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/toposnap5.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - NULL Geometry
:memory: #use in-memory database
SELECT ST_TopoSnap('topo', NULL, -1, 1, 1);
1 # rows (not including the header row)
1 # columns
ST_TopoSnap('topo', NULL, -1, 1, 1)
SQL/MM Spatial exception - null argument.

Added test/sql_stmt_rttopo_tests/toposnap6.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - Int Geometry
:memory: #use in-memory database
SELECT ST_TopoSnap('topo', 1, -1, 1, 1);
1 # rows (not including the header row)
1 # columns
ST_TopoSnap('topo', 1, -1, 1, 1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/toposnap7.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - Int Geometry
:memory: #use in-memory database
SELECT ST_TopoSnap('topo', 1-5, -1, 1, 1);
1 # rows (not including the header row)
1 # columns
ST_TopoSnap('topo', 1.5, -1, 1, 1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/toposnap8.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - Text Geometry
:memory: #use in-memory database
SELECT ST_TopoSnap('topo', 'geom', -1, 1, 1);
1 # rows (not including the header row)
1 # columns
ST_TopoSnap('topo', 'geom', -1, 1, 1)
SQL/MM Spatial exception - invalid argument.

Added test/sql_stmt_rttopo_tests/toposnap9.testcase.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
ST_TopoSnap - Invalid BLOB Geometry
:memory: #use in-memory database
SELECT ST_TopoSnap('topo', zeroblob(100), -1, 1, 1);
1 # rows (not including the header row)
1 # columns
ST_TopoSnap('topo', zeroblob(100), -1, 1, 1)
SQL/MM Spatial exception - invalid argument.

Changes to test/sql_stmt_sequence_tests/Makefile.

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
PACKAGE_STRING = libspatialite 4.4.0-RC1
PACKAGE_TARNAME = libspatialite
PACKAGE_URL = 
PACKAGE_VERSION = 4.4.0-RC1
PATH_SEPARATOR = :
PKG_CONFIG = /usr/bin/pkg-config
PKG_CONFIG_LIBDIR = 
PKG_CONFIG_PATH = /usr/local/lib/pkgconfig
RANLIB = ranlib
SED = /usr/bin/sed
SET_MAKE = 
SHELL = /bin/sh
STRIP = strip
VERSION = 4.4.0-RC1
abs_builddir = /home/sandro/fossil/libspatialite/test/sql_stmt_sequence_tests







|







187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
PACKAGE_STRING = libspatialite 4.4.0-RC1
PACKAGE_TARNAME = libspatialite
PACKAGE_URL = 
PACKAGE_VERSION = 4.4.0-RC1
PATH_SEPARATOR = :
PKG_CONFIG = /usr/bin/pkg-config
PKG_CONFIG_LIBDIR = 
PKG_CONFIG_PATH = 
RANLIB = ranlib
SED = /usr/bin/sed
SET_MAKE = 
SHELL = /bin/sh
STRIP = strip
VERSION = 4.4.0-RC1
abs_builddir = /home/sandro/fossil/libspatialite/test/sql_stmt_sequence_tests

Changes to test/sql_stmt_voronoj1_tests/Makefile.

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
PACKAGE_STRING = libspatialite 4.4.0-RC1
PACKAGE_TARNAME = libspatialite
PACKAGE_URL = 
PACKAGE_VERSION = 4.4.0-RC1
PATH_SEPARATOR = :
PKG_CONFIG = /usr/bin/pkg-config
PKG_CONFIG_LIBDIR = 
PKG_CONFIG_PATH = /usr/local/lib/pkgconfig
RANLIB = ranlib
SED = /usr/bin/sed
SET_MAKE = 
SHELL = /bin/sh
STRIP = strip
VERSION = 4.4.0-RC1
abs_builddir = /home/sandro/fossil/libspatialite/test/sql_stmt_voronoj1_tests







|







187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
PACKAGE_STRING = libspatialite 4.4.0-RC1
PACKAGE_TARNAME = libspatialite
PACKAGE_URL = 
PACKAGE_VERSION = 4.4.0-RC1
PATH_SEPARATOR = :
PKG_CONFIG = /usr/bin/pkg-config
PKG_CONFIG_LIBDIR = 
PKG_CONFIG_PATH = 
RANLIB = ranlib
SED = /usr/bin/sed
SET_MAKE = 
SHELL = /bin/sh
STRIP = strip
VERSION = 4.4.0-RC1
abs_builddir = /home/sandro/fossil/libspatialite/test/sql_stmt_voronoj1_tests

Changes to test/sql_stmt_voronoj2_tests/Makefile.

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
PACKAGE_STRING = libspatialite 4.4.0-RC1
PACKAGE_TARNAME = libspatialite
PACKAGE_URL = 
PACKAGE_VERSION = 4.4.0-RC1
PATH_SEPARATOR = :
PKG_CONFIG = /usr/bin/pkg-config
PKG_CONFIG_LIBDIR = 
PKG_CONFIG_PATH = /usr/local/lib/pkgconfig
RANLIB = ranlib
SED = /usr/bin/sed
SET_MAKE = 
SHELL = /bin/sh
STRIP = strip
VERSION = 4.4.0-RC1
abs_builddir = /home/sandro/fossil/libspatialite/test/sql_stmt_voronoj2_tests







|







187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
PACKAGE_STRING = libspatialite 4.4.0-RC1
PACKAGE_TARNAME = libspatialite
PACKAGE_URL = 
PACKAGE_VERSION = 4.4.0-RC1
PATH_SEPARATOR = :
PKG_CONFIG = /usr/bin/pkg-config
PKG_CONFIG_LIBDIR = 
PKG_CONFIG_PATH = 
RANLIB = ranlib
SED = /usr/bin/sed
SET_MAKE = 
SHELL = /bin/sh
STRIP = strip
VERSION = 4.4.0-RC1
abs_builddir = /home/sandro/fossil/libspatialite/test/sql_stmt_voronoj2_tests