aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPGeometryData.m149
-rw-r--r--Source/SPGeometryDataView.h17
-rw-r--r--Source/SPGeometryDataView.m98
3 files changed, 153 insertions, 111 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPGeometryData.m b/Frameworks/MCPKit/MCPFoundationKit/MCPGeometryData.m
index b46a0dc7..1bf8c471 100644
--- a/Frameworks/MCPKit/MCPFoundationKit/MCPGeometryData.m
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPGeometryData.m
@@ -427,7 +427,7 @@
[NSNumber numberWithDouble:y_min],
[NSNumber numberWithDouble:y_max],
nil], @"bbox",
- coordinates, @"coordinates",
+ [NSArray arrayWithObjects:coordinates,nil], @"coordinates",
@"LINESTRING", @"type",
nil];
break;
@@ -462,64 +462,95 @@
nil];
break;
- // case wkb_multipoint:
- // [wkt setString:@"MULTIPOINT("];
- // numberOfItems = geoBuffer[ptr];
- // ptr += SIZEOF_STORED_UINT32+WKB_HEADER_SIZE;
- // for(i=0; i < numberOfItems; i++) {
- // memcpy(&aPoint, &geoBuffer[ptr], POINT_DATA_SIZE);
- // [wkt appendFormat:@"%.16g %.16g%@", aPoint.x, aPoint.y, (i < numberOfItems-1) ? @"," : @""];
- // ptr += POINT_DATA_SIZE+WKB_HEADER_SIZE;
- // }
- // [wkt appendString:@")"];
- // return wkt;
- // break;
- //
- // case wkb_multilinestring:
- // [wkt setString:@"MULTILINESTRING("];
- // numberOfItems = geoBuffer[ptr];
- // ptr += SIZEOF_STORED_UINT32+WKB_HEADER_SIZE;
- // for(i=0; i < numberOfItems; i++) {
- // numberOfSubItems = geoBuffer[ptr];
- // ptr += SIZEOF_STORED_UINT32;
- // [wkt appendString:@"("];
- // for(j=0; j < numberOfSubItems; j++) {
- // memcpy(&aPoint, &geoBuffer[ptr], POINT_DATA_SIZE);
- // [wkt appendFormat:@"%.16g %.16g%@", aPoint.x, aPoint.y, (j < numberOfSubItems-1) ? @"," : @""];
- // ptr += POINT_DATA_SIZE;
- // }
- // ptr += WKB_HEADER_SIZE;
- // [wkt appendFormat:@")%@", (i < numberOfItems-1) ? @"," : @""];
- // }
- // [wkt appendString:@")"];
- // return wkt;
- // break;
- //
- // case wkb_multipolygon:
- // [wkt setString:@"MULTIPOLYGON("];
- // numberOfItems = geoBuffer[ptr];
- // ptr += SIZEOF_STORED_UINT32+WKB_HEADER_SIZE;
- // for(i=0; i < numberOfItems; i++) {
- // numberOfSubItems = geoBuffer[ptr];
- // ptr += SIZEOF_STORED_UINT32;
- // [wkt appendString:@"("];
- // for(j=0; j < numberOfSubItems; j++) {
- // numberOfSubSubItems = geoBuffer[ptr];
- // ptr += SIZEOF_STORED_UINT32;
- // [wkt appendString:@"("];
- // for(k=0; k < numberOfSubSubItems; k++) {
- // memcpy(&aPoint, &geoBuffer[ptr], POINT_DATA_SIZE);
- // [wkt appendFormat:@"%.16g %.16g%@", aPoint.x, aPoint.y, (k < numberOfSubSubItems-1) ? @"," : @""];
- // ptr += POINT_DATA_SIZE;
- // }
- // [wkt appendFormat:@")%@", (j < numberOfSubItems-1) ? @"," : @""];
- // }
- // ptr += WKB_HEADER_SIZE;
- // [wkt appendFormat:@")%@", (i < numberOfItems-1) ? @"," : @""];
- // }
- // [wkt appendString:@")"];
- // return wkt;
- // break;
+ case wkb_multipoint:
+ numberOfItems = geoBuffer[ptr];
+ ptr += SIZEOF_STORED_UINT32+WKB_HEADER_SIZE;
+ for(i=0; i < numberOfItems; i++) {
+ memcpy(&aPoint, &geoBuffer[ptr], POINT_DATA_SIZE);
+ x_min = (aPoint.x < x_min) ? aPoint.x : x_min;
+ x_max = (aPoint.x > x_max) ? aPoint.x : x_max;
+ y_min = (aPoint.y < y_min) ? aPoint.y : y_min;
+ y_max = (aPoint.y > y_max) ? aPoint.y : y_max;
+ [coordinates addObject:NSStringFromPoint(NSMakePoint(aPoint.x, aPoint.y))];
+ ptr += POINT_DATA_SIZE+WKB_HEADER_SIZE;
+ }
+ return [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSArray arrayWithObjects:
+ [NSNumber numberWithDouble:x_min],
+ [NSNumber numberWithDouble:x_max],
+ [NSNumber numberWithDouble:y_min],
+ [NSNumber numberWithDouble:y_max],
+ nil], @"bbox",
+ coordinates, @"coordinates",
+ @"MULTIPOINT", @"type",
+ nil];
+ break;
+
+ case wkb_multilinestring:
+ numberOfItems = geoBuffer[ptr];
+ ptr += SIZEOF_STORED_UINT32+WKB_HEADER_SIZE;
+ for(i=0; i < numberOfItems; i++) {
+ numberOfSubItems = geoBuffer[ptr];
+ ptr += SIZEOF_STORED_UINT32;
+ for(j=0; j < numberOfSubItems; j++) {
+ memcpy(&aPoint, &geoBuffer[ptr], POINT_DATA_SIZE);
+ x_min = (aPoint.x < x_min) ? aPoint.x : x_min;
+ x_max = (aPoint.x > x_max) ? aPoint.x : x_max;
+ y_min = (aPoint.y < y_min) ? aPoint.y : y_min;
+ y_max = (aPoint.y > y_max) ? aPoint.y : y_max;
+ [subcoordinates addObject:NSStringFromPoint(NSMakePoint(aPoint.x, aPoint.y))];
+ ptr += POINT_DATA_SIZE;
+ }
+ ptr += WKB_HEADER_SIZE;
+ [coordinates addObject:[[subcoordinates copy] autorelease]];
+ [subcoordinates removeAllObjects];
+ }
+ return [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSArray arrayWithObjects:
+ [NSNumber numberWithDouble:x_min],
+ [NSNumber numberWithDouble:x_max],
+ [NSNumber numberWithDouble:y_min],
+ [NSNumber numberWithDouble:y_max],
+ nil], @"bbox",
+ coordinates, @"coordinates",
+ @"MULTILINESTRING", @"type",
+ nil];
+ break;
+
+ case wkb_multipolygon:
+ numberOfItems = geoBuffer[ptr];
+ ptr += SIZEOF_STORED_UINT32+WKB_HEADER_SIZE;
+ for(i=0; i < numberOfItems; i++) {
+ numberOfSubItems = geoBuffer[ptr];
+ ptr += SIZEOF_STORED_UINT32;
+ for(j=0; j < numberOfSubItems; j++) {
+ numberOfSubSubItems = geoBuffer[ptr];
+ ptr += SIZEOF_STORED_UINT32;
+ for(k=0; k < numberOfSubSubItems; k++) {
+ memcpy(&aPoint, &geoBuffer[ptr], POINT_DATA_SIZE);
+ x_min = (aPoint.x < x_min) ? aPoint.x : x_min;
+ x_max = (aPoint.x > x_max) ? aPoint.x : x_max;
+ y_min = (aPoint.y < y_min) ? aPoint.y : y_min;
+ y_max = (aPoint.y > y_max) ? aPoint.y : y_max;
+ [subcoordinates addObject:NSStringFromPoint(NSMakePoint(aPoint.x, aPoint.y))];
+ ptr += POINT_DATA_SIZE;
+ }
+ [coordinates addObject:[[subcoordinates copy] autorelease]];
+ [subcoordinates removeAllObjects];
+ }
+ ptr += WKB_HEADER_SIZE;
+ }
+ return [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSArray arrayWithObjects:
+ [NSNumber numberWithDouble:x_min],
+ [NSNumber numberWithDouble:x_max],
+ [NSNumber numberWithDouble:y_min],
+ [NSNumber numberWithDouble:y_max],
+ nil], @"bbox",
+ coordinates, @"coordinates",
+ @"MULTIPOLYGON", @"type",
+ nil];
+ break;
//
// case wkb_geometrycollection:
// [wkt setString:@"GEOMETRYCOLLECTION("];
diff --git a/Source/SPGeometryDataView.h b/Source/SPGeometryDataView.h
index 3ff72110..c40cff97 100644
--- a/Source/SPGeometryDataView.h
+++ b/Source/SPGeometryDataView.h
@@ -29,14 +29,15 @@
{
NSString *type;
NSArray *coordinates;
- double x_min;
- double x_max;
- double y_min;
- double y_max;
- double width;
- double height;
- double zoom_factor;
- double margin_offset;
+ CGFloat x_min;
+ CGFloat x_max;
+ CGFloat y_min;
+ CGFloat y_max;
+ CGFloat width;
+ CGFloat height;
+ CGFloat zoom_factor;
+ CGFloat margin_offset;
+
}
- (id)initWithCoordinates:(NSDictionary*)coord;
diff --git a/Source/SPGeometryDataView.m b/Source/SPGeometryDataView.m
index 45d9632b..0a5a0294 100644
--- a/Source/SPGeometryDataView.m
+++ b/Source/SPGeometryDataView.m
@@ -33,39 +33,59 @@
- (id)initWithCoordinates:(NSDictionary*)coord
{
- margin_offset = 5.0;
+ margin_offset = 10.0;
type = [coord objectForKey:@"type"];
coordinates = [coord objectForKey:@"coordinates"];
- x_min = [[[coord objectForKey:@"bbox"] objectAtIndex:0] doubleValue] - margin_offset;
- x_max = [[[coord objectForKey:@"bbox"] objectAtIndex:1] doubleValue] + margin_offset;
- y_min = [[[coord objectForKey:@"bbox"] objectAtIndex:2] doubleValue] - margin_offset;
- y_max = [[[coord objectForKey:@"bbox"] objectAtIndex:3] doubleValue] + margin_offset;
-
+ x_min = (CGFloat)[[[coord objectForKey:@"bbox"] objectAtIndex:0] doubleValue];
+ x_max = (CGFloat)[[[coord objectForKey:@"bbox"] objectAtIndex:1] doubleValue];
+ y_min = (CGFloat)[[[coord objectForKey:@"bbox"] objectAtIndex:2] doubleValue];
+ y_max = (CGFloat)[[[coord objectForKey:@"bbox"] objectAtIndex:3] doubleValue];
zoom_factor = 1.0;
width = x_max - x_min;
height = y_max - y_min;
-
- if ( self = [super initWithFrame:NSMakeRect(0,0,width,height)] )
+ // make it a square due to aspect ratio
+ if(width>height)
+ height = width;
+ else
+ width = height;
+
+ if ( self = [super initWithFrame:NSMakeRect(0,0,width+margin_offset*2,height+margin_offset*2)] )
{
;
}
- return self;
+ return self;
}
- (NSPoint)normalizePoint:(NSPoint)aPoint
{
+
+ aPoint.x-=x_min;
+ aPoint.y-=y_min;
+ aPoint.x+=margin_offset;
+ aPoint.y+=margin_offset;
+
return aPoint;
}
+- (void)drawPoint:(NSPoint)aPoint
+{
+ NSBezierPath *circlePath = [NSBezierPath bezierPath];
+ [circlePath appendBezierPathWithOvalInRect:NSMakeRect(aPoint.x-2,aPoint.y-2,4,4)];
+ [[NSColor grayColor] setStroke];
+ [[NSColor redColor] setFill];
+ [circlePath stroke];
+ [circlePath fill];
+}
+
- (void)drawRect:(NSRect)dirtyRect
{
if(!type || ![type length] || !coordinates || ![coordinates count]) return;
- NSBezierPath *path, *circlePath;
+ NSBezierPath *path;
NSColor *polyFillColor = [NSColor colorWithCalibratedRed:.5 green:.5 blue:0.5 alpha:0.05];
BOOL isFirst = YES;
@@ -82,39 +102,33 @@
[[NSColor blackColor] set];
[path setLineWidth:1];
- if ([type isEqualToString:@"POINT"]) {
- circlePath = [NSBezierPath bezierPath];
- [circlePath appendBezierPathWithOvalInRect:NSMakeRect(width/2-2,height/2-2,4,4)];
- [[NSColor grayColor] setStroke];
- [[NSColor redColor] setFill];
- [circlePath stroke];
- [circlePath fill];
+ if ([type hasSuffix:@"POINT"]) {
+ for(NSString* coord in coordinates)
+ [self drawPoint:[self normalizePoint:NSPointFromString(coord)]];
}
- else if([type isEqualToString:@"LINESTRING"]) {
-
- for(NSString* coord in coordinates) {
- aPoint = [self normalizePoint:NSPointFromString(coord)];
- if(isFirst) {
- [path moveToPoint:aPoint];
- isFirst = NO;
- } else {
- [path lineToPoint:aPoint];
+ else if([type hasSuffix:@"LINESTRING"]) {
+
+ for(NSArray* lines in coordinates) {
+ path = [NSBezierPath bezierPath];
+ isFirst = YES;
+ for(NSString* coord in lines) {
+ aPoint = [self normalizePoint:NSPointFromString(coord)];
+ if(isFirst) {
+ [path moveToPoint:aPoint];
+ isFirst = NO;
+ } else {
+ [path lineToPoint:aPoint];
+ }
+ [self drawPoint:aPoint];
}
- circlePath = [NSBezierPath bezierPath];
- [circlePath appendBezierPathWithOvalInRect:NSMakeRect(aPoint.x-2,aPoint.y-2,4,4)];
- [[NSColor grayColor] setStroke];
- [[NSColor redColor] setFill];
- [circlePath stroke];
- [circlePath fill];
+ [[NSColor blackColor] setStroke];
+ [path stroke];
}
- [[NSColor blackColor] setStroke];
- [path stroke];
-
}
- else if([type isEqualToString:@"POLYGON"]) {
- for(NSArray* polygon in coordinates) {
+ else if([type hasSuffix:@"POLYGON"]) {
+ for(NSArray* polygons in coordinates) {
isFirst = YES;
- for(NSString* coord in polygon) {
+ for(NSString* coord in polygons) {
aPoint = [self normalizePoint:NSPointFromString(coord)];
if(isFirst) {
[path moveToPoint:aPoint];
@@ -122,12 +136,7 @@
} else {
[path lineToPoint:aPoint];
}
- circlePath = [NSBezierPath bezierPath];
- [circlePath appendBezierPathWithOvalInRect:NSMakeRect(aPoint.x-2,aPoint.y-2,4,4)];
- [[NSColor grayColor] setStroke];
- [[NSColor redColor] setFill];
- [circlePath stroke];
- [circlePath fill];
+ [self drawPoint:aPoint];
}
[[NSColor blackColor] setStroke];
[polyFillColor setFill];
@@ -147,6 +156,7 @@
NSBitmapImageRep *bitmap = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:[self bounds]] autorelease];
[image addRepresentation:bitmap];
return image;
+
}
/**