From c3926679e056452830aa8ba1fd20b162dbb669d2 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 7 Oct 2010 23:08:50 +0000 Subject: =?UTF-8?q?=E2=80=A2=20spatial=20field=20support=20-=20fixed=20iss?= =?UTF-8?q?ue=20while=20editing=20geometry=20data=20in=20Content=20View;?= =?UTF-8?q?=20once=20a=20geometry=20field=20was=20edited=20it=20will=20be?= =?UTF-8?q?=20stored=20as=20NSString,=20if=20not=20it=20keeps=20a=20MCPGeo?= =?UTF-8?q?metryData=20-=20some=20code=20cosmetics=20and=20commenting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MCPKit/MCPFoundationKit/MCPGeometryData.m | 93 +++++++++++++++------- Source/SPTableContent.m | 2 +- 2 files changed, 65 insertions(+), 30 deletions(-) diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPGeometryData.m b/Frameworks/MCPKit/MCPFoundationKit/MCPGeometryData.m index 6a41e657..172596a0 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPGeometryData.m +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPGeometryData.m @@ -32,8 +32,9 @@ @implementation MCPGeometryData -- (id)copyWithZone:(NSZone *)zone { return [self retain]; } - +/** + * Initialize the MCPGeometryData object + */ - (id)init { if ((self = [super init])) { @@ -43,6 +44,9 @@ return self; } +/** + * Initialize the MCPGeometryData object with the WKB data + */ - (id)initWithBytes:(Byte*)geoData length:(NSUInteger)length { if ((self = [self init])) { @@ -53,40 +57,64 @@ return self; } - +/** + * Return an autorelease MCPGeometryData object + */ + (id)dataWithBytes:(Byte*)geoData length:(NSUInteger)length { return [[[MCPGeometryData alloc] initWithBytes:geoData length:length] autorelease]; } +/** + * copyWithZone + */ +- (id)copyWithZone:(NSZone *)zone +{ + return [self retain]; +} + +/** + * Return the hex representation of the WKB buffer (only for convenience) + */ - (NSString*)description { return [[NSData dataWithBytes:geoBuffer length:bufferLength] description]; } +/** + * Return the length of the WKB buffer + */ - (NSUInteger)length { return bufferLength; } +/** + * Return NSData pointer of the WKB buffer + */ - (NSData*)data { return [NSData dataWithBytes:geoBuffer length:bufferLength]; } +/** + * Return a human readable WKT string of the internal format (it imitate the SQL function AsText()). + */ - (NSString*)wktString { + char byteOrder; - UInt32 geoType, c, c1; + UInt32 geoType, numberOfItems, numberOfSubItems; st_point_2d aPoint; - NSUInteger ptr; - double x, y; + + NSUInteger ptr, i, j; + NSMutableString *wkt = [NSMutableString string]; - NSUInteger i,j; - BOOL raw = NO; + + BOOL raw = NO; // is needed later if (bufferLength < WKB_HEADER_SIZE) - return @"Error"; + return @"Header Error"; ptr = (raw) ? 0 : 4; @@ -99,81 +127,88 @@ geoType = geoBuffer[ptr]; ptr += SIZEOF_STORED_UINT32; - NSData *d; switch(geoType) { + case wkb_point: memcpy(&aPoint, &geoBuffer[ptr], POINT_DATA_SIZE); - return [NSString stringWithFormat:@"POINT(%.16g %.16g)",aPoint.x, aPoint.y]; + return [NSString stringWithFormat:@"POINT(%.16g %.16g)", aPoint.x, aPoint.y]; break; + case wkb_linestring: [wkt setString:@"LINESTRING("]; - c = geoBuffer[ptr]; + numberOfItems = geoBuffer[ptr]; ptr += SIZEOF_STORED_UINT32; - for(i=0; i