3
check_contro_points.c -- SpatiaLite Test Case
5
Author: Sandro Furieri <a.furieri@lqt.it>
7
------------------------------------------------------------------------------
9
Version: MPL 1.1/GPL 2.0/LGPL 2.1
11
The contents of this file are subject to the Mozilla Public License Version
12
1.1 (the "License"); you may not use this file except in compliance with
13
the License. You may obtain a copy of the License at
14
http://www.mozilla.org/MPL/
16
Software distributed under the License is distributed on an "AS IS" basis,
17
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
18
for the specific language governing rights and limitations under the
21
The Original Code is the SpatiaLite library
23
The Initial Developer of the Original Code is Alessandro Furieri
25
Portions created by the Initial Developer are Copyright (C) 2011
26
the Initial Developer. All Rights Reserved.
29
Brad Hards <bradh@frogmouth.net>
31
Alternatively, the contents of this file may be used under the terms of
32
either the GNU General Public License Version 2 or later (the "GPL"), or
33
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
34
in which case the provisions of the GPL or the LGPL are applicable instead
35
of those above. If you wish to allow use of your version of this file only
36
under the terms of either the GPL or the LGPL, and not to allow others to
37
use your version of this file under the terms of the MPL, indicate your
38
decision by deleting the provisions above and replace them with the notice
39
and other provisions required by the GPL or the LGPL. If you do not delete
40
the provisions above, a recipient may use your version of this file under
41
the terms of any one of the MPL, the GPL or the LGPL.
51
#include "spatialite.h"
54
test_query (sqlite3 * sqlite, const char *sql, const char *expected)
56
/* testing some SQL query */
58
sqlite3_stmt *stmt = NULL;
60
ret = sqlite3_prepare_v2 (sqlite, sql, strlen (sql), &stmt, NULL);
63
fprintf (stderr, "%s\n: \"%s\"\n", sql, sqlite3_errmsg (sqlite));
68
/* scrolling the result set rows */
69
ret = sqlite3_step (stmt);
70
if (ret == SQLITE_DONE)
71
break; /* end of result set */
72
if (ret == SQLITE_ROW)
75
if (sqlite3_column_type (stmt, 0) == SQLITE_NULL)
82
"Unexpected NULL result\nExpected: %s\n",
87
value = (const char *) sqlite3_column_text (stmt, 0);
90
fprintf (stderr, "Unexpected result %s\nExpected: NULL\n",
94
if (strcasecmp (value, expected) != 0)
96
fprintf (stderr, "Unexpected result %s\nExpected: %s\n",
104
sqlite3_finalize (stmt);
109
sqlite3_finalize (stmt);
114
test_transform (sqlite3 * handle, int order)
116
/* testing GCP_Transform */
120
/* resolving Control Points 2D - CGP_Transform XY */
121
sql = sqlite3_mprintf ("SELECT AsText(GCP_Transform(g.geometry, b.gcp)) "
122
"FROM test_xy AS g, "
123
"(SELECT GCP_Compute(a.geometry, b.geometry, %d) AS gcp "
124
"FROM point_a_xy AS a, point_b_xy AS b WHERE a.id = b.id) AS b",
127
test_query (handle, sql,
128
"GEOMETRYCOLLECTION(POINT(-161 -64), LINESTRING(-160 -63, -159 -62), "
129
"POLYGON((-151 -54, -141 -54, -141 -44, -151 -44, -151 -54), "
130
"(-147 -50, -145 -50, -145 -48, -147 -48, -147 -50)))");
135
/* resolving Control Points 2D - CGP_Transform XYM */
136
sql = sqlite3_mprintf ("SELECT AsText(GCP_Transform(g.geometry, b.gcp)) "
137
"FROM test_xym AS g, "
138
"(SELECT GCP_Compute(a.geometry, b.geometry, %d) AS gcp "
139
"FROM point_a_xy AS a, point_b_xy AS b WHERE a.id = b.id) AS b",
142
test_query (handle, sql,
143
"GEOMETRYCOLLECTION M(POINT M(-161 -64 1), "
144
"LINESTRING M(-160 -63 1, -159 -62 3), "
145
"POLYGON M((-151 -54 1, -141 -54 2, -141 -44 3, -151 -44 2, -151 -54 1), "
146
"(-147 -50 1, -145 -50 2, -145 -48 2, -147 -48 2, -147 -50 1)))");
151
/* resolving Control Points 3D - CGP_Transform XYZ */
154
("SELECT IsValid(GCP_Transform(g.geometry, b.gcp)) "
155
"FROM test_xyz AS g, "
156
"(SELECT GCP_Compute(a.geometry, b.geometry, %d) AS gcp "
157
"FROM point_a_xyz AS a, point_b_xyz AS b WHERE a.id = b.id) AS b",
159
ret = test_query (handle, sql, "1");
164
/* resolving Control Points 3D - CGP_Transform XYZM */
167
("SELECT IsValid(GCP_Transform(g.geometry, b.gcp)) "
168
"FROM test_xyzm AS g, "
169
"(SELECT GCP_Compute(a.geometry, b.geometry, %d) AS gcp "
170
"FROM point_a_xyz AS a, point_b_xyz AS b WHERE a.id = b.id) AS b",
172
ret = test_query (handle, sql, "1");
181
test_invalid (sqlite3 * handle)
183
/* testing invalid calls */
186
sql = "SELECT GCP_Compute(NULL, GeomFromText('POINT(1 1)'))";
187
if (!test_query (handle, sql, NULL))
189
sql = "SELECT GCP_Compute(GeomFromText('POINT(1 1)'), NULL)";
190
if (!test_query (handle, sql, NULL))
193
"SELECT GCP_Compute(GeomFromText('POINT(1 1)'), GeomFromText('POINT(2 2)'), NULL)";
194
if (!test_query (handle, sql, NULL))
197
"SELECT GCP_Compute(GeomFromText('POINT(1 1)'), GeomFromText('POINT(2 2)'), -1)";
198
if (!test_query (handle, sql, NULL))
201
"SELECT GCP_Compute(GeomFromText('POINT(1 1)'), GeomFromText('POINT(2 2)'), 4)";
202
if (!test_query (handle, sql, NULL))
205
"SELECT GCP_Compute(GeomFromText('POINT(1 1)'), GeomFromText('POINTZ(2 2 2)'))";
206
if (!test_query (handle, sql, NULL))
209
"SELECT GCP_Compute(GeomFromText('POINT(1 1)'), GeomFromText('POINT(2 2)'))";
210
if (!test_query (handle, sql, NULL))
213
"SELECT GCP_Compute(GeomFromText('POINT(1 1)'), GeomFromText('LINESTRING(2 2, 3 2)'))";
214
if (!test_query (handle, sql, NULL))
217
"SELECT GCP_Compute(GeomFromText('LINESTRING(2 2, 3 2)'), GeomFromText('POINT(1 1)'))";
218
if (!test_query (handle, sql, NULL))
220
sql = "SELECT GCP_Compute(GeomFromText('POINT(1 1)'), NULL)";
221
if (!test_query (handle, sql, NULL))
223
sql = "SELECT GCP_Compute(GeomFromText('POINT(1 1)'), zeroblob(10))";
224
if (!test_query (handle, sql, NULL))
226
sql = "SELECT GCP_Transform(NULL, b.gcp) "
227
"FROM (SELECT GCP_Compute(a.geometry, b.geometry) AS gcp "
228
"FROM point_a_xyz AS a, point_b_xyz AS b WHERE a.id = b.id) AS b";
229
if (!test_query (handle, sql, NULL))
231
sql = "SELECT GCP_Transform(zeroblob(10), b.gcp) "
232
"FROM (SELECT GCP_Compute(a.geometry, b.geometry) AS gcp "
233
"FROM point_a_xyz AS a, point_b_xyz AS b WHERE a.id = b.id) AS b";
234
if (!test_query (handle, sql, NULL))
236
sql = "SELECT GCP_Transform(GeomFromText('POINT(1 1)'), zeroblob(4))";
237
if (!test_query (handle, sql, NULL))
239
sql = "SELECT GCP_IsValid(NULL)";
240
if (!test_query (handle, sql, "-1"))
242
sql = "SELECT GCP_IsValid(zeroblob(0))";
243
if (!test_query (handle, sql, "0"))
245
sql = "SELECT GCP_AsText(NULL)";
246
if (!test_query (handle, sql, NULL))
248
sql = "SELECT GCP_AsText(zeroblob(0))";
249
if (!test_query (handle, sql, NULL))
251
sql = "SELECT GCP_Transform(GeomFromText('POINT(1 1)'), b.gcp, 1.0) "
252
"FROM (SELECT GCP_Compute(a.geometry, b.geometry) AS gcp "
253
"FROM point_a_xyz AS a, point_b_xyz AS b WHERE a.id = b.id) AS b";
254
if (!test_query (handle, sql, NULL))
256
sql = "SELECT GCP_Transform(zeroblob(4), b.gcp, 32632) "
257
"FROM (SELECT GCP_Compute(a.geometry, b.geometry) AS gcp "
258
"FROM point_a_xyz AS a, point_b_xyz AS b WHERE a.id = b.id) AS b";
259
if (!test_query (handle, sql, NULL))
261
sql = "SELECT GCP_Transform(GeomFromText('POINT(1 1)'), NULL)";
262
if (!test_query (handle, sql, NULL))
264
sql = "SELECT GCP2ATM(NULL)";
265
if (!test_query (handle, sql, NULL))
267
sql = "SELECT GCP2ATM(zeroblob(100))";
268
if (!test_query (handle, sql, NULL))
270
sql = "SELECT GCP2ATM(b.gcp) "
271
"FROM (SELECT GCP_Compute(a.geometry, b.geometry, 2) AS gcp "
272
"FROM point_a_xy AS a, point_b_xy AS b WHERE a.id = b.id) AS b";
273
if (!test_query (handle, sql, NULL))
275
sql = "SELECT GCP2ATM(b.gcp) "
276
"FROM (SELECT GCP_Compute(a.geometry, b.geometry, 3) AS gcp "
277
"FROM point_a_xy AS a, point_b_xy AS b WHERE a.id = b.id) AS b";
278
if (!test_query (handle, sql, NULL))
280
sql = "SELECT GCP2ATM(b.gcp) "
281
"FROM (SELECT GCP_Compute(a.geometry, b.geometry, 0) AS gcp "
282
"FROM point_a_xy AS a, point_b_xy AS b WHERE a.id = b.id) AS b";
283
if (!test_query (handle, sql, NULL))
290
main (int argc, char *argv[])
292
#ifdef ENABLE_GCP /* only if Control Points (Grass) is enabled */
295
char *err_msg = NULL;
298
void *cache = spatialite_alloc_connection ();
300
if (argc > 1 || argv[0] == NULL)
301
argc = 1; /* silencing stupid compiler warnings */
304
sqlite3_open_v2 (":memory:", &handle,
305
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
306
if (ret != SQLITE_OK)
308
fprintf (stderr, "cannot open in-memory databse: %s\n",
309
sqlite3_errmsg (handle));
310
sqlite3_close (handle);
314
spatialite_init_ex (handle, cache, 0);
317
sqlite3_exec (handle, "SELECT InitSpatialMetadata(1)", NULL, NULL,
319
if (ret != SQLITE_OK)
321
fprintf (stderr, "InitSpatialMetadata() error: %s\n", err_msg);
322
sqlite3_free (err_msg);
323
sqlite3_close (handle);
327
/* creating and populating a test table - XY */
328
ret = sqlite3_exec (handle, "CREATE TABLE test_xy ("
329
"id INTEGER PRIMARY KEY AUTOINCREMENT)", NULL, NULL,
331
if (ret != SQLITE_OK)
333
fprintf (stderr, "CREATE test_xy error: %s\n", err_msg);
334
sqlite3_free (err_msg);
335
sqlite3_close (handle);
338
ret = sqlite3_exec (handle, "SELECT AddGeometryColumn("
339
"'test_xy', 'geometry', 4326, 'GEOMETRYCOLLECTION', 'XY')",
340
NULL, NULL, &err_msg);
341
if (ret != SQLITE_OK)
343
fprintf (stderr, "CREATE test_xy Geometry error: %s\n", err_msg);
344
sqlite3_free (err_msg);
345
sqlite3_close (handle);
348
ret = sqlite3_exec (handle, "INSERT INTO test_xy VALUES (NULL, "
349
"GeomFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(1 1, 2 2), "
350
"POLYGON((10 10, 20 10, 20 20, 10 20, 10 10), "
351
"(14 14, 16 14, 16 16, 14 16, 14 14)))', 4326))", NULL,
353
if (ret != SQLITE_OK)
355
fprintf (stderr, "INSERT INTO test_xy Geometry error: %s\n", err_msg);
356
sqlite3_free (err_msg);
357
sqlite3_close (handle);
361
/* creating and populating a test table - XYZ */
362
ret = sqlite3_exec (handle, "CREATE TABLE test_xyz ("
363
"id INTEGER PRIMARY KEY AUTOINCREMENT)", NULL, NULL,
365
if (ret != SQLITE_OK)
367
fprintf (stderr, "CREATE test_xyz error: %s\n", err_msg);
368
sqlite3_free (err_msg);
369
sqlite3_close (handle);
372
ret = sqlite3_exec (handle, "SELECT AddGeometryColumn("
373
"'test_xyz', 'geometry', 4326, 'GEOMETRYCOLLECTION', 'XYz')",
374
NULL, NULL, &err_msg);
375
if (ret != SQLITE_OK)
377
fprintf (stderr, "CREATE test_xyz Geometry error: %s\n", err_msg);
378
sqlite3_free (err_msg);
379
sqlite3_close (handle);
382
ret = sqlite3_exec (handle, "INSERT INTO test_xyz VALUES (NULL, "
383
"GeomFromText('GEOMETRYCOLLECTIONZ(POINTZ(0 0 1), "
384
"LINESTRINGZ(1 1 1, 2 2 3), "
385
"POLYGONZ((10 10 1, 20 10 2, 20 20 3, 10 20 2, 10 10 1), "
386
"(14 14 1, 16 14 2, 16 16 2, 14 16 2, 14 14 1)))', 4326))",
387
NULL, NULL, &err_msg);
388
if (ret != SQLITE_OK)
390
fprintf (stderr, "INSERT INTO test_xyz Geometry error: %s\n",
392
sqlite3_free (err_msg);
393
sqlite3_close (handle);
397
/* creating and populating a test table - XYM */
398
ret = sqlite3_exec (handle, "CREATE TABLE test_xym ("
399
"id INTEGER PRIMARY KEY AUTOINCREMENT)", NULL, NULL,
401
if (ret != SQLITE_OK)
403
fprintf (stderr, "CREATE test_xym error: %s\n", err_msg);
404
sqlite3_free (err_msg);
405
sqlite3_close (handle);
408
ret = sqlite3_exec (handle, "SELECT AddGeometryColumn("
409
"'test_xym', 'geometry', 4326, 'GEOMETRYCOLLECTION', 'XYM')",
410
NULL, NULL, &err_msg);
411
if (ret != SQLITE_OK)
413
fprintf (stderr, "CREATE test_xym Geometry error: %s\n", err_msg);
414
sqlite3_free (err_msg);
415
sqlite3_close (handle);
418
ret = sqlite3_exec (handle, "INSERT INTO test_xym VALUES (NULL, "
419
"GeomFromText('GEOMETRYCOLLECTIONM(POINTM(0 0 1), "
420
"LINESTRINGM(1 1 1, 2 2 3), "
421
"POLYGONM((10 10 1, 20 10 2, 20 20 3, 10 20 2, 10 10 1), "
422
"(14 14 1, 16 14 2, 16 16 2, 14 16 2, 14 14 1)))', 4326))",
423
NULL, NULL, &err_msg);
424
if (ret != SQLITE_OK)
426
fprintf (stderr, "INSERT INTO test_xym Geometry error: %s\n",
428
sqlite3_free (err_msg);
429
sqlite3_close (handle);
433
/* creating and populating a test table - XYZM */
434
ret = sqlite3_exec (handle, "CREATE TABLE test_xyzm ("
435
"id INTEGER PRIMARY KEY AUTOINCREMENT)", NULL, NULL,
437
if (ret != SQLITE_OK)
439
fprintf (stderr, "CREATE test_xyzm error: %s\n", err_msg);
440
sqlite3_free (err_msg);
441
sqlite3_close (handle);
444
ret = sqlite3_exec (handle, "SELECT AddGeometryColumn("
445
"'test_xyzm', 'geometry', 4326, 'GEOMETRYCOLLECTION', 'XYZM')",
446
NULL, NULL, &err_msg);
447
if (ret != SQLITE_OK)
449
fprintf (stderr, "CREATE test_xyzm Geometry error: %s\n", err_msg);
450
sqlite3_free (err_msg);
451
sqlite3_close (handle);
454
ret = sqlite3_exec (handle, "INSERT INTO test_xyzm VALUES (NULL, "
455
"GeomFromText('GEOMETRYCOLLECTIONZM(POINTZM(0 0 1 1), "
456
"LINESTRINGZM(1 1 1 1, 2 2 3 3), "
457
"POLYGONZM((10 10 1 1, 20 10 2 2, 20 20 3 3, 10 20 2 2, 10 10 1 1), "
458
"(14 14 1 1, 16 14 2 2, 16 16 2 2, 14 16 2 2, 14 14 1 1)))', 4326))",
459
NULL, NULL, &err_msg);
460
if (ret != SQLITE_OK)
462
fprintf (stderr, "INSERT INTO test_xyzm Geometry error: %s\n",
464
sqlite3_free (err_msg);
465
sqlite3_close (handle);
469
/* creating and populating Point table #1 - XY */
470
ret = sqlite3_exec (handle, "CREATE TABLE point_a_xy ("
471
"id INTEGER PRIMARY KEY AUTOINCREMENT)", NULL, NULL,
473
if (ret != SQLITE_OK)
475
fprintf (stderr, "CREATE point_a_xy error: %s\n", err_msg);
476
sqlite3_free (err_msg);
477
sqlite3_close (handle);
480
ret = sqlite3_exec (handle, "SELECT AddGeometryColumn("
481
"'point_a_xy', 'geometry', 4326, 'POINT', 'XY')", NULL,
483
if (ret != SQLITE_OK)
485
fprintf (stderr, "CREATE point_a_xy Geometry error: %s\n", err_msg);
486
sqlite3_free (err_msg);
487
sqlite3_close (handle);
490
ret = sqlite3_exec (handle, "INSERT INTO point_a_xy VALUES "
491
"(NULL, MakePoint(0, 0, 4326)), (NULL, MakePoint(1, 1, 4326)), "
492
"(NULL, MakePoint(10, 10, 4326)), (NULL, MakePoint(11, 11, 4326)), "
493
"(NULL, MakePoint(10, 0, 4326)), (NULL, MakePoint(11, 1, 4326)), "
494
"(NULL, MakePoint(0, 10, 4326)), (NULL, MakePoint(1, 11, 4326)) ",
495
NULL, NULL, &err_msg);
496
if (ret != SQLITE_OK)
498
fprintf (stderr, "INSERT INTO point_a_xy Geometry error: %s\n",
500
sqlite3_free (err_msg);
501
sqlite3_close (handle);
504
ret = sqlite3_exec (handle, "INSERT INTO point_a_xy VALUES "
505
"(NULL, MakePoint(5, 4, 4326)), (NULL, MakePoint(4, 5, 4326)), "
506
"(NULL, MakePoint(8, 2, 4326)), (NULL, MakePoint(2, 8, 4326)), "
507
"(NULL, MakePoint(20, 20, 4326)), (NULL, MakePoint(21, 21, 4326)), "
508
"(NULL, MakePoint(30, 30, 4326)), (NULL, MakePoint(31, 31, 4326)), "
509
"(NULL, MakePoint(30, 20, 4326)), (NULL, MakePoint(31, 21, 4326)) ",
510
NULL, NULL, &err_msg);
511
if (ret != SQLITE_OK)
513
fprintf (stderr, "INSERT INTO point_a_xy Geometry error: %s\n",
515
sqlite3_free (err_msg);
516
sqlite3_close (handle);
519
ret = sqlite3_exec (handle, "INSERT INTO point_a_xy VALUES "
520
"(NULL, MakePoint(20, 30, 4326)), (NULL, MakePoint(21, 31, 4326)), "
521
"(NULL, MakePoint(25, 24, 4326)), (NULL, MakePoint(24, 25, 4326)), "
522
"(NULL, MakePoint(28, 22, 4326)), (NULL, MakePoint(22, 28, 4326)), "
523
"(NULL, MakePoint(30, 0, 4326)), (NULL, MakePoint(0, 30, 4326)) ",
524
NULL, NULL, &err_msg);
525
if (ret != SQLITE_OK)
527
fprintf (stderr, "INSERT INTO point_a_xy Geometry error: %s\n",
529
sqlite3_free (err_msg);
530
sqlite3_close (handle);
534
/* creating and populating Point table #2 - XY */
535
ret = sqlite3_exec (handle, "CREATE TABLE point_b_xy ("
536
"id INTEGER PRIMARY KEY AUTOINCREMENT)", NULL, NULL,
538
if (ret != SQLITE_OK)
540
fprintf (stderr, "CREATE point_b_xy error: %s\n", err_msg);
541
sqlite3_free (err_msg);
542
sqlite3_close (handle);
545
ret = sqlite3_exec (handle, "SELECT AddGeometryColumn("
546
"'point_b_xy', 'geometry', 4326, 'POINT', 'XY')", NULL,
548
if (ret != SQLITE_OK)
550
fprintf (stderr, "CREATE point_b_xy Geometry error: %s\n", err_msg);
551
sqlite3_free (err_msg);
552
sqlite3_close (handle);
555
ret = sqlite3_exec (handle, "INSERT INTO point_b_xy VALUES "
556
"(NULL, MakePoint(-161 + 0, -64 + 0, 4326)), "
557
"(NULL, MakePoint(-161 + 1, -64 + 1, 4326)), "
558
"(NULL, MakePoint(-161 + 10, -64 + 10, 4326)), "
559
"(NULL, MakePoint(-161 + 11, -64 + 11, 4326)), "
560
"(NULL, MakePoint(-161 + 10, -64 + 0, 4326)), "
561
"(NULL, MakePoint(-161 + 11, -64 + 1, 4326)) ", NULL,
563
if (ret != SQLITE_OK)
565
fprintf (stderr, "INSERT INTO point_b_xy Geometry error: %s\n",
567
sqlite3_free (err_msg);
568
sqlite3_close (handle);
571
ret = sqlite3_exec (handle, "INSERT INTO point_b_xy VALUES "
572
"(NULL, MakePoint(-161 + 0, -64 + 10, 4326)), "
573
"(NULL, MakePoint(-161 + 1, -64 + 11, 4326)), "
574
"(NULL, MakePoint(-161 + 5, -64 + 4, 4326)), "
575
"(NULL, MakePoint(-161 + 4, -64 + 5, 4326)), "
576
"(NULL, MakePoint(-161 + 8, -64 + 2, 4326)), "
577
"(NULL, MakePoint(-161 + 2, -64 + 8, 4326)) ", NULL,
579
if (ret != SQLITE_OK)
581
fprintf (stderr, "INSERT INTO point_b_xy Geometry error: %s\n",
583
sqlite3_free (err_msg);
584
sqlite3_close (handle);
587
ret = sqlite3_exec (handle, "INSERT INTO point_b_xy VALUES "
588
"(NULL, MakePoint(-161 + 20, -64 + 20, 4326)), "
589
"(NULL, MakePoint(-161 + 21, -64 + 21, 4326)), "
590
"(NULL, MakePoint(-161 + 30, -64 + 30, 4326)), "
591
"(NULL, MakePoint(-161 + 31, -64 + 31, 4326)), "
592
"(NULL, MakePoint(-161 + 30, -64 + 20, 4326)), "
593
"(NULL, MakePoint(-161 + 31, -64 + 21, 4326)) ", NULL,
595
if (ret != SQLITE_OK)
597
fprintf (stderr, "INSERT INTO point_b_xy Geometry error: %s\n",
599
sqlite3_free (err_msg);
600
sqlite3_close (handle);
603
ret = sqlite3_exec (handle, "INSERT INTO point_b_xy VALUES "
604
"(NULL, MakePoint(-161 + 20, -64 + 30, 4326)), "
605
"(NULL, MakePoint(-161 + 21, -64 + 31, 4326)), "
606
"(NULL, MakePoint(-161 + 25, -64 + 24, 4326)), "
607
"(NULL, MakePoint(-161 + 24, -64 + 25, 4326)), "
608
"(NULL, MakePoint(-161 + 28, -64 + 22, 4326)), "
609
"(NULL, MakePoint(-161 + 22, -64 + 28, 4326)), "
610
"(NULL, MakePoint(-161 + 30, -64 + 0, 4326)), "
611
"(NULL, MakePoint(-161 + 0, -64 + 30, 4326)) ", NULL,
613
if (ret != SQLITE_OK)
615
fprintf (stderr, "INSERT INTO point_b_xy Geometry error: %s\n",
617
sqlite3_free (err_msg);
618
sqlite3_close (handle);
622
/* creating and populating Point table #1 - XYZ */
623
ret = sqlite3_exec (handle, "CREATE TABLE point_a_xyz ("
624
"id INTEGER PRIMARY KEY AUTOINCREMENT)", NULL, NULL,
626
if (ret != SQLITE_OK)
628
fprintf (stderr, "CREATE point_a_xyz error: %s\n", err_msg);
629
sqlite3_free (err_msg);
630
sqlite3_close (handle);
633
ret = sqlite3_exec (handle, "SELECT AddGeometryColumn("
634
"'point_a_xyz', 'geometry', 4326, 'POINT', 'XYZ')",
635
NULL, NULL, &err_msg);
636
if (ret != SQLITE_OK)
638
fprintf (stderr, "CREATE point_a_xy Geometry error: %s\n", err_msg);
639
sqlite3_free (err_msg);
640
sqlite3_close (handle);
643
ret = sqlite3_exec (handle, "INSERT INTO point_a_xyz VALUES "
644
"(NULL, MakePointZ(0, 0, 1, 4326)), (NULL, MakePointZ(1, 1, 2, 4326)), "
645
"(NULL, MakePointZ(10, 10, 1, 4326)), (NULL, MakePointZ(11, 11, 2, 4326)), "
646
"(NULL, MakePointZ(10, 0, 1, 4326)), (NULL, MakePointZ(11, 1, 2, 4326)), "
647
"(NULL, MakePointZ(0, 10, 1, 4326)), (NULL, MakePointZ(1, 11, 2, 4326)) ",
648
NULL, NULL, &err_msg);
649
if (ret != SQLITE_OK)
651
fprintf (stderr, "INSERT INTO point_a_xyz Geometry error: %s\n",
653
sqlite3_free (err_msg);
654
sqlite3_close (handle);
657
ret = sqlite3_exec (handle, "INSERT INTO point_a_xyz VALUES "
658
"(NULL, MakePointZ(5, 4, 1, 4326)), (NULL, MakePointZ(4, 5, 2, 4326)), "
659
"(NULL, MakePointZ(8, 2, 1, 4326)), (NULL, MakePointZ(2, 8, 2, 4326)), "
660
"(NULL, MakePointZ(20, 20, 1, 4326)), (NULL, MakePointZ(21, 21, 2, 4326)), "
661
"(NULL, MakePointZ(70, 70, 1, 4326)), (NULL, MakePointZ(51, 51, 2, 4326)), "
662
"(NULL, MakePointZ(30, 20, 1, 4326)), (NULL, MakePointZ(31, 21, 2, 4326)) ",
663
NULL, NULL, &err_msg);
664
if (ret != SQLITE_OK)
666
fprintf (stderr, "INSERT INTO point_a_xyz Geometry error: %s\n",
668
sqlite3_free (err_msg);
669
sqlite3_close (handle);
672
ret = sqlite3_exec (handle, "INSERT INTO point_a_xyz VALUES "
673
"(NULL, MakePointZ(20, 30, 1, 4326)), (NULL, MakePointZ(21, 31, 2, 4326)), "
674
"(NULL, MakePointZ(25, 24, 1, 4326)), (NULL, MakePointZ(24, 25, 2, 4326)), "
675
"(NULL, MakePointZ(28, 22, 1, 4326)), (NULL, MakePointZ(22, 28, 2, 4326)), "
676
"(NULL, MakePointZ(30, 0, 1, 4326)), (NULL, MakePointZ(0, 30, 2, 4326)) ",
677
NULL, NULL, &err_msg);
678
if (ret != SQLITE_OK)
680
fprintf (stderr, "INSERT INTO point_a_xyz Geometry error: %s\n",
682
sqlite3_free (err_msg);
683
sqlite3_close (handle);
687
/* creating and populating Point table #2 - XYZ */
688
ret = sqlite3_exec (handle, "CREATE TABLE point_b_xyz ("
689
"id INTEGER PRIMARY KEY AUTOINCREMENT)", NULL, NULL,
691
if (ret != SQLITE_OK)
693
fprintf (stderr, "CREATE point_b_xyz error: %s\n", err_msg);
694
sqlite3_free (err_msg);
695
sqlite3_close (handle);
698
ret = sqlite3_exec (handle, "SELECT AddGeometryColumn("
699
"'point_b_xyz', 'geometry', 4326, 'POINT', 'XYZ')",
700
NULL, NULL, &err_msg);
701
if (ret != SQLITE_OK)
703
fprintf (stderr, "CREATE point_b_xyz Geometry error: %s\n", err_msg);
704
sqlite3_free (err_msg);
705
sqlite3_close (handle);
708
ret = sqlite3_exec (handle, "INSERT INTO point_b_xyz VALUES "
709
"(NULL, MakePointZ(-161 + 0, -64 + 0, 11, 4326)), "
710
"(NULL, MakePointZ(-161 + 1, -64 + 1, 12, 4326)), "
711
"(NULL, MakePointZ(-161 + 10, -64 + 10, 11, 4326)), "
712
"(NULL, MakePointZ(-161 + 11, -64 + 11, 12, 4326)), "
713
"(NULL, MakePointZ(-161 + 10, -64 + 0, 11, 4326)), "
714
"(NULL, MakePointZ(-161 + 11, -64 + 1, 12, 4326)) ",
715
NULL, NULL, &err_msg);
716
if (ret != SQLITE_OK)
718
fprintf (stderr, "INSERT INTO point_b_xyz Geometry error: %s\n",
720
sqlite3_free (err_msg);
721
sqlite3_close (handle);
724
ret = sqlite3_exec (handle, "INSERT INTO point_b_xyz VALUES "
725
"(NULL, MakePointZ(-161 + 0, -64 + 10, 11, 4326)), "
726
"(NULL, MakePointZ(-161 + 1, -64 + 11, 12, 4326)), "
727
"(NULL, MakePointZ(-161 + 5, -64 + 4, 11, 4326)), "
728
"(NULL, MakePointZ(-161 + 4, -64 + 5, 12, 4326)), "
729
"(NULL, MakePointZ(-161 + 8, -64 + 2, 11, 4326)), "
730
"(NULL, MakePointZ(-161 + 2, -64 + 8, 12, 4326)) ",
731
NULL, NULL, &err_msg);
732
if (ret != SQLITE_OK)
734
fprintf (stderr, "INSERT INTO point_b_xyz Geometry error: %s\n",
736
sqlite3_free (err_msg);
737
sqlite3_close (handle);
740
ret = sqlite3_exec (handle, "INSERT INTO point_b_xyz VALUES "
741
"(NULL, MakePointZ(-161 + 20, -64 + 20, 11, 4326)), "
742
"(NULL, MakePointZ(-161 + 21, -64 + 21, 12, 4326)), "
743
"(NULL, MakePointZ(-161 + 70, -64 + 70, 11, 4326)), "
744
"(NULL, MakePointZ(-161 + 51, -64 + 51, 12, 4326)), "
745
"(NULL, MakePointZ(-161 + 30, -64 + 20, 11, 4326)), "
746
"(NULL, MakePointZ(-161 + 31, -64 + 21, 12, 4326)), "
747
"(NULL, MakePointZ(-161 + 20, -64 + 30, 11, 4326)) ",
748
NULL, NULL, &err_msg);
749
if (ret != SQLITE_OK)
751
fprintf (stderr, "INSERT INTO point_b_xyz Geometry error: %s\n",
753
sqlite3_free (err_msg);
754
sqlite3_close (handle);
757
ret = sqlite3_exec (handle, "INSERT INTO point_b_xyz VALUES "
758
"(NULL, MakePointZ(-161 + 21, -64 + 31, 12, 4326)), "
759
"(NULL, MakePointZ(-161 + 25, -64 + 24, 11, 4326)), "
760
"(NULL, MakePointZ(-161 + 24, -64 + 25, 12, 4326)), "
761
"(NULL, MakePointZ(-161 + 28, -64 + 22, 11, 4326)), "
762
"(NULL, MakePointZ(-161 + 22, -64 + 28, 12, 4326)), "
763
"(NULL, MakePointZ(-161 + 30, -64 + 0, 11, 4326)), "
764
"(NULL, MakePointZ(-161 + 0, -64 + 30, 12, 4326)) ",
765
NULL, NULL, &err_msg);
766
if (ret != SQLITE_OK)
768
fprintf (stderr, "INSERT INTO point_b_xyz Geometry error: %s\n",
770
sqlite3_free (err_msg);
771
sqlite3_close (handle);
775
/* resolving Control Points 2D - 1st order - IsValid */
776
sql = "SELECT GCP_IsValid(GCP_Compute(a.geometry, b.geometry, 1)) "
777
"FROM point_a_xy AS a, point_b_xy AS b WHERE a.id = b.id";
778
if (!test_query (handle, sql, "1"))
780
/* resolving Control Points 2D - 1st order- AsText */
781
sql = "SELECT GCP_AsText(GCP_Compute(a.geometry, b.geometry)) "
782
"FROM point_a_xy AS a, point_b_xy AS b WHERE a.id = b.id";
785
"E{-161.0000000000,1.0000000000,-0.0000000000}, "
786
"N{-64.0000000000,-0.0000000000,1.0000000000}"))
789
/* resolving Control Points 2D - 1st order - GCP2ATM */
790
sql = "SELECT ATM_IsValid(GCP2ATM(GCP_Compute(a.geometry, b.geometry))) "
791
"FROM point_a_xy AS a, point_b_xy AS b WHERE a.id = b.id";
792
if (!test_query (handle, sql, "1"))
795
/* resolving Control Points 3D - 1st order - IsValid */
796
sql = "SELECT GCP_IsValid(GCP_Compute(a.geometry, b.geometry, 1)) "
797
"FROM point_a_xyz AS a, point_b_xyz AS b WHERE a.id = b.id";
798
if (!test_query (handle, sql, "1"))
801
/* resolving Control Points 3D - 1st order - AsText */
802
sql = "SELECT GCP_AsText(GCP_Compute(a.geometry, b.geometry)) "
803
"FROM point_a_xyz AS a, point_b_xyz AS b WHERE a.id = b.id";
804
if (!test_query (handle, sql,
805
"E{-161.0000000000,1.0000000000,-0.0000000000,0.0000000000}, "
806
"N{-64.0000000000,0.0000000000,1.0000000000,0.0000000000}, "
807
"Z{10.0000000000,-0.0000000000,0.0000000000,1.0000000000}"))
810
/* resolving Control Points 3D - 1st order - GCP2ATM */
811
sql = "SELECT ATM_IsValid(GCP2ATM(GCP_Compute(a.geometry, b.geometry))) "
812
"FROM point_a_xyz AS a, point_b_xyz AS b WHERE a.id = b.id";
813
if (!test_query (handle, sql, "1"))
816
/* resolving Control Points 2D - 2nd order - IsValid */
817
sql = "SELECT GCP_IsValid(GCP_Compute(a.geometry, b.geometry, 2)) "
818
"FROM point_a_xy AS a, point_b_xy AS b WHERE a.id = b.id";
819
if (!test_query (handle, sql, "1"))
822
/* resolving Control Points 2D - 2nd order- AsText */
823
sql = "SELECT GCP_IsValid(GCP_Compute(a.geometry, b.geometry, 2)) "
824
"FROM point_a_xy AS a, point_b_xy AS b WHERE a.id = b.id";
825
if (!test_query (handle, sql,"1"))
828
/* resolving Control Points 2D - 2nd order - GCP2ATM */
829
sql = "SELECT ATM_IsValid(GCP2ATM(GCP_Compute(a.geometry, b.geometry, 2))) "
830
"FROM point_a_xy AS a, point_b_xy AS b WHERE a.id = b.id";
831
if (!test_query (handle, sql, "-1"))
834
/* resolving Control Points 3D - 2nd order - IsValid */
835
sql = "SELECT GCP_IsValid(GCP_Compute(a.geometry, b.geometry, 2)) "
836
"FROM point_a_xyz AS a, point_b_xyz AS b WHERE a.id = b.id";
837
if (!test_query (handle, sql, "1"))
840
/* resolving Control Points 3D - 2nd order - AsText */
841
sql = "SELECT GCP_IsValid(GCP_Compute(a.geometry, b.geometry, 2)) "
842
"FROM point_a_xyz AS a, point_b_xyz AS b WHERE a.id = b.id";
843
if (!test_query (handle, sql, "1"))
846
/* resolving Control Points 3D - 2nd order - GCP2ATM */
847
sql = "SELECT ATM_IsValid(GCP2ATM(GCP_Compute(a.geometry, b.geometry, 2))) "
848
"FROM point_a_xyz AS a, point_b_xyz AS b WHERE a.id = b.id";
849
if (!test_query (handle, sql, "-1"))
852
/* resolving Control Points 2D - 3nd order - IsValid */
853
sql = "SELECT GCP_IsValid(GCP_Compute(a.geometry, b.geometry, 3)) "
854
"FROM point_a_xy AS a, point_b_xy AS b WHERE a.id = b.id";
855
if (!test_query (handle, sql, "1"))
858
/* resolving Control Points 2D - 3nd order- AsText */
859
sql = "SELECT GCP_IsValid(GCP_Compute(a.geometry, b.geometry, 3)) "
860
"FROM point_a_xy AS a, point_b_xy AS b WHERE a.id = b.id";
861
if (!test_query (handle, sql, "1"))
864
/* resolving Control Points 2D - 3nd order - GCP2ATM */
865
sql = "SELECT ATM_IsValid(GCP2ATM(GCP_Compute(a.geometry, b.geometry, 3))) "
866
"FROM point_a_xy AS a, point_b_xy AS b WHERE a.id = b.id";
867
if (!test_query (handle, sql, "-1"))
870
/* resolving Control Points 3D - 3nd order - IsValid */
871
sql = "SELECT GCP_IsValid(GCP_Compute(a.geometry, b.geometry, 3)) "
872
"FROM point_a_xyz AS a, point_b_xyz AS b WHERE a.id = b.id";
873
if (!test_query (handle, sql, "1"))
876
/* resolving Control Points 3D - 3nd order - AsText */
877
sql = "SELECT GCP_IsValid(GCP_Compute(a.geometry, b.geometry, 3)) "
878
"FROM point_a_xyz AS a, point_b_xyz AS b WHERE a.id = b.id";
879
if (!test_query (handle, sql, "1"))
882
/* resolving Control Points 3D - 3nd order - GCP2ATM */
883
sql = "SELECT ATM_IsValid(GCP2ATM(GCP_Compute(a.geometry, b.geometry, 3))) "
884
"FROM point_a_xyz AS a, point_b_xyz AS b WHERE a.id = b.id";
885
if (!test_query (handle, sql, "-1"))
888
for (order = 0; order <= 3; order++)
891
if (!test_transform (handle, order))
895
if (!test_invalid (handle))
898
ret = sqlite3_close (handle);
899
if (ret != SQLITE_OK)
901
fprintf (stderr, "sqlite3_close() error: %s\n",
902
sqlite3_errmsg (handle));
906
spatialite_cleanup_ex (cache);
908
#endif /* end CGP conditional */
910
spatialite_shutdown ();