RMProjection.m
1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//
// Projection.m
// Images
//
// Created by Joseph Gentle on 18/08/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "RMProjection.h"
#import "proj_api.h"
@implementation RMProjection
@synthesize internalProjection;
-(id) initWithString: (NSString*)params
{
if (![super init])
return nil;
internalProjection = pj_init_plus([params UTF8String]);
if (internalProjection == NULL)
{
NSLog(@"Unhandled error creating projection. String is %@", params);
[self dealloc];
return nil;
}
return self;
}
-(id) init
{
return [self initWithString:@"+proj=latlong +ellps=WGS84"];
}
-(void) dealloc
{
if (internalProjection)
pj_free(internalProjection);
[super dealloc];
}
-(CLLocationCoordinate2D) projectForward: (CLLocationCoordinate2D)point
{
projUV uv = {
point.longitude * DEG_TO_RAD,
point.latitude * DEG_TO_RAD
};
projUV result = pj_fwd(uv, internalProjection);
CLLocationCoordinate2D result_point = {
result.v,
result.u,
};
return result_point;
}
-(CLLocationCoordinate2D) projectInverse: (CLLocationCoordinate2D)point
{
projUV uv = {
point.longitude,
point.latitude,
};
projUV result = pj_inv(uv, internalProjection);
CLLocationCoordinate2D result_point = {
result.v * RAD_TO_DEG,
result.u * RAD_TO_DEG,
};
return result_point;
}
static RMProjection* _google = nil;
static RMProjection* _latlong = nil;
+(RMProjection*) EPSGGoogle
{
if (_google)
{
return _google;
}
else
{
_google = [[RMProjection alloc] initWithString:@"+title= Google Mercator EPSG:900913 +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs"];
return _google;
}
}
+(RMProjection*) EPSGLatLong;
{
if (_latlong)
{
return _latlong;
}
else
{
_latlong = [[RMProjection alloc] initWithString:@"+proj=latlong +ellps=WGS84"];
return _latlong;
}
}
@end