[Gislite-admins] SF.net SVN: gislite: [4] trunk
Status: Planning
Brought to you by:
ctomasin
|
From: <cto...@us...> - 2007-08-24 10:41:23
|
Revision: 4
http://gislite.svn.sourceforge.net/gislite/?rev=4&view=rev
Author: ctomasin
Date: 2007-08-24 03:41:27 -0700 (Fri, 24 Aug 2007)
Log Message:
-----------
Added implementation of X(), Y() and Z() functions as implemented by Domenico. From now on the code management is interely managed by SVN.
Modified Paths:
--------------
trunk/sqlfunc.c
trunk/wkgfunc.c
Modified: trunk/sqlfunc.c
===================================================================
--- trunk/sqlfunc.c 2007-08-23 21:25:37 UTC (rev 3)
+++ trunk/sqlfunc.c 2007-08-24 10:41:27 UTC (rev 4)
@@ -1,3 +1,8 @@
+/**
+ * @file sqlfunc.h
+ * Functions used from SQL interface
+ * */
+
/**
* SQL function toWKT(b)
* Returns a WKT openGis Geometry representation from a sqlite blob b.
@@ -90,55 +95,133 @@
/**
* SQL function X(b)
- * Returns the X-coordinate value for the BLOB b as a double.
+ * Returns the X-coordinate value for the blob b containing WKBGeometry Point as a double.
* Ex:
* sqlite> SELECT X(BLOB_POINT) FROM testGeom WHERE INDEX=1;
* sqlite> 5.8926358638273
*
- * @param BLOB containing a WKBGeometry
+ * @param blob containing WKBGeometry
*
* @return double x coordinate
*/
+static void X(
+ sqlite3_context *context,
+ int argc,
+ sqlite3_value **argv
+){
+ WKBGeometry Geom;
+ //only if value type is BLOB
+ if( sqlite3_value_type(argv[0]) == SQLITE_BLOB){
+ //get blob from argv and fill structure from blob
+ FromBinary((unsigned char*) sqlite3_value_blob(argv[0]), &Geom);
+ //return coordinate
+ if(Geom.point.wkbType == 3001)
+ sqlite3_result_double(context, Geom.point.point.x);
+ else
+ sqlite3_result_error(context, messages[5], -1);
+ }else{
+ sqlite3_result_error(context, messages[4], -1);
+ }
+}
+
/**
* SQL function Y(b)
- * Returns the Y-coordinate value for the BLOB b as a double.
+ * Returns the Y-coordinate value for the blob b containiing WKBGeometry Point as a double.
* Ex:
* sqlite> SELECT Y(BLOB_POINT) FROM testGeom WHERE INDEX=1;
* sqlite> 1.2837445657488
*
- * @param BLOB containing a WKBGeometry
+ * @param blob containing WKBGeometry
*
* @return double y coordinate
*/
+static void Y(
+ sqlite3_context *context,
+ int argc,
+ sqlite3_value **argv
+){
+ WKBGeometry Geom;
+ //only if value type is BLOB
+ if( sqlite3_value_type(argv[0]) == SQLITE_BLOB){
+ //get blob from argv and fill structure from blob
+ FromBinary((unsigned char*) sqlite3_value_blob(argv[0]), &Geom);
+ //return coordinate
+ if(Geom.point.wkbType == 3001)
+ sqlite3_result_double(context, Geom.point.point.y);
+ else
+ sqlite3_result_error(context, messages[5], -1);
+ }else{
+ sqlite3_result_error(context, messages[4], -1);
+ }
+}
/**
* SQL function Z(b)
- * Returns the Z-coordinate value for the BLOB b as a double.
+ * Returns the Z-coordinate value for the blob b containing WKBGeometry Point as a double.
* Ex:
* sqlite> SELECT Z(BLOB_POINT) FROM testGeom WHERE INDEX=1;
* sqlite> 0.0
*
- * @param BLOB containing a WKBGeometry
+ * @param blob containing WKBGeometry
*
* @return double z coordinate
*/
+static void Z(
+ sqlite3_context *context,
+ int argc,
+ sqlite3_value **argv
+){
+ WKBGeometry Geom;
+ //only if value type is BLOB
+ if( sqlite3_value_type(argv[0]) == SQLITE_BLOB){
+ //get blob from argv and fill structure from blob
+ FromBinary((unsigned char*) sqlite3_value_blob(argv[0]), &Geom);
+ //return coordinate
+ if(Geom.point.wkbType == 3001)
+ sqlite3_result_double(context, Geom.point.point.z);
+ else
+ sqlite3_result_error(context, messages[5], -1);
+ }else{
+ sqlite3_result_error(context, messages[4], -1);
+ }
+}
+
/**
* SQL function M(b)
- * Returns the M-value for the BLOB b as a double.
+ * Returns the M-value for the blob containing WKBGeometry Point as a double.
* Ex:
* sqlite> SELECT M(BLOB_POINT) FROM testGeom WHERE INDEX=1;
* sqlite> 5.0
*
- * @param BLOB containing a WKBGeometry
+ * @param blob containing WKBGeometry
*
* @return double m value
*/
+static void M(
+ sqlite3_context *context,
+ int argc,
+ sqlite3_value **argv
+){
+ WKBGeometry Geom;
+ //only if value type is BLOB
+ if( sqlite3_value_type(argv[0]) == SQLITE_BLOB){
+ //get blob from argv and fill structure from blob
+ FromBinary((unsigned char*) sqlite3_value_blob(argv[0]), &Geom);
+ //return coordinate
+ if(Geom.point.wkbType == 3001)
+ sqlite3_result_double(context, Geom.point.point.m);
+ else
+ sqlite3_result_error(context, messages[5], -1);
+ }else{
+ sqlite3_result_error(context, messages[4], -1);
+ }
+}
/**
@@ -233,10 +316,10 @@
SQLITE_EXTENSION_INIT2(pApi)
sqlite3_create_function(db, "toWKT", 1, SQLITE_ANY, 0, toWKT, 0, 0);
sqlite3_create_function(db, "toWKB", 1, SQLITE_ANY, 0, toWKB, 0, 0);
- //sqlite3_create_function(db, "X", 1, SQLITE_ANY, 0, X, 0, 0);
- //sqlite3_create_function(db, "Y", 1, SQLITE_ANY, 0, Y, 0, 0);
- //sqlite3_create_function(db, "Z", 1, SQLITE_ANY, 0, Z, 0, 0);
- //sqlite3_create_function(db, "M", 1, SQLITE_ANY, 0, M, 0, 0);
+ sqlite3_create_function(db, "X", 1, SQLITE_ANY, 0, X, 0, 0);
+ sqlite3_create_function(db, "Y", 1, SQLITE_ANY, 0, Y, 0, 0);
+ sqlite3_create_function(db, "Z", 1, SQLITE_ANY, 0, Z, 0, 0);
+ sqlite3_create_function(db, "M", 1, SQLITE_ANY, 0, M, 0, 0);
return 0;
}
Modified: trunk/wkgfunc.c
===================================================================
--- trunk/wkgfunc.c 2007-08-23 21:25:37 UTC (rev 3)
+++ trunk/wkgfunc.c 2007-08-24 10:41:27 UTC (rev 4)
@@ -8,11 +8,13 @@
SQLITE_EXTENSION_INIT1
char *messages[5] = {
- "ok"
- ,"unrecognized text type"
- ,"parse error"
- ,"unrecognized geometry type"
- ,"unable to convert from blob"
+ "ok" // 0
+ ,"unrecognized text type" // 1
+ ,"parse error" // 2
+ ,"unrecognized geometry type" // 3
+ ,"unable to convert from blob" // 4
+ ,"unable to convert from blob" // 5
+
};
//char debug[50];
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|