[Gislite-admins] SF.net SVN: gislite: [13] trunk/sqlfunc.c
Status: Planning
Brought to you by:
ctomasin
|
From: <cto...@us...> - 2007-09-05 19:35:49
|
Revision: 13
http://gislite.svn.sourceforge.net/gislite/?rev=13&view=rev
Author: ctomasin
Date: 2007-09-05 12:35:51 -0700 (Wed, 05 Sep 2007)
Log Message:
-----------
Sql function Distance() added
Modified Paths:
--------------
trunk/sqlfunc.c
Modified: trunk/sqlfunc.c
===================================================================
--- trunk/sqlfunc.c 2007-09-04 18:22:20 UTC (rev 12)
+++ trunk/sqlfunc.c 2007-09-05 19:35:51 UTC (rev 13)
@@ -219,6 +219,32 @@
}
}
+/**
+ * SQL function Distance(geomA,geomB)
+ * Returns the distance between two geometries.
+ * Ex:
+ * sqlite> SELECT Distance(BLOB_POINT,BLOB_POINT);
+ * sqlite> 1.2000
+ *
+ * @param geomA WKBGeometry structure
+ * @param geomB WKBGeometry structure
+ *
+ * @return double representing the distance
+ */
+static void Distance(
+ sqlite3_context *context,
+ int argc,
+ sqlite3_value **argv
+){
+ WKBGeometry *pGeomA, *pGeomB;
+
+ if( sqlite3_value_type(argv[0]) != SQLITE_BLOB || sqlite3_value_type(argv[1]) != SQLITE_BLOB )
+ sqlite3_result_error(context,messages[4],-1); // verify message text
+
+ pGeomA = GeomFromBinary((unsigned char*)sqlite3_value_blob(argv[0]));
+ pGeomB = GeomFromBinary((unsigned char*)sqlite3_value_blob(argv[1]));
+ sqlite3_result_double(context,GeomDistance(pGeomA,pGeomB));
+}
/**
* SQL function StartPoint(g)
@@ -314,6 +340,7 @@
//Geometry functions
sqlite3_create_function(db, "AsText", 1, SQLITE_ANY, 0, AsText, 0, 0);
sqlite3_create_function(db, "AsBinary", 1, SQLITE_ANY, 0, AsBinary, 0, 0);
+ sqlite3_create_function(db, "Distance", 2, SQLITE_ANY, 0, Distance, 0, 0);
//sqlite3_create_function(db, "SRID", 1, SQLITE_ANY, 0, SRID, 0, 0);
//sqlite3_create_function(db, "Dimension", 1, SQLITE_ANY, 0, Dimension, 0, 0);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|