Skip to content

Commit

Permalink
Added missing initWithGeosGeometry methods to point and polyline classes
Browse files Browse the repository at this point in the history
  • Loading branch information
mweisman committed Aug 27, 2010
1 parent 8637d9f commit e673015
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion ShapeKit/ShapeKitGeometry.mm
Expand Up @@ -87,7 +87,7 @@ void log_and_exit(const char *fmt,...) {
vfprintf( stdout, fmt, ap);
va_end(ap);
fprintf( stdout, "\n" );
exit(1);
// exit(1);
}

@end
Expand All @@ -114,6 +114,24 @@ -(id)initWithWKT:(NSString *) wkt {
return self;
}

-(id)initWithGeosGeometry:(GEOSGeometry *)geom {
[super initWithGeosGeometry:geom];
GEOSCoordSequence *sequence = GEOSCoordSeq_clone(GEOSGeom_getCoordSeq(geosGeom));
geometry = [[MKPointAnnotation alloc] init];
double xCoord;
GEOSCoordSeq_getX(sequence, 0, &xCoord);

double yCoord;
GEOSCoordSeq_getY(sequence, 0, &yCoord);
geometry.coordinate = CLLocationCoordinate2DMake(yCoord, xCoord);

GEOSCoordSeq_getSize(sequence, &numberOfCoords);
GEOSCoordSeq_destroy(sequence);

return self;
}


- (void) dealloc
{
[geometry release];
Expand Down Expand Up @@ -148,6 +166,28 @@ -(id)initWithWKT:(NSString *) wkt {
return self;
}

-(id)initWithGeosGeometry:(GEOSGeometry *)geom {
[super initWithGeosGeometry:geom];
GEOSCoordSequence *sequence = GEOSCoordSeq_clone(GEOSGeom_getCoordSeq(geosGeom));
GEOSCoordSeq_getSize(sequence, &numberOfCoords);
CLLocationCoordinate2D coords[numberOfCoords];

for (int coord = 0; coord < numberOfCoords; coord++) {
double xCoord = NULL;
GEOSCoordSeq_getX(sequence, coord, &xCoord);

double yCoord = NULL;
GEOSCoordSeq_getY(sequence, coord, &yCoord);
coords[coord] = CLLocationCoordinate2DMake(yCoord, xCoord);
}
geometry = [MKPolyline polylineWithCoordinates:coords count:numberOfCoords];

GEOSCoordSeq_destroy(sequence);

return self;

}

@end

#pragma mark -
Expand Down

0 comments on commit e673015

Please sign in to comment.