├── TODO ├── README ├── COPYRIGHT ├── CLLocation+CH1903.h ├── LICENSE └── CLLocation+CH1903.m /TODO: -------------------------------------------------------------------------------- 1 | + (add) unit test! 2 | + (add) x-code project 3 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This small extension allows you to easly manage CH1903 (swiss coordinate system) within the CLLocation object. 2 | All the calculation are based on the official swiss federal informations: 3 | http://www.swisstopo.admin.ch/internet/swisstopo/de/home/products/software/products/skripts.html 4 | 5 | 6 | Version 7 | ======= 8 | 0.1 9 | 10 | License 11 | ======= 12 | BSD-4-Clause 13 | 14 | Changelog 15 | ========== 16 | 01/27/2010 – Version 0.1 - package started 17 | 18 | Author 19 | ====== 20 | Jonas Schnelli / include7 AG - www.include7.ch 21 | 22 | 23 | _ __ __ _____ 24 | (_)___ _____/ /_ ______/ /_/__ / 25 | / / __ \/ ___/ / / / / __ / _ \/ / 26 | / / / / / /__/ / /_/ / /_/ / __/ / 27 | /_/_/ /_/\___/_/\__,_/\__,_/\___/_/........ 28 | 29 | 30 | 31 | URL 32 | === 33 | http://github.com/jonasschnelli/CLLocation-CH1903 34 | 35 | Info 36 | ==== 37 | Have fun while using and extending this package. 38 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 include7 AG – Jonas Schnelli 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /CLLocation+CH1903.h: -------------------------------------------------------------------------------- 1 | // 2 | // CLLocation+CH1903.h 3 | // g7 4 | // 5 | // Created by Jonas Schnelli on 22.04.10. 6 | // Copyright 2010 include7 AG. All rights reserved. 7 | // 8 | // check: http://github.com/jonasschnelli/CLLocation-CH1903 9 | 10 | #import 11 | #import 12 | 13 | @interface CLLocation (CH1903) 14 | 15 | /*! 16 | @method initWithCH1903x 17 | @abstract initialize a CLLocation-Instance with CH1903 x/y coorinates 18 | */ 19 | - (id) initWithCH1903x:(double)x y:(double)y; 20 | 21 | 22 | /*! 23 | @method CH1903Y 24 | @abstract returns the CH1903 y value of the location 25 | */ 26 | - (double)CH1903Y; 27 | 28 | /*! 29 | @method CH1903X 30 | @abstract returns the CH1903 x value of the location 31 | */ 32 | - (double)CH1903X; 33 | 34 | 35 | #pragma mark - 36 | #pragma mark static methodes 37 | 38 | + (double)CHtoWGSlatWithX:(double)x y:(double)y; 39 | + (double)CHtoWGSlongWithX:(double)x y:(double)y; 40 | + (double)WGStoCHyWithLatitude:(double)lat longitude:(double)lng; 41 | + (double)WGStoCHxWithLatitude:(double)lat longitude:(double)lng; 42 | 43 | + (double)decToSex:(double)angle; 44 | + (double)degToSec:(double)angle; 45 | + (double)sexToDec:(double)angle; 46 | 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | copyright (c) 2010 include7 AG – Jonas Schnelli 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1) Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2) Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | 3) All advertising materials mentioning features or use of this software 16 | must display the following acknowledgement: “This product includes software 17 | developed by the include7 AG, Switzerland and its contributors.” 18 | 19 | 4) Neither the name of the include7 AG, Switzerland nor the names of 20 | its contributors may be used to endorse or promote products derived from 21 | this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INCLUDE7 AG OR CONTRIBUTORS BE 27 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | POSSIBILITY OF SUCH DAMAGE. 34 | 35 | -------------------------------------------------------------------------------- /CLLocation+CH1903.m: -------------------------------------------------------------------------------- 1 | // 2 | // CLLocation+CH1903.m 3 | // g7 4 | // 5 | // Created by Jonas Schnelli on 22.04.10. 6 | // Copyright 2010 include7 AG. All rights reserved. 7 | // 8 | // check: http://github.com/jonasschnelli/CLLocation-CH1903 9 | 10 | #import "CLLocation+CH1903.h" 11 | 12 | 13 | @implementation CLLocation (CH1903) 14 | 15 | 16 | - (id) initWithCH1903x:(double)x y:(double)y 17 | { 18 | self = [self initWithLatitude:[CLLocation CHtoWGSlatWithX:x y:y] longitude:[CLLocation CHtoWGSlongWithX:x y:y]]; 19 | if (self != nil) { 20 | 21 | } 22 | return self; 23 | } 24 | 25 | 26 | - (double)CH1903Y { 27 | return [CLLocation WGStoCHyWithLatitude:self.coordinate.latitude longitude:self.coordinate.longitude]; 28 | } 29 | 30 | - (double)CH1903X { 31 | return [CLLocation WGStoCHxWithLatitude:self.coordinate.latitude longitude:self.coordinate.longitude]; 32 | } 33 | 34 | 35 | + (double)CHtoWGSlatWithX:(double)x y:(double)y { 36 | 37 | // Converts militar to civil and to unit = 1000km 38 | // Axiliary values (% Bern) 39 | double y_aux = (y - 600000)/1000000.0; 40 | double x_aux = (x - 200000)/1000000.0; 41 | 42 | // Process lat 43 | double lat = 16.9023892 44 | + 3.238272 * x_aux 45 | - 0.270978 * pow(y_aux,2) 46 | - 0.002528 * pow(x_aux,2) 47 | - 0.0447 * pow(y_aux,2) * x_aux 48 | - 0.0140 * pow(x_aux,3); 49 | 50 | // Unit 10000" to 1 " and converts seconds to degrees (dec) 51 | lat = lat * 100/36.0; 52 | 53 | return lat; 54 | 55 | } 56 | 57 | // Convert CH y/x to WGS long 58 | + (double)CHtoWGSlongWithX:(double)x y:(double)y { 59 | 60 | // Converts militar to civil and to unit = 1000km 61 | // Axiliary values (% Bern) 62 | double y_aux = (y - 600000)/1000000.0; 63 | double x_aux = (x - 200000)/1000000.0; 64 | 65 | // Process long 66 | double lng = 2.6779094 67 | + 4.728982 * y_aux 68 | + 0.791484 * y_aux * x_aux 69 | + 0.1306 * y_aux * pow(x_aux,2) 70 | - 0.0436 * pow(y_aux,3); 71 | 72 | // Unit 10000" to 1 " and converts seconds to degrees (dec) 73 | lng = lng * 100/36.0; 74 | 75 | return lng; 76 | } 77 | 78 | 79 | 80 | + (double)WGStoCHyWithLatitude:(double)lat longitude:(double)lng { 81 | // Converts degrees dec to sex 82 | lat = [CLLocation decToSex:lat]; 83 | lng = [CLLocation decToSex:lng]; 84 | 85 | // Converts degrees to seconds (sex) 86 | lat = [CLLocation degToSec:lat]; 87 | lng = [CLLocation degToSec:lng]; 88 | 89 | // Axiliary values (% Bern) 90 | double lat_aux = (lat - 169028.66)/10000; 91 | double lng_aux = (lng - 26782.5)/10000; 92 | 93 | // Process Y 94 | double y = 600072.37 + 211455.93 * lng_aux - 10938.51 * lng_aux * lat_aux - 0.36 * lng_aux * pow(lat_aux,2) - 44.54 * pow(lng_aux,3); 95 | 96 | return y; 97 | 98 | } 99 | 100 | + (double)WGStoCHxWithLatitude:(double)lat longitude:(double)lng { 101 | // Converts degrees dec to sex 102 | lat = [CLLocation decToSex:lat]; 103 | lng = [CLLocation decToSex:lng]; 104 | 105 | // Converts degrees to seconds (sex) 106 | lat = [CLLocation degToSec:lat]; 107 | lng = [CLLocation degToSec:lng]; 108 | 109 | // Axiliary values (% Bern) 110 | double lat_aux = (lat - 169028.66)/10000.0; 111 | double lng_aux = (lng - 26782.5)/10000.0; 112 | 113 | // Process X 114 | double x = 200147.07 + 308807.95 * lat_aux + 3745.25 * pow(lng_aux,2) + 76.63 * pow(lat_aux,2)- 194.56 * pow(lng_aux,2) * lat_aux+ 119.79 * pow(lat_aux,3); 115 | 116 | return x; 117 | } 118 | 119 | 120 | 121 | 122 | // Convert DEC angle to SEX DMS 123 | + (double)decToSex:(double)angle { 124 | // Extract DMS 125 | int deg = (int) angle; 126 | int min = (int) ((angle-deg)*60); 127 | double sec = (((angle-deg)*60) - min) * 60; 128 | 129 | // Result in degrees sex (dd.mmss) 130 | return deg + min/100.0 + sec/10000.0; 131 | } 132 | 133 | + (double)degToSec:(double)angle { 134 | // Extract DMS 135 | int deg = (int) angle; 136 | int min = (int) ((angle-deg)*100); 137 | double sec = (((angle-deg)*100.0) - min) * 100.0; 138 | 139 | // Result in degrees sex (dd.mmss) 140 | return sec + min*60.0 + deg*3600.0; 141 | } 142 | 143 | + (double)sexToDec:(double)angle { 144 | // Extract DMS 145 | int deg = (int) angle; 146 | int min = (int) ((angle-deg)*100); 147 | double sec = (((angle-deg)*100.0) - min) * 100.0; 148 | 149 | // Result in degrees sex (dd.mmss) 150 | return deg + (sec/60.0 + min)/60.0; 151 | } 152 | @end 153 | --------------------------------------------------------------------------------