gislite-admins Mailing List for gislite
Status: Planning
Brought to you by:
ctomasin
You can subscribe to this list here.
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(7) |
Sep
(5) |
Oct
|
Nov
|
Dec
|
|---|
|
From: <cto...@us...> - 2007-09-06 17:11:45
|
Revision: 14
http://gislite.svn.sourceforge.net/gislite/?rev=14&view=rev
Author: ctomasin
Date: 2007-09-06 10:11:48 -0700 (Thu, 06 Sep 2007)
Log Message:
-----------
Tagged version 0.1 presented to september, 7th 2007 "sistemi informativi" exam in Bologna
Modified Paths:
--------------
tags/0.1/wkgfunc.c
trunk/wkgfunc.c
Added Paths:
-----------
tags/0.1/
Copied: tags/0.1 (from rev 13, trunk)
Modified: tags/0.1/wkgfunc.c
===================================================================
--- trunk/wkgfunc.c 2007-09-05 19:35:51 UTC (rev 13)
+++ tags/0.1/wkgfunc.c 2007-09-06 17:11:48 UTC (rev 14)
@@ -184,7 +184,7 @@
/**
* function GeomFromBinary(b)
- * @param pointer to unsigned char b blob to be read
+ * @param pBin pointer to binary to be read
*
* @return pointer to WKGeometry to be filled
*/
@@ -238,7 +238,8 @@
/**
* function GeomAsBinary(g)
* @param pGeom pointer to WKGeometry to be converted
- *
+ * @param len output parameter used to get the lenght of the binary returned
+ *
* @return pointer to unsigned char to be filled
*/
unsigned char* GeomAsBinary(WKBGeometry* pGeom,uint32 *len){
Modified: trunk/wkgfunc.c
===================================================================
--- trunk/wkgfunc.c 2007-09-05 19:35:51 UTC (rev 13)
+++ trunk/wkgfunc.c 2007-09-06 17:11:48 UTC (rev 14)
@@ -184,7 +184,7 @@
/**
* function GeomFromBinary(b)
- * @param pointer to unsigned char b blob to be read
+ * @param pBin pointer to binary to be read
*
* @return pointer to WKGeometry to be filled
*/
@@ -238,7 +238,8 @@
/**
* function GeomAsBinary(g)
* @param pGeom pointer to WKGeometry to be converted
- *
+ * @param len output parameter used to get the lenght of the binary returned
+ *
* @return pointer to unsigned char to be filled
*/
unsigned char* GeomAsBinary(WKBGeometry* pGeom,uint32 *len){
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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.
|
|
From: <cto...@us...> - 2007-09-04 18:22:19
|
Revision: 12
http://gislite.svn.sourceforge.net/gislite/?rev=12&view=rev
Author: ctomasin
Date: 2007-09-04 11:22:20 -0700 (Tue, 04 Sep 2007)
Log Message:
-----------
Now AsText(AsBinary('POINT(1 2 3 4)')) woks; the problem was caused by an incorrect management of the dimension value of the binary obtained by the call AsBinary;
AsBinary() function has a new parameter that shows how long is the binary data obtained by the serialization
Modified Paths:
--------------
trunk/sqlfunc.c
trunk/wkgfunc.c
trunk/wkgfunc.h
Modified: trunk/sqlfunc.c
===================================================================
--- trunk/sqlfunc.c 2007-09-03 21:20:22 UTC (rev 11)
+++ trunk/sqlfunc.c 2007-09-04 18:22:20 UTC (rev 12)
@@ -66,21 +66,21 @@
int argc,
sqlite3_value **argv
){
- int sizeBin;
+ uint32 sizeBin;
char *pBuf;
unsigned char *pBin;
WKBGeometry *pGeom;
- //check for null values
- if(sqlite3_value_type(argv[0]) == SQLITE_NULL) return;
+ //check for null values
+ if(sqlite3_value_type(argv[0]) == SQLITE_NULL) return;
//assign sqlite parameter
pBuf = (char*)sqlite3_value_text(argv[0]);
//read WKT into geometry
pGeom = (WKBGeometry*)GeomFromText(pBuf);
//fill char array
- pBin = (unsigned char*)GeomAsBinary(pGeom);
+ pBin = (unsigned char*)GeomAsBinary(pGeom,&sizeBin);
//measure binary buffer as char array
- sizeBin = strlen((char*)pBin)+1;
+ //sizeBin = strlen((char*)pBin)+1; /* beware: strlen measures the chars to the first '\0': not good for binary! */
//assign binary buffer
sqlite3_result_blob(context, pBin, sizeBin, SQLITE_TRANSIENT);
//free allocated memory
Modified: trunk/wkgfunc.c
===================================================================
--- trunk/wkgfunc.c 2007-09-03 21:20:22 UTC (rev 11)
+++ trunk/wkgfunc.c 2007-09-04 18:22:20 UTC (rev 12)
@@ -207,7 +207,7 @@
switch(wkbType){
case wkbPoint:
//alloc WKBGeometry for Point size
- pGeom = (WKBGeometry*) sqlite3_malloc(sizeof(WKBPoint));
+ pGeom = (WKBGeometry*) sqlite3_malloc(sizeof(WKBPoint));
//assign order-first byte and type
pGeom->point.byteOrder = pBin[0];
pGeom->point.wkbType = wkbType;
@@ -241,17 +241,16 @@
*
* @return pointer to unsigned char to be filled
*/
-unsigned char* GeomAsBinary(WKBGeometry* pGeom){
- int dim;
+unsigned char* GeomAsBinary(WKBGeometry* pGeom,uint32 *len){
unsigned char *pBuffer;
unsigned char *pChar;
//alloc by wkbType
switch(pGeom->point.wkbType){
case wkbPoint:
- dim = sizeof(WKBPoint);
- pBuffer = (unsigned char*)sqlite3_malloc(dim);
- memset(pBuffer, 0, dim);
+ *len = sizeof(WKBPoint); // ok: it uses more memory than needed but only a few
+ pBuffer = (unsigned char*)sqlite3_malloc(*len);
+ memset(pBuffer, 0, *len);
pChar = pBuffer;
//fill Geometry
memcpy(pChar, (unsigned char*)&pGeom->point.byteOrder, sizeof(byte));
@@ -265,6 +264,8 @@
memcpy(pChar, &pGeom->point.point.z, sizeof(double));
pChar += sizeof(double);
memcpy(pChar, &pGeom->point.point.m, sizeof(double));
+ pChar += sizeof(double);
+ *len = (uint32)(pChar - pBuffer); // now *len contains the real space used by the blob field
break;
case wkbLineString:
Modified: trunk/wkgfunc.h
===================================================================
--- trunk/wkgfunc.h 2007-09-03 21:20:22 UTC (rev 11)
+++ trunk/wkgfunc.h 2007-09-04 18:22:20 UTC (rev 12)
@@ -17,7 +17,7 @@
WKBGeometry* GeomFromBinary(unsigned char *pBin);
-unsigned char* GeomAsBinary(WKBGeometry* pGeom);
+unsigned char* GeomAsBinary(WKBGeometry* pGeom, uint32 *len);
double GeomDistance(WKBGeometry *pGeomA,WKBGeometry *pGeomB);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cto...@us...> - 2007-09-03 21:20:20
|
Revision: 11
http://gislite.svn.sourceforge.net/gislite/?rev=11&view=rev
Author: ctomasin
Date: 2007-09-03 14:20:22 -0700 (Mon, 03 Sep 2007)
Log Message:
-----------
It didn't compile and now it does. Tried to understand why AsText(AsBinary(POINT())) desn't works.
Modified Paths:
--------------
trunk/Makefile
trunk/sqlfunc.c
trunk/wkgfunc.c
Modified: trunk/Makefile
===================================================================
--- trunk/Makefile 2007-09-02 16:06:04 UTC (rev 10)
+++ trunk/Makefile 2007-09-03 21:20:22 UTC (rev 11)
@@ -3,7 +3,7 @@
ifeq ($(UNAME),Linux)
DYNAMIC = -shared
- OPTIONS = -lsqlite3 -lm -g
+ OPTIONS = -lsqlite3 -lm -g -O0
else
DYNAMIC= -fno-common -dynamiclib
OPTIONS=
@@ -16,7 +16,7 @@
gcc $(DYNAMIC) $(OPTIONS) -o $@ $(OBJS)
%.o : %.c
- gcc -Wall -O0 -D_GNU_SOURCE -c $<
+ gcc -Wall -O0 -g -D_GNU_SOURCE -c $<
clean :
Modified: trunk/sqlfunc.c
===================================================================
--- trunk/sqlfunc.c 2007-09-02 16:06:04 UTC (rev 10)
+++ trunk/sqlfunc.c 2007-09-03 21:20:22 UTC (rev 11)
@@ -112,7 +112,7 @@
//get blob from argv and fill structure from blob
pGeom = (WKBGeometry*)GeomFromBinary((unsigned char*) sqlite3_value_blob(argv[0]));
//return coordinate
- if(pGeom->point.wkbType == 3001)
+ if(pGeom->point.wkbType == (byte)wkbPoint)
sqlite3_result_double(context, pGeom->point.point.x);
else
sqlite3_result_error(context, messages[5], -1);
@@ -145,7 +145,7 @@
//get blob from argv and fill structure from blob
pGeom = (WKBGeometry*)GeomFromBinary((unsigned char*) sqlite3_value_blob(argv[0]));
//return coordinate
- if(pGeom->point.wkbType == 3001)
+ if(pGeom->point.wkbType == (byte)wkbPoint)
sqlite3_result_double(context, pGeom->point.point.y);
else
sqlite3_result_error(context, messages[5], -1);
@@ -177,7 +177,7 @@
//get blob from argv and fill structure from blob
pGeom = (WKBGeometry*)GeomFromBinary((unsigned char*) sqlite3_value_blob(argv[0]));
//return coordinate
- if(pGeom->point.wkbType == 3001)
+ if(pGeom->point.wkbType == (byte)wkbPoint)
sqlite3_result_double(context, pGeom->point.point.z);
else
sqlite3_result_error(context, messages[5], -1);
@@ -210,7 +210,7 @@
//get blob from argv and fill structure from blob
pGeom = (WKBGeometry*)GeomFromBinary((unsigned char*) sqlite3_value_blob(argv[0]));
//return coordinate
- if(pGeom->point.wkbType == 3001)
+ if(pGeom->point.wkbType == (byte)wkbPoint)
sqlite3_result_double(context, pGeom->point.point.m);
else
sqlite3_result_error(context, messages[5], -1);
Modified: trunk/wkgfunc.c
===================================================================
--- trunk/wkgfunc.c 2007-09-02 16:06:04 UTC (rev 10)
+++ trunk/wkgfunc.c 2007-09-03 21:20:22 UTC (rev 11)
@@ -50,7 +50,7 @@
* @return pointer to WKGeometry
*/
WKBGeometry* GeomFromText(char *pWKT){
- int len, i;
+ int len, i, num;
char *ppos;
char *pType;
char *pContent;
@@ -74,8 +74,8 @@
if(strncmp(pType, "POINT", 5)==0){
pGeom = (WKBGeometry*) sqlite3_malloc(sizeof(WKBPoint));
//fill geometry as point
- pGeom->point.byteOrder = (byte)'1';//little endian ... autoconf endianness
- pGeom->point.wkbType = (uint32)3001;
+ pGeom->point.byteOrder = (byte)wkbNDR;//little endian ... autoconf endianness
+ pGeom->point.wkbType = (uint32)wkbPoint;
if(sscanf(pContent+1, "%lf %lf %lf %lf",
&pGeom->point.point.x,
&pGeom->point.point.y,
@@ -91,23 +91,23 @@
//LINESTRING(1 1 1 1, 2 2 2 2, 3 3 3 3)
else if(strncmp(pWKT,"LINESTRING", 10)==0){
- //pContent points count
- len = strlen(pContent);
- num = 0;//init
- for(i=0; i<=len; ++i) if(pContent[i]==',') num++;
- //test search result
- if(num==0 || i>=len) return NULL;// "unrecognized content type"
- //points are 1 more than commas
- num++;//points
- //mallocate space enough for counted points and geom stuff
- pGeom = (WKBGeometry*)sqlite3_malloc(sizeof(Point)*num+sizeof(byte)+sizeof(uint32));
- pGeom->point.byteOrder = (byte)'1';//little endian ... autoconf endianness
- pGeom->point.wkbType = (uint32)3002;
- //parse pContent
- pContent[len] = '\0';//substitute last ) with string termination
- //scan pContent repeatedly parsing at ","
- for(i=0; i<num, (ppos = strsep(&pContent, ",")) != NULL; i++){
- if(*ppos != '\0'){
+ //pContent points count
+ len = strlen(pContent);
+ num = 0;//init
+ for(i=0; i<=len; ++i) if(pContent[i]==',') num++;
+ //test search result
+ if(num==0 || i>=len) return NULL;// "unrecognized content type"
+ //points are 1 more than commas
+ num++;//points
+ //mallocate space enough for counted points and geom stuff
+ pGeom = (WKBGeometry*)sqlite3_malloc(sizeof(Point)*num+sizeof(byte)+sizeof(uint32));
+ pGeom->point.byteOrder = (byte)'1';//little endian ... autoconf endianness
+ pGeom->point.wkbType = (uint32)wkbLineString;
+ //parse pContent
+ pContent[len] = '\0';//substitute last ) with string termination
+ //scan pContent repeatedly parsing at ","
+ for(i=0; i < num && (ppos = strsep(&pContent, ",")) != NULL; i++){
+ if(*ppos != '\0'){
/*
//fill geometry from token
sscanf(ppos+1, "%lf %lf %lf %lf",
@@ -117,6 +117,8 @@
&pGeom->linestring.points[i].m
);
*/
+ }
+ }
}
//POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))
@@ -153,18 +155,18 @@
//create string by wkbType
switch(pGeom->point.wkbType){
- case 3001: // wkbPoint
- //POINT(1.200000 1.300000 1.400000 1.500000)
- pWKT = sqlite3_mprintf("POINT(%lf %lf %lf %lf)"
+ case wkbPoint:
+ //POINT(1.200000 1.300000 1.400000 1.500000)
+ pWKT = sqlite3_mprintf("POINT(%lf %lf %lf %lf)"
, pGeom->point.point.x
, pGeom->point.point.y
, pGeom->point.point.z
, pGeom->point.point.m);
- break;
+ break;
- case 3002: // wkbLineString
- //LINESTRING(0 0, 10 10, 20 25, 50 60)
- break;
+ case wkbLineString:
+ //LINESTRING(0 0, 10 10, 20 25, 50 60)
+ break;
//POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))
//MULTIPOINT(0 0, 20 20, 60 60)
@@ -172,8 +174,8 @@
//MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)),((5 5,7 5,7 7,5 7, 5 5)))
//GEOMETRYCOLLECTION(POINT(10 10), POINT(30 30), LINESTRING(15 15, 20 20))
- default:
- pWKT = sqlite3_mprintf("Error: %s", messages[4]);
+ default:
+ pWKT = sqlite3_mprintf("Error: %s", messages[4]);
}
return pWKT;
@@ -194,7 +196,7 @@
WKBGeometry *pGeom;
//determining endianness from first byte
- if (pBin[0] == '0') bBigendian = 1; // Big endian
+ if (pBin[0] == (byte)wkbXDR) bBigendian = 1; // Big endian
else bBigendian = 0; // Little endian
//type
@@ -203,30 +205,30 @@
//set Geometry by wkbType
switch(wkbType){
- case 3001: // wkbPoint
- //alloc WKBGeometry for Point size
- pGeom = (WKBGeometry*) sqlite3_malloc(sizeof(WKBPoint));
- //assign order-first byte and type
- pGeom->point.byteOrder = pBin[0];
- pGeom->point.wkbType = wkbType;
- //read coordinates from blob into WKBGeometry
- size = sizeof(byte) + sizeof(uint32);
- memcpy(&pGeom->point.point.x, pBin+size, sizedbl);
- size += sizedbl;
- memcpy(&pGeom->point.point.y, pBin+size, sizedbl);
- size += sizedbl;
- memcpy(&pGeom->point.point.z, pBin+size, sizedbl);
- size += sizedbl;
- memcpy(&pGeom->point.point.m, pBin+size, sizedbl);
- //return filled pointer
- return pGeom;
- break;
+ case wkbPoint:
+ //alloc WKBGeometry for Point size
+ pGeom = (WKBGeometry*) sqlite3_malloc(sizeof(WKBPoint));
+ //assign order-first byte and type
+ pGeom->point.byteOrder = pBin[0];
+ pGeom->point.wkbType = wkbType;
+ //read coordinates from blob into WKBGeometry
+ size = sizeof(byte) + sizeof(uint32);
+ memcpy(&pGeom->point.point.x, pBin+size, sizedbl);
+ size += sizedbl;
+ memcpy(&pGeom->point.point.y, pBin+size, sizedbl);
+ size += sizedbl;
+ memcpy(&pGeom->point.point.z, pBin+size, sizedbl);
+ size += sizedbl;
+ memcpy(&pGeom->point.point.m, pBin+size, sizedbl);
+ //return filled pointer
+ return pGeom;
+ break;
- case 3002: // wkbLineString
- break;
+ case wkbLineString:
+ break;
default:
- return NULL;// "unable to convert from blob"
+ return NULL;// "unable to convert from blob"
}
return NULL;
@@ -246,32 +248,32 @@
//alloc by wkbType
switch(pGeom->point.wkbType){
- case 3001: // wkbPoint
- dim = sizeof(WKBPoint);
- pBuffer = (unsigned char*)sqlite3_malloc(dim);
- memset(pBuffer, 0, dim);
- pChar = pBuffer;
- //fill Geometry
- memcpy(pChar, (unsigned char*)&pGeom->point.byteOrder, sizeof(byte));
- pChar += sizeof(byte);
- memcpy(pChar, &pGeom->point.wkbType, sizeof(uint32));
- pChar += sizeof(uint32);
- memcpy(pChar, &pGeom->point.point.x, sizeof(double));
- pChar += sizeof(double);
- memcpy(pChar, &pGeom->point.point.y, sizeof(double));
- pChar += sizeof(double);
- memcpy(pChar, &pGeom->point.point.z, sizeof(double));
- pChar += sizeof(double);
- memcpy(pChar, &pGeom->point.point.m, sizeof(double));
- break;
+ case wkbPoint:
+ dim = sizeof(WKBPoint);
+ pBuffer = (unsigned char*)sqlite3_malloc(dim);
+ memset(pBuffer, 0, dim);
+ pChar = pBuffer;
+ //fill Geometry
+ memcpy(pChar, (unsigned char*)&pGeom->point.byteOrder, sizeof(byte));
+ pChar += sizeof(byte);
+ memcpy(pChar, &pGeom->point.wkbType, sizeof(uint32));
+ pChar += sizeof(uint32);
+ memcpy(pChar, &pGeom->point.point.x, sizeof(double));
+ pChar += sizeof(double);
+ memcpy(pChar, &pGeom->point.point.y, sizeof(double));
+ pChar += sizeof(double);
+ memcpy(pChar, &pGeom->point.point.z, sizeof(double));
+ pChar += sizeof(double);
+ memcpy(pChar, &pGeom->point.point.m, sizeof(double));
+ break;
- case 3002: // wkbLineString
- //sprintf(debug,"2");
- break;
+ case wkbLineString:
+ //sprintf(debug,"2");
+ break;
- default:
- pBuffer = NULL;// "unrecognized geometry type"
- //to be tested outside
+ default:
+ pBuffer = NULL;// "unrecognized geometry type"
+ //to be tested outside
}
return pBuffer;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <oci...@us...> - 2007-09-02 16:06:10
|
Revision: 10
http://gislite.svn.sourceforge.net/gislite/?rev=10&view=rev
Author: ocinemod
Date: 2007-09-02 09:06:04 -0700 (Sun, 02 Sep 2007)
Log Message:
-----------
Starting LineString part of GeomFromText() in wkgfunc.c
Modified Paths:
--------------
trunk/Makefile
trunk/sqlfunc.c
trunk/wkgfunc.c
Modified: trunk/Makefile
===================================================================
--- trunk/Makefile 2007-08-31 17:52:04 UTC (rev 9)
+++ trunk/Makefile 2007-09-02 16:06:04 UTC (rev 10)
@@ -1,14 +1,3 @@
-#
-# This is not valid in a Makefile
-#
-# if test -d /proc ; then
-# DYNAMIC= '-shared'
-# OPTIONS= ' -lsqlite3 -lm -g'
-# else
-# DYNAMIC= '-fno-common -dynamiclib'
-# OPTIONS= ''
-# fi
-
#UNAME = Darwin
UNAME = Linux
Modified: trunk/sqlfunc.c
===================================================================
--- trunk/sqlfunc.c 2007-08-31 17:52:04 UTC (rev 9)
+++ trunk/sqlfunc.c 2007-09-02 16:06:04 UTC (rev 10)
@@ -88,33 +88,7 @@
sqlite3_free((void*)pGeom);
}
-/**
- * SQL function Distance(b)
- * Returns the distance between two well know binaries as a double
- * Ex:
- * sqlite> SELECT AsText(BLOB_POINT) FROM testGeom WHERE Distance(BLOB_POINT,AsBinary('POINT(1.2 1.3 1.4 1.5)')) < 100.0
- */
-static void Distance(
- sqlite3_context *context,
- int argc,
- sqlite3_value **argv
-){
- WKBGeometry *pGeomA, *pGeomB;
- double distance;
- if( sqlite3_value_type(argv[0]) == SQLITE_BLOB && sqlite3_value_type(argv[1]) == SQLITE_BLOB){
- pGeomA = GeomFromBinary((unsigned char *)sqlite3_value_blob(argv[0]));
- pGeomB = GeomFromBinary((unsigned char *)sqlite3_value_blob(argv[1]));
- distance = GeomDistance(pGeomA,pGeomB);
- if( distance < 0.0 )
- sqlite3_result_null(context); // if negative means distance can't be evalued
- sqlite3_result_double(context,distance);
- } else {
- sqlite3_result_error(context,messages[6],-1);
- }
-}
-
-
/**
* SQL function X(b)
* Returns the X-coordinate value for the blob b containing WKBGeometry Point as a double.
@@ -342,8 +316,7 @@
sqlite3_create_function(db, "AsBinary", 1, SQLITE_ANY, 0, AsBinary, 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);
- sqlite3_create_function(db, "Distance", 2, SQLITE_ANY, 0,Distance, 0, 0);
-
+
//Point functions
sqlite3_create_function(db, "X", 1, SQLITE_ANY, 0, X, 0, 0);
sqlite3_create_function(db, "Y", 1, SQLITE_ANY, 0, Y, 0, 0);
Modified: trunk/wkgfunc.c
===================================================================
--- trunk/wkgfunc.c 2007-08-31 17:52:04 UTC (rev 9)
+++ trunk/wkgfunc.c 2007-09-02 16:06:04 UTC (rev 10)
@@ -51,6 +51,7 @@
*/
WKBGeometry* GeomFromText(char *pWKT){
int len, i;
+ char *ppos;
char *pType;
char *pContent;
WKBGeometry *pGeom;
@@ -90,6 +91,32 @@
//LINESTRING(1 1 1 1, 2 2 2 2, 3 3 3 3)
else if(strncmp(pWKT,"LINESTRING", 10)==0){
+ //pContent points count
+ len = strlen(pContent);
+ num = 0;//init
+ for(i=0; i<=len; ++i) if(pContent[i]==',') num++;
+ //test search result
+ if(num==0 || i>=len) return NULL;// "unrecognized content type"
+ //points are 1 more than commas
+ num++;//points
+ //mallocate space enough for counted points and geom stuff
+ pGeom = (WKBGeometry*)sqlite3_malloc(sizeof(Point)*num+sizeof(byte)+sizeof(uint32));
+ pGeom->point.byteOrder = (byte)'1';//little endian ... autoconf endianness
+ pGeom->point.wkbType = (uint32)3002;
+ //parse pContent
+ pContent[len] = '\0';//substitute last ) with string termination
+ //scan pContent repeatedly parsing at ","
+ for(i=0; i<num, (ppos = strsep(&pContent, ",")) != NULL; i++){
+ if(*ppos != '\0'){
+/*
+ //fill geometry from token
+ sscanf(ppos+1, "%lf %lf %lf %lf",
+ &pGeom->linestring.points[i].x,
+ &pGeom->linestring.points[i].y,
+ &pGeom->linestring.points[i].z,
+ &pGeom->linestring.points[i].m
+ );
+*/
}
//POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cto...@us...> - 2007-08-31 17:52:02
|
Revision: 9
http://gislite.svn.sourceforge.net/gislite/?rev=9&view=rev
Author: ctomasin
Date: 2007-08-31 10:52:04 -0700 (Fri, 31 Aug 2007)
Log Message:
-----------
Added GeomDistance() function and the corrisponding Distance() SQL function
Modified Paths:
--------------
trunk/Makefile
trunk/sqlfunc.c
trunk/wkg.h
trunk/wkgfunc.c
trunk/wkgfunc.h
Modified: trunk/Makefile
===================================================================
--- trunk/Makefile 2007-08-30 18:22:10 UTC (rev 8)
+++ trunk/Makefile 2007-08-31 17:52:04 UTC (rev 9)
@@ -1,16 +1,30 @@
-if test -d /proc ; then
- DYNAMIC= '-shared'
- OPTIONS= ' -lsqlite3 -lm -g'
+#
+# This is not valid in a Makefile
+#
+# if test -d /proc ; then
+# DYNAMIC= '-shared'
+# OPTIONS= ' -lsqlite3 -lm -g'
+# else
+# DYNAMIC= '-fno-common -dynamiclib'
+# OPTIONS= ''
+# fi
+
+#UNAME = Darwin
+UNAME = Linux
+
+ifeq ($(UNAME),Linux)
+ DYNAMIC = -shared
+ OPTIONS = -lsqlite3 -lm -g
else
- DYNAMIC= '-fno-common -dynamiclib'
- OPTIONS= ''
-fi
+ DYNAMIC= -fno-common -dynamiclib
+ OPTIONS=
+endif
NAME = gislite.so
SOURCES = wkgfunc.c sqlfunc.c
OBJS = $(SOURCES:%.c=%.o)
$(NAME) : $(OBJS)
- gcc $(DYNAMIC) $(OPTIONS) -o $@ $(OBJS)
+ gcc $(DYNAMIC) $(OPTIONS) -o $@ $(OBJS)
%.o : %.c
gcc -Wall -O0 -D_GNU_SOURCE -c $<
Modified: trunk/sqlfunc.c
===================================================================
--- trunk/sqlfunc.c 2007-08-30 18:22:10 UTC (rev 8)
+++ trunk/sqlfunc.c 2007-08-31 17:52:04 UTC (rev 9)
@@ -88,7 +88,33 @@
sqlite3_free((void*)pGeom);
}
+/**
+ * SQL function Distance(b)
+ * Returns the distance between two well know binaries as a double
+ * Ex:
+ * sqlite> SELECT AsText(BLOB_POINT) FROM testGeom WHERE Distance(BLOB_POINT,AsBinary('POINT(1.2 1.3 1.4 1.5)')) < 100.0
+ */
+static void Distance(
+ sqlite3_context *context,
+ int argc,
+ sqlite3_value **argv
+){
+ WKBGeometry *pGeomA, *pGeomB;
+ double distance;
+ if( sqlite3_value_type(argv[0]) == SQLITE_BLOB && sqlite3_value_type(argv[1]) == SQLITE_BLOB){
+ pGeomA = GeomFromBinary((unsigned char *)sqlite3_value_blob(argv[0]));
+ pGeomB = GeomFromBinary((unsigned char *)sqlite3_value_blob(argv[1]));
+ distance = GeomDistance(pGeomA,pGeomB);
+ if( distance < 0.0 )
+ sqlite3_result_null(context); // if negative means distance can't be evalued
+ sqlite3_result_double(context,distance);
+ } else {
+ sqlite3_result_error(context,messages[6],-1);
+ }
+}
+
+
/**
* SQL function X(b)
* Returns the X-coordinate value for the blob b containing WKBGeometry Point as a double.
@@ -316,7 +342,8 @@
sqlite3_create_function(db, "AsBinary", 1, SQLITE_ANY, 0, AsBinary, 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);
-
+ sqlite3_create_function(db, "Distance", 2, SQLITE_ANY, 0,Distance, 0, 0);
+
//Point functions
sqlite3_create_function(db, "X", 1, SQLITE_ANY, 0, X, 0, 0);
sqlite3_create_function(db, "Y", 1, SQLITE_ANY, 0, Y, 0, 0);
Modified: trunk/wkg.h
===================================================================
--- trunk/wkg.h 2007-08-30 18:22:10 UTC (rev 8)
+++ trunk/wkg.h 2007-08-31 17:52:04 UTC (rev 9)
@@ -28,7 +28,7 @@
typedef struct {
uint32 numPoints;
- Point points[1]; // [numPoints] init
+ Point *points; // [numPoints] init
}LinearRing;
enum wkbByteOrder {
@@ -56,42 +56,42 @@
byte byteOrder;
uint32 wkbType; // = 3002;
uint32 numPoints;
- Point points[1]; // init [numPoints]
+ Point *points; // init [numPoints]
}WKBLineString;
typedef struct {
byte byteOrder;
uint32 wkbType; // = 3003;
uint32 numRings;
- LinearRing rings[1]; // init [numRings]
+ LinearRing *rings; // init [numRings]
}WKBPolygon;
typedef struct {
byte byteOrder;
uint32 wkbType; // = 3004;
uint32 num_wkbPoints;
- WKBPoint WKBPoints[1]; // init [num_wkbPoints]
+ WKBPoint *wKBPoints; // init [num_wkbPoints]
}WKBMultiPoint;
typedef struct {
byte byteOrder;
uint32 wkbType; // = 3005;
uint32 num_wkbLineStrings;
- WKBLineString WKBLineStrings[1]; // init [num_wkbLineStrings]
+ WKBLineString *wKBLineStrings; // init [num_wkbLineStrings]
}WKBMultiLineString;
typedef struct {
byte byteOrder;
uint32 wkbType; // = 3006;
uint32 num_wkbPolygons;
- WKBPolygon wkbPolygons[1]; // init [num_wkbPolygons]
+ WKBPolygon *wkbPolygons; // init [num_wkbPolygons]
}WKBMultiPolygon;
typedef struct {
byte byteOrder;
uint32 wkbType; // = 3007;
uint32 num_wkbGeometries;
- char wkbGeometries[1]; // init [num_wkbGeometries];
+ /*WKBGeometry*/ char *wkbGeometries; // init [num_wkbGeometries];
}WKBGeometryCollection;
typedef struct {
@@ -105,4 +105,6 @@
WKBGeometryCollection collection;
};
}WKBGeometry;
+
+
#endif
Modified: trunk/wkgfunc.c
===================================================================
--- trunk/wkgfunc.c 2007-08-30 18:22:10 UTC (rev 8)
+++ trunk/wkgfunc.c 2007-08-31 17:52:04 UTC (rev 9)
@@ -5,19 +5,21 @@
#include <stdio.h>
#include <string.h>
+#include <math.h>
#include "wkgfunc.h"
#include <sqlite3ext.h> // needed by portable sqlite-specific functions
SQLITE_EXTENSION_INIT1 // needed by portable sqlite-specific functions
//char debug[50];
-char *messages[6] = {
+char *messages[7] = {
"ok" // 0
,"unrecognized text type" // 1
,"parse error" // 2
,"unrecognized geometry type" // 3
,"unable to convert from blob" // 4
,"geometry is not a point" // 5
+ ,"wrong parameter type" // 6
};
@@ -210,7 +212,7 @@
*
* @return pointer to unsigned char to be filled
*/
-unsigned char* asBinary(WKBGeometry* pGeom){
+unsigned char* GeomAsBinary(WKBGeometry* pGeom){
int dim;
unsigned char *pBuffer;
unsigned char *pChar;
@@ -248,4 +250,46 @@
return pBuffer;
}
+/**
+ * function GeomDimension(g)
+ * @param pGeom pointer to WKGeometry
+ *
+ * @return number of dimensions of the Geometry
+ */
+int GeomDimension(WKBGeometry *pGeom){
+ int dims;
+ switch(pGeom->point.wkbType){
+ case wkbPoint:
+ dims = 0;
+ break;
+ case wkbLineString:
+ dims = 1;
+ break;
+ default:
+ dims = 0;
+ break;
+ }
+ return dims;
+}
+
+
+/**
+ * function GeomDistance(g)
+ * @param pGeomA pointer to first geometry
+ * @param pGeomB pointer to second geometry
+ *
+ * @return distance between the two geometries
+ */
+double GeomDistance(WKBGeometry *pGeomA,WKBGeometry *pGeomB){
+ double distance;
+ if(pGeomA->point.wkbType == wkbPoint && pGeomB->point.wkbType == wkbPoint){
+ distance = sqrt(pow(pGeomB->point.point.x - pGeomA->point.point.x,2) +
+ pow(pGeomB->point.point.y - pGeomA->point.point.y,2) +
+ pow(pGeomB->point.point.z - pGeomA->point.point.z,2) +
+ pow(pGeomB->point.point.m - pGeomA->point.point.m,2));
+ }else{
+ distance = -1.0; // not able to measure
+ }
+ return distance;
+}
Modified: trunk/wkgfunc.h
===================================================================
--- trunk/wkgfunc.h 2007-08-30 18:22:10 UTC (rev 8)
+++ trunk/wkgfunc.h 2007-08-31 17:52:04 UTC (rev 9)
@@ -19,6 +19,7 @@
unsigned char* GeomAsBinary(WKBGeometry* pGeom);
+double GeomDistance(WKBGeometry *pGeomA,WKBGeometry *pGeomB);
extern char *messages[];
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cto...@us...> - 2007-08-30 18:22:09
|
Revision: 8
http://gislite.svn.sourceforge.net/gislite/?rev=8&view=rev
Author: ctomasin
Date: 2007-08-30 11:22:10 -0700 (Thu, 30 Aug 2007)
Log Message:
-----------
Some modify by Domenico committed by Carlo
Modified Paths:
--------------
trunk/Makefile
trunk/sqlfunc.c
trunk/wkgfunc.c
trunk/wkgfunc.h
Modified: trunk/Makefile
===================================================================
--- trunk/Makefile 2007-08-24 15:20:12 UTC (rev 7)
+++ trunk/Makefile 2007-08-30 18:22:10 UTC (rev 8)
@@ -1,3 +1,11 @@
+if test -d /proc ; then
+ DYNAMIC= '-shared'
+ OPTIONS= ' -lsqlite3 -lm -g'
+else
+ DYNAMIC= '-fno-common -dynamiclib'
+ OPTIONS= ''
+fi
+
NAME = gislite.so
SOURCES = wkgfunc.c sqlfunc.c
OBJS = $(SOURCES:%.c=%.o)
@@ -2,3 +10,3 @@
$(NAME) : $(OBJS)
- gcc -shared -lsqlite3 -lm -g -o $@ $(OBJS)
+ gcc $(DYNAMIC) $(OPTIONS) -o $@ $(OBJS)
Modified: trunk/sqlfunc.c
===================================================================
--- trunk/sqlfunc.c 2007-08-24 15:20:12 UTC (rev 7)
+++ trunk/sqlfunc.c 2007-08-30 18:22:10 UTC (rev 8)
@@ -7,95 +7,85 @@
#include <string.h>
#include <sqlite3ext.h>
#include "wkgfunc.h"
+
SQLITE_EXTENSION_INIT1
/**
- * SQL function toWKT(b)
+ * SQL function AsText(b)
* Returns a WKT openGis Geometry representation from a sqlite blob b.
* Ex:
- * sqlite> SELECT (toWKT(BLOB_POINT)) FROM testGeom WHERE INDEX=1;
+ * sqlite> SELECT (AsText(BLOB_POINT)) FROM testGeom WHERE INDEX=1;
* sqlite> POINT(1.1 1.2 1.3 4.4)
*
* @param argv blob well-known binary to sqlite by its own function
*
* @return string geometry as well-known text
*/
-static void ToWKT(
+static void AsText(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
unsigned char *pBlob;
- int error;
char *pString;
- WKBGeometry Geom;
+ WKBGeometry *pGeom;
//check for null values
if(sqlite3_value_type(argv[0]) == SQLITE_NULL) return;
//only if value type is BLOB
- switch( sqlite3_value_type(argv[0])){
- case SQLITE_BLOB:
+ if( sqlite3_value_type(argv[0]) == SQLITE_BLOB){
//get blob from argv
pBlob = (unsigned char*) sqlite3_value_blob(argv[0]);
//fill structure from blob
- error = 0;
- error = fromBinary(pBlob, &Geom);
- if(error) sqlite3_result_error(context, messages[error], -1);
+ pGeom = (WKBGeometry*)GeomFromBinary(pBlob);
//convert to string
- pString = asText(&Geom);
- break;
- default:
+ pString = (char*)GeomAsText(pGeom);
+ }else{
sqlite3_result_error(context, messages[4], -1);
}
//write out results
sqlite3_result_text(context, pString, -1, SQLITE_TRANSIENT);
-
//free AsText allocated memory
- sqlite3_free(pString);
+ sqlite3_free((void*)pString);
+ sqlite3_free((void*)pGeom);
}
/**
- * SQL function toWKB(t)
+ * SQL function AsBinary(t)
* Returns a WKB blob from a WKT openGis Geometry representation t
* Ex:
- * sqlite> INSERT INTO testGeom (BLOB_POINT) VALUES (toWKB('POINT(1.2 1.3 1.4 1.5)'));
+ * sqlite> INSERT INTO testGeom (BLOB_POINT) VALUES (AsBinary('POINT(1.2 1.3 1.4 1.5)'));
*
* @param argv string geometry as well-known text
*
* @return blob well-known binary to sqlite by its own function
*/
-static void ToWKB(
+static void AsBinary(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
- int error, sizeBin;
+ int sizeBin;
char *pBuf;
unsigned char *pBin;
- WKBGeometry Geom;
+ WKBGeometry *pGeom;
//check for null values
if(sqlite3_value_type(argv[0]) == SQLITE_NULL) return;
- //assign parameter
+ //assign sqlite parameter
pBuf = (char*)sqlite3_value_text(argv[0]);
-
- error = 0;
- error = fromText(pBuf, &Geom);
- if(error) sqlite3_result_error(context, messages[error], -1);
+ //read WKT into geometry
+ pGeom = (WKBGeometry*)GeomFromText(pBuf);
//fill char array
- pBin = asBinary(&Geom);
-//double tmp;
-//memcpy(&tmp, pBin+sizeof(byte)+sizeof(uint32)+sizeof(double),sizeof(double));
-//sprintf(debug,"bin: %lf",tmp);
-//sqlite3_result_error(context, debug, -1);
-
- //sizeBin = strlen((char*)pBin);
- sizeBin = sizeof(WKBGeometry);
+ pBin = (unsigned char*)GeomAsBinary(pGeom);
+ //measure binary buffer as char array
+ sizeBin = strlen((char*)pBin)+1;
+ //assign binary buffer
sqlite3_result_blob(context, pBin, sizeBin, SQLITE_TRANSIENT);
-
- //free memory allocated by asBinary()
+ //free allocated memory
sqlite3_free((void*)pBin);
+ sqlite3_free((void*)pGeom);
}
@@ -115,15 +105,15 @@
int argc,
sqlite3_value **argv
){
- WKBGeometry Geom;
+ WKBGeometry *pGeom;
//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);
+ pGeom = (WKBGeometry*)GeomFromBinary((unsigned char*) sqlite3_value_blob(argv[0]));
//return coordinate
- if(Geom.point.wkbType == 3001)
- sqlite3_result_double(context, Geom.point.point.x);
+ if(pGeom->point.wkbType == 3001)
+ sqlite3_result_double(context, pGeom->point.point.x);
else
sqlite3_result_error(context, messages[5], -1);
}else{
@@ -148,15 +138,15 @@
int argc,
sqlite3_value **argv
){
- WKBGeometry Geom;
+ WKBGeometry *pGeom;
//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);
+ pGeom = (WKBGeometry*)GeomFromBinary((unsigned char*) sqlite3_value_blob(argv[0]));
//return coordinate
- if(Geom.point.wkbType == 3001)
- sqlite3_result_double(context, Geom.point.point.y);
+ if(pGeom->point.wkbType == 3001)
+ sqlite3_result_double(context, pGeom->point.point.y);
else
sqlite3_result_error(context, messages[5], -1);
}else{
@@ -180,15 +170,15 @@
int argc,
sqlite3_value **argv
){
- WKBGeometry Geom;
+ WKBGeometry *pGeom;
//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);
+ pGeom = (WKBGeometry*)GeomFromBinary((unsigned char*) sqlite3_value_blob(argv[0]));
//return coordinate
- if(Geom.point.wkbType == 3001)
- sqlite3_result_double(context, Geom.point.point.z);
+ if(pGeom->point.wkbType == 3001)
+ sqlite3_result_double(context, pGeom->point.point.z);
else
sqlite3_result_error(context, messages[5], -1);
}else{
@@ -213,15 +203,15 @@
int argc,
sqlite3_value **argv
){
- WKBGeometry Geom;
+ WKBGeometry *pGeom;
//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);
+ pGeom = (WKBGeometry*)GeomFromBinary((unsigned char*) sqlite3_value_blob(argv[0]));
//return coordinate
- if(Geom.point.wkbType == 3001)
- sqlite3_result_double(context, Geom.point.point.m);
+ if(pGeom->point.wkbType == 3001)
+ sqlite3_result_double(context, pGeom->point.point.m);
else
sqlite3_result_error(context, messages[5], -1);
}else{
@@ -234,7 +224,7 @@
* SQL function StartPoint(g)
* Returns the start Point of a WKBGeometry LineString g.
* Ex:
- * sqlite> SELECT AsText(StartPoint(GeomfromBinary(BLOB_LINE))) FROM testGeom WHERE INDEX=1;
+ * sqlite> SELECT AsText(StartPoint(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
* sqlite> POINT(1.1 1.2 1.3 4.4)
*
* @param g WKBGeometry structure containing LineString
@@ -247,7 +237,7 @@
* SQL function EndPoint(g)
* Returns the end Point of a LineString.
* Ex:
- * sqlite> SELECT AsText(EndPoint(GeomfromBinary(BLOB_LINE))) FROM testGeom WHERE INDEX=1;
+ * sqlite> SELECT AsText(EndPoint(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
* sqlite> POINT(5.1 5.2 5.3 4.4)
*
* @param g WKBGeometry structure containing LineString
@@ -260,7 +250,7 @@
* SQL function Length(g)
* Returns the length of the LineString geometry g as double.
* Ex:
- * sqlite> SELECT Length(GeomfromBinary(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
+ * sqlite> SELECT Length(BLOB_LINE) FROM testGeom WHERE INDEX=1;
* sqlite> 5.8926358638273
*
* @param g WKBGeometry structure containing LineString
@@ -273,7 +263,7 @@
* SQL function NumPoints(g)
* Returns the number of points in the WKBGeometry LineString g.
* Ex:
- * sqlite> SELECT NumPoints(GeomfromBinary(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
+ * sqlite> SELECT NumPoints(BLOB_LINE) FROM testGeom WHERE INDEX=1;
* sqlite> 12
*
* @param g WKBGeometry structure containing LineString
@@ -286,7 +276,7 @@
* SQL function PointN(g, n)
* Returns the n-th point in the WKBGeometry Linestring g. Point numbers begin at 0.
* Ex:
- * sqlite> SELECT AsText(PointN(GeomfromBinary(BLOB_LINE),10)) FROM testGeom WHERE INDEX=1;
+ * sqlite> SELECT AsText(PointN(BLOB_LINE,10)) FROM testGeom WHERE INDEX=1;
* sqlite> POINT(1.1 1.2 0.0 0.0)
*
* @param g WKBGeometry structure containing LineString
@@ -301,7 +291,7 @@
* Returns 1 if the WKBGeometry LineString g is closed and is simple.
* Returns 0 if ls is not a ring, and -1 if it is NULL.
* Ex:
- * sqlite> SELECT IsRing(GeomfromBinary(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
+ * sqlite> SELECT IsRing(BLOB_LINE) FROM testGeom WHERE INDEX=1;
* sqlite> 1
*
* @param g WKBGeometry structure containing LineString
@@ -320,8 +310,14 @@
const sqlite3_api_routines *pApi
){
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);
+
+ //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, "SRID", 1, SQLITE_ANY, 0, SRID, 0, 0);
+ //sqlite3_create_function(db, "Dimension", 1, SQLITE_ANY, 0, Dimension, 0, 0);
+
+ //Point functions
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);
Modified: trunk/wkgfunc.c
===================================================================
--- trunk/wkgfunc.c 2007-08-24 15:20:12 UTC (rev 7)
+++ trunk/wkgfunc.c 2007-08-30 18:22:10 UTC (rev 8)
@@ -39,24 +39,26 @@
swap_char(i+3, i);
swap_char(i+2, i+1);
}
+
+
/**
- * function FromText
+ * function GeomFromText(t)
* @param pWKT pointer to string in WKT encoding
- * @param pGeom pointer to WKGeometry to be filled
*
- * @return integer error code
+ * @return pointer to WKGeometry
*/
-int fromText(char *pWKT, WKBGeometry *pGeom){
+WKBGeometry* GeomFromText(char *pWKT){
int len, i;
char *pType;
char *pContent;
+ WKBGeometry *pGeom;
//parse string passed as parameter
//search first '('
len = strlen(pWKT);
for (i=0; pWKT[i]!='(' && i<=len; ++i) ;
//test search result
- if(i<5 || i>=len) return 1;// "unrecognized text type"
+ if(i<5 || i>=len) return NULL;// "unrecognized text type"
//copy geometry type
pType = (char*)sqlite3_malloc((int)i+1);
strncpy(pType, pWKT, i);
@@ -67,6 +69,7 @@
//assigning structure to blob
//POINT(1.1 1.2 1.3 1.4)
if(strncmp(pType, "POINT", 5)==0){
+ pGeom = (WKBGeometry*) sqlite3_malloc(sizeof(WKBPoint));
//fill geometry as point
pGeom->point.byteOrder = (byte)'1';//little endian ... autoconf endianness
pGeom->point.wkbType = (uint32)3001;
@@ -79,8 +82,8 @@
//free all allocated memory
sqlite3_free((void*)pType);
sqlite3_free((void*)pContent);
- return 2;//"parse error"
}
+ return pGeom;
}
//LINESTRING(1 1 1 1, 2 2 2 2, 3 3 3 3)
@@ -98,25 +101,24 @@
//free all allocated memory
sqlite3_free((void*)pType);
sqlite3_free((void*)pContent);
- return 3;// "unrecognized geometry type"
+ return NULL;// "unrecognized geometry type"
}
//free all allocated memory
sqlite3_free((void*)pType);
sqlite3_free((void*)pContent);
- return 0;
+ return NULL;
}
/**
- * function AsText
+ * function GeomAsText(g)
* @param pGeom pointer to WKGeometry to be encoded
- * @param pWKT pointer to string containing the text rapresentation created by the function
*
- * @return as pWKT
+ * @return pointer to string
*/
-char* asText(WKBGeometry *pGeom){
- int len;
+char* GeomAsText(WKBGeometry *pGeom){
+ //int len;
char *pWKT;
//char *sBuffer;
@@ -124,7 +126,7 @@
switch(pGeom->point.wkbType){
case 3001: // wkbPoint
//POINT(1.200000 1.300000 1.400000 1.500000)
- len = asprintf(&pWKT, "POINT(%lf %lf %lf %lf)"
+ pWKT = sqlite3_mprintf("POINT(%lf %lf %lf %lf)"
, pGeom->point.point.x
, pGeom->point.point.y
, pGeom->point.point.z
@@ -142,7 +144,7 @@
//GEOMETRYCOLLECTION(POINT(10 10), POINT(30 30), LINESTRING(15 15, 20 20))
default:
- asprintf(&pWKT, "Error: %s", messages[4]);
+ pWKT = sqlite3_mprintf("Error: %s", messages[4]);
}
return pWKT;
@@ -150,16 +152,17 @@
/**
- * function FromBinary
- * @param pBin pointer to unsigned char to be read
- * @param pGeom pointer to WKGeometry to be filled
+ * function GeomFromBinary(b)
+ * @param pointer to unsigned char b blob to be read
*
- * @return integer error code
+ * @return pointer to WKGeometry to be filled
*/
-int fromBinary(unsigned char *pBin, WKBGeometry *pGeom){
+WKBGeometry* GeomFromBinary(unsigned char *pBin){
int bBigendian;
uint32 wkbType;
- int size, sizedbl=sizeof(double);
+ int size;
+ int sizedbl = sizeof(double);
+ WKBGeometry *pGeom;
//determining endianness from first byte
if (pBin[0] == '0') bBigendian = 1; // Big endian
@@ -172,6 +175,9 @@
//set Geometry by wkbType
switch(wkbType){
case 3001: // wkbPoint
+ //alloc WKBGeometry for Point size
+ pGeom = (WKBGeometry*) sqlite3_malloc(sizeof(WKBPoint));
+ //assign order-first byte and type
pGeom->point.byteOrder = pBin[0];
pGeom->point.wkbType = wkbType;
//read coordinates from blob into WKBGeometry
@@ -183,21 +189,23 @@
memcpy(&pGeom->point.point.z, pBin+size, sizedbl);
size += sizedbl;
memcpy(&pGeom->point.point.m, pBin+size, sizedbl);
+ //return filled pointer
+ return pGeom;
break;
case 3002: // wkbLineString
break;
default:
- return 4;// "unable to convert from blob"
+ return NULL;// "unable to convert from blob"
}
- return 0;
+ return NULL;
}
/**
- * function AsBinary
+ * function GeomAsBinary(g)
* @param pGeom pointer to WKGeometry to be converted
*
* @return pointer to unsigned char to be filled
Modified: trunk/wkgfunc.h
===================================================================
--- trunk/wkgfunc.h 2007-08-24 15:20:12 UTC (rev 7)
+++ trunk/wkgfunc.h 2007-08-30 18:22:10 UTC (rev 8)
@@ -8,13 +8,17 @@
void flip_endian_int32(char *i);
-int fromText(char *pWKT, WKBGeometry *pGeom);
-char* asText(WKBGeometry *pGeom);
+//Geometry function declarations
-int fromBinary(unsigned char *pBin, WKBGeometry *pGeom);
+WKBGeometry* GeomFromText(char *pWKT);
-unsigned char* asBinary(WKBGeometry* pGeom);
+char* GeomAsText(WKBGeometry *pGeom);
+WKBGeometry* GeomFromBinary(unsigned char *pBin);
+
+unsigned char* GeomAsBinary(WKBGeometry* pGeom);
+
+
extern char *messages[];
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cto...@us...> - 2007-08-24 15:21:05
|
Revision: 7
http://gislite.svn.sourceforge.net/gislite/?rev=7&view=rev
Author: ctomasin
Date: 2007-08-24 08:20:12 -0700 (Fri, 24 Aug 2007)
Log Message:
-----------
Some modifies
Added the Makefile used in Linux system to compile gislite.so.
Project compile but functionalities has not been tested due to a lack of time.
Modified Paths:
--------------
trunk/sqlfunc.c
trunk/wkg.h
trunk/wkgfunc.c
trunk/wkgfunc.h
Added Paths:
-----------
trunk/Makefile
Added: trunk/Makefile
===================================================================
--- trunk/Makefile (rev 0)
+++ trunk/Makefile 2007-08-24 15:20:12 UTC (rev 7)
@@ -0,0 +1,12 @@
+NAME = gislite.so
+SOURCES = wkgfunc.c sqlfunc.c
+OBJS = $(SOURCES:%.c=%.o)
+$(NAME) : $(OBJS)
+ gcc -shared -lsqlite3 -lm -g -o $@ $(OBJS)
+
+%.o : %.c
+ gcc -Wall -O0 -D_GNU_SOURCE -c $<
+
+
+clean :
+ rm -f $(NAME) $(OBJS)
Modified: trunk/sqlfunc.c
===================================================================
--- trunk/sqlfunc.c 2007-08-24 13:57:30 UTC (rev 6)
+++ trunk/sqlfunc.c 2007-08-24 15:20:12 UTC (rev 7)
@@ -3,6 +3,12 @@
* Functions used from SQL interface
* */
+#include <stdio.h>
+#include <string.h>
+#include <sqlite3ext.h>
+#include "wkgfunc.h"
+SQLITE_EXTENSION_INIT1
+
/**
* SQL function toWKT(b)
* Returns a WKT openGis Geometry representation from a sqlite blob b.
@@ -14,7 +20,7 @@
*
* @return string geometry as well-known text
*/
-static void toWKT(
+static void ToWKT(
sqlite3_context *context,
int argc,
sqlite3_value **argv
@@ -33,10 +39,10 @@
pBlob = (unsigned char*) sqlite3_value_blob(argv[0]);
//fill structure from blob
error = 0;
- error = FromBinary(pBlob, &Geom);
+ error = fromBinary(pBlob, &Geom);
if(error) sqlite3_result_error(context, messages[error], -1);
//convert to string
- pString = AsText(&Geom);
+ pString = asText(&Geom);
break;
default:
sqlite3_result_error(context, messages[4], -1);
@@ -46,7 +52,7 @@
sqlite3_result_text(context, pString, -1, SQLITE_TRANSIENT);
//free AsText allocated memory
- free(pString);
+ sqlite3_free(pString);
}
/**
@@ -59,7 +65,7 @@
*
* @return blob well-known binary to sqlite by its own function
*/
-static void toWKB(
+static void ToWKB(
sqlite3_context *context,
int argc,
sqlite3_value **argv
@@ -75,10 +81,10 @@
pBuf = (char*)sqlite3_value_text(argv[0]);
error = 0;
- error = FromText(pBuf, &Geom);
+ error = fromText(pBuf, &Geom);
if(error) sqlite3_result_error(context, messages[error], -1);
//fill char array
- pBin = AsBinary(&Geom);
+ pBin = asBinary(&Geom);
//double tmp;
//memcpy(&tmp, pBin+sizeof(byte)+sizeof(uint32)+sizeof(double),sizeof(double));
//sprintf(debug,"bin: %lf",tmp);
@@ -114,7 +120,7 @@
//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);
+ fromBinary((unsigned char*) sqlite3_value_blob(argv[0]), &Geom);
//return coordinate
if(Geom.point.wkbType == 3001)
sqlite3_result_double(context, Geom.point.point.x);
@@ -147,7 +153,7 @@
//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);
+ fromBinary((unsigned char*) sqlite3_value_blob(argv[0]), &Geom);
//return coordinate
if(Geom.point.wkbType == 3001)
sqlite3_result_double(context, Geom.point.point.y);
@@ -179,7 +185,7 @@
//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);
+ fromBinary((unsigned char*) sqlite3_value_blob(argv[0]), &Geom);
//return coordinate
if(Geom.point.wkbType == 3001)
sqlite3_result_double(context, Geom.point.point.z);
@@ -212,7 +218,7 @@
//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);
+ fromBinary((unsigned char*) sqlite3_value_blob(argv[0]), &Geom);
//return coordinate
if(Geom.point.wkbType == 3001)
sqlite3_result_double(context, Geom.point.point.m);
@@ -228,7 +234,7 @@
* SQL function StartPoint(g)
* Returns the start Point of a WKBGeometry LineString g.
* Ex:
- * sqlite> SELECT AsText(StartPoint(GeomFromBinary(BLOB_LINE))) FROM testGeom WHERE INDEX=1;
+ * sqlite> SELECT AsText(StartPoint(GeomfromBinary(BLOB_LINE))) FROM testGeom WHERE INDEX=1;
* sqlite> POINT(1.1 1.2 1.3 4.4)
*
* @param g WKBGeometry structure containing LineString
@@ -241,7 +247,7 @@
* SQL function EndPoint(g)
* Returns the end Point of a LineString.
* Ex:
- * sqlite> SELECT AsText(EndPoint(GeomFromBinary(BLOB_LINE))) FROM testGeom WHERE INDEX=1;
+ * sqlite> SELECT AsText(EndPoint(GeomfromBinary(BLOB_LINE))) FROM testGeom WHERE INDEX=1;
* sqlite> POINT(5.1 5.2 5.3 4.4)
*
* @param g WKBGeometry structure containing LineString
@@ -254,7 +260,7 @@
* SQL function Length(g)
* Returns the length of the LineString geometry g as double.
* Ex:
- * sqlite> SELECT Length(GeomFromBinary(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
+ * sqlite> SELECT Length(GeomfromBinary(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
* sqlite> 5.8926358638273
*
* @param g WKBGeometry structure containing LineString
@@ -267,7 +273,7 @@
* SQL function NumPoints(g)
* Returns the number of points in the WKBGeometry LineString g.
* Ex:
- * sqlite> SELECT NumPoints(GeomFromBinary(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
+ * sqlite> SELECT NumPoints(GeomfromBinary(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
* sqlite> 12
*
* @param g WKBGeometry structure containing LineString
@@ -280,7 +286,7 @@
* SQL function PointN(g, n)
* Returns the n-th point in the WKBGeometry Linestring g. Point numbers begin at 0.
* Ex:
- * sqlite> SELECT AsText(PointN(GeomFromBinary(BLOB_LINE),10)) FROM testGeom WHERE INDEX=1;
+ * sqlite> SELECT AsText(PointN(GeomfromBinary(BLOB_LINE),10)) FROM testGeom WHERE INDEX=1;
* sqlite> POINT(1.1 1.2 0.0 0.0)
*
* @param g WKBGeometry structure containing LineString
@@ -295,7 +301,7 @@
* Returns 1 if the WKBGeometry LineString g is closed and is simple.
* Returns 0 if ls is not a ring, and -1 if it is NULL.
* Ex:
- * sqlite> SELECT IsRing(GeomFromBinary(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
+ * sqlite> SELECT IsRing(GeomfromBinary(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
* sqlite> 1
*
* @param g WKBGeometry structure containing LineString
@@ -314,8 +320,8 @@
const sqlite3_api_routines *pApi
){
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, "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);
Modified: trunk/wkg.h
===================================================================
--- trunk/wkg.h 2007-08-24 13:57:30 UTC (rev 6)
+++ trunk/wkg.h 2007-08-24 15:20:12 UTC (rev 7)
@@ -5,7 +5,8 @@
* as in: OGC 06-103r3 (8.2.8)
* expressed as C structures
*/
-
+#ifndef WKG_H
+#define WKG_H
//postGIS: 3d geometries are encoded as in OGR by adding WKBZOFFSET to the type.
#define WKBZOFFSET 0x80000000
#define WKBMOFFSET 0x40000000
@@ -104,3 +105,4 @@
WKBGeometryCollection collection;
};
}WKBGeometry;
+#endif
Modified: trunk/wkgfunc.c
===================================================================
--- trunk/wkgfunc.c 2007-08-24 13:57:30 UTC (rev 6)
+++ trunk/wkgfunc.c 2007-08-24 15:20:12 UTC (rev 7)
@@ -5,24 +5,21 @@
#include <stdio.h>
#include <string.h>
-//#include <stdlib.h>
-#include <sqlite3ext.h>
-#include "wkg.h"
#include "wkgfunc.h"
+#include <sqlite3ext.h> // needed by portable sqlite-specific functions
-SQLITE_EXTENSION_INIT1
+SQLITE_EXTENSION_INIT1 // needed by portable sqlite-specific functions
-char *messages[5] = {
- "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];
+char *messages[6] = {
+ "ok" // 0
+ ,"unrecognized text type" // 1
+ ,"parse error" // 2
+ ,"unrecognized geometry type" // 3
+ ,"unable to convert from blob" // 4
+ ,"geometry is not a point" // 5
};
-//char debug[50];
void swap_char(char *a,char *b){
char c;
@@ -49,7 +46,7 @@
*
* @return integer error code
*/
-int FromText(char *pWKT, WKBGeometry *pGeom){
+int fromText(char *pWKT, WKBGeometry *pGeom){
int len, i;
char *pType;
char *pContent;
@@ -118,8 +115,8 @@
*
* @return as pWKT
*/
-char* AsText(WKBGeometry *pGeom){
- int len, i;
+char* asText(WKBGeometry *pGeom){
+ int len;
char *pWKT;
//char *sBuffer;
@@ -159,7 +156,7 @@
*
* @return integer error code
*/
-int FromBinary(unsigned char *pBin, WKBGeometry *pGeom){
+int fromBinary(unsigned char *pBin, WKBGeometry *pGeom){
int bBigendian;
uint32 wkbType;
int size, sizedbl=sizeof(double);
@@ -205,8 +202,8 @@
*
* @return pointer to unsigned char to be filled
*/
-unsigned char* AsBinary(WKBGeometry* pGeom){
- int dim, i;
+unsigned char* asBinary(WKBGeometry* pGeom){
+ int dim;
unsigned char *pBuffer;
unsigned char *pChar;
Modified: trunk/wkgfunc.h
===================================================================
--- trunk/wkgfunc.h 2007-08-24 13:57:30 UTC (rev 6)
+++ trunk/wkgfunc.h 2007-08-24 15:20:12 UTC (rev 7)
@@ -1,3 +1,5 @@
+#ifndef WKGGFUNC_H
+#define WKGFUNC_H
#include "wkg.h"
void swap_char(char *a,char *b);
@@ -6,11 +8,13 @@
void flip_endian_int32(char *i);
-int FromText(char *pWKT, WKBGeometry *pGeom);
+int fromText(char *pWKT, WKBGeometry *pGeom);
-char* AsText(WKBGeometry *pGeom);
+char* asText(WKBGeometry *pGeom);
-int FromBinary(unsigned char *pBin, WKBGeometry *pGeom);
+int fromBinary(unsigned char *pBin, WKBGeometry *pGeom);
-unsigned char* AsBinary(WKBGeometry* pGeom);
+unsigned char* asBinary(WKBGeometry* pGeom);
+extern char *messages[];
+#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cto...@us...> - 2007-08-24 13:57:33
|
Revision: 6
http://gislite.svn.sourceforge.net/gislite/?rev=6&view=rev
Author: ctomasin
Date: 2007-08-24 06:57:30 -0700 (Fri, 24 Aug 2007)
Log Message:
-----------
Modified @param structural commands in comments
Modified Paths:
--------------
trunk/sqlfunc.c
trunk/wkgfunc.c
Modified: trunk/sqlfunc.c
===================================================================
--- trunk/sqlfunc.c 2007-08-24 11:15:19 UTC (rev 5)
+++ trunk/sqlfunc.c 2007-08-24 13:57:30 UTC (rev 6)
@@ -10,7 +10,7 @@
* sqlite> SELECT (toWKT(BLOB_POINT)) FROM testGeom WHERE INDEX=1;
* sqlite> POINT(1.1 1.2 1.3 4.4)
*
- * @param blob well-known binary to sqlite by its own function
+ * @param argv blob well-known binary to sqlite by its own function
*
* @return string geometry as well-known text
*/
@@ -55,7 +55,7 @@
* Ex:
* sqlite> INSERT INTO testGeom (BLOB_POINT) VALUES (toWKB('POINT(1.2 1.3 1.4 1.5)'));
*
- * @param string geometry as well-known text
+ * @param argv string geometry as well-known text
*
* @return blob well-known binary to sqlite by its own function
*/
@@ -100,7 +100,7 @@
* sqlite> SELECT X(BLOB_POINT) FROM testGeom WHERE INDEX=1;
* sqlite> 5.8926358638273
*
- * @param blob containing WKBGeometry
+ * @param argv blob containing WKBGeometry
*
* @return double x coordinate
*/
@@ -133,7 +133,7 @@
* sqlite> SELECT Y(BLOB_POINT) FROM testGeom WHERE INDEX=1;
* sqlite> 1.2837445657488
*
- * @param blob containing WKBGeometry
+ * @param argv blob containing WKBGeometry
*
* @return double y coordinate
*/
@@ -165,7 +165,7 @@
* sqlite> SELECT Z(BLOB_POINT) FROM testGeom WHERE INDEX=1;
* sqlite> 0.0
*
- * @param blob containing WKBGeometry
+ * @param argv blob containing WKBGeometry
*
* @return double z coordinate
*/
@@ -198,7 +198,7 @@
* sqlite> SELECT M(BLOB_POINT) FROM testGeom WHERE INDEX=1;
* sqlite> 5.0
*
- * @param blob containing WKBGeometry
+ * @param argv blob containing WKBGeometry
*
* @return double m value
*/
@@ -231,7 +231,7 @@
* sqlite> SELECT AsText(StartPoint(GeomFromBinary(BLOB_LINE))) FROM testGeom WHERE INDEX=1;
* sqlite> POINT(1.1 1.2 1.3 4.4)
*
- * @param WKBGeometry structure g containing LineString
+ * @param g WKBGeometry structure containing LineString
*
* @return WKBGeometry structure containing WKBPoint
*/
@@ -244,7 +244,7 @@
* sqlite> SELECT AsText(EndPoint(GeomFromBinary(BLOB_LINE))) FROM testGeom WHERE INDEX=1;
* sqlite> POINT(5.1 5.2 5.3 4.4)
*
- * @param WKBGeometry structure g containing LineString
+ * @param g WKBGeometry structure containing LineString
*
* @return WKBGeometry structure containing WKBPoint
*/
@@ -257,7 +257,7 @@
* sqlite> SELECT Length(GeomFromBinary(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
* sqlite> 5.8926358638273
*
- * @param WKBGeometry structure g containing LineString
+ * @param g WKBGeometry structure containing LineString
*
* @return double length
*/
@@ -270,7 +270,7 @@
* sqlite> SELECT NumPoints(GeomFromBinary(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
* sqlite> 12
*
- * @param WKBGeometry structure g containing LineString
+ * @param g WKBGeometry structure containing LineString
*
* @return integer number of points
*/
@@ -283,8 +283,8 @@
* sqlite> SELECT AsText(PointN(GeomFromBinary(BLOB_LINE),10)) FROM testGeom WHERE INDEX=1;
* sqlite> POINT(1.1 1.2 0.0 0.0)
*
- * @param WKBGeometry structure g containing LineString
- * @param integer point position starting at 0
+ * @param g WKBGeometry structure containing LineString
+ * @param n integer point position starting at 0
*
* @return WKBGeometry structure containing WKBPoint
*/
@@ -298,7 +298,7 @@
* sqlite> SELECT IsRing(GeomFromBinary(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
* sqlite> 1
*
- * @param WKBGeometry structure g containing LineString
+ * @param g WKBGeometry structure containing LineString
*
* @return boolean 1 if LineString is a ring 0 if it is not, -1 if NULL
*/
Modified: trunk/wkgfunc.c
===================================================================
--- trunk/wkgfunc.c 2007-08-24 11:15:19 UTC (rev 5)
+++ trunk/wkgfunc.c 2007-08-24 13:57:30 UTC (rev 6)
@@ -44,8 +44,8 @@
}
/**
* function FromText
- * @param pointer to string in WKT encoding
- * @param pointer to WKGeometry to be filled
+ * @param pWKT pointer to string in WKT encoding
+ * @param pGeom pointer to WKGeometry to be filled
*
* @return integer error code
*/
@@ -113,9 +113,10 @@
/**
* function AsText
- * @param pointer to WKGeometry to be encoded
- *
- * @return pointer to string to be filled
+ * @param pGeom pointer to WKGeometry to be encoded
+ * @param pWKT pointer to string containing the text rapresentation created by the function
+ *
+ * @return as pWKT
*/
char* AsText(WKBGeometry *pGeom){
int len, i;
@@ -153,8 +154,8 @@
/**
* function FromBinary
- * @param pointer to unsigned char to be read
- * @param pointer to WKGeometry to be filled
+ * @param pBin pointer to unsigned char to be read
+ * @param pGeom pointer to WKGeometry to be filled
*
* @return integer error code
*/
@@ -200,7 +201,7 @@
/**
* function AsBinary
- * @param pointer to WKGeometry to be converted
+ * @param pGeom pointer to WKGeometry to be converted
*
* @return pointer to unsigned char to be filled
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cto...@us...> - 2007-08-24 11:15:16
|
Revision: 5
http://gislite.svn.sourceforge.net/gislite/?rev=5&view=rev
Author: ctomasin
Date: 2007-08-24 04:15:19 -0700 (Fri, 24 Aug 2007)
Log Message:
-----------
Added the configuration file used by doxygen to produce the documenttion automatically
Modified Paths:
--------------
trunk/sqlfunc.c
trunk/wkg.h
trunk/wkgfunc.c
Added Paths:
-----------
trunk/Doxyfile
Added: trunk/Doxyfile
===================================================================
--- trunk/Doxyfile (rev 0)
+++ trunk/Doxyfile 2007-08-24 11:15:19 UTC (rev 5)
@@ -0,0 +1,276 @@
+# Doxyfile 1.5.1
+#---------------------------------------------------------------------------
+# Project related configuration options
+# This file is part of the code managed by SVN, but the documentation generated
+# is not; documentation will be generated in a directory ../../doc on the same level of the directory containing the working copy so to not include the documentation in the source control management without the need of adding svn directives svn:ignore
+#---------------------------------------------------------------------------
+PROJECT_NAME = gislite
+PROJECT_NUMBER =
+OUTPUT_DIRECTORY = ../../doc/
+CREATE_SUBDIRS = NO
+OUTPUT_LANGUAGE = English
+USE_WINDOWS_ENCODING = NO
+BRIEF_MEMBER_DESC = YES
+REPEAT_BRIEF = YES
+ABBREVIATE_BRIEF = "The $name class" \
+ "The $name widget" \
+ "The $name file" \
+ is \
+ provides \
+ specifies \
+ contains \
+ represents \
+ a \
+ an \
+ the
+ALWAYS_DETAILED_SEC = NO
+INLINE_INHERITED_MEMB = NO
+FULL_PATH_NAMES = YES
+STRIP_FROM_PATH = ./
+STRIP_FROM_INC_PATH =
+SHORT_NAMES = NO
+JAVADOC_AUTOBRIEF = NO
+MULTILINE_CPP_IS_BRIEF = NO
+DETAILS_AT_TOP = NO
+INHERIT_DOCS = YES
+SEPARATE_MEMBER_PAGES = NO
+TAB_SIZE = 8
+ALIASES =
+OPTIMIZE_OUTPUT_FOR_C = YES
+OPTIMIZE_OUTPUT_JAVA = NO
+BUILTIN_STL_SUPPORT = NO
+DISTRIBUTE_GROUP_DOC = NO
+SUBGROUPING = YES
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+EXTRACT_ALL = NO
+EXTRACT_PRIVATE = YES
+EXTRACT_STATIC = YES
+EXTRACT_LOCAL_CLASSES = YES
+EXTRACT_LOCAL_METHODS = NO
+HIDE_UNDOC_MEMBERS = YES
+HIDE_UNDOC_CLASSES = YES
+HIDE_FRIEND_COMPOUNDS = NO
+HIDE_IN_BODY_DOCS = NO
+INTERNAL_DOCS = NO
+CASE_SENSE_NAMES = YES
+HIDE_SCOPE_NAMES = NO
+SHOW_INCLUDE_FILES = YES
+INLINE_INFO = YES
+SORT_MEMBER_DOCS = YES
+SORT_BRIEF_DOCS = NO
+SORT_BY_SCOPE_NAME = NO
+GENERATE_TODOLIST = YES
+GENERATE_TESTLIST = YES
+GENERATE_BUGLIST = YES
+GENERATE_DEPRECATEDLIST= YES
+ENABLED_SECTIONS =
+MAX_INITIALIZER_LINES = 30
+SHOW_USED_FILES = YES
+SHOW_DIRECTORIES = YES
+FILE_VERSION_FILTER =
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+QUIET = NO
+WARNINGS = YES
+WARN_IF_UNDOCUMENTED = YES
+WARN_IF_DOC_ERROR = YES
+WARN_NO_PARAMDOC = NO
+WARN_FORMAT = "$file:$line: $text"
+WARN_LOGFILE =
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+INPUT = ./
+FILE_PATTERNS = *.c \
+ *.cc \
+ *.cxx \
+ *.cpp \
+ *.c++ \
+ *.d \
+ *.java \
+ *.ii \
+ *.ixx \
+ *.ipp \
+ *.i++ \
+ *.inl \
+ *.h \
+ *.hh \
+ *.hxx \
+ *.hpp \
+ *.h++ \
+ *.idl \
+ *.odl \
+ *.cs \
+ *.php \
+ *.php3 \
+ *.inc \
+ *.m \
+ *.mm \
+ *.dox \
+ *.py \
+ *.C \
+ *.CC \
+ *.C++ \
+ *.II \
+ *.I++ \
+ *.H \
+ *.HH \
+ *.H++ \
+ *.CS \
+ *.PHP \
+ *.PHP3 \
+ *.M \
+ *.MM \
+ *.PY
+RECURSIVE = YES
+EXCLUDE =
+EXCLUDE_SYMLINKS = NO
+EXCLUDE_PATTERNS =
+EXAMPLE_PATH =
+EXAMPLE_PATTERNS = *
+EXAMPLE_RECURSIVE = NO
+IMAGE_PATH =
+INPUT_FILTER =
+FILTER_PATTERNS =
+FILTER_SOURCE_FILES = NO
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+SOURCE_BROWSER = NO
+INLINE_SOURCES = NO
+STRIP_CODE_COMMENTS = YES
+REFERENCED_BY_RELATION = NO
+REFERENCES_RELATION = NO
+REFERENCES_LINK_SOURCE = YES
+USE_HTAGS = NO
+VERBATIM_HEADERS = NO
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+ALPHABETICAL_INDEX = NO
+COLS_IN_ALPHA_INDEX = 5
+IGNORE_PREFIX =
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+GENERATE_HTML = YES
+HTML_OUTPUT = html
+HTML_FILE_EXTENSION = .html
+HTML_HEADER =
+HTML_FOOTER =
+HTML_STYLESHEET =
+HTML_ALIGN_MEMBERS = YES
+GENERATE_HTMLHELP = NO
+CHM_FILE =
+HHC_LOCATION =
+GENERATE_CHI = NO
+BINARY_TOC = NO
+TOC_EXPAND = NO
+DISABLE_INDEX = NO
+ENUM_VALUES_PER_LINE = 4
+GENERATE_TREEVIEW = NO
+TREEVIEW_WIDTH = 250
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+GENERATE_LATEX = NO
+LATEX_OUTPUT = latex
+LATEX_CMD_NAME = latex
+MAKEINDEX_CMD_NAME = makeindex
+COMPACT_LATEX = NO
+PAPER_TYPE = a4wide
+EXTRA_PACKAGES =
+LATEX_HEADER =
+PDF_HYPERLINKS = NO
+USE_PDFLATEX = NO
+LATEX_BATCHMODE = NO
+LATEX_HIDE_INDICES = NO
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+GENERATE_RTF = NO
+RTF_OUTPUT = rtf
+COMPACT_RTF = NO
+RTF_HYPERLINKS = NO
+RTF_STYLESHEET_FILE =
+RTF_EXTENSIONS_FILE =
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+GENERATE_MAN = NO
+MAN_OUTPUT = man
+MAN_EXTENSION = .3
+MAN_LINKS = NO
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+GENERATE_XML = NO
+XML_OUTPUT = xml
+XML_SCHEMA =
+XML_DTD =
+XML_PROGRAMLISTING = YES
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+GENERATE_AUTOGEN_DEF = NO
+#---------------------------------------------------------------------------
+# configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+GENERATE_PERLMOD = NO
+PERLMOD_LATEX = NO
+PERLMOD_PRETTY = YES
+PERLMOD_MAKEVAR_PREFIX =
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+ENABLE_PREPROCESSING = YES
+MACRO_EXPANSION = NO
+EXPAND_ONLY_PREDEF = NO
+SEARCH_INCLUDES = YES
+INCLUDE_PATH =
+INCLUDE_FILE_PATTERNS =
+PREDEFINED =
+EXPAND_AS_DEFINED =
+SKIP_FUNCTION_MACROS = YES
+#---------------------------------------------------------------------------
+# Configuration::additions related to external references
+#---------------------------------------------------------------------------
+TAGFILES =
+GENERATE_TAGFILE =
+ALLEXTERNALS = NO
+EXTERNAL_GROUPS = YES
+PERL_PATH = /usr/bin/perl
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+CLASS_DIAGRAMS = NO
+HIDE_UNDOC_RELATIONS = YES
+HAVE_DOT = YES
+CLASS_GRAPH = YES
+COLLABORATION_GRAPH = YES
+GROUP_GRAPHS = YES
+UML_LOOK = NO
+TEMPLATE_RELATIONS = NO
+INCLUDE_GRAPH = YES
+INCLUDED_BY_GRAPH = YES
+CALL_GRAPH = NO
+CALLER_GRAPH = NO
+GRAPHICAL_HIERARCHY = YES
+DIRECTORY_GRAPH = YES
+DOT_IMAGE_FORMAT = png
+DOT_PATH =
+DOTFILE_DIRS =
+MAX_DOT_GRAPH_WIDTH = 1024
+MAX_DOT_GRAPH_HEIGHT = 1024
+MAX_DOT_GRAPH_DEPTH = 1000
+DOT_TRANSPARENT = NO
+DOT_MULTI_TARGETS = NO
+GENERATE_LEGEND = YES
+DOT_CLEANUP = YES
+#---------------------------------------------------------------------------
+# Configuration::additions related to the search engine
+#---------------------------------------------------------------------------
+SEARCHENGINE = NO
Modified: trunk/sqlfunc.c
===================================================================
--- trunk/sqlfunc.c 2007-08-24 10:41:27 UTC (rev 4)
+++ trunk/sqlfunc.c 2007-08-24 11:15:19 UTC (rev 5)
@@ -1,5 +1,5 @@
/**
- * @file sqlfunc.h
+ * @file sqlfunc.c
* Functions used from SQL interface
* */
Modified: trunk/wkg.h
===================================================================
--- trunk/wkg.h 2007-08-24 10:41:27 UTC (rev 4)
+++ trunk/wkg.h 2007-08-24 11:15:19 UTC (rev 5)
@@ -1,5 +1,5 @@
/**
- * wkg.h
+ * @file wkg.h
*
* Open Geospatial Consortium Well Known Binary Geometry
* as in: OGC 06-103r3 (8.2.8)
Modified: trunk/wkgfunc.c
===================================================================
--- trunk/wkgfunc.c 2007-08-24 10:41:27 UTC (rev 4)
+++ trunk/wkgfunc.c 2007-08-24 11:15:19 UTC (rev 5)
@@ -1,3 +1,8 @@
+/**
+ * @file wkgfunc.c
+ * Functions used to manage the WKGeometry structures.
+ * */
+
#include <stdio.h>
#include <string.h>
//#include <stdlib.h>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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.
|
|
From: <cto...@us...> - 2007-08-23 21:25:34
|
Revision: 3
http://gislite.svn.sourceforge.net/gislite/?rev=3&view=rev
Author: ctomasin
Date: 2007-08-23 14:25:37 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
The file gislite.c has been splitted into sqlfunc.c and wkgfunc.c to reflect the distinction between WGK management C functions (wkgfunc.c) and SQL callable functions (sqlfunc.c)
Added Paths:
-----------
trunk/sqlfunc.c
trunk/wkgfunc.c
trunk/wkgfunc.h
Removed Paths:
-------------
trunk/gislite.c
Deleted: trunk/gislite.c
===================================================================
--- trunk/gislite.c 2007-08-23 19:44:42 UTC (rev 2)
+++ trunk/gislite.c 2007-08-23 21:25:37 UTC (rev 3)
@@ -1,484 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-//#include <stdlib.h>
-#include <sqlite3ext.h>
-#include "wkg.h"
-
-
-SQLITE_EXTENSION_INIT1
-
-char *messages[5] = {
- "ok"
- ,"unrecognized text type"
- ,"parse error"
- ,"unrecognized geometry type"
- ,"unable to convert from blob"
-};
-
-//char debug[50];
-
-void swap_char(char *a,char *b){
- char c;
- c = *a;
- *a=*b;
- *b=c;
-}
-
-void flip_endian_double(char *d){
- swap_char(d+7, d);
- swap_char(d+6, d+1);
- swap_char(d+5, d+2);
- swap_char(d+4, d+3);
-}
-
-void flip_endian_int32(char *i){
- swap_char(i+3, i);
- swap_char(i+2, i+1);
-}
-
-
-/**
- * function AsText
- * @param pointer to WKGeometry to be encoded
- *
- * @return pointer to string to be filled
- */
-char* AsText(WKBGeometry *pGeom){
- int len, i;
- char *pWKT;
- //char *sBuffer;
-
- //create string by wkbType
- switch(pGeom->point.wkbType){
- case 3001: // wkbPoint
- //POINT(1.200000 1.300000 1.400000 1.500000)
- len = asprintf(&pWKT, "POINT(%lf %lf %lf %lf)"
- , pGeom->point.point.x
- , pGeom->point.point.y
- , pGeom->point.point.z
- , pGeom->point.point.m);
- break;
-
- case 3002: // wkbLineString
- //LINESTRING(0 0, 10 10, 20 25, 50 60)
- break;
-
- //POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))
- //MULTIPOINT(0 0, 20 20, 60 60)
- //MULTILINESTRING((10 10, 20 20), (15 15, 30 15))
- //MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)),((5 5,7 5,7 7,5 7, 5 5)))
- //GEOMETRYCOLLECTION(POINT(10 10), POINT(30 30), LINESTRING(15 15, 20 20))
-
- default:
- asprintf(&pWKT, "Error: %s", messages[4]);
- }
-
- return pWKT;
-}
-
-
-/**
- * function FromBinary
- * @param pointer to unsigned char to be read
- * @param pointer to WKGeometry to be filled
- *
- * @return integer error code
- */
-int FromBinary(unsigned char *pBin, WKBGeometry *pGeom){
- int bBigendian;
- uint32 wkbType;
- int size, sizedbl=sizeof(double);
-
- //determining endianness from first byte
- if (pBin[0] == '0') bBigendian = 1; // Big endian
- else bBigendian = 0; // Little endian
-
- //type
- memcpy(&wkbType, pBin+1, sizeof(uint32));
- //if(bBigendian) flip_endian_int32((char*)&wkbType);
-
- //set Geometry by wkbType
- switch(wkbType){
- case 3001: // wkbPoint
- pGeom->point.byteOrder = pBin[0];
- pGeom->point.wkbType = wkbType;
- //read coordinates from blob into WKBGeometry
- size = sizeof(byte) + sizeof(uint32);
- memcpy(&pGeom->point.point.x, pBin+size, sizedbl);
- size += sizedbl;
- memcpy(&pGeom->point.point.y, pBin+size, sizedbl);
- size += sizedbl;
- memcpy(&pGeom->point.point.z, pBin+size, sizedbl);
- size += sizedbl;
- memcpy(&pGeom->point.point.m, pBin+size, sizedbl);
- break;
-
- case 3002: // wkbLineString
- break;
-
- default:
- return 4;// "unable to convert from blob"
- }
-
- return 0;
-}
-
-
-
-/**
- * SQL function toWKT(b)
- * Returns a WKT openGis Geometry representation from a sqlite blob b.
- * Ex:
- * sqlite> SELECT (toWKT(BLOB_POINT)) FROM testGeom WHERE INDEX=1;
- * sqlite> POINT(1.1 1.2 1.3 4.4)
- *
- * @param blob well-known binary to sqlite by its own function
- *
- * @return string geometry as well-known text
- */
-static void toWKT(
- sqlite3_context *context,
- int argc,
- sqlite3_value **argv
-){
- unsigned char *pBlob;
- int error;
- char *pString;
- WKBGeometry Geom;
-
- //check for null values
- if(sqlite3_value_type(argv[0]) == SQLITE_NULL) return;
- //only if value type is BLOB
- switch( sqlite3_value_type(argv[0])){
- case SQLITE_BLOB:
- //get blob from argv
- pBlob = (unsigned char*) sqlite3_value_blob(argv[0]);
- //fill structure from blob
- error = 0;
- error = FromBinary(pBlob, &Geom);
- if(error) sqlite3_result_error(context, messages[error], -1);
- //convert to string
- pString = AsText(&Geom);
- break;
- default:
- sqlite3_result_error(context, messages[4], -1);
- }
-
- //write out results
- sqlite3_result_text(context, pString, -1, SQLITE_TRANSIENT);
-
- //free AsText allocated memory
- free(pString);
-}
-
-
-/**
- * function FromText
- * @param pointer to string in WKT encoding
- * @param pointer to WKGeometry to be filled
- *
- * @return integer error code
- */
-int FromText(char *pWKT, WKBGeometry *pGeom){
- int len, i;
- char *pType;
- char *pContent;
-
- //parse string passed as parameter
- //search first '('
- len = strlen(pWKT);
- for (i=0; pWKT[i]!='(' && i<=len; ++i) ;
- //test search result
- if(i<5 || i>=len) return 1;// "unrecognized text type"
- //copy geometry type
- pType = (char*)sqlite3_malloc((int)i+1);
- strncpy(pType, pWKT, i);
- //copy geometry content
- pContent = (char*)sqlite3_malloc((int)len-i);
- strncpy(pContent, pWKT+i, len-(i-1));
-
- //assigning structure to blob
- //POINT(1.1 1.2 1.3 1.4)
- if(strncmp(pType, "POINT", 5)==0){
- //fill geometry as point
- pGeom->point.byteOrder = (byte)'1';//little endian ... autoconf endianness
- pGeom->point.wkbType = (uint32)3001;
- if(sscanf(pContent+1, "%lf %lf %lf %lf",
- &pGeom->point.point.x,
- &pGeom->point.point.y,
- &pGeom->point.point.z,
- &pGeom->point.point.m)
- !=4){
- //free all allocated memory
- sqlite3_free((void*)pType);
- sqlite3_free((void*)pContent);
- return 2;//"parse error"
- }
- }
-
- //LINESTRING(1 1 1 1, 2 2 2 2, 3 3 3 3)
- else if(strncmp(pWKT,"LINESTRING", 10)==0){
- }
-
- //POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))
- //MULTIPOINT(0 0, 20 20, 60 60)
- //MULTILINESTRING((10 10, 20 20), (15 15, 30 15))
- //MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)),((5 5,7 5,7 7,5 7, 5 5)))
- //GEOMETRYCOLLECTION(POINT(10 10), POINT(30 30), LINESTRING(15 15, 20 20))
-
- //ERROR
- else{
- //free all allocated memory
- sqlite3_free((void*)pType);
- sqlite3_free((void*)pContent);
- return 3;// "unrecognized geometry type"
- }
-
- //free all allocated memory
- sqlite3_free((void*)pType);
- sqlite3_free((void*)pContent);
- return 0;
-}
-
-
-/**
- * function AsBinary
- * @param pointer to WKGeometry to be converted
- *
- * @return pointer to unsigned char to be filled
- */
-unsigned char* AsBinary(WKBGeometry* pGeom){
- int dim, i;
- unsigned char *pBuffer;
- unsigned char *pChar;
-
- //alloc by wkbType
- switch(pGeom->point.wkbType){
- case 3001: // wkbPoint
- dim = sizeof(WKBPoint);
- pBuffer = (unsigned char*)sqlite3_malloc(dim);
- memset(pBuffer, 0, dim);
- pChar = pBuffer;
- //fill Geometry
- memcpy(pChar, (unsigned char*)&pGeom->point.byteOrder, sizeof(byte));
- pChar += sizeof(byte);
- memcpy(pChar, &pGeom->point.wkbType, sizeof(uint32));
- pChar += sizeof(uint32);
- memcpy(pChar, &pGeom->point.point.x, sizeof(double));
- pChar += sizeof(double);
- memcpy(pChar, &pGeom->point.point.y, sizeof(double));
- pChar += sizeof(double);
- memcpy(pChar, &pGeom->point.point.z, sizeof(double));
- pChar += sizeof(double);
- memcpy(pChar, &pGeom->point.point.m, sizeof(double));
- break;
-
- case 3002: // wkbLineString
- //sprintf(debug,"2");
- break;
-
- default:
- pBuffer = NULL;// "unrecognized geometry type"
- //to be tested outside
- }
-
- return pBuffer;
-}
-
-
-/**
- * SQL function toWKB(t)
- * Returns a WKB blob from a WKT openGis Geometry representation t
- * Ex:
- * sqlite> INSERT INTO testGeom (BLOB_POINT) VALUES (toWKB('POINT(1.2 1.3 1.4 1.5)'));
- *
- * @param string geometry as well-known text
- *
- * @return blob well-known binary to sqlite by its own function
- */
-static void toWKB(
- sqlite3_context *context,
- int argc,
- sqlite3_value **argv
-){
- int error, sizeBin;
- char *pBuf;
- unsigned char *pBin;
- WKBGeometry Geom;
-
- //check for null values
- if(sqlite3_value_type(argv[0]) == SQLITE_NULL) return;
- //assign parameter
- pBuf = (char*)sqlite3_value_text(argv[0]);
-
- error = 0;
- error = FromText(pBuf, &Geom);
- if(error) sqlite3_result_error(context, messages[error], -1);
- //fill char array
- pBin = AsBinary(&Geom);
-//double tmp;
-//memcpy(&tmp, pBin+sizeof(byte)+sizeof(uint32)+sizeof(double),sizeof(double));
-//sprintf(debug,"bin: %lf",tmp);
-//sqlite3_result_error(context, debug, -1);
-
- //sizeBin = strlen((char*)pBin);
- sizeBin = sizeof(WKBGeometry);
- sqlite3_result_blob(context, pBin, sizeBin, SQLITE_TRANSIENT);
-
- //free memory allocated by asBinary()
- sqlite3_free((void*)pBin);
-}
-
-
-/**
- * SQL function X(g)
- * Returns the X-coordinate value for the WKBGeometry Point g as a double.
- * Ex:
- * sqlite> SELECT X(GeomFromBinary(BLOB_POINT)) FROM testGeom WHERE INDEX=1;
- * sqlite> 5.8926358638273
- *
- * @param WKBGeometry structure g containing Point
- *
- * @return double x coordinate
- */
-
-
-/**
- * SQL function Y(g)
- * Returns the Y-coordinate value for the WKBGeometry Point g as a double.
- * Ex:
- * sqlite> SELECT Y(GeomFromBinary(BLOB_POINT)) FROM testGeom WHERE INDEX=1;
- * sqlite> 1.2837445657488
- *
- * @param WKBGeometry structure g containing Point
- *
- * @return double y coordinate
- */
-
-
-/**
- * SQL function Z(g)
- * Returns the Z-coordinate value for the WKBGeometry Point g as a double.
- * Ex:
- * sqlite> SELECT Z(GeomFromBinary(BLOB_POINT)) FROM testGeom WHERE INDEX=1;
- * sqlite> 0.0
- *
- * @param WKBGeometry structure g containing Point
- *
- * @return double z coordinate
- */
-
-
-/**
- * SQL function M(g)
- * Returns the M-value for the WKBGeometry Point g as a double.
- * Ex:
- * sqlite> SELECT M(GeomFromBinary(BLOB_POINT)) FROM testGeom WHERE INDEX=1;
- * sqlite> 5.0
- *
- * @param WKBGeometry structure g containing Point
- *
- * @return double m value
- */
-
-
-
-/**
- * SQL function StartPoint(g)
- * Returns the start Point of a WKBGeometry LineString g.
- * Ex:
- * sqlite> SELECT AsText(StartPoint(GeomFromBinary(BLOB_LINE))) FROM testGeom WHERE INDEX=1;
- * sqlite> POINT(1.1 1.2 1.3 4.4)
- *
- * @param WKBGeometry structure g containing LineString
- *
- * @return WKBGeometry structure containing WKBPoint
- */
-
-
-/**
- * SQL function EndPoint(g)
- * Returns the end Point of a LineString.
- * Ex:
- * sqlite> SELECT AsText(EndPoint(GeomFromBinary(BLOB_LINE))) FROM testGeom WHERE INDEX=1;
- * sqlite> POINT(5.1 5.2 5.3 4.4)
- *
- * @param WKBGeometry structure g containing LineString
- *
- * @return WKBGeometry structure containing WKBPoint
- */
-
-
-/**
- * SQL function Length(g)
- * Returns the length of the LineString geometry g as double.
- * Ex:
- * sqlite> SELECT Length(GeomFromBinary(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
- * sqlite> 5.8926358638273
- *
- * @param WKBGeometry structure g containing LineString
- *
- * @return double length
- */
-
-
-/**
- * SQL function NumPoints(g)
- * Returns the number of points in the WKBGeometry LineString g.
- * Ex:
- * sqlite> SELECT NumPoints(GeomFromBinary(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
- * sqlite> 12
- *
- * @param WKBGeometry structure g containing LineString
- *
- * @return integer number of points
- */
-
-
-/**
- * SQL function PointN(g, n)
- * Returns the n-th point in the WKBGeometry Linestring g. Point numbers begin at 0.
- * Ex:
- * sqlite> SELECT AsText(PointN(GeomFromBinary(BLOB_LINE),10)) FROM testGeom WHERE INDEX=1;
- * sqlite> POINT(1.1 1.2 0.0 0.0)
- *
- * @param WKBGeometry structure g containing LineString
- * @param integer point position starting at 0
- *
- * @return WKBGeometry structure containing WKBPoint
- */
-
-
-/**
- * SQL function IsRing(g)
- * Returns 1 if the WKBGeometry LineString g is closed and is simple.
- * Returns 0 if ls is not a ring, and -1 if it is NULL.
- * Ex:
- * sqlite> SELECT IsRing(GeomFromBinary(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
- * sqlite> 1
- *
- * @param WKBGeometry structure g containing LineString
- *
- * @return boolean 1 if LineString is a ring 0 if it is not, -1 if NULL
- */
-
-
-
-/*
- * sqlite functions linking
- */
-int sqlite3_extension_init(
- sqlite3 *db,
- char **pzErrMsg,
- const sqlite3_api_routines *pApi
-){
- 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);
- return 0;
-}
-
Added: trunk/sqlfunc.c
===================================================================
--- trunk/sqlfunc.c (rev 0)
+++ trunk/sqlfunc.c 2007-08-23 21:25:37 UTC (rev 3)
@@ -0,0 +1,242 @@
+/**
+ * SQL function toWKT(b)
+ * Returns a WKT openGis Geometry representation from a sqlite blob b.
+ * Ex:
+ * sqlite> SELECT (toWKT(BLOB_POINT)) FROM testGeom WHERE INDEX=1;
+ * sqlite> POINT(1.1 1.2 1.3 4.4)
+ *
+ * @param blob well-known binary to sqlite by its own function
+ *
+ * @return string geometry as well-known text
+ */
+static void toWKT(
+ sqlite3_context *context,
+ int argc,
+ sqlite3_value **argv
+){
+ unsigned char *pBlob;
+ int error;
+ char *pString;
+ WKBGeometry Geom;
+
+ //check for null values
+ if(sqlite3_value_type(argv[0]) == SQLITE_NULL) return;
+ //only if value type is BLOB
+ switch( sqlite3_value_type(argv[0])){
+ case SQLITE_BLOB:
+ //get blob from argv
+ pBlob = (unsigned char*) sqlite3_value_blob(argv[0]);
+ //fill structure from blob
+ error = 0;
+ error = FromBinary(pBlob, &Geom);
+ if(error) sqlite3_result_error(context, messages[error], -1);
+ //convert to string
+ pString = AsText(&Geom);
+ break;
+ default:
+ sqlite3_result_error(context, messages[4], -1);
+ }
+
+ //write out results
+ sqlite3_result_text(context, pString, -1, SQLITE_TRANSIENT);
+
+ //free AsText allocated memory
+ free(pString);
+}
+
+/**
+ * SQL function toWKB(t)
+ * Returns a WKB blob from a WKT openGis Geometry representation t
+ * Ex:
+ * sqlite> INSERT INTO testGeom (BLOB_POINT) VALUES (toWKB('POINT(1.2 1.3 1.4 1.5)'));
+ *
+ * @param string geometry as well-known text
+ *
+ * @return blob well-known binary to sqlite by its own function
+ */
+static void toWKB(
+ sqlite3_context *context,
+ int argc,
+ sqlite3_value **argv
+){
+ int error, sizeBin;
+ char *pBuf;
+ unsigned char *pBin;
+ WKBGeometry Geom;
+
+ //check for null values
+ if(sqlite3_value_type(argv[0]) == SQLITE_NULL) return;
+ //assign parameter
+ pBuf = (char*)sqlite3_value_text(argv[0]);
+
+ error = 0;
+ error = FromText(pBuf, &Geom);
+ if(error) sqlite3_result_error(context, messages[error], -1);
+ //fill char array
+ pBin = AsBinary(&Geom);
+//double tmp;
+//memcpy(&tmp, pBin+sizeof(byte)+sizeof(uint32)+sizeof(double),sizeof(double));
+//sprintf(debug,"bin: %lf",tmp);
+//sqlite3_result_error(context, debug, -1);
+
+ //sizeBin = strlen((char*)pBin);
+ sizeBin = sizeof(WKBGeometry);
+ sqlite3_result_blob(context, pBin, sizeBin, SQLITE_TRANSIENT);
+
+ //free memory allocated by asBinary()
+ sqlite3_free((void*)pBin);
+}
+
+
+/**
+ * SQL function X(b)
+ * Returns the X-coordinate value for the BLOB b as a double.
+ * Ex:
+ * sqlite> SELECT X(BLOB_POINT) FROM testGeom WHERE INDEX=1;
+ * sqlite> 5.8926358638273
+ *
+ * @param BLOB containing a WKBGeometry
+ *
+ * @return double x coordinate
+ */
+
+
+/**
+ * SQL function Y(b)
+ * Returns the Y-coordinate value for the BLOB b as a double.
+ * Ex:
+ * sqlite> SELECT Y(BLOB_POINT) FROM testGeom WHERE INDEX=1;
+ * sqlite> 1.2837445657488
+ *
+ * @param BLOB containing a WKBGeometry
+ *
+ * @return double y coordinate
+ */
+
+
+/**
+ * SQL function Z(b)
+ * Returns the Z-coordinate value for the BLOB b as a double.
+ * Ex:
+ * sqlite> SELECT Z(BLOB_POINT) FROM testGeom WHERE INDEX=1;
+ * sqlite> 0.0
+ *
+ * @param BLOB containing a WKBGeometry
+ *
+ * @return double z coordinate
+ */
+
+
+/**
+ * SQL function M(b)
+ * Returns the M-value for the BLOB b as a double.
+ * Ex:
+ * sqlite> SELECT M(BLOB_POINT) FROM testGeom WHERE INDEX=1;
+ * sqlite> 5.0
+ *
+ * @param BLOB containing a WKBGeometry
+ *
+ * @return double m value
+ */
+
+
+
+/**
+ * SQL function StartPoint(g)
+ * Returns the start Point of a WKBGeometry LineString g.
+ * Ex:
+ * sqlite> SELECT AsText(StartPoint(GeomFromBinary(BLOB_LINE))) FROM testGeom WHERE INDEX=1;
+ * sqlite> POINT(1.1 1.2 1.3 4.4)
+ *
+ * @param WKBGeometry structure g containing LineString
+ *
+ * @return WKBGeometry structure containing WKBPoint
+ */
+
+
+/**
+ * SQL function EndPoint(g)
+ * Returns the end Point of a LineString.
+ * Ex:
+ * sqlite> SELECT AsText(EndPoint(GeomFromBinary(BLOB_LINE))) FROM testGeom WHERE INDEX=1;
+ * sqlite> POINT(5.1 5.2 5.3 4.4)
+ *
+ * @param WKBGeometry structure g containing LineString
+ *
+ * @return WKBGeometry structure containing WKBPoint
+ */
+
+
+/**
+ * SQL function Length(g)
+ * Returns the length of the LineString geometry g as double.
+ * Ex:
+ * sqlite> SELECT Length(GeomFromBinary(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
+ * sqlite> 5.8926358638273
+ *
+ * @param WKBGeometry structure g containing LineString
+ *
+ * @return double length
+ */
+
+
+/**
+ * SQL function NumPoints(g)
+ * Returns the number of points in the WKBGeometry LineString g.
+ * Ex:
+ * sqlite> SELECT NumPoints(GeomFromBinary(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
+ * sqlite> 12
+ *
+ * @param WKBGeometry structure g containing LineString
+ *
+ * @return integer number of points
+ */
+
+
+/**
+ * SQL function PointN(g, n)
+ * Returns the n-th point in the WKBGeometry Linestring g. Point numbers begin at 0.
+ * Ex:
+ * sqlite> SELECT AsText(PointN(GeomFromBinary(BLOB_LINE),10)) FROM testGeom WHERE INDEX=1;
+ * sqlite> POINT(1.1 1.2 0.0 0.0)
+ *
+ * @param WKBGeometry structure g containing LineString
+ * @param integer point position starting at 0
+ *
+ * @return WKBGeometry structure containing WKBPoint
+ */
+
+
+/**
+ * SQL function IsRing(g)
+ * Returns 1 if the WKBGeometry LineString g is closed and is simple.
+ * Returns 0 if ls is not a ring, and -1 if it is NULL.
+ * Ex:
+ * sqlite> SELECT IsRing(GeomFromBinary(BLOB_LINE)) FROM testGeom WHERE INDEX=1;
+ * sqlite> 1
+ *
+ * @param WKBGeometry structure g containing LineString
+ *
+ * @return boolean 1 if LineString is a ring 0 if it is not, -1 if NULL
+ */
+
+
+
+/*
+ * sqlite functions linking
+ */
+int sqlite3_extension_init(
+ sqlite3 *db,
+ char **pzErrMsg,
+ const sqlite3_api_routines *pApi
+){
+ 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);
+ return 0;
+}
+
Copied: trunk/wkgfunc.c (from rev 2, trunk/gislite.c)
===================================================================
--- trunk/wkgfunc.c (rev 0)
+++ trunk/wkgfunc.c 2007-08-23 21:25:37 UTC (rev 3)
@@ -0,0 +1,238 @@
+#include <stdio.h>
+#include <string.h>
+//#include <stdlib.h>
+#include <sqlite3ext.h>
+#include "wkg.h"
+#include "wkgfunc.h"
+
+SQLITE_EXTENSION_INIT1
+
+char *messages[5] = {
+ "ok"
+ ,"unrecognized text type"
+ ,"parse error"
+ ,"unrecognized geometry type"
+ ,"unable to convert from blob"
+};
+
+//char debug[50];
+
+void swap_char(char *a,char *b){
+ char c;
+ c = *a;
+ *a=*b;
+ *b=c;
+}
+
+void flip_endian_double(char *d){
+ swap_char(d+7, d);
+ swap_char(d+6, d+1);
+ swap_char(d+5, d+2);
+ swap_char(d+4, d+3);
+}
+
+void flip_endian_int32(char *i){
+ swap_char(i+3, i);
+ swap_char(i+2, i+1);
+}
+/**
+ * function FromText
+ * @param pointer to string in WKT encoding
+ * @param pointer to WKGeometry to be filled
+ *
+ * @return integer error code
+ */
+int FromText(char *pWKT, WKBGeometry *pGeom){
+ int len, i;
+ char *pType;
+ char *pContent;
+
+ //parse string passed as parameter
+ //search first '('
+ len = strlen(pWKT);
+ for (i=0; pWKT[i]!='(' && i<=len; ++i) ;
+ //test search result
+ if(i<5 || i>=len) return 1;// "unrecognized text type"
+ //copy geometry type
+ pType = (char*)sqlite3_malloc((int)i+1);
+ strncpy(pType, pWKT, i);
+ //copy geometry content
+ pContent = (char*)sqlite3_malloc((int)len-i);
+ strncpy(pContent, pWKT+i, len-(i-1));
+
+ //assigning structure to blob
+ //POINT(1.1 1.2 1.3 1.4)
+ if(strncmp(pType, "POINT", 5)==0){
+ //fill geometry as point
+ pGeom->point.byteOrder = (byte)'1';//little endian ... autoconf endianness
+ pGeom->point.wkbType = (uint32)3001;
+ if(sscanf(pContent+1, "%lf %lf %lf %lf",
+ &pGeom->point.point.x,
+ &pGeom->point.point.y,
+ &pGeom->point.point.z,
+ &pGeom->point.point.m)
+ !=4){
+ //free all allocated memory
+ sqlite3_free((void*)pType);
+ sqlite3_free((void*)pContent);
+ return 2;//"parse error"
+ }
+ }
+
+ //LINESTRING(1 1 1 1, 2 2 2 2, 3 3 3 3)
+ else if(strncmp(pWKT,"LINESTRING", 10)==0){
+ }
+
+ //POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))
+ //MULTIPOINT(0 0, 20 20, 60 60)
+ //MULTILINESTRING((10 10, 20 20), (15 15, 30 15))
+ //MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)),((5 5,7 5,7 7,5 7, 5 5)))
+ //GEOMETRYCOLLECTION(POINT(10 10), POINT(30 30), LINESTRING(15 15, 20 20))
+
+ //ERROR
+ else{
+ //free all allocated memory
+ sqlite3_free((void*)pType);
+ sqlite3_free((void*)pContent);
+ return 3;// "unrecognized geometry type"
+ }
+
+ //free all allocated memory
+ sqlite3_free((void*)pType);
+ sqlite3_free((void*)pContent);
+ return 0;
+}
+
+
+/**
+ * function AsText
+ * @param pointer to WKGeometry to be encoded
+ *
+ * @return pointer to string to be filled
+ */
+char* AsText(WKBGeometry *pGeom){
+ int len, i;
+ char *pWKT;
+ //char *sBuffer;
+
+ //create string by wkbType
+ switch(pGeom->point.wkbType){
+ case 3001: // wkbPoint
+ //POINT(1.200000 1.300000 1.400000 1.500000)
+ len = asprintf(&pWKT, "POINT(%lf %lf %lf %lf)"
+ , pGeom->point.point.x
+ , pGeom->point.point.y
+ , pGeom->point.point.z
+ , pGeom->point.point.m);
+ break;
+
+ case 3002: // wkbLineString
+ //LINESTRING(0 0, 10 10, 20 25, 50 60)
+ break;
+
+ //POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))
+ //MULTIPOINT(0 0, 20 20, 60 60)
+ //MULTILINESTRING((10 10, 20 20), (15 15, 30 15))
+ //MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)),((5 5,7 5,7 7,5 7, 5 5)))
+ //GEOMETRYCOLLECTION(POINT(10 10), POINT(30 30), LINESTRING(15 15, 20 20))
+
+ default:
+ asprintf(&pWKT, "Error: %s", messages[4]);
+ }
+
+ return pWKT;
+}
+
+
+/**
+ * function FromBinary
+ * @param pointer to unsigned char to be read
+ * @param pointer to WKGeometry to be filled
+ *
+ * @return integer error code
+ */
+int FromBinary(unsigned char *pBin, WKBGeometry *pGeom){
+ int bBigendian;
+ uint32 wkbType;
+ int size, sizedbl=sizeof(double);
+
+ //determining endianness from first byte
+ if (pBin[0] == '0') bBigendian = 1; // Big endian
+ else bBigendian = 0; // Little endian
+
+ //type
+ memcpy(&wkbType, pBin+1, sizeof(uint32));
+ //if(bBigendian) flip_endian_int32((char*)&wkbType);
+
+ //set Geometry by wkbType
+ switch(wkbType){
+ case 3001: // wkbPoint
+ pGeom->point.byteOrder = pBin[0];
+ pGeom->point.wkbType = wkbType;
+ //read coordinates from blob into WKBGeometry
+ size = sizeof(byte) + sizeof(uint32);
+ memcpy(&pGeom->point.point.x, pBin+size, sizedbl);
+ size += sizedbl;
+ memcpy(&pGeom->point.point.y, pBin+size, sizedbl);
+ size += sizedbl;
+ memcpy(&pGeom->point.point.z, pBin+size, sizedbl);
+ size += sizedbl;
+ memcpy(&pGeom->point.point.m, pBin+size, sizedbl);
+ break;
+
+ case 3002: // wkbLineString
+ break;
+
+ default:
+ return 4;// "unable to convert from blob"
+ }
+
+ return 0;
+}
+
+
+/**
+ * function AsBinary
+ * @param pointer to WKGeometry to be converted
+ *
+ * @return pointer to unsigned char to be filled
+ */
+unsigned char* AsBinary(WKBGeometry* pGeom){
+ int dim, i;
+ unsigned char *pBuffer;
+ unsigned char *pChar;
+
+ //alloc by wkbType
+ switch(pGeom->point.wkbType){
+ case 3001: // wkbPoint
+ dim = sizeof(WKBPoint);
+ pBuffer = (unsigned char*)sqlite3_malloc(dim);
+ memset(pBuffer, 0, dim);
+ pChar = pBuffer;
+ //fill Geometry
+ memcpy(pChar, (unsigned char*)&pGeom->point.byteOrder, sizeof(byte));
+ pChar += sizeof(byte);
+ memcpy(pChar, &pGeom->point.wkbType, sizeof(uint32));
+ pChar += sizeof(uint32);
+ memcpy(pChar, &pGeom->point.point.x, sizeof(double));
+ pChar += sizeof(double);
+ memcpy(pChar, &pGeom->point.point.y, sizeof(double));
+ pChar += sizeof(double);
+ memcpy(pChar, &pGeom->point.point.z, sizeof(double));
+ pChar += sizeof(double);
+ memcpy(pChar, &pGeom->point.point.m, sizeof(double));
+ break;
+
+ case 3002: // wkbLineString
+ //sprintf(debug,"2");
+ break;
+
+ default:
+ pBuffer = NULL;// "unrecognized geometry type"
+ //to be tested outside
+ }
+
+ return pBuffer;
+}
+
+
Added: trunk/wkgfunc.h
===================================================================
--- trunk/wkgfunc.h (rev 0)
+++ trunk/wkgfunc.h 2007-08-23 21:25:37 UTC (rev 3)
@@ -0,0 +1,16 @@
+#include "wkg.h"
+
+void swap_char(char *a,char *b);
+
+void flip_endian_double(char *d);
+
+void flip_endian_int32(char *i);
+
+int FromText(char *pWKT, WKBGeometry *pGeom);
+
+char* AsText(WKBGeometry *pGeom);
+
+int FromBinary(unsigned char *pBin, WKBGeometry *pGeom);
+
+unsigned char* AsBinary(WKBGeometry* pGeom);
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|