[Gislite-admins] SF.net SVN: gislite: [12] trunk
Status: Planning
Brought to you by:
ctomasin
|
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.
|