├── .gitignore ├── LICENSE ├── Mapkit_ShapeFile.xcodeproj └── project.pbxproj ├── Mapkit_ShapeFile ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ └── Main.storyboard ├── Controllers │ ├── ViewController+MapOverlay.h │ ├── ViewController+MapOverlay.m │ ├── ViewController.h │ └── ViewController.m ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── LaunchImage.launchimage │ │ └── Contents.json ├── Mapkit_ShapeFile-Info.plist ├── Mapkit_ShapeFile-Prefix.pch ├── Models │ ├── GeoRegion.h │ ├── GeoRegion.m │ ├── GeoRegionStack.h │ └── GeoRegionStack.m ├── Shapes │ ├── countries.dbf │ ├── countries.shp │ ├── countries.shx │ ├── countries.txt │ ├── ne_10m_parks_and_protected_lands_area.dbf │ ├── ne_10m_parks_and_protected_lands_area.shp │ ├── ne_10m_parks_and_protected_lands_area.shx │ ├── states.dbf │ ├── states.prj │ ├── states.sbn │ ├── states.sbx │ ├── states.shp │ ├── states.shp.xml │ └── states.shx ├── en.lproj │ └── InfoPlist.strings └── main.m ├── Mapkit_ShapeFileTests ├── Mapkit_ShapeFileTests-Info.plist ├── Mapkit_ShapeFileTests.m └── en.lproj │ └── InfoPlist.strings ├── Podfile ├── Podfile.lock ├── Pods ├── MMDrawerController+Storyboard │ ├── LICENSE │ ├── MMDrawerController+Storyboard.h │ └── MMDrawerController+Storyboard.m ├── MMDrawerController │ ├── LICENSE │ ├── MMDrawerController │ │ ├── MMDrawerBarButtonItem.h │ │ ├── MMDrawerBarButtonItem.m │ │ ├── MMDrawerController+Subclass.h │ │ ├── MMDrawerController.h │ │ ├── MMDrawerController.m │ │ ├── MMDrawerVisualState.h │ │ ├── MMDrawerVisualState.m │ │ ├── UIViewController+MMDrawerController.h │ │ └── UIViewController+MMDrawerController.m │ └── README.md ├── Manifest.lock ├── Pods.xcodeproj │ └── project.pbxproj └── shapelib │ ├── LICENSE.LGPL │ ├── README │ ├── README.tree │ ├── dbfadd.c │ ├── dbfcreate.c │ ├── dbfdump.c │ ├── dbfopen.c │ ├── safileio.c │ ├── shapefil.h │ ├── shpadd.c │ ├── shpcreate.c │ ├── shpdump.c │ ├── shpopen.c │ ├── shprewind.c │ ├── shptest.c │ ├── shptree.c │ ├── shptreedump.c │ └── shputils.c ├── README.md └── assets └── images ├── country.png ├── mapkitshapefile.gif ├── state.png └── statepark.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | *.xcworkspace 13 | !default.xcworkspace 14 | xcuserdata 15 | profile 16 | *.moved-aside 17 | DerivedData 18 | .idea/ 19 | # Pods - for those of you who use CocoaPods 20 | Pods 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 rydewnd2 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Mapkit_ShapeFile/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // Mapkit_ShapeFile 4 | // 5 | // Created by Al Tyus on 10/13/13. 6 | // Copyright (c) 2013 Al Tyus. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Mapkit_ShapeFile/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // Mapkit_ShapeFile 4 | // 5 | // Created by Al Tyus on 10/13/13. 6 | // Copyright (c) 2013 Al Tyus. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "MMDrawerController+Storyboard.h" 11 | 12 | @implementation AppDelegate 13 | 14 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 15 | { 16 | // Override point for customization after application launch. 17 | 18 | MMDrawerController *drawerController = (MMDrawerController *)self.window.rootViewController; 19 | 20 | [drawerController setMaximumLeftDrawerWidth:200]; 21 | [drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll]; 22 | [drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll]; 23 | 24 | 25 | return YES; 26 | } 27 | 28 | - (void)applicationWillResignActive:(UIApplication *)application 29 | { 30 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 31 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 32 | } 33 | 34 | - (void)applicationDidEnterBackground:(UIApplication *)application 35 | { 36 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 37 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 38 | } 39 | 40 | - (void)applicationWillEnterForeground:(UIApplication *)application 41 | { 42 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 43 | } 44 | 45 | - (void)applicationDidBecomeActive:(UIApplication *)application 46 | { 47 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 48 | } 49 | 50 | - (void)applicationWillTerminate:(UIApplication *)application 51 | { 52 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /Mapkit_ShapeFile/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 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 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /Mapkit_ShapeFile/Controllers/ViewController+MapOverlay.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController+MapOverlay.h 3 | // Mapkit_ShapeFile 4 | // 5 | // Created by Al Tyus on 10/14/13. 6 | // Copyright (c) 2013 Al Tyus. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "GeoRegionStack.h" 11 | #import "GeoRegion.h" 12 | #import "ViewController.h" 13 | #import 14 | 15 | @interface UIViewController (MapOverlay) 16 | -(void)drawOverlaysWithGeoRegionStack:(GeoRegionStack *)stack onMapView:(MKMapView *)mapView; 17 | - (UIColor *)randomColor; 18 | -(MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id)overlay; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Mapkit_ShapeFile/Controllers/ViewController+MapOverlay.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController+MapOverlay.m 3 | // Mapkit_ShapeFile 4 | // 5 | // Created by Al Tyus on 10/14/13. 6 | // Copyright (c) 2013 Al Tyus. All rights reserved. 7 | // 8 | 9 | #import "ViewController+MapOverlay.h" 10 | 11 | @implementation ViewController (MapOverlay) 12 | 13 | #pragma mark - Draw Overlays 14 | -(void)drawOverlaysWithGeoRegionStack:(GeoRegionStack *)stack onMapView:(MKMapView *)mapView 15 | { 16 | self.geoRegionDict = [[NSMutableDictionary alloc] init]; 17 | 18 | for (GeoRegion *region in stack.geoRegions) 19 | { 20 | for (Polygon *polygon in region.polygons) 21 | { 22 | NSInteger count = [polygon.coordinates count]; 23 | CLLocationCoordinate2D coords[count]; 24 | 25 | for (NSInteger c = 0; c < count; c++) 26 | { 27 | NSValue *coordValue = polygon.coordinates[c]; 28 | CLLocationCoordinate2D coord = [coordValue MKCoordinateValue]; 29 | coords[c] = coord; 30 | } 31 | MKPolygon *polygon = [MKPolygon polygonWithCoordinates:coords count:count]; 32 | polygon.title = region.name; 33 | [self.geoRegionDict setObject:region forKey:region.name]; 34 | [mapView addOverlay:polygon]; 35 | } 36 | } 37 | } 38 | 39 | #pragma mark - MapViewDelegate 40 | 41 | -(MKOverlayRenderer *)mapView:(MKMapView *)mapView 42 | rendererForOverlay:(id)overlay 43 | { 44 | MKPolygonRenderer *renderer = [[MKPolygonRenderer alloc] initWithPolygon:overlay]; 45 | if ([overlay isKindOfClass:[MKPolygon class]]) 46 | { 47 | GeoRegion *myRegion = [self.geoRegionDict objectForKey:[(MKPolygon *)overlay title]]; 48 | if (myRegion) 49 | { 50 | renderer.fillColor = myRegion.color; 51 | renderer.strokeColor = [UIColor blackColor]; 52 | renderer.lineWidth = 1.0; 53 | renderer.lineCap = kCGLineCapRound; 54 | } 55 | 56 | return renderer; 57 | } 58 | else return nil; 59 | 60 | } 61 | 62 | @end 63 | 64 | -------------------------------------------------------------------------------- /Mapkit_ShapeFile/Controllers/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // Mapkit_ShapeFile 4 | // 5 | // Created by Al Tyus on 10/13/13. 6 | // Copyright (c) 2013 Al Tyus. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "ViewController+MapOverlay.h" 12 | 13 | @interface ViewController : UIViewController 14 | 15 | @property (strong, nonatomic) NSMutableDictionary *geoRegionDict; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Mapkit_ShapeFile/Controllers/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // Mapkit_ShapeFile 4 | // 5 | // Created by Al Tyus on 10/13/13. 6 | // Copyright (c) 2013 Al Tyus. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | @interface ViewController () 12 | 13 | @property (weak, nonatomic) IBOutlet MKMapView *mapView; 14 | @property (weak, nonatomic) IBOutlet UISwitch *randomSwitch; 15 | @property (weak, nonatomic) IBOutlet UISegmentedControl *regionSegmentedControl; 16 | 17 | 18 | @end 19 | 20 | @implementation ViewController 21 | 22 | #pragma mark - LifeCycle Methods 23 | 24 | - (void)viewDidLoad 25 | { 26 | [super viewDidLoad]; 27 | // Do any additional setup after loading the view, typically from a nib. 28 | 29 | //set mapView Delegate and Map Type 30 | self.mapView.delegate = self; 31 | [self.mapView setMapType:MKMapTypeSatellite]; 32 | 33 | //Load initial MapOverlays 34 | GeoRegionStack *countryRegionStack = [[GeoRegionStack alloc] initWithPathComponent:@"countries" 35 | withFieldName:@"CNTRY_NAME" 36 | withColorForRegion:nil 37 | randomRegionColor:YES]; 38 | [self drawOverlaysWithGeoRegionStack:countryRegionStack 39 | onMapView:self.mapView]; 40 | } 41 | 42 | #pragma mark - IBActions 43 | 44 | //Change overlay with segmented control index 45 | - (IBAction)overlayTypeValueChanged:(id)sender { 46 | if ([sender isKindOfClass:[UISegmentedControl class]]) 47 | { 48 | [self updateUI]; 49 | } 50 | } 51 | 52 | - (IBAction)randomColorValueChanged:(id)sender { 53 | [self updateUI]; 54 | } 55 | 56 | #pragma mark - UI 57 | 58 | -(void)updateUI 59 | { 60 | BOOL random; 61 | 62 | if (self.randomSwitch.isOn) 63 | { 64 | random = YES; 65 | } 66 | else random = NO; 67 | 68 | //remove existing overlays 69 | [self.mapView removeOverlays:[self.mapView overlays]]; 70 | 71 | //Draw Overlays here 72 | 73 | GeoRegionStack *stack; 74 | 75 | switch (self.regionSegmentedControl.selectedSegmentIndex) { 76 | case 0: 77 | { 78 | stack = [[GeoRegionStack alloc] initWithPathComponent:@"countries" 79 | withFieldName:@"CNTRY_NAME" 80 | withColorForRegion:[UIColor purpleColor] 81 | randomRegionColor:random]; 82 | } 83 | break; 84 | case 1: 85 | { 86 | stack = [[GeoRegionStack alloc] initWithPathComponent:@"states" 87 | withFieldName:@"STATE_NAME" 88 | withColorForRegion:[UIColor greenColor] 89 | randomRegionColor:random]; 90 | } 91 | break; 92 | case 2: 93 | { 94 | stack = [[GeoRegionStack alloc] initWithPathComponent:@"ne_10m_parks_and_protected_lands_area" 95 | withFieldName:@"Name" 96 | withColorForRegion:[UIColor grayColor] 97 | randomRegionColor:random]; 98 | } 99 | break; 100 | default: 101 | stack = nil; 102 | break; 103 | } 104 | 105 | [self drawOverlaysWithGeoRegionStack:stack onMapView:self.mapView]; 106 | 107 | } 108 | 109 | @end 110 | -------------------------------------------------------------------------------- /Mapkit_ShapeFile/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "40x40", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "60x60", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Mapkit_ShapeFile/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Mapkit_ShapeFile/Mapkit_ShapeFile-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.al-tyus.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Mapkit_ShapeFile/Mapkit_ShapeFile-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_5_0 10 | #warning "This project uses features only available in iOS SDK 5.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #endif 17 | -------------------------------------------------------------------------------- /Mapkit_ShapeFile/Models/GeoRegion.h: -------------------------------------------------------------------------------- 1 | // 2 | // GeoRegion.h 3 | // Mapkit_ShapeFile 4 | // 5 | // Created by Al Tyus on 10/13/13. 6 | // Copyright (c) 2013 Al Tyus. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "shapefil.h" 11 | #import 12 | 13 | @interface GeoRegion : NSObject 14 | 15 | @property (nonatomic, strong) NSString *name; 16 | @property (nonatomic, strong) NSArray *polygons; 17 | @property (nonatomic, strong) UIColor *color; 18 | 19 | @property (nonatomic, assign) double minLat; 20 | @property (nonatomic, assign) double maxLat; 21 | @property (nonatomic, assign) double minLong; 22 | @property (nonatomic, assign) double maxLong; 23 | 24 | - (id)init; 25 | - (instancetype)initWithShapeObject:(SHPObject *)shape 26 | databaseFilePath:(NSString *)dbfPath 27 | fieldName:(NSString *)fieldName 28 | color:(UIColor *)color; 29 | 30 | @end 31 | 32 | @interface Polygon : NSObject 33 | 34 | @property (nonatomic, strong) NSArray *coordinates; 35 | 36 | @end -------------------------------------------------------------------------------- /Mapkit_ShapeFile/Models/GeoRegion.m: -------------------------------------------------------------------------------- 1 | // 2 | // GeoRegion.m 3 | // Mapkit_ShapeFile 4 | // 5 | // Created by Al Tyus on 10/13/13. 6 | // Copyright (c) 2013 Al Tyus. All rights reserved. 7 | // 8 | 9 | #import "GeoRegion.h" 10 | 11 | @implementation Polygon 12 | @end 13 | @implementation GeoRegion 14 | 15 | #pragma mark - Initializers 16 | 17 | - (id)init 18 | { 19 | self = [super init]; 20 | if (self) 21 | { 22 | _name = @""; 23 | _polygons = @[]; 24 | _color = [UIColor whiteColor]; 25 | 26 | _minLat = 0; 27 | _maxLat = 0; 28 | _minLong = 0; 29 | _maxLong = 0; 30 | } 31 | return self; 32 | } 33 | 34 | -(instancetype)initWithShapeObject:(SHPObject *)shape 35 | databaseFilePath:(NSString *)dbfPath 36 | fieldName:(NSString *)fieldName 37 | color:(UIColor *)color 38 | { 39 | self = [super init]; 40 | if (self) 41 | { 42 | 43 | _minLat = shape->dfYMin; 44 | _maxLat = shape->dfYMax; 45 | _minLong = shape->dfXMin; 46 | _maxLong = shape->dfXMax; 47 | _color = color; 48 | 49 | [self setupShapeFileWithShapeObject:shape 50 | databaseFilePath:dbfPath 51 | fieldName:fieldName 52 | color:color]; 53 | 54 | } 55 | return self; 56 | } 57 | 58 | 59 | - (void)setupShapeFileWithShapeObject:(SHPObject *)shape 60 | databaseFilePath:(NSString *)dbfPath 61 | fieldName:(NSString *)fieldName 62 | color:(UIColor *)color 63 | 64 | { 65 | int numParts = shape->nParts; 66 | int totalVertexCount = shape->nVertices; 67 | 68 | //Build Array of Polygons for shape 69 | NSMutableArray *polygons = [NSMutableArray arrayWithCapacity:numParts]; 70 | for (int n=0; npanPartStart[n]; 73 | int partVertexCount = (n == numParts - 1) ? totalVertexCount - startVertex : shape->panPartStart[n+1] - startVertex; 74 | Polygon *polygon = [[Polygon alloc] init]; 75 | NSMutableArray *coordinates = [NSMutableArray arrayWithCapacity:partVertexCount]; 76 | int endIndex = startVertex + partVertexCount; 77 | for (int pv = startVertex; pv < endIndex; pv++) 78 | { 79 | CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(shape->padfY[pv], 80 | shape->padfX[pv]); 81 | [coordinates addObject:[NSValue valueWithMKCoordinate:coord]]; 82 | polygon.coordinates = coordinates; 83 | } 84 | [polygons addObject:polygon]; 85 | _polygons = polygons; 86 | } 87 | 88 | //initialize the region's name property 89 | NSString *resourcePath = [[NSBundle mainBundle] resourcePath]; 90 | NSString *regionDBFPath = [resourcePath stringByAppendingPathComponent:dbfPath]; 91 | const char *pszPath = [regionDBFPath cStringUsingEncoding:NSUTF8StringEncoding]; 92 | DBFHandle dbf = DBFOpen(pszPath, "rb"); 93 | 94 | const char *cFieldName = [fieldName cStringUsingEncoding:NSUTF8StringEncoding]; 95 | int nameIndex = DBFGetFieldIndex(dbf, cFieldName); 96 | _name = [NSString stringWithUTF8String:DBFReadStringAttribute(dbf,shape->nShapeId, nameIndex)]; 97 | DBFClose(dbf); 98 | } 99 | 100 | @end 101 | -------------------------------------------------------------------------------- /Mapkit_ShapeFile/Models/GeoRegionStack.h: -------------------------------------------------------------------------------- 1 | // 2 | // GeoRegionStack.h 3 | // Mapkit_ShapeFile 4 | // 5 | // Created by Al Tyus on 10/13/13. 6 | // Copyright (c) 2013 Al Tyus. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface GeoRegionStack : NSObject 12 | 13 | @property (readonly, nonatomic) NSArray *geoRegions; //Array of GeoRegion Objects 14 | @property (nonatomic)BOOL randomColor; 15 | 16 | - (id)init; 17 | - (instancetype)initWithPathComponent:(NSString *)pathComponent 18 | withFieldName:(NSString *)fieldName 19 | withColorForRegion:(UIColor *)color 20 | randomRegionColor:(BOOL)random; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Mapkit_ShapeFile/Models/GeoRegionStack.m: -------------------------------------------------------------------------------- 1 | // 2 | // GeoRegionStack.m 3 | // Mapkit_ShapeFile 4 | // 5 | // Created by Al Tyus on 10/13/13. 6 | // Copyright (c) 2013 Al Tyus. All rights reserved. 7 | // 8 | 9 | #import "GeoRegionStack.h" 10 | #import "GeoRegion.h" 11 | 12 | @interface GeoRegionStack() 13 | 14 | @property (strong, nonatomic) NSMutableArray *geoRegions; 15 | 16 | @end 17 | 18 | @implementation GeoRegionStack 19 | 20 | - (id)init 21 | { 22 | return [self initWithPathComponent:@"" 23 | withFieldName:@"" 24 | withColorForRegion:[UIColor whiteColor] 25 | randomRegionColor:NO]; 26 | } 27 | 28 | - (instancetype)initWithPathComponent:(NSString *)pathComponent 29 | withFieldName:(NSString *)fieldName 30 | withColorForRegion:(UIColor *)color 31 | randomRegionColor:(BOOL)random 32 | { 33 | self = [super init]; 34 | if (self) 35 | { 36 | [self setupGeoRegionStackWithPathComponent:(NSString *)pathComponent 37 | withFieldName:(NSString *)fieldName 38 | withColorForRegion:(UIColor *)color 39 | randomRegionColor:(BOOL)random]; 40 | } 41 | return self; 42 | } 43 | 44 | - (void)setupGeoRegionStackWithPathComponent:(NSString *)pathComponent 45 | withFieldName:(NSString *)fieldName 46 | withColorForRegion:(UIColor *)color 47 | randomRegionColor:(BOOL)random 48 | { 49 | _randomColor = random; 50 | //open Database 51 | NSString *resourcePath = [[NSBundle mainBundle] resourcePath]; 52 | NSString *shpPath = [resourcePath stringByAppendingPathComponent:pathComponent]; 53 | const char * pszPath = [shpPath cStringUsingEncoding:NSUTF8StringEncoding]; 54 | SHPHandle shp = SHPOpen(pszPath, "rb"); 55 | int numEntities; 56 | int shapeType; 57 | SHPGetInfo(shp, &numEntities, &shapeType, NULL, NULL); 58 | 59 | //Iterate through each GeoRegion in database 60 | 61 | NSMutableArray *mutableGeoRegions = [[NSMutableArray alloc] init]; 62 | 63 | for (int i=0; i 2 | 3 | {6C2FDF67-E8D4-4EE4-BE98-859E452FFE24}2006110120281300TRUECreateFeatureclass C:\ESRI\AEJEE_XTRA\AEJEE23data\usa states # states_Layer SAME_AS_TEMPLATE SAME_AS_TEMPLATE "GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];-178.217598362366 18.921786345087 999999.999068677;0 100000;0 100000" # 0 0 0 C:\ESRI\AEJEE_XTRA\AEJEE23data\usa\states.shpAppend states_Layer C:\ESRI\AEJEE_XTRA\AEJEE23data\usa\states.shp TEST C:\ESRI\AEJEE_XTRA\AEJEE23data\usa\states.shpFeatureClassToFeatureClass D:\usa\census\states.sdc\states C:\ESRI\AEJEE_XTRA\AEJEE23data\usa states # "STATE_NAME STATE_NAME VISIBLE;STATE_FIPS STATE_FIPS VISIBLE;SUB_REGION SUB_REGION VISIBLE;STATE_ABBR STATE_ABBR VISIBLE;POP2000 POP2000 VISIBLE;POP2005 POP2005 VISIBLE;POP00_SQMI POP00_SQMI VISIBLE;POP05_SQMI POP05_SQMI VISIBLE;WHITE WHITE VISIBLE;BLACK BLACK VISIBLE;AMERI_ES AMERI_ES VISIBLE;ASIAN ASIAN VISIBLE;HAWN_PI HAWN_PI VISIBLE;OTHER OTHER VISIBLE;MULT_RACE MULT_RACE VISIBLE;HISPANIC HISPANIC VISIBLE;MALES MALES VISIBLE;FEMALES FEMALES VISIBLE;AGE_UNDER5 AGE_UNDER5 VISIBLE;AGE_5_17 AGE_5_17 VISIBLE;AGE_18_21 AGE_18_21 VISIBLE;AGE_22_29 AGE_22_29 VISIBLE;AGE_30_39 AGE_30_39 VISIBLE;AGE_40_49 AGE_40_49 VISIBLE;AGE_50_64 AGE_50_64 VISIBLE;AGE_65_UP AGE_65_UP VISIBLE;MED_AGE MED_AGE VISIBLE;MED_AGE_M MED_AGE_M VISIBLE;MED_AGE_F MED_AGE_F VISIBLE;HOUSEHOLDS HOUSEHOLDS VISIBLE;AVE_HH_SZ AVE_HH_SZ VISIBLE;HSEHLD_1_M HSEHLD_1_M VISIBLE;HSEHLD_1_F HSEHLD_1_F VISIBLE;MARHH_CHD MARHH_CHD VISIBLE;MARHH_NO_C MARHH_NO_C VISIBLE;MHH_CHILD MHH_CHILD VISIBLE;FHH_CHILD FHH_CHILD VISIBLE;FAMILIES FAMILIES VISIBLE;AVE_FAM_SZ AVE_FAM_SZ VISIBLE;HSE_UNITS HSE_UNITS VISIBLE;VACANT VACANT VISIBLE;OWNER_OCC OWNER_OCC VISIBLE;RENTER_OCC RENTER_OCC VISIBLE;NO_FARMS97 NO_FARMS97 VISIBLE;AVG_SIZE97 AVG_SIZE97 VISIBLE;CROP_ACR97 CROP_ACR97 VISIBLE;AVG_SALE97 AVG_SALE97 VISIBLE;SQMI SQMI VISIBLE" SAME_AS_TEMPLATE SAME_AS_TEMPLATE # 0 C:\ESRI\AEJEE_XTRA\AEJEE23data\usa\states.shp 4 | -------------------------------------------------------------------------------- /Mapkit_ShapeFile/Shapes/states.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altyus/Mapkit_ShapeFile/e81e3559997fea97e018ba6c73f4c643bd2eb28e/Mapkit_ShapeFile/Shapes/states.shx -------------------------------------------------------------------------------- /Mapkit_ShapeFile/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Mapkit_ShapeFile/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // Mapkit_ShapeFile 4 | // 5 | // Created by Al Tyus on 10/13/13. 6 | // Copyright (c) 2013 Al Tyus. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Mapkit_ShapeFileTests/Mapkit_ShapeFileTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.al-tyus.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Mapkit_ShapeFileTests/Mapkit_ShapeFileTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // Mapkit_ShapeFileTests.m 3 | // Mapkit_ShapeFileTests 4 | // 5 | // Created by Al Tyus on 10/13/13. 6 | // Copyright (c) 2013 Al Tyus. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface Mapkit_ShapeFileTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation Mapkit_ShapeFileTests 16 | 17 | - (void)setUp 18 | { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown 24 | { 25 | // Put teardown code here. This method is called after the invocation of each test method in the class. 26 | [super tearDown]; 27 | } 28 | 29 | - (void)testExample 30 | { 31 | XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Mapkit_ShapeFileTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Podfile: -------------------------------------------------------------------------------- 1 | platform :ios, '7.0' 2 | 3 | pod 'shapelib' 4 | pod 'MMDrawerController+Storyboard' 5 | -------------------------------------------------------------------------------- /Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - MMDrawerController (0.4.0): 3 | - MMDrawerController/Core (= 0.4.0) 4 | - MMDrawerController/MMDrawerBarButtonItem (= 0.4.0) 5 | - MMDrawerController/MMDrawerVisualStates (= 0.4.0) 6 | - MMDrawerController/Subclass (= 0.4.0) 7 | - MMDrawerController+Storyboard (0.0.1): 8 | - MMDrawerController (~> 0.4.0) 9 | - MMDrawerController/Core (0.4.0) 10 | - MMDrawerController/MMDrawerBarButtonItem (0.4.0): 11 | - MMDrawerController/Core 12 | - MMDrawerController/MMDrawerVisualStates (0.4.0): 13 | - MMDrawerController/Core 14 | - MMDrawerController/Subclass (0.4.0): 15 | - MMDrawerController/Core 16 | - shapelib (1.3) 17 | 18 | DEPENDENCIES: 19 | - MMDrawerController+Storyboard 20 | - shapelib 21 | 22 | SPEC CHECKSUMS: 23 | MMDrawerController: b3731a50b80a7b2c017ac1c4e20f64724fbca006 24 | MMDrawerController+Storyboard: d1bde200dfd22d9caac6187cac4fa4ce62ce0a9b 25 | shapelib: 622b987882111dd347fd30062319e896e8e74bed 26 | 27 | COCOAPODS: 0.35.0 28 | -------------------------------------------------------------------------------- /Pods/MMDrawerController+Storyboard/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Nicholas Hodapp (nicholashodapp@gmail.com) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /Pods/MMDrawerController+Storyboard/MMDrawerController+Storyboard.h: -------------------------------------------------------------------------------- 1 | // 2 | // MMDrawerController+Storyboard.h 3 | // 4 | // Created by Nicholas Hodapp on 5/28/13. 5 | // Copyright (c) 2013 Nicholas Hodapp. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | #import "MMDrawerController.h" 26 | 27 | @interface MMDrawerController (Storyboard) 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Pods/MMDrawerController+Storyboard/MMDrawerController+Storyboard.m: -------------------------------------------------------------------------------- 1 | // 2 | // MMDrawerController+Storyboard.m 3 | // 4 | // Created by Nicholas Hodapp on 5/28/13. 5 | // Copyright (c) 2013 Nicholas Hodapp. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | #import "MMDrawerController+Storyboard.h" 26 | #import "MMDrawerController.h" 27 | 28 | // custom placeholder segue 29 | @interface MMDrawerControllerSegue : UIStoryboardSegue 30 | @end 31 | 32 | @implementation MMDrawerControllerSegue 33 | -(void)perform 34 | { 35 | // noop 36 | 37 | NSAssert( [self.sourceViewController isKindOfClass: [MMDrawerController class]], @"MMDrawerControllerSegue only to be used to define left/center/right controllers for a MMDrawerController!"); 38 | } 39 | @end 40 | 41 | @implementation MMDrawerController (Storyboard) 42 | 43 | -(void)awakeFromNib 44 | { 45 | // If we were instantiated via a storybard then we'll assume that we have pre-defined segues to denote 46 | // our center controller, and optionally left and right controllers! 47 | if ( self.storyboard != nil ) 48 | { 49 | // Required segue "mm_center". Uncaught exception if undefined in storyboard. 50 | [self performSegueWithIdentifier: @"mm_center" sender: self]; 51 | 52 | // Optional segue "mm_left". 53 | @try 54 | { 55 | [self performSegueWithIdentifier: @"mm_left" sender: self]; 56 | } 57 | @catch (NSException *exception) 58 | { 59 | } 60 | @finally 61 | { 62 | } 63 | 64 | // Optional segue "mm_right". 65 | @try 66 | { 67 | [self performSegueWithIdentifier: @"mm_right" sender: self]; 68 | } 69 | @catch (NSException *exception) 70 | { 71 | } 72 | @finally 73 | { 74 | } 75 | } 76 | } 77 | 78 | -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 79 | { 80 | if ( [segue.identifier isEqualToString: @"mm_center"] ) 81 | { 82 | NSParameterAssert( [segue isKindOfClass: [MMDrawerControllerSegue class]]); 83 | [self setCenterViewController: segue.destinationViewController]; 84 | } 85 | else 86 | if ( [segue.identifier isEqualToString: @"mm_left"] ) 87 | { 88 | NSParameterAssert( [segue isKindOfClass: [MMDrawerControllerSegue class]]); 89 | [self setLeftDrawerViewController: segue.destinationViewController]; 90 | } 91 | else 92 | if ( [segue.identifier isEqualToString: @"mm_right"] ) 93 | { 94 | NSParameterAssert( [segue isKindOfClass: [MMDrawerControllerSegue class]]); 95 | [self setRightDrawerViewController: segue.destinationViewController]; 96 | } 97 | } 98 | 99 | @end 100 | -------------------------------------------------------------------------------- /Pods/MMDrawerController/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Mutual Mobile (http://mutualmobile.com/) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /Pods/MMDrawerController/MMDrawerController/MMDrawerBarButtonItem.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 Mutual Mobile (http://mutualmobile.com/) 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #import 22 | 23 | /** 24 | `MMDrawerBarButtonItem` provides convenience methods to create `UIBarButtonItems` with a default hamburger-menu asset. 25 | */ 26 | 27 | @interface MMDrawerBarButtonItem : UIBarButtonItem 28 | 29 | ///--------------------------------------- 30 | /// @name Initializing a `MMDrawerBarButtonItem` 31 | ///--------------------------------------- 32 | 33 | /** 34 | Creates and initializes an `MMDrawerBarButtonItem` without a border. 35 | 36 | @param target The target to forward the `action` to when the button is pressed. 37 | @param action The action to call when the button is pressed. 38 | 39 | @return The newly-initialized bar button item. 40 | */ 41 | -(id)initWithTarget:(id)target action:(SEL)action; 42 | 43 | /** 44 | Returns the current color of the menu button for the state requested. 45 | 46 | @param state The UIControl state that the color is being requested for. 47 | 48 | @return The menu button color for the requested state. 49 | */ 50 | -(UIColor *)menuButtonColorForState:(UIControlState)state; 51 | 52 | /** 53 | Sets the color of the menu button for the specified state. For this control, only set colors for `UIControlStateNormal` and `UIControlStateHighlighted`. 54 | 55 | @param color The color to set. 56 | @param state The state to set the color for. 57 | */ 58 | -(void)setMenuButtonColor:(UIColor *)color forState:(UIControlState)state; 59 | 60 | /** 61 | Returns the current color of the shadow for the state requested. 62 | 63 | @param state The UIControl state that the color is being requested for. 64 | 65 | @return The menu button color for the requested state. 66 | */ 67 | -(UIColor *)shadowColorForState:(UIControlState)state; 68 | 69 | /** 70 | Sets the color of the shadow for the specified state. For this control, only set colors for `UIControlStateNormal` and `UIControlStateHighlighted`. 71 | 72 | @param color The color to set. 73 | @param state The state to set the color for. 74 | */ 75 | -(void)setShadowColor:(UIColor *)color forState:(UIControlState)state; 76 | 77 | @end 78 | -------------------------------------------------------------------------------- /Pods/MMDrawerController/MMDrawerController/MMDrawerBarButtonItem.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 Mutual Mobile (http://mutualmobile.com/) 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | 22 | #import "MMDrawerBarButtonItem.h" 23 | 24 | @interface MMDrawerMenuButtonView : UIButton 25 | @property (nonatomic,strong) UIColor * menuButtonNormalColor; 26 | @property (nonatomic,strong) UIColor * menuButtonHighlightedColor; 27 | 28 | @property (nonatomic,strong) UIColor * shadowNormalColor; 29 | @property (nonatomic,strong) UIColor * shadowHighlightedColor; 30 | 31 | -(UIColor *)menuButtonColorForState:(UIControlState)state; 32 | -(void)setMenuButtonColor:(UIColor *)color forState:(UIControlState)state; 33 | 34 | -(UIColor *)shadowColorForState:(UIControlState)state; 35 | -(void)setShadowColor:(UIColor *)color forState:(UIControlState)state; 36 | 37 | @end 38 | 39 | @implementation MMDrawerMenuButtonView 40 | 41 | -(id)initWithFrame:(CGRect)frame{ 42 | self = [super initWithFrame:frame]; 43 | if(self){ 44 | [self setMenuButtonNormalColor:[[UIColor whiteColor] colorWithAlphaComponent:0.9f]]; 45 | [self setMenuButtonHighlightedColor:[UIColor colorWithRed:139.0/255.0 46 | green:135.0/255.0 47 | blue:136.0/255.0 48 | alpha:0.9f]]; 49 | 50 | [self setShadowNormalColor:[[UIColor blackColor] colorWithAlphaComponent:0.5f]]; 51 | [self setShadowHighlightedColor:[[UIColor blackColor] colorWithAlphaComponent:0.2f]]; 52 | } 53 | return self; 54 | } 55 | 56 | -(UIColor *)menuButtonColorForState:(UIControlState)state{ 57 | UIColor * color; 58 | switch (state) { 59 | case UIControlStateNormal: 60 | color = self.menuButtonNormalColor; 61 | break; 62 | case UIControlStateHighlighted: 63 | color = self.menuButtonHighlightedColor; 64 | break; 65 | default: 66 | break; 67 | } 68 | return color; 69 | } 70 | 71 | -(void)setMenuButtonColor:(UIColor *)color forState:(UIControlState)state{ 72 | switch (state) { 73 | case UIControlStateNormal: 74 | [self setMenuButtonNormalColor:color]; 75 | break; 76 | case UIControlStateHighlighted: 77 | [self setMenuButtonHighlightedColor:color]; 78 | break; 79 | default: 80 | break; 81 | } 82 | [self setNeedsDisplay]; 83 | } 84 | 85 | -(UIColor *)shadowColorForState:(UIControlState)state{ 86 | UIColor * color; 87 | switch (state) { 88 | case UIControlStateNormal: 89 | color = self.shadowNormalColor; 90 | break; 91 | case UIControlStateHighlighted: 92 | color = self.shadowHighlightedColor; 93 | break; 94 | default: 95 | break; 96 | } 97 | return color; 98 | } 99 | 100 | -(void)setShadowColor:(UIColor *)color forState:(UIControlState)state{ 101 | switch (state) { 102 | case UIControlStateNormal: 103 | [self setShadowNormalColor:color]; 104 | break; 105 | case UIControlStateHighlighted: 106 | [self setShadowHighlightedColor:color]; 107 | break; 108 | default: 109 | break; 110 | } 111 | [self setNeedsDisplay]; 112 | } 113 | 114 | -(void)drawRect:(CGRect)rect{ 115 | //// General Declarations 116 | CGContextRef context = UIGraphicsGetCurrentContext(); 117 | 118 | //Sizes 119 | CGFloat buttonWidth = CGRectGetWidth(self.bounds)*.80; 120 | CGFloat buttonHeight = CGRectGetHeight(self.bounds)*.16; 121 | CGFloat xOffset = CGRectGetWidth(self.bounds)*.10; 122 | CGFloat yOffset = CGRectGetHeight(self.bounds)*.12; 123 | CGFloat cornerRadius = 1.0; 124 | 125 | //// Color Declarations 126 | UIColor* buttonColor = [self menuButtonColorForState:self.state]; 127 | UIColor* shadowColor = [self shadowColorForState:self.state]; 128 | 129 | 130 | //// Shadow Declarations 131 | UIColor* shadow = shadowColor; 132 | CGSize shadowOffset = CGSizeMake(0.0, 1.0); 133 | CGFloat shadowBlurRadius = 0; 134 | 135 | //// Top Bun Drawing 136 | UIBezierPath* topBunPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(xOffset, yOffset, buttonWidth, buttonHeight) cornerRadius:cornerRadius]; 137 | CGContextSaveGState(context); 138 | CGContextSetShadowWithColor(context, shadowOffset, shadowBlurRadius, shadow.CGColor); 139 | [buttonColor setFill]; 140 | [topBunPath fill]; 141 | CGContextRestoreGState(context); 142 | 143 | //// Meat Drawing 144 | UIBezierPath* meatPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(xOffset, yOffset*2 + buttonHeight, buttonWidth, buttonHeight) cornerRadius:cornerRadius]; 145 | CGContextSaveGState(context); 146 | CGContextSetShadowWithColor(context, shadowOffset, shadowBlurRadius, shadow.CGColor); 147 | [buttonColor setFill]; 148 | [meatPath fill]; 149 | CGContextRestoreGState(context); 150 | 151 | //// Bottom Bun Drawing 152 | UIBezierPath* bottomBunPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(xOffset, yOffset*3 + buttonHeight*2, buttonWidth, buttonHeight) cornerRadius:cornerRadius]; 153 | CGContextSaveGState(context); 154 | CGContextSetShadowWithColor(context, shadowOffset, shadowBlurRadius, shadow.CGColor); 155 | [buttonColor setFill]; 156 | [bottomBunPath fill]; 157 | CGContextRestoreGState(context); 158 | } 159 | 160 | -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 161 | [super touchesBegan:touches withEvent:event]; 162 | [self setNeedsDisplay]; 163 | } 164 | 165 | -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ 166 | [super touchesEnded:touches withEvent:event]; 167 | [self setNeedsDisplay]; 168 | } 169 | 170 | -(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ 171 | [super touchesCancelled:touches withEvent:event]; 172 | [self setNeedsDisplay]; 173 | } 174 | 175 | - (void)setSelected:(BOOL)selected{ 176 | [super setSelected:selected]; 177 | [self setNeedsDisplay]; 178 | } 179 | 180 | - (void)setHighlighted:(BOOL)highlighted{ 181 | [super setHighlighted:highlighted]; 182 | [self setNeedsDisplay]; 183 | } 184 | @end 185 | 186 | @interface MMDrawerBarButtonItem () 187 | @property (nonatomic,strong) MMDrawerMenuButtonView * buttonView; 188 | 189 | @end 190 | 191 | @implementation MMDrawerBarButtonItem 192 | 193 | -(id)initWithTarget:(id)target action:(SEL)action{ 194 | MMDrawerMenuButtonView * buttonView = [[MMDrawerMenuButtonView alloc] initWithFrame:CGRectMake(0, 0, 26, 26)]; 195 | [buttonView addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; 196 | self = [self initWithCustomView:buttonView]; 197 | if(self){ 198 | [self setButtonView:buttonView]; 199 | } 200 | return self; 201 | } 202 | 203 | -(UIColor *)menuButtonColorForState:(UIControlState)state{ 204 | return [self.buttonView menuButtonColorForState:state]; 205 | } 206 | 207 | -(void)setMenuButtonColor:(UIColor *)color forState:(UIControlState)state{ 208 | [self.buttonView setMenuButtonColor:color forState:state]; 209 | } 210 | 211 | -(UIColor *)shadowColorForState:(UIControlState)state{ 212 | return [self.buttonView shadowColorForState:state]; 213 | } 214 | 215 | -(void)setShadowColor:(UIColor *)color forState:(UIControlState)state{ 216 | [self.buttonView setShadowColor:color forState:state]; 217 | } 218 | 219 | @end 220 | -------------------------------------------------------------------------------- /Pods/MMDrawerController/MMDrawerController/MMDrawerController+Subclass.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 Mutual Mobile (http://mutualmobile.com/) 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #import "MMDrawerController.h" 22 | 23 | /** 24 | This class extension is designed for use by subclasses of `MMDrawerController` to customize the functionality to support a specific use-case by a developer. When importing this file, there is no need to also call `#import MMDrawerController.h`. 25 | 26 | None of these methods are meant to be called by non-subclasses of `MMDrawerController`. 27 | */ 28 | 29 | @interface MMDrawerController (Subclass) 30 | ///--------------------------------------- 31 | /// @name Gesture Interaction 32 | ///--------------------------------------- 33 | /** 34 | `MMDrawerController`'s single-tap gesture recognizer callback. This method is called every time the `UITapGestureRecognizer` is triggered. 35 | 36 | @param tapGesture The single-tap gesture recognizer instance that triggered the callback 37 | */ 38 | -(void)tapGestureCallback:(UITapGestureRecognizer *)tapGesture __attribute((objc_requires_super)); 39 | 40 | /** 41 | `MMDrawerController`'s pan gesture recognizer callback. This method is called every time the `UIPanGestureRecognizer` is updated. 42 | 43 | @warning This method do the minimal amount of work to keep the pan gesture responsive. 44 | 45 | @param panGesture The pan gesture recognizer instance that triggered the callback 46 | */ 47 | -(void)panGestureCallback:(UIPanGestureRecognizer *)panGesture __attribute((objc_requires_super)); 48 | 49 | /** 50 | A `UIGestureRecognizerDelegate` method that is queried by `MMDrawerController`'s gestures to determine if it should receive the touch. 51 | 52 | @param gestureRecognizer The gesture recognizer that is asking if it should recieve a touch 53 | @param touch The touch in question in gestureRecognizer.view's coordinate space 54 | */ 55 | -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch __attribute((objc_requires_super)); 56 | 57 | ///--------------------------------------- 58 | /// @name Drawer Presentation 59 | ///--------------------------------------- 60 | /** 61 | Sets the initial conditions for `MMDrawerController` and its child view controllers to prepare the drawer for a transition. If a drawer is open and the opposite drawer is being presented, it prepares that drawer to be hidden and vice-versa for the closing drawer. 62 | 63 | @param drawer The drawer side that will be presented 64 | @param animated A boolean that indicates whether the presentation is being animated or not 65 | */ 66 | -(void)prepareToPresentDrawer:(MMDrawerSide)drawer animated:(BOOL)animated __attribute((objc_requires_super)); 67 | 68 | ///--------------------------------------- 69 | /// @name Opening/Closing Drawer 70 | ///--------------------------------------- 71 | /** 72 | The method that handles closing the drawer. You can subclass this method to get a callback every time the drawer is about to be closed. You can inspect the current open side to determine what side is about to be closed. 73 | 74 | @param animated A boolean that indicates whether the drawer should close with animation 75 | @param velocity A float indicating how fast the drawer should close 76 | @param animationOptions A mask defining the animation options of the animation 77 | @param completion A completion block to be called when the drawer is finished closing 78 | */ 79 | -(void)closeDrawerAnimated:(BOOL)animated velocity:(CGFloat)velocity animationOptions:(UIViewAnimationOptions)options completion:(void (^)(BOOL))completion __attribute((objc_requires_super)); 80 | 81 | /** 82 | The method that handles opening the drawer. You can subclass this method to get a callback every time the drawer is about to be opened. 83 | 84 | @param drawerSide The drawer side that will be opened 85 | @param animated A boolean that indicates whether the drawer should open with animation 86 | @param velocity A float indicating how fast the drawer should open 87 | @param animationOptions A mask defining the animation options of the animation 88 | @param completion A completion block to be called when the drawer is finished opening 89 | */ 90 | -(void)openDrawerSide:(MMDrawerSide)drawerSide animated:(BOOL)animated velocity:(CGFloat)velocity animationOptions:(UIViewAnimationOptions)options completion:(void (^)(BOOL))completion __attribute((objc_requires_super)); 91 | 92 | ///--------------------------------------- 93 | /// @name `UIViewController` Subclass Methods 94 | ///--------------------------------------- 95 | /** 96 | Included here to ensure subclasses call `super`. 97 | 98 | @param toInterfaceOrientation The interface orientation that the interface is moving to 99 | @param duration The duration of the interface orientation animation 100 | */ 101 | -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration __attribute((objc_requires_super)); 102 | 103 | /** 104 | Included here to ensure subclasses call `super`. 105 | 106 | @param toInterfaceOrientation The interface orientation that the interface is moving to 107 | @param duration The duration of the interface orientation animation 108 | */ 109 | -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration __attribute((objc_requires_super)); 110 | 111 | @end 112 | -------------------------------------------------------------------------------- /Pods/MMDrawerController/MMDrawerController/MMDrawerController.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 Mutual Mobile (http://mutualmobile.com/) 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | 22 | #import 23 | 24 | /** 25 | `MMDrawerController` is a side drawer navigation container view controller designed to support the growing number of applications that leverage the side drawer paradigm. This library is designed to exclusively support side drawer navigation in light-weight, focused approach. 26 | 27 | ## Creating a MMDrawerController 28 | `MMDrawerController` is a container view controller, similiar to `UINavigationController` or `UITabBarController`, with up to three child view controllers - Center, LeftDrawer, and RightDrawer. To create a `MMDrawerController`, you must first instantiate the drawer view controllers and the initial center controller, then call one of the init methods listed in this class. 29 | 30 | ## Handling a UINavigationController as the centerViewController 31 | `MMDrawerController` automatically supports handling a `UINavigationController` as the `centerViewController`, and will correctly handle the proper gestures on each view (the navigation bar view as well as the content view for the visible view controller). Note that while this library does support other container view controllers, the open/close gestures are not customized to support them. 32 | 33 | ## Accessing MMDrawerController from the Child View Controller 34 | You can leverage the category class (UIViewController+MMDrawerController) included with this library to access information about the parent `MMDrawerController`. Note that if you are contained within a UINavigationController, the `drawerContainerViewController` will still return the proper reference to the `drawerContainerViewController` parent, even though it is not the direct parent. Refer to the documentation included with the category for more information. 35 | 36 | ## How MMDrawerOpenCenterInteractionMode is handled 37 | `MMDrawerOpenCenterInteractionMode` controls how the user should be able to interact with the center view controller when either drawer is open. By default, this is set to `MMDrawerOpenCenterInteractionModeNavigationBarOnly`, which allows the user to interact with UINavigationBarItems while either drawer is open (typicaly used to click the menu button to close). If you set the interaction mode to `MMDrawerOpenCenterInteractionModeNone`, no items within the center view will be able to be interacted with while a drawer is open. Note that this setting has no effect at all on the `MMCloseDrawerGestureMode`. 38 | 39 | ## How Open/Close Gestures are handled 40 | Two gestures are added to every instance of a drawer controller, one for pan and one for touch. `MMDrawerController` is the delegate for each of the gesture recoginzers, and determines if a touch should be sent to the appropriate gesture when a touch is detected compared with the masks set for open and close gestures and the state of the drawer controller. 41 | 42 | ## Integrating with State Restoration 43 | In order to opt in to state restoration for `MMDrawerController`, you must set the `restorationIdentifier` of your drawer controller. Instances of your centerViewController, leftDrawerViewController and rightDrawerViewController must also be configured with their own `restorationIdentifier` (and optionally a restorationClass) if you intend for those to be restored as well. If your MMDrawerController had an open drawer when your app was sent to the background, that state will also be restored. 44 | 45 | ## What this library doesn't do. 46 | This library is not meant for: 47 | - Top or bottom drawer views 48 | - Displaying both drawers at one time 49 | - Displaying a minimum drawer width 50 | - Support container view controllers other than `UINavigationController` as the center view controller. 51 | */ 52 | 53 | typedef NS_ENUM(NSInteger,MMDrawerSide){ 54 | MMDrawerSideNone = 0, 55 | MMDrawerSideLeft, 56 | MMDrawerSideRight, 57 | }; 58 | 59 | typedef NS_OPTIONS(NSInteger, MMOpenDrawerGestureMode) { 60 | MMOpenDrawerGestureModeNone = 0, 61 | MMOpenDrawerGestureModePanningNavigationBar = 1 << 1, 62 | MMOpenDrawerGestureModePanningCenterView = 1 << 2, 63 | MMOpenDrawerGestureModeBezelPanningCenterView = 1 << 3, 64 | MMOpenDrawerGestureModeCustom = 1 << 4, 65 | MMOpenDrawerGestureModeAll = MMOpenDrawerGestureModePanningNavigationBar | 66 | MMOpenDrawerGestureModePanningCenterView | 67 | MMOpenDrawerGestureModeBezelPanningCenterView | 68 | MMOpenDrawerGestureModeCustom, 69 | }; 70 | 71 | typedef NS_OPTIONS(NSInteger, MMCloseDrawerGestureMode) { 72 | MMCloseDrawerGestureModeNone = 0, 73 | MMCloseDrawerGestureModePanningNavigationBar = 1 << 1, 74 | MMCloseDrawerGestureModePanningCenterView = 1 << 2, 75 | MMCloseDrawerGestureModeBezelPanningCenterView = 1 << 3, 76 | MMCloseDrawerGestureModeTapNavigationBar = 1 << 4, 77 | MMCloseDrawerGestureModeTapCenterView = 1 << 5, 78 | MMCloseDrawerGestureModePanningDrawerView = 1 << 6, 79 | MMCloseDrawerGestureModeCustom = 1 << 7, 80 | MMCloseDrawerGestureModeAll = MMCloseDrawerGestureModePanningNavigationBar | 81 | MMCloseDrawerGestureModePanningCenterView | 82 | MMCloseDrawerGestureModeBezelPanningCenterView | 83 | MMCloseDrawerGestureModeTapNavigationBar | 84 | MMCloseDrawerGestureModeTapCenterView | 85 | MMCloseDrawerGestureModePanningDrawerView | 86 | MMCloseDrawerGestureModeCustom, 87 | }; 88 | 89 | typedef NS_ENUM(NSInteger, MMDrawerOpenCenterInteractionMode) { 90 | MMDrawerOpenCenterInteractionModeNone, 91 | MMDrawerOpenCenterInteractionModeFull, 92 | MMDrawerOpenCenterInteractionModeNavigationBarOnly, 93 | }; 94 | 95 | @class MMDrawerController; 96 | typedef void (^MMDrawerControllerDrawerVisualStateBlock)(MMDrawerController * drawerController, MMDrawerSide drawerSide, CGFloat percentVisible); 97 | 98 | @interface MMDrawerController : UIViewController 99 | 100 | ///--------------------------------------- 101 | /// @name Accessing Drawer Container View Controller Properties 102 | ///--------------------------------------- 103 | 104 | /** 105 | The center view controller. 106 | 107 | This can only be set via the init methods, as well as the `setNewCenterViewController:...` methods. The size of this view controller will automatically be set to the size of the drawer container view controller, and it's position is modified from within this class. Do not modify the frame externally. 108 | */ 109 | @property (nonatomic, strong) UIViewController * centerViewController; 110 | 111 | /** 112 | The left drawer view controller. 113 | 114 | The size of this view controller is managed within this class, and is automatically set to the appropriate size based on the `maximumLeftDrawerWidth`. Do not modify the frame externally. 115 | */ 116 | @property (nonatomic, strong) UIViewController * leftDrawerViewController; 117 | 118 | /** 119 | The right drawer view controller. 120 | 121 | The size of this view controller is managed within this class, and is automatically set to the appropriate size based on the `maximumRightDrawerWidth`. Do not modify the frame externally. 122 | */ 123 | @property (nonatomic, strong) UIViewController * rightDrawerViewController; 124 | 125 | /** 126 | The maximum width of the `leftDrawerViewController`. 127 | 128 | By default, this is set to 280. If the `leftDrawerViewController` is nil, this property will return 0.0; 129 | */ 130 | @property (nonatomic, assign) CGFloat maximumLeftDrawerWidth; 131 | 132 | /** 133 | The maximum width of the `rightDrawerViewController`. 134 | 135 | By default, this is set to 280. If the `rightDrawerViewController` is nil, this property will return 0.0; 136 | 137 | */ 138 | @property (nonatomic, assign) CGFloat maximumRightDrawerWidth; 139 | 140 | /** 141 | The visible width of the `leftDrawerViewController`. 142 | 143 | Note this value can be greater than `maximumLeftDrawerWidth` during the full close animation when setting a new center view controller; 144 | */ 145 | @property (nonatomic, assign, readonly) CGFloat visibleLeftDrawerWidth; 146 | 147 | /** 148 | The visible width of the `rightDrawerViewController`. 149 | 150 | Note this value can be greater than `maximumRightDrawerWidth` during the full close animation when setting a new center view controller; 151 | */ 152 | @property (nonatomic, assign, readonly) CGFloat visibleRightDrawerWidth; 153 | 154 | /** 155 | The animation velocity of the open and close methods, measured in points per second. 156 | 157 | By default, this is set to 840 points per second (three times the default drawer width), meaning it takes 1/3 of a second for the `centerViewController` to open/close across the default drawer width. Note that there is a minimum .1 second duration for built in animations, to account for small distance animations. 158 | */ 159 | @property (nonatomic, assign) CGFloat animationVelocity; 160 | 161 | /** 162 | A boolean that determines whether or not the panning gesture will "hard-stop" at the maximum width for a given drawer side. 163 | 164 | By default, this value is set to YES. Enabling `shouldStretchDrawer` will give the pan a gradual asymptotic stopping point much like `UIScrollView` behaves. Note that if this value is set to YES, the `drawerVisualStateBlock` can be passed a `percentVisible` greater than 1.0, so be sure to handle that case appropriately. 165 | */ 166 | @property (nonatomic, assign) BOOL shouldStretchDrawer; 167 | 168 | /** 169 | The current open side of the drawer. 170 | 171 | Note this value will change as soon as a pan gesture opens a drawer, or when a open/close animation is finished. 172 | */ 173 | @property (nonatomic, assign, readonly) MMDrawerSide openSide; 174 | 175 | /** 176 | How a user is allowed to open a drawer using gestures. 177 | 178 | By default, this is set to `MMOpenDrawerGestureModeNone`. Note these gestures may affect user interaction with the `centerViewController`, so be sure to use appropriately. 179 | */ 180 | @property (nonatomic, assign) MMOpenDrawerGestureMode openDrawerGestureModeMask; 181 | 182 | /** 183 | How a user is allowed to close a drawer. 184 | 185 | By default, this is set to `MMCloseDrawerGestureModeNone`. Note these gestures may affect user interaction with the `centerViewController`, so be sure to use appropriately. 186 | */ 187 | @property (nonatomic, assign) MMCloseDrawerGestureMode closeDrawerGestureModeMask; 188 | 189 | /** 190 | The value determining if the user can interact with the `centerViewController` when a side drawer is open. 191 | 192 | By default, it is `MMDrawerOpenCenterInteractionModeNavigationBarOnly`, meaning that the user can only interact with the buttons on the `UINavigationBar`, if the center view controller is a `UINavigationController`. Otherwise, the user cannot interact with any other center view controller elements. 193 | */ 194 | @property (nonatomic, assign) MMDrawerOpenCenterInteractionMode centerHiddenInteractionMode; 195 | 196 | /** 197 | The flag determining if a shadow should be drawn off of `centerViewController` when a drawer is open. 198 | 199 | By default, this is set to YES. 200 | */ 201 | @property (nonatomic, assign) BOOL showsShadow; 202 | 203 | ///--------------------------------------- 204 | /// @name Initializing a `MMDrawerController` 205 | ///--------------------------------------- 206 | 207 | /** 208 | Creates and initializes an `MMDrawerController` object with the specified center view controller, left drawer view controller, and right drawer view controller. 209 | 210 | @param centerViewController The center view controller. This argument must not be `nil`. 211 | @param leftDrawerViewController The left drawer view controller. 212 | @param rightDrawerViewController The right drawer controller. 213 | 214 | @return The newly-initialized drawer container view controller. 215 | */ 216 | -(id)initWithCenterViewController:(UIViewController *)centerViewController leftDrawerViewController:(UIViewController *)leftDrawerViewController rightDrawerViewController:(UIViewController *)rightDrawerViewController; 217 | 218 | /** 219 | Creates and initializes an `MMDrawerController` object with the specified center view controller, left drawer view controller. 220 | 221 | @param centerViewController The center view controller. This argument must not be `nil`. 222 | @param leftDrawerViewController The left drawer view controller. 223 | 224 | @return The newly-initialized drawer container view controller. 225 | */ 226 | -(id)initWithCenterViewController:(UIViewController *)centerViewController leftDrawerViewController:(UIViewController *)leftDrawerViewController; 227 | 228 | /** 229 | Creates and initializes an `MMDrawerController` object with the specified center view controller, right drawer view controller. 230 | 231 | @param centerViewController The center view controller. This argument must not be `nil`. 232 | @param rightDrawerViewController The right drawer controller. 233 | 234 | @return The newly-initialized drawer container view controller. 235 | */ 236 | -(id)initWithCenterViewController:(UIViewController *)centerViewController rightDrawerViewController:(UIViewController *)rightDrawerViewController; 237 | 238 | ///--------------------------------------- 239 | /// @name Opening and Closing a Drawer 240 | ///--------------------------------------- 241 | 242 | /** 243 | Toggles the drawer open/closed based on the `drawer` passed in. 244 | 245 | Note that if you attempt to toggle a drawer closed while the other is open, nothing will happen. For example, if you pass in MMDrawerSideLeft, but the right drawer is open, nothing will happen. In addition, the completion block will be called with the finished flag set to NO. 246 | 247 | @param drawerSide The `MMDrawerSide` to toggle. This value cannot be `MMDrawerSideNone`. 248 | @param animated Determines whether the `drawer` should be toggle animated. 249 | @param completion The block that is called when the toggle is complete, or if no toggle took place at all. 250 | 251 | */ 252 | -(void)toggleDrawerSide:(MMDrawerSide)drawerSide animated:(BOOL)animated completion:(void(^)(BOOL finished))completion; 253 | 254 | /** 255 | Closes the open drawer. 256 | 257 | @param animated Determines whether the drawer side should be closed animated 258 | @param completion The block that is called when the close is complete 259 | 260 | */ 261 | -(void)closeDrawerAnimated:(BOOL)animated completion:(void(^)(BOOL finished))completion; 262 | 263 | /** 264 | Opens the `drawer` passed in. 265 | 266 | @param drawerSide The `MMDrawerSide` to open. This value cannot be `MMDrawerSideNone`. 267 | @param animated Determines whether the `drawer` should be open animated. 268 | @param completion The block that is called when the toggle is open. 269 | 270 | */ 271 | -(void)openDrawerSide:(MMDrawerSide)drawerSide animated:(BOOL)animated completion:(void(^)(BOOL finished))completion; 272 | 273 | ///--------------------------------------- 274 | /// @name Setting a new Center View Controller 275 | ///--------------------------------------- 276 | 277 | /** 278 | Sets the new `centerViewController`. 279 | 280 | This sets the view controller and will automatically adjust the frame based on the current state of the drawer controller. If `closeAnimated` is YES, it will immediately change the center view controller, and close the drawer from its current position. 281 | 282 | @param centerViewController The new `centerViewController`. 283 | @param closeAnimated Determines whether the drawer should be closed with an animation. 284 | @param completion The block called when the animation is finsihed. 285 | 286 | */ 287 | -(void)setCenterViewController:(UIViewController *)centerViewController withCloseAnimation:(BOOL)closeAnimated completion:(void(^)(BOOL finished))completion; 288 | 289 | /** 290 | Sets the new `centerViewController`. 291 | 292 | This sets the view controller and will automatically adjust the frame based on the current state of the drawer controller. If `closeFullAnimated` is YES, the current center view controller will animate off the screen, the new center view controller will then be set, followed by the drawer closing across the full width of the screen. 293 | 294 | @param newCenterViewController The new `centerViewController`. 295 | @param fullCloseAnimated Determines whether the drawer should be closed with an animation. 296 | @param completion The block called when the animation is finsihed. 297 | 298 | */ 299 | -(void)setCenterViewController:(UIViewController *)newCenterViewController withFullCloseAnimation:(BOOL)fullCloseAnimated completion:(void(^)(BOOL finished))completion; 300 | 301 | ///--------------------------------------- 302 | /// @name Animating the Width of a Drawer 303 | ///--------------------------------------- 304 | 305 | /** 306 | Sets the maximum width of the left drawer view controller. 307 | 308 | If the drawer is open, and `animated` is YES, it will animate the drawer frame as well as adjust the center view controller. If the drawer is not open, this change will take place immediately. 309 | 310 | @param width The new width of left drawer view controller. This must be greater than zero. 311 | @param animated Determines whether the drawer should be adjusted with an animation. 312 | @param completion The block called when the animation is finished. 313 | 314 | */ 315 | -(void)setMaximumLeftDrawerWidth:(CGFloat)width animated:(BOOL)animated completion:(void(^)(BOOL finished))completion; 316 | 317 | /** 318 | Sets the maximum width of the right drawer view controller. 319 | 320 | If the drawer is open, and `animated` is YES, it will animate the drawer frame as well as adjust the center view controller. If the drawer is not open, this change will take place immediately. 321 | 322 | @param width The new width of right drawer view controller. This must be greater than zero. 323 | @param animated Determines whether the drawer should be adjusted with an animation. 324 | @param completion The block called when the animation is finished. 325 | 326 | */ 327 | -(void)setMaximumRightDrawerWidth:(CGFloat)width animated:(BOOL)animated completion:(void(^)(BOOL finished))completion; 328 | 329 | ///--------------------------------------- 330 | /// @name Previewing a Drawer 331 | ///--------------------------------------- 332 | 333 | /** 334 | Bounce preview for the specified `drawerSide` a distance of 40 points. 335 | 336 | @param drawerSide The drawer to preview. This value cannot be `MMDrawerSideNone`. 337 | @param completion The block called when the animation is finsihed. 338 | 339 | */ 340 | -(void)bouncePreviewForDrawerSide:(MMDrawerSide)drawerSide completion:(void(^)(BOOL finished))completion; 341 | 342 | /** 343 | Bounce preview for the specified `drawerSide`. 344 | 345 | @param drawerSide The drawer side to preview. This value cannot be `MMDrawerSideNone`. 346 | @param distance The distance to bounce. 347 | @param completion The block called when the animation is finsihed. 348 | 349 | */ 350 | -(void)bouncePreviewForDrawerSide:(MMDrawerSide)drawerSide distance:(CGFloat)distance completion:(void(^)(BOOL finished))completion; 351 | 352 | ///--------------------------------------- 353 | /// @name Custom Drawer Animations 354 | ///--------------------------------------- 355 | 356 | /** 357 | Sets a callback to be called when a drawer visual state needs to be updated. 358 | 359 | This block is responsible for updating the drawer's view state, and the drawer controller will handle animating to that state from the current state. This block will be called when the drawer is opened or closed, as well when the user is panning the drawer. This block is not responsible for doing animations directly, but instead just updating the state of the properies (such as alpha, anchor point, transform, etc). Note that if `shouldStretchDrawer` is set to YES, it is possible for `percentVisible` to be greater than 1.0. If `shouldStretchDrawer` is set to NO, `percentVisible` will never be greater than 1.0. 360 | 361 | Note that when the drawer is finished opening or closing, the side drawer controller view will be reset with the following properies: 362 | 363 | - alpha: 1.0 364 | - transform: CATransform3DIdentity 365 | - anchorPoint: (0.5,0.5) 366 | 367 | @param drawerVisualStateBlock A block object to be called that allows the implementer to update visual state properties on the drawer. `percentVisible` represents the amount of the drawer space that is current visible, with drawer space being defined as the edge of the screen to the maxmimum drawer width. Note that you do have access to the drawerController, which will allow you to update things like the anchor point of the side drawer layer. 368 | */ 369 | -(void)setDrawerVisualStateBlock:(void(^)(MMDrawerController * drawerController, MMDrawerSide drawerSide, CGFloat percentVisible))drawerVisualStateBlock; 370 | 371 | ///--------------------------------------- 372 | /// @name Gesture Completion Handling 373 | ///--------------------------------------- 374 | 375 | /** 376 | Sets a callback to be called when a gesture has been completed. 377 | 378 | This block is called when a gesture action has been completed. You can query the `openSide` of the `drawerController` to determine what the new state of the drawer is. 379 | 380 | @param gestureCompletionBlock A block object to be called that allows the implementer be notified when a gesture action has been completed. 381 | */ 382 | -(void)setGestureCompletionBlock:(void(^)(MMDrawerController * drawerController, UIGestureRecognizer * gesture))gestureCompletionBlock; 383 | 384 | ///--------------------------------------- 385 | /// @name Custom Gesture Handler 386 | ///--------------------------------------- 387 | 388 | /** 389 | Sets a callback to be called to determine if a UIGestureRecognizer should recieve the given UITouch. 390 | 391 | This block provides a way to allow a gesture to be recognized with custom logic. For example, you may have a certain part of your view that should accept a pan gesture recognizer to open the drawer, but not another a part. If you return YES, the gesture is recognized and the appropriate action is taken. This provides similar support to how Facebook allows you to pan on the background view of the main table view, but not the content itself. You can inspect the `openSide` property of the `drawerController` to determine the current state of the drawer, and apply the appropriate logic within your block. 392 | 393 | Note that either `openDrawerGestureModeMask` must contain `MMOpenDrawerGestureModeCustom`, or `closeDrawerGestureModeMask` must contain `MMCloseDrawerGestureModeCustom` for this block to be consulted. 394 | 395 | @param gestureShouldRecognizeTouchBlock A block object to be called to determine if the given `touch` should be recognized by the given gesture. 396 | */ 397 | -(void)setGestureShouldRecognizeTouchBlock:(BOOL(^)(MMDrawerController * drawerController, UIGestureRecognizer * gesture, UITouch * touch))gestureShouldRecognizeTouchBlock; 398 | 399 | @end 400 | -------------------------------------------------------------------------------- /Pods/MMDrawerController/MMDrawerController/MMDrawerVisualState.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 Mutual Mobile (http://mutualmobile.com/) 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | 22 | #import 23 | #import "MMDrawerController.h" 24 | 25 | /** 26 | `MMDrawerVisualState` provides prebuilt visual state update blocks that can be used in the callback block of `MMDrawerController` for drawer animation. 27 | */ 28 | 29 | @interface MMDrawerVisualState : NSObject 30 | 31 | /** 32 | Creates a slide and scale visual state block that gives an experience similar to Mailbox.app. It scales from 90% to 100%, and translates 50 pixels in the x direction. In addition, it also sets alpha from 0.0 to 1.0. 33 | 34 | @return The visual state block. 35 | */ 36 | +(MMDrawerControllerDrawerVisualStateBlock)slideAndScaleVisualStateBlock; 37 | 38 | /** 39 | Creates a slide visual state block that gives the user an experience that slides at the same speed of the center view controller during animation. This is equal to calling `parallaxVisualStateBlockWithParallaxFactor:` with a parallax factor of 1.0. 40 | 41 | @return The visual state block. 42 | */ 43 | +(MMDrawerControllerDrawerVisualStateBlock)slideVisualStateBlock; 44 | 45 | /** 46 | Creates a swinging door visual state block that gives the user an experience that animates the drawer in along the hinge. 47 | 48 | @return The visual state block. 49 | */ 50 | +(MMDrawerControllerDrawerVisualStateBlock)swingingDoorVisualStateBlock; 51 | 52 | /** 53 | Creates a parallax experience that slides the side drawer view controller at a different rate than the center view controller during animation. For every parallaxFactor of points moved by the center view controller, the side drawer view controller will move 1 point. Passing in 1.0 is the equivalent of a applying a sliding animation, while passing in MAX_FLOAT is the equivalent of having no animation at all. 54 | 55 | @param parallaxFactor The amount of parallax applied to the side drawer conroller. This value must be greater than 1.0. The closer the value is to 1.0, the faster the side drawer view controller will be parallaxing. 56 | 57 | @return The visual state block. 58 | */ 59 | +(MMDrawerControllerDrawerVisualStateBlock)parallaxVisualStateBlockWithParallaxFactor:(CGFloat)parallaxFactor; 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /Pods/MMDrawerController/MMDrawerController/MMDrawerVisualState.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 Mutual Mobile (http://mutualmobile.com/) 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | 22 | #import "MMDrawerVisualState.h" 23 | #import 24 | 25 | @implementation MMDrawerVisualState 26 | +(MMDrawerControllerDrawerVisualStateBlock)slideAndScaleVisualStateBlock{ 27 | MMDrawerControllerDrawerVisualStateBlock visualStateBlock = 28 | ^(MMDrawerController * drawerController, MMDrawerSide drawerSide, CGFloat percentVisible){ 29 | CGFloat minScale = .90; 30 | CGFloat scale = minScale + (percentVisible*(1.0-minScale)); 31 | CATransform3D scaleTransform = CATransform3DMakeScale(scale, scale, scale); 32 | 33 | CGFloat maxDistance = 50; 34 | CGFloat distance = maxDistance * percentVisible; 35 | CATransform3D translateTransform = CATransform3DIdentity; 36 | UIViewController * sideDrawerViewController; 37 | if(drawerSide == MMDrawerSideLeft) { 38 | sideDrawerViewController = drawerController.leftDrawerViewController; 39 | translateTransform = CATransform3DMakeTranslation((maxDistance-distance), 0.0, 0.0); 40 | } 41 | else if(drawerSide == MMDrawerSideRight){ 42 | sideDrawerViewController = drawerController.rightDrawerViewController; 43 | translateTransform = CATransform3DMakeTranslation(-(maxDistance-distance), 0.0, 0.0); 44 | } 45 | 46 | [sideDrawerViewController.view.layer setTransform:CATransform3DConcat(scaleTransform, translateTransform)]; 47 | [sideDrawerViewController.view setAlpha:percentVisible]; 48 | }; 49 | return visualStateBlock; 50 | } 51 | 52 | +(MMDrawerControllerDrawerVisualStateBlock)slideVisualStateBlock{ 53 | return [self parallaxVisualStateBlockWithParallaxFactor:1.0]; 54 | } 55 | 56 | 57 | +(MMDrawerControllerDrawerVisualStateBlock)swingingDoorVisualStateBlock{ 58 | MMDrawerControllerDrawerVisualStateBlock visualStateBlock = 59 | ^(MMDrawerController * drawerController, MMDrawerSide drawerSide, CGFloat percentVisible){ 60 | UIViewController * sideDrawerViewController; 61 | CGPoint anchorPoint = CGPointMake(0.5, 0.5); 62 | CGFloat maxDrawerWidth = 0.0; 63 | CGFloat xOffset; 64 | CGFloat angle = 0.0; 65 | 66 | if(drawerSide==MMDrawerSideLeft){ 67 | 68 | sideDrawerViewController = drawerController.leftDrawerViewController; 69 | anchorPoint = CGPointMake(1.0, .5); 70 | maxDrawerWidth = MAX(drawerController.maximumLeftDrawerWidth,drawerController.visibleLeftDrawerWidth); 71 | xOffset = -(maxDrawerWidth/2.0) + (maxDrawerWidth)*percentVisible; 72 | angle = -M_PI_2+(percentVisible*M_PI_2); 73 | } 74 | else { 75 | sideDrawerViewController = drawerController.rightDrawerViewController; 76 | anchorPoint = CGPointMake(0.0, .5); 77 | maxDrawerWidth = MAX(drawerController.maximumRightDrawerWidth,drawerController.visibleRightDrawerWidth); 78 | xOffset = (maxDrawerWidth/2.0) - (maxDrawerWidth)*percentVisible; 79 | angle = M_PI_2-(percentVisible*M_PI_2); 80 | } 81 | 82 | [sideDrawerViewController.view.layer setAnchorPoint:anchorPoint]; 83 | [sideDrawerViewController.view.layer setShouldRasterize:YES]; 84 | [sideDrawerViewController.view.layer setRasterizationScale:[[UIScreen mainScreen] scale]]; 85 | 86 | CATransform3D swingingDoorTransform = CATransform3DIdentity; 87 | if (percentVisible <= 1.f) { 88 | 89 | CATransform3D identity = CATransform3DIdentity; 90 | identity.m34 = -1.0/1000.0; 91 | CATransform3D rotateTransform = CATransform3DRotate(identity, angle, 0.0, 1.0, 0.0); 92 | 93 | CATransform3D translateTransform = CATransform3DMakeTranslation(xOffset, 0.0, 0.0); 94 | 95 | CATransform3D concatTransform = CATransform3DConcat(rotateTransform, translateTransform); 96 | 97 | swingingDoorTransform = concatTransform; 98 | } 99 | else{ 100 | CATransform3D overshootTransform = CATransform3DMakeScale(percentVisible, 1.f, 1.f); 101 | 102 | NSInteger scalingModifier = 1.f; 103 | if (drawerSide == MMDrawerSideRight) { 104 | scalingModifier = -1.f; 105 | } 106 | 107 | overshootTransform = CATransform3DTranslate(overshootTransform, scalingModifier*maxDrawerWidth/2, 0.f, 0.f); 108 | swingingDoorTransform = overshootTransform; 109 | } 110 | 111 | [sideDrawerViewController.view.layer setTransform:swingingDoorTransform]; 112 | }; 113 | return visualStateBlock; 114 | } 115 | 116 | +(MMDrawerControllerDrawerVisualStateBlock)parallaxVisualStateBlockWithParallaxFactor:(CGFloat)parallaxFactor{ 117 | MMDrawerControllerDrawerVisualStateBlock visualStateBlock = 118 | ^(MMDrawerController * drawerController, MMDrawerSide drawerSide, CGFloat percentVisible){ 119 | NSParameterAssert(parallaxFactor >= 1.0); 120 | CATransform3D transform = CATransform3DIdentity; 121 | UIViewController * sideDrawerViewController; 122 | if(drawerSide == MMDrawerSideLeft) { 123 | sideDrawerViewController = drawerController.leftDrawerViewController; 124 | CGFloat distance = MAX(drawerController.maximumLeftDrawerWidth,drawerController.visibleLeftDrawerWidth); 125 | if (percentVisible <= 1.f) { 126 | transform = CATransform3DMakeTranslation((-distance)/parallaxFactor+(distance*percentVisible/parallaxFactor), 0.0, 0.0); 127 | } 128 | else{ 129 | transform = CATransform3DMakeScale(percentVisible, 1.f, 1.f); 130 | transform = CATransform3DTranslate(transform, drawerController.maximumLeftDrawerWidth*(percentVisible-1.f)/2, 0.f, 0.f); 131 | } 132 | } 133 | else if(drawerSide == MMDrawerSideRight){ 134 | sideDrawerViewController = drawerController.rightDrawerViewController; 135 | CGFloat distance = MAX(drawerController.maximumRightDrawerWidth,drawerController.visibleRightDrawerWidth); 136 | if(percentVisible <= 1.f){ 137 | transform = CATransform3DMakeTranslation((distance)/parallaxFactor-(distance*percentVisible)/parallaxFactor, 0.0, 0.0); 138 | } 139 | else{ 140 | transform = CATransform3DMakeScale(percentVisible, 1.f, 1.f); 141 | transform = CATransform3DTranslate(transform, -drawerController.maximumRightDrawerWidth*(percentVisible-1.f)/2, 0.f, 0.f); 142 | } 143 | } 144 | 145 | [sideDrawerViewController.view.layer setTransform:transform]; 146 | }; 147 | return visualStateBlock; 148 | } 149 | 150 | @end 151 | -------------------------------------------------------------------------------- /Pods/MMDrawerController/MMDrawerController/UIViewController+MMDrawerController.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 Mutual Mobile (http://mutualmobile.com/) 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #import 22 | 23 | #import "MMDrawerController.h" 24 | 25 | /** 26 | A helper category on `UIViewController` that exposes the parent drawer controller, the visible side drawer frame, and a `mm_drawerWillAppear` method that is called when the drawer is about to appear. 27 | */ 28 | 29 | @interface UIViewController (MMDrawerController) 30 | 31 | ///--------------------------------------- 32 | /// @name Accessing Drawer View Controller Properties 33 | ///--------------------------------------- 34 | 35 | /** 36 | The `MMDrawerController` that the view controller is contained within. If the view controller is not contained within a `MMDrawerController`, this property is nil. Note that if the view controller is contained within a `UINavigationController`, that navigation controller is contained within a `MMDrawerController`, this property will return a refernce to the `MMDrawerController`, despite the fact that it is not the direct parent of the view controller. 37 | */ 38 | @property(nonatomic, strong, readonly) MMDrawerController *mm_drawerController; 39 | 40 | /** 41 | The visible rect of the side drawer view controller in the drawer controller coordinate space. If the view controller is not a drawer in a `MMDrawerController`, then this property returns `CGRectNull` 42 | */ 43 | @property(nonatomic, assign, readonly) CGRect mm_visibleDrawerFrame; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Pods/MMDrawerController/MMDrawerController/UIViewController+MMDrawerController.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 Mutual Mobile (http://mutualmobile.com/) 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | 22 | #import "UIViewController+MMDrawerController.h" 23 | 24 | @implementation UIViewController (MMDrawerController) 25 | 26 | 27 | -(MMDrawerController*)mm_drawerController{ 28 | UIViewController *parentViewController = self.parentViewController; 29 | while (parentViewController != nil) { 30 | if([parentViewController isKindOfClass:[MMDrawerController class]]){ 31 | return (MMDrawerController *)parentViewController; 32 | } 33 | parentViewController = parentViewController.parentViewController; 34 | } 35 | return nil; 36 | } 37 | 38 | -(CGRect)mm_visibleDrawerFrame{ 39 | if([self isEqual:self.mm_drawerController.leftDrawerViewController] || 40 | [self.navigationController isEqual:self.mm_drawerController.leftDrawerViewController]){ 41 | CGRect rect = self.mm_drawerController.view.bounds; 42 | rect.size.width = self.mm_drawerController.maximumLeftDrawerWidth; 43 | return rect; 44 | 45 | } 46 | else if([self isEqual:self.mm_drawerController.rightDrawerViewController] || 47 | [self.navigationController isEqual:self.mm_drawerController.rightDrawerViewController]){ 48 | CGRect rect = self.mm_drawerController.view.bounds; 49 | rect.size.width = self.mm_drawerController.maximumRightDrawerWidth; 50 | rect.origin.x = CGRectGetWidth(self.mm_drawerController.view.bounds)-rect.size.width; 51 | return rect; 52 | } 53 | else { 54 | return CGRectNull; 55 | } 56 | } 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /Pods/MMDrawerController/README.md: -------------------------------------------------------------------------------- 1 | #Mutual Mobile Drawer Controller 2 | `MMDrawerController` is a side drawer navigation container view controller designed to support the growing number of applications that leverage the side drawer paradigm. This library is designed to exclusively support side drawer navigation in a light-weight, focused approach while exposing the ability to provide custom animations for presenting and dismissing the drawer. 3 | 4 |

5 | 6 | 7 |

8 | 9 | --- 10 | ##Documentation 11 | Official appledoc documentation can be found at [CocoaDocs](http://cocoadocs.org/docsets/MMDrawerController/). 12 | 13 | --- 14 | ##Installing MMDrawerController 15 |
16 | You can install MMDrawerController in your project by using [CocoaPods](https://github.com/cocoapods/cocoapods): 17 | 18 | ```Ruby 19 | pod 'MMDrawerController', '~> 0.4.0' 20 | ``` 21 | 22 | --- 23 | ##Creating a Drawer Controller 24 | Creating a `MMDrawerController` is as easy as creating a center view controller and the drawer view controllers, and init'int the drawer. 25 | 26 | ```Objective-C 27 | UIViewController * leftDrawer = [[UIViewController alloc] init]; 28 | UIViewController * center = [[UIViewController alloc] init]; 29 | UIViewController * rightDrawer = [[UIViewController alloc] init]; 30 | 31 | MMDrawerController * drawerController = [[MMDrawerController alloc] 32 | initWithCenterViewController:center 33 | leftDrawerViewController:leftDrawer 34 | rightDrawerViewController:rightDrawer]; 35 | ``` 36 | 37 | --- 38 | ##Features 39 | 40 | ###UINavigationController Support 41 | `MMDrawerController` seamlessly accepts a `UINavigationController` as the `centerViewController`, and will update all of the gesture support automatically. In addition, any child view controller contained within the `UINavigationController` will have access to the parent drawer controller using the category explained [below](#accessing-the-drawer-controller-from-a-child-view-controller). 42 | 43 | ###UIGestureRecognizer Support 44 | `MMDrawerController` exposes gesture support for opening and closing the drawer through two masks, one for opening and one for closing. The options are as follows: 45 | 46 | * **MMOpenDrawerGestureMode** 47 | * **MMOpenDrawerGestureModePanningNavigationBar**: The user can open the drawer by panning anywhere on the navigation bar. 48 | * **MMOpenDrawerGestureModePanningCenterView**: The user can open the drawer by panning anywhere on the center view. 49 | * **MMOpenDrawerGestureModeBezelPanningCenterView**: The user can open the drawer by starting a pan anywhere within 20 points of the bezel. 50 | * **MMOpenDrawerGestureModeCustom**: The developer can provide a callback block to determine if the gesture should be recognized. More information below. 51 | 52 | * **MMCloseDrawerGestureMode** 53 | * **MMCloseDrawerGestureModePanningNavigationBar**: The user can close the drawer by panning anywhere on the navigation bar. 54 | * **MMCloseDrawerGestureModePanningCenterView**: The user can close the drawer by panning anywhere on the center view. 55 | * **MMCloseDrawerGestureModeBezelPanningCenterView**: The user can close the drawer by starting a pan anywhere within the bezel of the center view. 56 | * **MMCloseDrawerGestureModeTapNavigationBar**: The user can close the drawer by tapping the navigation bar. 57 | * **MMCloseDrawerGestureModeTapCenterView**: The user can close the drawer by tapping the center view. 58 | * **MMCloseDrawerGestureModePanningDrawerView**: The user can close the drawer by panning anywhere on the drawer view. 59 | * **MMCloseDrawerGestureModeCustom**: The developer can provide a callback block to determine if the gesture should be recognized. More information below. 60 | 61 | You are free to set whatever combination you want for opening and closing. Note that these gestures may impact touches sent to the child view controllers, so be sure to use these appropriately for your application. For example, you wouldn't want `MMOpenDrawerGestureModePanningCenterView` set if a `MKMapView` is your center view controller, since it would intercept the pan meant for moving around the map. 62 | 63 | ####Custom Gesture Recognizer Support 64 | Starting with version 0.3.0, you can now provide a callback block to determine if a gesture should be recognized using the `setGestureShouldRecognizeTouchBlock:` method. This method provides three parameters - the drawer controller, the gesture, and the touch. As a developer, you are responsible for inspecting those elements and determining if the gesture should be recognized or not. Note the block is only consulted if you have set `MMOpenDrawerGestureModeCustom`/`MMCloseDrawerGestureModeCustom` on the appropriate mask. 65 | 66 | For example, lets say you have a center view controller that contains a few elements, and you only want the pan gesture to be recognized to open the drawer when the touch begins within a certain subview. You would make sure that the `openDrawerGestureModeMask` contains `MMOpenDrawerGestureModeCustom`, and you could set a block below as so: 67 | 68 | ```Objective-C 69 | [myDrawerController 70 | setGestureShouldRecognizeTouchBlock:^BOOL(MMDrawerController *drawerController, UIGestureRecognizer *gesture, UITouch *touch) { 71 | BOOL shouldRecognizeTouch = NO; 72 | if(drawerController.openSide == MMDrawerSideNone && 73 | [gesture isKindOfClass:[UIPanGestureRecognizer class]]){ 74 | UIView * customView = [drawerController.centerViewController myCustomSubview]; 75 | CGPoint location = [touch locationInView:customView]; 76 | shouldRecognizeTouch = (CGRectContainsPoint(customView.bounds, location)); 77 | } 78 | return shouldRecognizeTouch; 79 | }]; 80 | ``` 81 | Note that you would not want the `openDrawerGestureModeMask` to contain `MMOpenDrawerGestureModePanningCenterView`, since that would take over and be applied automatically regardless of where the touch begins within the center view. 82 | 83 | ###Custom Drawer Open/Close Animations 84 | `MMDrawerController` provides a callback block that allows you to implement your own custom state for the drawer controller when an open/close or pan gesture event happens. Within the block, you are responsible for updating the visual state of the drawer controller, and the drawer controller will handle animating to that state. 85 | 86 | For example, to set the alpha of the side drawer controller from 0 to 1 during an animation, you would do the following: 87 | 88 | ```Objective-C 89 | [drawerController 90 | setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) { 91 | UIViewController * sideDrawerViewController; 92 | if(drawerSide == MMDrawerSideLeft){ 93 | sideDrawerViewController = drawerController.leftDrawerViewController; 94 | } 95 | else if(drawerSide == MMDrawerSideRight){ 96 | sideDrawerViewController = drawerController.rightDrawerViewController; 97 | } 98 | [sideDrawerViewController.view setAlpha:percentVisible]; 99 | }]; 100 | ``` 101 | 102 | In addition, `MMDrawerController` ships with several prebuilt animations to let you go crazy right out of the box. These are included as a subspec for the project, and more information can be found [below](#prebuilt-example-animations). 103 | 104 | ###Center View Controller Interaction Mode 105 | When a drawer is open, you can control how a user can interact with the center view controller. 106 | 107 | * **MMDrawerOpenCenterInteractionModeNone**: The user can not interact with any content in the center view. 108 | * **MMDrawerOpenCenterInteractionModeFull**: The user can interact with all content in the center view. 109 | * **MMDrawerOpenCenterInteractionModeNavigationBarOnly**: The user can interact with only content on the navigation bar. The setting allows the menu button to still respond, allowing you to toggle the drawer closed when it is open. This is the default setting. 110 | 111 | ###Accessing the Drawer Controller from a Child View Controller 112 | You can use the `UIViewController+MMDrawerController` category in order to query the drawerController directly from child view controllers. 113 | 114 | ###State Restoration 115 | Beginning with 0.4.0, `MMDrawerController` supports iOS state restoration. In order to opt in to state restoration for `MMDrawerController`, you must set the `restorationIdentifier` of your drawer controller. Instances of your `centerViewController`, `leftDrawerViewController` and `rightDrawerViewController` must also be configured with their own `restorationIdentifier` (and optionally a restorationClass) if you intend for those to be restored as well. If your MMDrawerController had an open drawer when your app was sent to the background, that state will also be restored. 116 | 117 | --- 118 | ##Subclassing 119 | If you plan to subclass `MMDrawerController`, import `MMDrawerController+Subclass.h` into your subclass to access protected methods for `MMDrawerController.` Note that several methods assume and require you to call super, so be sure to follow that convention. 120 | 121 | If there is specific functionality you need that is not supported by these methods, please open a Github issue explaining your needs and we can try and find a way to open up methods that can help you out. 122 | 123 | --- 124 | ##Bells and Whistles 125 | A few extras to make your life easier... 126 | 127 | ###MMDrawerBarButtonItem 128 | Using Paint Code, we created a standard Menu Button that you can use in any `UINavigationBar`, and make it whatever color you want. It's included as a subspec to this library. Enjoy. 129 | 130 | ###Prebuilt Example Animations 131 | In order to make it as easy as possible for you to use this library, we built some of the common animations we see out there today. Simply include the `MMDrawerVisualState` subspec, and use any of the prebuilt visual states. 132 | 133 | For example, if you wanted to use a slide and scale animation, you would do the following: 134 | 135 | ```Objective-C 136 | [drawerController setDrawerVisualStateBlock:[MMDrawerVisualState slideAndScaleVisualStateBlock]]; 137 | ``` 138 | 139 | And that's it... 140 | 141 | Here's a quick list of the built in animations: 142 | 143 | * **Slide**: The drawer slides at the same rate as the center view controller. 144 | * **Slide and Scale**: The drawer slides and scales up at the same time, while also alpha'ing from 0.0 to 1.0. 145 | * **Swinging Door**: The drawer swings in along a hinge on the center view controller. 146 | * **Parallax**: The drawer slides in at a slower rate than the center view controller, giving a parallax effect. 147 | 148 | ###Stretchy Drawer 149 | By default, the side drawer will stretch if the user pans past the maximum drawer width. This gives a playful stretch effect. You can disable this by setting `shouldStretchDrawer` to NO, or you can make your own overshoot animation by creating a custom visual state block and setting up custom transforms for when percentVisible is greater than 1.0 150 | 151 | ###Nifty Example 152 | We decided to spruce up the example a bit using graphics generated from PaintCode. Hope you like it. 153 | 154 | The example shows off all the features of the library. Give it a whirl. 155 | 156 | --- 157 | ##What this Library Doesn't Do 158 | In order to keep this library light-weight, we had to make some design trade off decisions. Specifically, we decided this library would NOT DO the following: 159 | 160 | * Top or bottom drawer views 161 | * Displaying both drawers at one time 162 | * Displaying a minimum drawer width 163 | * Support container view controllers other than `UINavigationController` (such as `UITabBarController` or `UISplitViewController`) as the center view controller. 164 | * Support presenting the drawer above the center view controller (like the Google+ app). 165 | 166 | We're sure this list will grow over time. But that's the cost of keeping something maintainable :) 167 | 168 | --- 169 | ##Credit 170 | Designed and Developed by these fine folks at [Mutual Mobile](http://mutualmobile.com): 171 | 172 | ###Development 173 | 174 | * [Kevin Harwood](http://twitter.com/kevinharwood) 175 | * [Lars Anderson](http://twitter.com/theonlylars) 176 | * [Rene Cacheaux](http://twitter.com/rcachatx) 177 | * [Conrad Stoll](http://twitter.com/conradstoll) 178 | 179 | ###Design 180 | 181 | * [Matt McDaniel](http://twitter.com/supermattzor) 182 | 183 | --- 184 | ##Feedback 185 | We'd love to hear feedback on the library. Create Github issues, or hit us up on Twitter. 186 | 187 | --- 188 | ##License 189 | `MMDrawerController` is available under the MIT license. See the LICENSE file for more info. -------------------------------------------------------------------------------- /Pods/Manifest.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - MMDrawerController (0.4.0): 3 | - MMDrawerController/Core (= 0.4.0) 4 | - MMDrawerController/MMDrawerBarButtonItem (= 0.4.0) 5 | - MMDrawerController/MMDrawerVisualStates (= 0.4.0) 6 | - MMDrawerController/Subclass (= 0.4.0) 7 | - MMDrawerController+Storyboard (0.0.1): 8 | - MMDrawerController (~> 0.4.0) 9 | - MMDrawerController/Core (0.4.0) 10 | - MMDrawerController/MMDrawerBarButtonItem (0.4.0): 11 | - MMDrawerController/Core 12 | - MMDrawerController/MMDrawerVisualStates (0.4.0): 13 | - MMDrawerController/Core 14 | - MMDrawerController/Subclass (0.4.0): 15 | - MMDrawerController/Core 16 | - shapelib (1.3) 17 | 18 | DEPENDENCIES: 19 | - MMDrawerController+Storyboard 20 | - shapelib 21 | 22 | SPEC CHECKSUMS: 23 | MMDrawerController: b3731a50b80a7b2c017ac1c4e20f64724fbca006 24 | MMDrawerController+Storyboard: d1bde200dfd22d9caac6187cac4fa4ce62ce0a9b 25 | shapelib: 622b987882111dd347fd30062319e896e8e74bed 26 | 27 | COCOAPODS: 0.35.0 28 | -------------------------------------------------------------------------------- /Pods/shapelib/README: -------------------------------------------------------------------------------- 1 | 2 | Please read shapelib.html. 3 | 4 | Building on Unix 5 | ---------------- 6 | 7 | 1) Edit Makefile, and set CFLAGS, and CC macros as required for the 8 | target system. Often the defaults will work fine. 9 | 10 | 2) type "make" 11 | 12 | The result should be: 13 | 14 | Core shapelib support. 15 | shpopen.o 16 | dbfopen.o 17 | safileio.o 18 | shptree.o 19 | libshp.a 20 | 21 | Utility/demonstration programs: 22 | shpcreate, shpdump, shpadd, dbfcreate, dbfdump, dbfadd, shptreedump 23 | 24 | 3) To test type: 25 | make test 26 | 27 | 4) To libshp.a and the test binaries in /usr/local: 28 | make install 29 | 30 | 31 | Building on Windows 32 | ------------------- 33 | 34 | If you have run the VC++ VCVARS32.BAT, you should be able to type the 35 | following in a command window to build the code and executables: 36 | 37 | C:> nmake /f makefile.vc 38 | 39 | Otherwise create your own VC++ project. There aren't many files to deal with 40 | here! 41 | 42 | -------------------------------------------------------------------------------- /Pods/shapelib/README.tree: -------------------------------------------------------------------------------- 1 | Venkat, 2 | 3 | I have completed the planned Shapefile quadtree mechanism. The additions 4 | to the traditional Shapelib are found in shptree.c (functions supporting 5 | quad tree searching and query). There are also some new prototypes for 6 | the tree stuff in shapefil.h ... including some prototypes for functions 7 | you don't require and hence that I haven't implemented at this time. 8 | 9 | I have also prepared a demonstration program using the API. That is 10 | the ``shpdumptree'' program, with the source code in shpdumptree.c. The 11 | shpdumptree program has two functions. One is to dump an ASCII rendering 12 | of the internal quadtree, and the other is example use of a quad tree 13 | searching function. 14 | 15 | Dumping the Tree 16 | ---------------- 17 | 18 | The tree dumping is done as shown below. The "-maxdepth" commandline 19 | switch can be used to control the maximum depth, otherwise it internally 20 | computes a ``reasonable depth'' to use based on the number of structures 21 | in the shapefile. 22 | 23 | warmerda@gdal[207]% shptreedump -maxdepth 6 eg_data/polygon.shp 24 | ( SHPTreeNode 25 | Min = (471127.19,4751545.00) 26 | Max = (489292.31,4765610.50) 27 | Shapes(0): 28 | ( SHPTreeNode 29 | Min = (471127.19,4751545.00) 30 | Max = (481118.01,4765610.50) 31 | Shapes(0): 32 | ( SHPTreeNode 33 | Min = (471127.19,4751545.00) 34 | Max = (481118.01,4759281.03) 35 | Shapes(0): 36 | ( SHPTreeNode 37 | Min = (471127.19,4751545.00) 38 | Max = (476622.14,4759281.03) 39 | Shapes(0): 40 | ( SHPTreeNode 41 | Min = (471127.19,4751545.00) 42 | Max = (476622.14,4755799.81) 43 | Shapes(0): 44 | ( SHPTreeNode 45 | Min = (471127.19,4751545.00) 46 | Max = (474149.41,4755799.81) 47 | Shapes(6): 395 397 402 404 405 422 48 | ) 49 | ( SHPTreeNode 50 | Min = (473599.92,4751545.00) 51 | Max = (476622.14,4755799.81) 52 | Shapes(10): 392 394 403 413 414 417 426 433 434 447 53 | ) 54 | ) 55 | ... 56 | 57 | A structure like the following represents one node in the tree. In 58 | this case it cover the region of 473599.92 < X < 476622.14,and 59 | 4751545.0 < Y < 4755799.81. There are ten shapes within this region 60 | who's shapeids are 392, 394 ... 447. This node has no children nodes. 61 | 62 | ( SHPTreeNode 63 | Min = (473599.92,4751545.00) 64 | Max = (476622.14,4755799.81) 65 | Shapes(10): 392 394 403 413 414 417 426 433 434 447 66 | ) 67 | 68 | The heirarchy of indentation is intended to show the parent, child 69 | relationship between nodes, with the tree being deeper the further to the 70 | right you go. 71 | 72 | The `-v' flag to the program can be used to expand the report to include 73 | the full information about shapes, not just their shapeid. This can result 74 | in a report looking more like this: 75 | 76 | ... 77 | ( SHPTreeNode 78 | Min = (478095.78,4751545.00) 79 | Max = (481118.01,4755799.81) 80 | Shapes(3): 81 | ( Shape 82 | ShapeId = 448 83 | Min = (479988.09,4753300.00) 84 | Max = (480705.59,4754236.50) 85 | Vertex[0] = (480136.59,4754174.50) 86 | Vertex[1] = (480229.97,4754182.00) 87 | Vertex[2] = (480370.09,4754200.50) 88 | Vertex[3] = (480695.12,4754236.50) 89 | Vertex[4] = (480687.97,4754129.50) 90 | Vertex[5] = (480650.47,4754075.50) 91 | Vertex[6] = (480520.62,4753948.00) 92 | Vertex[7] = (480490.00,4753900.00) 93 | Vertex[8] = (480499.78,4753840.50) 94 | Vertex[9] = (480500.97,4753820.50) 95 | Vertex[10] = (480534.75,4753660.50) 96 | Vertex[11] = (480560.00,4753565.00) 97 | Vertex[12] = (480574.91,4753550.50) 98 | ... 99 | 100 | While it is possible to part the output of the shptreedump program, and 101 | insert it into your database, my intention was that the shptreedump program 102 | would serve as an example of how to pre-order traversal of the quad tree, 103 | and collect the information you will need to insert into your database. 104 | I would then expect you to write a new program based on shptreedump that 105 | calls a C API for your database to insert objects instead of printing them 106 | out. Alternatively there may be an ASCII format for loading tables that 107 | you could modify the program to output. 108 | 109 | Searching 110 | --------- 111 | 112 | The other thing that you can do with the shptreedump program is to 113 | perform a search on the quadtree. For instance the following shows 114 | searching on a small region. 115 | 116 | % shptreedump -search 471127 4751545 476622 4759281 eg_data/polygon.shp 117 | Shape 17: not in area of interest, but fetched. 118 | Shape 31: not in area of interest, but fetched. 119 | Shape 52: not in area of interest, but fetched. 120 | Shape 76: not in area of interest, but fetched. 121 | Shape 82: not in area of interest, but fetched. 122 | Shape 104: not in area of interest, but fetched. 123 | Shape 124: not in area of interest, but fetched. 124 | Shape 134: not in area of interest, but fetched. 125 | Shape 139: not in area of interest, but fetched. 126 | Shape 154: not in area of interest, but fetched. 127 | Shape 175: not in area of interest, but fetched. 128 | Shape 177: not in area of interest, but fetched. 129 | Shape 185: not in area of interest, but fetched. 130 | Shape 192: not in area of interest, but fetched. 131 | Shape 196: appears to be in area of interest. 132 | .... 133 | 134 | 135 | I have included this capability (and the SHPTreeFindLikelyShapes() function) 136 | so that you can see a working example of how to search this quad tree. 137 | Note that searching is a multi-stage affair. 138 | 139 | First a pass is made over the quadtree, collecting the shapeids of all 140 | shapes contained in a quadtree node for which the bounding rectangle overlaps 141 | the search rectangle. This is all accomplished by SHPTreeFindLikelyShapes() 142 | in shptree.c. 143 | 144 | The second phase is to fetch the actual shapes, and verify if their bounding 145 | box falls within the area of interest. This is necessary because the shape 146 | will tend to have a significantly smaller bounding rectangle than the tree 147 | node in which it is found. This can result ``false positives'' on the first 148 | phase search, as indicated by teh ``not in area of interest, but fetched'' 149 | messages above. This stage is done in the SHPTreeNodeSearchAndDump() 150 | function in shptreedump.c. 151 | 152 | A possible third phase is to verify that the actualy line segments in the 153 | shape actually cross the area of interest. I don't both with this as it 154 | is complicated, and assuming that the drawing engine takes care of clipping 155 | it is quite a bit easier to let it fall through. 156 | 157 | Building 158 | -------- 159 | 160 | I have added a makefile.vc to the shapelib distribution. After you have 161 | unpacked the shapefile you should have a shapelib subdirectory. If you 162 | cd to that directory, and enter ``nmake -f makefile.vc'' in a DOS window 163 | you should be able to build everything with VC++ (assuming it is properly 164 | installed and in your path). 165 | 166 | You can also create a project in VC just including the files 167 | shpopen.c, shptree.c and shptreedump.c, building as a Win32 console 168 | application. 169 | 170 | For your convenience I am including prebuild .obj files, and .exe files 171 | in the distribution. 172 | 173 | -------------------------------------------------------------------------------- /Pods/shapelib/dbfadd.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * $Id: dbfadd.c,v 1.9 2004-09-26 20:09:35 fwarmerdam Exp $ 3 | * 4 | * Project: Shapelib 5 | * Purpose: Sample application for adding a record to an existing .dbf file. 6 | * Author: Frank Warmerdam, warmerdam@pobox.com 7 | * 8 | ****************************************************************************** 9 | * Copyright (c) 1999, Frank Warmerdam 10 | * 11 | * This software is available under the following "MIT Style" license, 12 | * or at the option of the licensee under the LGPL (see LICENSE.LGPL). This 13 | * option is discussed in more detail in shapelib.html. 14 | * 15 | * -- 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a 18 | * copy of this software and associated documentation files (the "Software"), 19 | * to deal in the Software without restriction, including without limitation 20 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 21 | * and/or sell copies of the Software, and to permit persons to whom the 22 | * Software is furnished to do so, subject to the following conditions: 23 | * 24 | * The above copyright notice and this permission notice shall be included 25 | * in all copies or substantial portions of the Software. 26 | * 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 28 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 29 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 30 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 31 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 32 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 33 | * DEALINGS IN THE SOFTWARE. 34 | ****************************************************************************** 35 | * 36 | * $Log: dbfadd.c,v $ 37 | * Revision 1.9 2004-09-26 20:09:35 fwarmerdam 38 | * avoid rcsid warnings 39 | * 40 | * Revision 1.8 2004/01/09 16:39:49 fwarmerdam 41 | * include standard include files 42 | * 43 | * Revision 1.7 2002/01/15 14:36:07 warmerda 44 | * updated email address 45 | * 46 | * Revision 1.6 2001/05/31 18:15:40 warmerda 47 | * Added support for NULL fields in DBF files 48 | * 49 | * Revision 1.5 1999/11/05 14:12:04 warmerda 50 | * updated license terms 51 | * 52 | * Revision 1.4 1998/12/03 16:36:06 warmerda 53 | * Added stdlib.h and math.h to get atof() prototype. 54 | * 55 | * Revision 1.3 1995/10/21 03:13:23 warmerda 56 | * Use binary mode.. 57 | * 58 | * Revision 1.2 1995/08/04 03:15:59 warmerda 59 | * Added header. 60 | * 61 | */ 62 | 63 | #include 64 | #include 65 | #include 66 | 67 | #include "shapefil.h" 68 | 69 | SHP_CVSID("$Id: dbfadd.c,v 1.9 2004-09-26 20:09:35 fwarmerdam Exp $") 70 | 71 | int main( int argc, char ** argv ) 72 | 73 | { 74 | DBFHandle hDBF; 75 | int i, iRecord; 76 | 77 | /* -------------------------------------------------------------------- */ 78 | /* Display a usage message. */ 79 | /* -------------------------------------------------------------------- */ 80 | if( argc < 3 ) 81 | { 82 | printf( "dbfadd xbase_file field_values\n" ); 83 | 84 | exit( 1 ); 85 | } 86 | 87 | /* -------------------------------------------------------------------- */ 88 | /* Create the database. */ 89 | /* -------------------------------------------------------------------- */ 90 | hDBF = DBFOpen( argv[1], "r+b" ); 91 | if( hDBF == NULL ) 92 | { 93 | printf( "DBFOpen(%s,\"rb+\") failed.\n", argv[1] ); 94 | exit( 2 ); 95 | } 96 | 97 | /* -------------------------------------------------------------------- */ 98 | /* Do we have the correct number of arguments? */ 99 | /* -------------------------------------------------------------------- */ 100 | if( DBFGetFieldCount( hDBF ) != argc - 2 ) 101 | { 102 | printf( "Got %d fields, but require %d\n", 103 | argc - 2, DBFGetFieldCount( hDBF ) ); 104 | exit( 3 ); 105 | } 106 | 107 | iRecord = DBFGetRecordCount( hDBF ); 108 | 109 | /* -------------------------------------------------------------------- */ 110 | /* Loop assigning the new field values. */ 111 | /* -------------------------------------------------------------------- */ 112 | for( i = 0; i < DBFGetFieldCount(hDBF); i++ ) 113 | { 114 | if( strcmp( argv[i+2], "" ) == 0 ) 115 | DBFWriteNULLAttribute(hDBF, iRecord, i ); 116 | else if( DBFGetFieldInfo( hDBF, i, NULL, NULL, NULL ) == FTString ) 117 | DBFWriteStringAttribute(hDBF, iRecord, i, argv[i+2] ); 118 | else 119 | DBFWriteDoubleAttribute(hDBF, iRecord, i, atof(argv[i+2]) ); 120 | } 121 | 122 | /* -------------------------------------------------------------------- */ 123 | /* Close and cleanup. */ 124 | /* -------------------------------------------------------------------- */ 125 | DBFClose( hDBF ); 126 | 127 | return( 0 ); 128 | } 129 | -------------------------------------------------------------------------------- /Pods/shapelib/dbfcreate.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * $Id: dbfcreate.c,v 1.7 2004-09-26 20:09:35 fwarmerdam Exp $ 3 | * 4 | * Project: Shapelib 5 | * Purpose: Sample application for creating a new .dbf file. 6 | * Author: Frank Warmerdam, warmerdam@pobox.com 7 | * 8 | ****************************************************************************** 9 | * Copyright (c) 1999, Frank Warmerdam 10 | * 11 | * This software is available under the following "MIT Style" license, 12 | * or at the option of the licensee under the LGPL (see LICENSE.LGPL). This 13 | * option is discussed in more detail in shapelib.html. 14 | * 15 | * -- 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a 18 | * copy of this software and associated documentation files (the "Software"), 19 | * to deal in the Software without restriction, including without limitation 20 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 21 | * and/or sell copies of the Software, and to permit persons to whom the 22 | * Software is furnished to do so, subject to the following conditions: 23 | * 24 | * The above copyright notice and this permission notice shall be included 25 | * in all copies or substantial portions of the Software. 26 | * 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 28 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 29 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 30 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 31 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 32 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 33 | * DEALINGS IN THE SOFTWARE. 34 | ****************************************************************************** 35 | * 36 | * $Log: dbfcreate.c,v $ 37 | * Revision 1.7 2004-09-26 20:09:35 fwarmerdam 38 | * avoid rcsid warnings 39 | * 40 | * Revision 1.6 2002/01/15 14:36:07 warmerda 41 | * updated email address 42 | * 43 | * Revision 1.5 2000/07/07 13:39:45 warmerda 44 | * removed unused variables, and added system include files 45 | * 46 | * Revision 1.4 1999/11/05 14:12:04 warmerda 47 | * updated license terms 48 | * 49 | * Revision 1.3 1999/04/01 18:47:44 warmerda 50 | * Fixed DBFAddField() call convention. 51 | * 52 | * Revision 1.2 1995/08/04 03:17:11 warmerda 53 | * Added header. 54 | * 55 | */ 56 | 57 | #include 58 | #include 59 | #include "shapefil.h" 60 | 61 | SHP_CVSID("$Id: dbfcreate.c,v 1.7 2004-09-26 20:09:35 fwarmerdam Exp $") 62 | 63 | int main( int argc, char ** argv ) 64 | 65 | { 66 | DBFHandle hDBF; 67 | int i; 68 | 69 | /* -------------------------------------------------------------------- */ 70 | /* Display a usage message. */ 71 | /* -------------------------------------------------------------------- */ 72 | if( argc < 2 ) 73 | { 74 | printf( "dbfcreate xbase_file [[-s field_name width],[-n field_name width decimals]]...\n" ); 75 | 76 | exit( 1 ); 77 | } 78 | 79 | /* -------------------------------------------------------------------- */ 80 | /* Create the database. */ 81 | /* -------------------------------------------------------------------- */ 82 | hDBF = DBFCreate( argv[1] ); 83 | if( hDBF == NULL ) 84 | { 85 | printf( "DBFCreate(%s) failed.\n", argv[1] ); 86 | exit( 2 ); 87 | } 88 | 89 | /* -------------------------------------------------------------------- */ 90 | /* Loop over the field definitions adding new fields. */ 91 | /* -------------------------------------------------------------------- */ 92 | for( i = 2; i < argc; i++ ) 93 | { 94 | if( strcmp(argv[i],"-s") == 0 && i < argc-2 ) 95 | { 96 | if( DBFAddField( hDBF, argv[i+1], FTString, atoi(argv[i+2]), 0 ) 97 | == -1 ) 98 | { 99 | printf( "DBFAddField(%s,FTString,%d,0) failed.\n", 100 | argv[i+1], atoi(argv[i+2]) ); 101 | exit( 4 ); 102 | } 103 | i = i + 2; 104 | } 105 | else if( strcmp(argv[i],"-n") == 0 && i < argc-3 ) 106 | { 107 | if( DBFAddField( hDBF, argv[i+1], FTDouble, atoi(argv[i+2]), 108 | atoi(argv[i+3]) ) == -1 ) 109 | { 110 | printf( "DBFAddField(%s,FTDouble,%d,%d) failed.\n", 111 | argv[i+1], atoi(argv[i+2]), atoi(argv[i+3]) ); 112 | exit( 4 ); 113 | } 114 | i = i + 3; 115 | } 116 | else 117 | { 118 | printf( "Argument incomplete, or unrecognised:%s\n", argv[i] ); 119 | exit( 3 ); 120 | } 121 | } 122 | 123 | DBFClose( hDBF ); 124 | 125 | return( 0 ); 126 | } 127 | -------------------------------------------------------------------------------- /Pods/shapelib/dbfdump.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * $Id: dbfdump.c,v 1.12 2006-06-17 00:15:08 fwarmerdam Exp $ 3 | * 4 | * Project: Shapelib 5 | * Purpose: Sample application for dumping .dbf files to the terminal. 6 | * Author: Frank Warmerdam, warmerdam@pobox.com 7 | * 8 | ****************************************************************************** 9 | * Copyright (c) 1999, Frank Warmerdam 10 | * 11 | * This software is available under the following "MIT Style" license, 12 | * or at the option of the licensee under the LGPL (see LICENSE.LGPL). This 13 | * option is discussed in more detail in shapelib.html. 14 | * 15 | * -- 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a 18 | * copy of this software and associated documentation files (the "Software"), 19 | * to deal in the Software without restriction, including without limitation 20 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 21 | * and/or sell copies of the Software, and to permit persons to whom the 22 | * Software is furnished to do so, subject to the following conditions: 23 | * 24 | * The above copyright notice and this permission notice shall be included 25 | * in all copies or substantial portions of the Software. 26 | * 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 28 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 29 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 30 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 31 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 32 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 33 | * DEALINGS IN THE SOFTWARE. 34 | ****************************************************************************** 35 | * 36 | * $Log: dbfdump.c,v $ 37 | * Revision 1.12 2006-06-17 00:15:08 fwarmerdam 38 | * Free panWidth for better memory testing. 39 | * 40 | * Revision 1.11 2006/02/15 01:11:27 fwarmerdam 41 | * added reporting of native type 42 | * 43 | * Revision 1.10 2004/09/26 20:09:35 fwarmerdam 44 | * avoid rcsid warnings 45 | * 46 | * Revision 1.9 2002/01/15 14:36:07 warmerda 47 | * updated email address 48 | * 49 | * Revision 1.8 2001/05/31 18:15:40 warmerda 50 | * Added support for NULL fields in DBF files 51 | * 52 | * Revision 1.7 2000/09/20 13:13:55 warmerda 53 | * added break after default: 54 | * 55 | * Revision 1.6 2000/07/07 13:39:45 warmerda 56 | * removed unused variables, and added system include files 57 | * 58 | * Revision 1.5 1999/11/05 14:12:04 warmerda 59 | * updated license terms 60 | * 61 | * Revision 1.4 1998/12/31 15:30:13 warmerda 62 | * Added -m, -r, and -h commandline options. 63 | * 64 | * Revision 1.3 1995/10/21 03:15:01 warmerda 65 | * Changed to use binary file access. 66 | * 67 | * Revision 1.2 1995/08/04 03:16:22 warmerda 68 | * Added header. 69 | * 70 | */ 71 | 72 | #include 73 | #include 74 | #include "shapefil.h" 75 | 76 | SHP_CVSID("$Id: dbfdump.c,v 1.12 2006-06-17 00:15:08 fwarmerdam Exp $") 77 | 78 | int main( int argc, char ** argv ) 79 | 80 | { 81 | DBFHandle hDBF; 82 | int *panWidth, i, iRecord; 83 | char szFormat[32], *pszFilename = NULL; 84 | int nWidth, nDecimals; 85 | int bHeader = 0; 86 | int bRaw = 0; 87 | int bMultiLine = 0; 88 | char szTitle[12]; 89 | 90 | /* -------------------------------------------------------------------- */ 91 | /* Handle arguments. */ 92 | /* -------------------------------------------------------------------- */ 93 | for( i = 1; i < argc; i++ ) 94 | { 95 | if( strcmp(argv[i],"-h") == 0 ) 96 | bHeader = 1; 97 | else if( strcmp(argv[i],"-r") == 0 ) 98 | bRaw = 1; 99 | else if( strcmp(argv[i],"-m") == 0 ) 100 | bMultiLine = 1; 101 | else 102 | pszFilename = argv[i]; 103 | } 104 | 105 | /* -------------------------------------------------------------------- */ 106 | /* Display a usage message. */ 107 | /* -------------------------------------------------------------------- */ 108 | if( pszFilename == NULL ) 109 | { 110 | printf( "dbfdump [-h] [-r] [-m] xbase_file\n" ); 111 | printf( " -h: Write header info (field descriptions)\n" ); 112 | printf( " -r: Write raw field info, numeric values not reformatted\n" ); 113 | printf( " -m: Multiline, one line per field.\n" ); 114 | exit( 1 ); 115 | } 116 | 117 | /* -------------------------------------------------------------------- */ 118 | /* Open the file. */ 119 | /* -------------------------------------------------------------------- */ 120 | hDBF = DBFOpen( pszFilename, "rb" ); 121 | if( hDBF == NULL ) 122 | { 123 | printf( "DBFOpen(%s,\"r\") failed.\n", argv[1] ); 124 | exit( 2 ); 125 | } 126 | 127 | /* -------------------------------------------------------------------- */ 128 | /* If there is no data in this file let the user know. */ 129 | /* -------------------------------------------------------------------- */ 130 | if( DBFGetFieldCount(hDBF) == 0 ) 131 | { 132 | printf( "There are no fields in this table!\n" ); 133 | exit( 3 ); 134 | } 135 | 136 | /* -------------------------------------------------------------------- */ 137 | /* Dump header definitions. */ 138 | /* -------------------------------------------------------------------- */ 139 | if( bHeader ) 140 | { 141 | for( i = 0; i < DBFGetFieldCount(hDBF); i++ ) 142 | { 143 | DBFFieldType eType; 144 | const char *pszTypeName; 145 | char chNativeType; 146 | 147 | chNativeType = DBFGetNativeFieldType( hDBF, i ); 148 | 149 | eType = DBFGetFieldInfo( hDBF, i, szTitle, &nWidth, &nDecimals ); 150 | if( eType == FTString ) 151 | pszTypeName = "String"; 152 | else if( eType == FTInteger ) 153 | pszTypeName = "Integer"; 154 | else if( eType == FTDouble ) 155 | pszTypeName = "Double"; 156 | else if( eType == FTInvalid ) 157 | pszTypeName = "Invalid"; 158 | 159 | printf( "Field %d: Type=%c/%s, Title=`%s', Width=%d, Decimals=%d\n", 160 | i, chNativeType, pszTypeName, szTitle, nWidth, nDecimals ); 161 | } 162 | } 163 | 164 | /* -------------------------------------------------------------------- */ 165 | /* Compute offsets to use when printing each of the field */ 166 | /* values. We make each field as wide as the field title+1, or */ 167 | /* the field value + 1. */ 168 | /* -------------------------------------------------------------------- */ 169 | panWidth = (int *) malloc( DBFGetFieldCount( hDBF ) * sizeof(int) ); 170 | 171 | for( i = 0; i < DBFGetFieldCount(hDBF) && !bMultiLine; i++ ) 172 | { 173 | DBFFieldType eType; 174 | 175 | eType = DBFGetFieldInfo( hDBF, i, szTitle, &nWidth, &nDecimals ); 176 | if( (int) strlen(szTitle) > nWidth ) 177 | panWidth[i] = strlen(szTitle); 178 | else 179 | panWidth[i] = nWidth; 180 | 181 | if( eType == FTString ) 182 | sprintf( szFormat, "%%-%ds ", panWidth[i] ); 183 | else 184 | sprintf( szFormat, "%%%ds ", panWidth[i] ); 185 | printf( szFormat, szTitle ); 186 | } 187 | printf( "\n" ); 188 | 189 | /* -------------------------------------------------------------------- */ 190 | /* Read all the records */ 191 | /* -------------------------------------------------------------------- */ 192 | for( iRecord = 0; iRecord < DBFGetRecordCount(hDBF); iRecord++ ) 193 | { 194 | if( bMultiLine ) 195 | printf( "Record: %d\n", iRecord ); 196 | 197 | for( i = 0; i < DBFGetFieldCount(hDBF); i++ ) 198 | { 199 | DBFFieldType eType; 200 | 201 | eType = DBFGetFieldInfo( hDBF, i, szTitle, &nWidth, &nDecimals ); 202 | 203 | if( bMultiLine ) 204 | { 205 | printf( "%s: ", szTitle ); 206 | } 207 | 208 | /* -------------------------------------------------------------------- */ 209 | /* Print the record according to the type and formatting */ 210 | /* information implicit in the DBF field description. */ 211 | /* -------------------------------------------------------------------- */ 212 | if( !bRaw ) 213 | { 214 | if( DBFIsAttributeNULL( hDBF, iRecord, i ) ) 215 | { 216 | if( eType == FTString ) 217 | sprintf( szFormat, "%%-%ds", nWidth ); 218 | else 219 | sprintf( szFormat, "%%%ds", nWidth ); 220 | 221 | printf( szFormat, "(NULL)" ); 222 | } 223 | else 224 | { 225 | switch( eType ) 226 | { 227 | case FTString: 228 | sprintf( szFormat, "%%-%ds", nWidth ); 229 | printf( szFormat, 230 | DBFReadStringAttribute( hDBF, iRecord, i ) ); 231 | break; 232 | 233 | case FTInteger: 234 | sprintf( szFormat, "%%%dd", nWidth ); 235 | printf( szFormat, 236 | DBFReadIntegerAttribute( hDBF, iRecord, i ) ); 237 | break; 238 | 239 | case FTDouble: 240 | sprintf( szFormat, "%%%d.%dlf", nWidth, nDecimals ); 241 | printf( szFormat, 242 | DBFReadDoubleAttribute( hDBF, iRecord, i ) ); 243 | break; 244 | 245 | default: 246 | break; 247 | } 248 | } 249 | } 250 | 251 | /* -------------------------------------------------------------------- */ 252 | /* Just dump in raw form (as formatted in the file). */ 253 | /* -------------------------------------------------------------------- */ 254 | else 255 | { 256 | sprintf( szFormat, "%%-%ds", nWidth ); 257 | printf( szFormat, 258 | DBFReadStringAttribute( hDBF, iRecord, i ) ); 259 | } 260 | 261 | /* -------------------------------------------------------------------- */ 262 | /* Write out any extra spaces required to pad out the field */ 263 | /* width. */ 264 | /* -------------------------------------------------------------------- */ 265 | if( !bMultiLine ) 266 | { 267 | sprintf( szFormat, "%%%ds", panWidth[i] - nWidth + 1 ); 268 | printf( szFormat, "" ); 269 | } 270 | 271 | if( bMultiLine ) 272 | printf( "\n" ); 273 | 274 | fflush( stdout ); 275 | } 276 | printf( "\n" ); 277 | } 278 | 279 | DBFClose( hDBF ); 280 | free( panWidth ); 281 | 282 | return( 0 ); 283 | } 284 | -------------------------------------------------------------------------------- /Pods/shapelib/safileio.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * $Id: safileio.c,v 1.4 2008-01-16 20:05:14 bram Exp $ 3 | * 4 | * Project: Shapelib 5 | * Purpose: Default implementation of file io based on stdio. 6 | * Author: Frank Warmerdam, warmerdam@pobox.com 7 | * 8 | ****************************************************************************** 9 | * Copyright (c) 2007, Frank Warmerdam 10 | * 11 | * This software is available under the following "MIT Style" license, 12 | * or at the option of the licensee under the LGPL (see LICENSE.LGPL). This 13 | * option is discussed in more detail in shapelib.html. 14 | * 15 | * -- 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a 18 | * copy of this software and associated documentation files (the "Software"), 19 | * to deal in the Software without restriction, including without limitation 20 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 21 | * and/or sell copies of the Software, and to permit persons to whom the 22 | * Software is furnished to do so, subject to the following conditions: 23 | * 24 | * The above copyright notice and this permission notice shall be included 25 | * in all copies or substantial portions of the Software. 26 | * 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 28 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 29 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 30 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 31 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 32 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 33 | * DEALINGS IN THE SOFTWARE. 34 | ****************************************************************************** 35 | * 36 | * $Log: safileio.c,v $ 37 | * Revision 1.4 2008-01-16 20:05:14 bram 38 | * Add file hooks that accept UTF-8 encoded filenames on some platforms. Use SASetupUtf8Hooks 39 | * tosetup the hooks and check SHPAPI_UTF8_HOOKS for its availability. Currently, this 40 | * is only available on the Windows platform that decodes the UTF-8 filenames to wide 41 | * character strings and feeds them to _wfopen and _wremove. 42 | * 43 | * Revision 1.3 2007/12/18 18:28:11 bram 44 | * - create hook for client specific atof (bugzilla ticket 1615) 45 | * - check for NULL handle before closing cpCPG file, and close after reading. 46 | * 47 | * Revision 1.2 2007/12/15 20:25:30 bram 48 | * dbfopen.c now reads the Code Page information from the DBF file, and exports 49 | * this information as a string through the DBFGetCodePage function. This is 50 | * either the number from the LDID header field ("LDID/") or as the 51 | * content of an accompanying .CPG file. When creating a DBF file, the code can 52 | * be set using DBFCreateEx. 53 | * 54 | * Revision 1.1 2007/12/06 06:56:41 fwarmerdam 55 | * new 56 | * 57 | */ 58 | 59 | #include "shapefil.h" 60 | 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | 68 | SHP_CVSID("$Id: safileio.c,v 1.4 2008-01-16 20:05:14 bram Exp $"); 69 | 70 | #ifdef SHPAPI_UTF8_HOOKS 71 | # ifdef SHPAPI_WINDOWS 72 | # define WIN32_LEAN_AND_MEAN 73 | # define NOMINMAX 74 | # include 75 | # pragma comment(lib, "kernel32.lib") 76 | # endif 77 | #endif 78 | 79 | /************************************************************************/ 80 | /* SADFOpen() */ 81 | /************************************************************************/ 82 | 83 | SAFile SADFOpen( const char *pszFilename, const char *pszAccess ) 84 | 85 | { 86 | return (SAFile) fopen( pszFilename, pszAccess ); 87 | } 88 | 89 | /************************************************************************/ 90 | /* SADFRead() */ 91 | /************************************************************************/ 92 | 93 | SAOffset SADFRead( void *p, SAOffset size, SAOffset nmemb, SAFile file ) 94 | 95 | { 96 | return (SAOffset) fread( p, (size_t) size, (size_t) nmemb, 97 | (FILE *) file ); 98 | } 99 | 100 | /************************************************************************/ 101 | /* SADFWrite() */ 102 | /************************************************************************/ 103 | 104 | SAOffset SADFWrite( void *p, SAOffset size, SAOffset nmemb, SAFile file ) 105 | 106 | { 107 | return (SAOffset) fwrite( p, (size_t) size, (size_t) nmemb, 108 | (FILE *) file ); 109 | } 110 | 111 | /************************************************************************/ 112 | /* SADFSeek() */ 113 | /************************************************************************/ 114 | 115 | SAOffset SADFSeek( SAFile file, SAOffset offset, int whence ) 116 | 117 | { 118 | return (SAOffset) fseek( (FILE *) file, (long) offset, whence ); 119 | } 120 | 121 | /************************************************************************/ 122 | /* SADFTell() */ 123 | /************************************************************************/ 124 | 125 | SAOffset SADFTell( SAFile file ) 126 | 127 | { 128 | return (SAOffset) ftell( (FILE *) file ); 129 | } 130 | 131 | /************************************************************************/ 132 | /* SADFFlush() */ 133 | /************************************************************************/ 134 | 135 | int SADFFlush( SAFile file ) 136 | 137 | { 138 | return fflush( (FILE *) file ); 139 | } 140 | 141 | /************************************************************************/ 142 | /* SADFClose() */ 143 | /************************************************************************/ 144 | 145 | int SADFClose( SAFile file ) 146 | 147 | { 148 | return fclose( (FILE *) file ); 149 | } 150 | 151 | /************************************************************************/ 152 | /* SADFClose() */ 153 | /************************************************************************/ 154 | 155 | int SADRemove( const char *filename ) 156 | 157 | { 158 | return remove( filename ); 159 | } 160 | 161 | /************************************************************************/ 162 | /* SADError() */ 163 | /************************************************************************/ 164 | 165 | void SADError( const char *message ) 166 | 167 | { 168 | fprintf( stderr, "%s\n", message ); 169 | } 170 | 171 | /************************************************************************/ 172 | /* SASetupDefaultHooks() */ 173 | /************************************************************************/ 174 | 175 | void SASetupDefaultHooks( SAHooks *psHooks ) 176 | 177 | { 178 | psHooks->FOpen = SADFOpen; 179 | psHooks->FRead = SADFRead; 180 | psHooks->FWrite = SADFWrite; 181 | psHooks->FSeek = SADFSeek; 182 | psHooks->FTell = SADFTell; 183 | psHooks->FFlush = SADFFlush; 184 | psHooks->FClose = SADFClose; 185 | psHooks->Remove = SADRemove; 186 | 187 | psHooks->Error = SADError; 188 | psHooks->Atof = atof; 189 | } 190 | 191 | 192 | 193 | 194 | #ifdef SHPAPI_WINDOWS 195 | 196 | /************************************************************************/ 197 | /* Utf8ToWideChar */ 198 | /************************************************************************/ 199 | 200 | const wchar_t* Utf8ToWideChar( const char *pszFilename ) 201 | { 202 | int nMulti, nWide; 203 | wchar_t *pwszFileName; 204 | 205 | nMulti = strlen(pszFilename) + 1; 206 | nWide = MultiByteToWideChar( CP_UTF8, 0, pszFilename, nMulti, 0, 0); 207 | if( nWide == 0 ) 208 | { 209 | return NULL; 210 | } 211 | pwszFileName = (wchar_t*) malloc(nWide * sizeof(wchar_t)); 212 | if ( pwszFileName == NULL ) 213 | { 214 | return NULL; 215 | } 216 | if( MultiByteToWideChar( CP_UTF8, 0, pszFilename, nMulti, pwszFileName, nWide ) == 0 ) 217 | { 218 | free( pwszFileName ); 219 | return NULL; 220 | } 221 | return pwszFileName; 222 | } 223 | 224 | /************************************************************************/ 225 | /* SAUtf8WFOpen */ 226 | /************************************************************************/ 227 | 228 | SAFile SAUtf8WFOpen( const char *pszFilename, const char *pszAccess ) 229 | { 230 | SAFile file = NULL; 231 | const wchar_t *pwszFileName, *pwszAccess; 232 | pwszFileName = Utf8ToWideChar( pszFilename ); 233 | pwszAccess = Utf8ToWideChar( pszAccess ); 234 | if( pwszFileName != NULL && pwszFileName != NULL) 235 | { 236 | file = (SAFile) _wfopen( pwszFileName, pwszAccess ); 237 | } 238 | free ((wchar_t*) pwszFileName); 239 | free ((wchar_t*) pwszAccess); 240 | return file; 241 | } 242 | 243 | /************************************************************************/ 244 | /* SAUtf8WRemove() */ 245 | /************************************************************************/ 246 | 247 | int SAUtf8WRemove( const char *pszFilename ) 248 | { 249 | const wchar_t *pwszFileName = Utf8ToWideChar( pszFilename ); 250 | int rc = -1; 251 | if( pwszFileName != NULL ) 252 | { 253 | rc = _wremove( pwszFileName ); 254 | } 255 | free ((wchar_t*) pwszFileName); 256 | return rc; 257 | } 258 | 259 | #endif 260 | 261 | #ifdef SHPAPI_UTF8_HOOKS 262 | 263 | /************************************************************************/ 264 | /* SASetupUtf8Hooks() */ 265 | /************************************************************************/ 266 | 267 | void SASetupUtf8Hooks( SAHooks *psHooks ) 268 | { 269 | #ifdef SHPAPI_WINDOWS 270 | psHooks->FOpen = SAUtf8WFOpen; 271 | psHooks->Remove = SAUtf8WRemove; 272 | #else 273 | # error "no implementations of UTF-8 hooks available for this platform" 274 | #endif 275 | psHooks->FRead = SADFRead; 276 | psHooks->FWrite = SADFWrite; 277 | psHooks->FSeek = SADFSeek; 278 | psHooks->FTell = SADFTell; 279 | psHooks->FFlush = SADFFlush; 280 | psHooks->FClose = SADFClose; 281 | 282 | psHooks->Error = SADError; 283 | psHooks->Atof = atof; 284 | } 285 | 286 | #endif 287 | -------------------------------------------------------------------------------- /Pods/shapelib/shpadd.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * $Id: shpadd.c,v 1.16 2010-06-21 20:41:52 fwarmerdam Exp $ 3 | * 4 | * Project: Shapelib 5 | * Purpose: Sample application for adding a shape to a shapefile. 6 | * Author: Frank Warmerdam, warmerdam@pobox.com 7 | * 8 | ****************************************************************************** 9 | * Copyright (c) 1999, Frank Warmerdam 10 | * 11 | * This software is available under the following "MIT Style" license, 12 | * or at the option of the licensee under the LGPL (see LICENSE.LGPL). This 13 | * option is discussed in more detail in shapelib.html. 14 | * 15 | * -- 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a 18 | * copy of this software and associated documentation files (the "Software"), 19 | * to deal in the Software without restriction, including without limitation 20 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 21 | * and/or sell copies of the Software, and to permit persons to whom the 22 | * Software is furnished to do so, subject to the following conditions: 23 | * 24 | * The above copyright notice and this permission notice shall be included 25 | * in all copies or substantial portions of the Software. 26 | * 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 28 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 29 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 30 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 31 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 32 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 33 | * DEALINGS IN THE SOFTWARE. 34 | ****************************************************************************** 35 | * 36 | * $Log: shpadd.c,v $ 37 | * Revision 1.16 2010-06-21 20:41:52 fwarmerdam 38 | * reformat white space 39 | * 40 | * Revision 1.15 2007-12-30 16:57:32 fwarmerdam 41 | * add support for z and m 42 | * 43 | * Revision 1.14 2004/09/26 20:09:35 fwarmerdam 44 | * avoid rcsid warnings 45 | * 46 | * Revision 1.13 2002/01/15 14:36:07 warmerda 47 | * updated email address 48 | * 49 | * Revision 1.12 2001/05/31 19:35:29 warmerda 50 | * added support for writing null shapes 51 | * 52 | * Revision 1.11 2000/07/07 13:39:45 warmerda 53 | * removed unused variables, and added system include files 54 | * 55 | * Revision 1.10 2000/05/24 15:09:22 warmerda 56 | * Added logic to graw vertex lists of needed. 57 | * 58 | * Revision 1.9 1999/11/05 14:12:04 warmerda 59 | * updated license terms 60 | * 61 | * Revision 1.8 1998/12/03 16:36:26 warmerda 62 | * Use r+b rather than rb+ for binary access. 63 | * 64 | * Revision 1.7 1998/11/09 20:57:04 warmerda 65 | * Fixed SHPGetInfo() call. 66 | * 67 | * Revision 1.6 1998/11/09 20:19:16 warmerda 68 | * Changed to use SHPObject based API. 69 | * 70 | * Revision 1.5 1997/03/06 14:05:02 warmerda 71 | * fixed typo. 72 | * 73 | * Revision 1.4 1997/03/06 14:01:16 warmerda 74 | * added memory allocation checking, and free()s. 75 | * 76 | * Revision 1.3 1995/10/21 03:14:37 warmerda 77 | * Changed to use binary file access 78 | * 79 | * Revision 1.2 1995/08/04 03:18:01 warmerda 80 | * Added header. 81 | * 82 | */ 83 | 84 | #include 85 | #include 86 | #include "shapefil.h" 87 | 88 | SHP_CVSID("$Id: shpadd.c,v 1.16 2010-06-21 20:41:52 fwarmerdam Exp $") 89 | 90 | int main( int argc, char ** argv ) 91 | 92 | { 93 | SHPHandle hSHP; 94 | int nShapeType, nVertices, nParts, *panParts, i, nVMax; 95 | double *padfX, *padfY, *padfZ = NULL, *padfM = NULL; 96 | SHPObject *psObject; 97 | const char *tuple = ""; 98 | const char *filename; 99 | 100 | /* -------------------------------------------------------------------- */ 101 | /* Display a usage message. */ 102 | /* -------------------------------------------------------------------- */ 103 | if( argc < 2 ) 104 | { 105 | printf( "shpadd shp_file [[x y] [+]]*\n" ); 106 | printf( " or\n" ); 107 | printf( "shpadd shp_file -m [[x y m] [+]]*\n" ); 108 | printf( " or\n" ); 109 | printf( "shpadd shp_file -z [[x y z] [+]]*\n" ); 110 | printf( " or\n" ); 111 | printf( "shpadd shp_file -zm [[x y z m] [+]]*\n" ); 112 | exit( 1 ); 113 | } 114 | 115 | filename = argv[1]; 116 | argv++; 117 | argc--; 118 | 119 | /* -------------------------------------------------------------------- */ 120 | /* Check for tuple description options. */ 121 | /* -------------------------------------------------------------------- */ 122 | if( argc > 1 123 | && (strcmp(argv[1],"-z") == 0 124 | || strcmp(argv[1],"-m") == 0 125 | || strcmp(argv[1],"-zm") == 0) ) 126 | { 127 | tuple = argv[1] + 1; 128 | argv++; 129 | argc--; 130 | } 131 | 132 | /* -------------------------------------------------------------------- */ 133 | /* Open the passed shapefile. */ 134 | /* -------------------------------------------------------------------- */ 135 | hSHP = SHPOpen( filename, "r+b" ); 136 | 137 | if( hSHP == NULL ) 138 | { 139 | printf( "Unable to open:%s\n", filename ); 140 | exit( 1 ); 141 | } 142 | 143 | SHPGetInfo( hSHP, NULL, &nShapeType, NULL, NULL ); 144 | 145 | if( argc == 1 ) 146 | nShapeType = SHPT_NULL; 147 | 148 | /* -------------------------------------------------------------------- */ 149 | /* Build a vertex/part list from the command line arguments. */ 150 | /* -------------------------------------------------------------------- */ 151 | nVMax = 1000; 152 | padfX = (double *) malloc(sizeof(double) * nVMax); 153 | padfY = (double *) malloc(sizeof(double) * nVMax); 154 | 155 | if( strchr(tuple,'z') ) 156 | padfZ = (double *) malloc(sizeof(double) * nVMax); 157 | if( strchr(tuple,'m') ) 158 | padfM = (double *) malloc(sizeof(double) * nVMax); 159 | 160 | nVertices = 0; 161 | 162 | if( (panParts = (int *) malloc(sizeof(int) * 1000 )) == NULL ) 163 | { 164 | printf( "Out of memory\n" ); 165 | exit( 1 ); 166 | } 167 | 168 | nParts = 1; 169 | panParts[0] = 0; 170 | 171 | for( i = 1; i < argc; ) 172 | { 173 | if( argv[i][0] == '+' ) 174 | { 175 | panParts[nParts++] = nVertices; 176 | i++; 177 | } 178 | else if( i < argc-1-strlen(tuple) ) 179 | { 180 | if( nVertices == nVMax ) 181 | { 182 | nVMax = nVMax * 2; 183 | padfX = (double *) realloc(padfX,sizeof(double)*nVMax); 184 | padfY = (double *) realloc(padfY,sizeof(double)*nVMax); 185 | if( padfZ ) 186 | padfZ = (double *) realloc(padfZ,sizeof(double)*nVMax); 187 | if( padfM ) 188 | padfM = (double *) realloc(padfM,sizeof(double)*nVMax); 189 | } 190 | 191 | sscanf( argv[i++], "%lg", padfX+nVertices ); 192 | sscanf( argv[i++], "%lg", padfY+nVertices ); 193 | if( padfZ ) 194 | sscanf( argv[i++], "%lg", padfZ+nVertices ); 195 | if( padfM ) 196 | sscanf( argv[i++], "%lg", padfM+nVertices ); 197 | 198 | nVertices += 1; 199 | } 200 | } 201 | 202 | /* -------------------------------------------------------------------- */ 203 | /* Write the new entity to the shape file. */ 204 | /* -------------------------------------------------------------------- */ 205 | psObject = SHPCreateObject( nShapeType, -1, nParts, panParts, NULL, 206 | nVertices, padfX, padfY, padfZ, padfM ); 207 | SHPWriteObject( hSHP, -1, psObject ); 208 | SHPDestroyObject( psObject ); 209 | 210 | SHPClose( hSHP ); 211 | 212 | free( panParts ); 213 | free( padfX ); 214 | free( padfY ); 215 | free( padfZ ); 216 | free( padfM ); 217 | 218 | return 0; 219 | } 220 | -------------------------------------------------------------------------------- /Pods/shapelib/shpcreate.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * $Id: shpcreate.c,v 1.8 2007-12-30 16:57:33 fwarmerdam Exp $ 3 | * 4 | * Project: Shapelib 5 | * Purpose: Sample application for creating a new shapefile. 6 | * Author: Frank Warmerdam, warmerdm@pobox.com 7 | * 8 | ****************************************************************************** 9 | * Copyright (c) 1999, Frank Warmerdam 10 | * 11 | * This software is available under the following "MIT Style" license, 12 | * or at the option of the licensee under the LGPL (see LICENSE.LGPL). This 13 | * option is discussed in more detail in shapelib.html. 14 | * 15 | * -- 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a 18 | * copy of this software and associated documentation files (the "Software"), 19 | * to deal in the Software without restriction, including without limitation 20 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 21 | * and/or sell copies of the Software, and to permit persons to whom the 22 | * Software is furnished to do so, subject to the following conditions: 23 | * 24 | * The above copyright notice and this permission notice shall be included 25 | * in all copies or substantial portions of the Software. 26 | * 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 28 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 29 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 30 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 31 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 32 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 33 | * DEALINGS IN THE SOFTWARE. 34 | ****************************************************************************** 35 | * 36 | * $Log: shpcreate.c,v $ 37 | * Revision 1.8 2007-12-30 16:57:33 fwarmerdam 38 | * add support for z and m 39 | * 40 | * Revision 1.7 2004/09/26 20:09:35 fwarmerdam 41 | * avoid rcsid warnings 42 | * 43 | * Revision 1.6 2004/01/09 16:39:49 fwarmerdam 44 | * include standard include files 45 | * 46 | * Revision 1.5 2002/01/15 14:36:07 warmerda 47 | * updated email address 48 | * 49 | * Revision 1.4 2000/07/07 13:39:45 warmerda 50 | * removed unused variables, and added system include files 51 | * 52 | * Revision 1.3 1999/11/05 14:12:04 warmerda 53 | * updated license terms 54 | * 55 | * Revision 1.2 1995/08/04 03:16:43 warmerda 56 | * Added header. 57 | * 58 | */ 59 | 60 | #include 61 | #include 62 | #include "shapefil.h" 63 | 64 | SHP_CVSID("$Id: shpcreate.c,v 1.8 2007-12-30 16:57:33 fwarmerdam Exp $") 65 | 66 | int main( int argc, char ** argv ) 67 | 68 | { 69 | SHPHandle hSHP; 70 | int nShapeType; 71 | 72 | /* -------------------------------------------------------------------- */ 73 | /* Display a usage message. */ 74 | /* -------------------------------------------------------------------- */ 75 | if( argc != 3 ) 76 | { 77 | printf( "shpcreate shp_file [point/arc/polygon/multipoint][/m/z]\n" ); 78 | exit( 1 ); 79 | } 80 | 81 | /* -------------------------------------------------------------------- */ 82 | /* Figure out the shape type. */ 83 | /* -------------------------------------------------------------------- */ 84 | if( strcmp(argv[2],"POINT") == 0 || strcmp(argv[2],"point") == 0 ) 85 | nShapeType = SHPT_POINT; 86 | else if( strcmp(argv[2],"ARC") == 0 || strcmp(argv[2],"arc") == 0 ) 87 | nShapeType = SHPT_ARC; 88 | else if( strcmp(argv[2],"POLYGON") == 0 || strcmp(argv[2],"polygon") == 0 ) 89 | nShapeType = SHPT_POLYGON; 90 | else if( strcmp(argv[2],"MULTIPOINT")==0 ||strcmp(argv[2],"multipoint")==0) 91 | nShapeType = SHPT_MULTIPOINT; 92 | else if( strcmp(argv[2],"POINTZ") == 0 || strcmp(argv[2],"pointz") == 0 ) 93 | nShapeType = SHPT_POINTZ; 94 | else if( strcmp(argv[2],"ARCZ") == 0 || strcmp(argv[2],"arcz") == 0 ) 95 | nShapeType = SHPT_ARCZ; 96 | else if( strcmp(argv[2],"POLYGONZ") == 0 || strcmp(argv[2],"polygonz") == 0) 97 | nShapeType = SHPT_POLYGONZ; 98 | else if( strcmp(argv[2],"MULTIPOINTZ") == 0 99 | || strcmp(argv[2],"multipointz") == 0) 100 | nShapeType = SHPT_MULTIPOINTZ; 101 | else if( strcmp(argv[2],"POINTM") == 0 || strcmp(argv[2],"pointm") == 0 ) 102 | nShapeType = SHPT_POINTM; 103 | else if( strcmp(argv[2],"ARCM") == 0 || strcmp(argv[2],"arcm") == 0 ) 104 | nShapeType = SHPT_ARCM; 105 | else if( strcmp(argv[2],"POLYGONM") == 0 || strcmp(argv[2],"polygonm") == 0) 106 | nShapeType = SHPT_POLYGONM; 107 | else if( strcmp(argv[2],"MULTIPOINTM") == 0 108 | || strcmp(argv[2],"multipointm") == 0 ) 109 | nShapeType = SHPT_MULTIPOINTM; 110 | else 111 | { 112 | printf( "Shape Type `%s' not recognised.\n", argv[2] ); 113 | exit( 2 ); 114 | } 115 | 116 | /* -------------------------------------------------------------------- */ 117 | /* Create the requested layer. */ 118 | /* -------------------------------------------------------------------- */ 119 | hSHP = SHPCreate( argv[1], nShapeType ); 120 | 121 | if( hSHP == NULL ) 122 | { 123 | printf( "Unable to create:%s\n", argv[1] ); 124 | exit( 3 ); 125 | } 126 | 127 | SHPClose( hSHP ); 128 | 129 | return 0; 130 | } 131 | -------------------------------------------------------------------------------- /Pods/shapelib/shpdump.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * $Id: shpdump.c,v 1.18 2011-07-24 03:05:14 fwarmerdam Exp $ 3 | * 4 | * Project: Shapelib 5 | * Purpose: Sample application for dumping contents of a shapefile to 6 | * the terminal in human readable form. 7 | * Author: Frank Warmerdam, warmerdam@pobox.com 8 | * 9 | ****************************************************************************** 10 | * Copyright (c) 1999, Frank Warmerdam 11 | * 12 | * This software is available under the following "MIT Style" license, 13 | * or at the option of the licensee under the LGPL (see LICENSE.LGPL). This 14 | * option is discussed in more detail in shapelib.html. 15 | * 16 | * -- 17 | * 18 | * Permission is hereby granted, free of charge, to any person obtaining a 19 | * copy of this software and associated documentation files (the "Software"), 20 | * to deal in the Software without restriction, including without limitation 21 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 22 | * and/or sell copies of the Software, and to permit persons to whom the 23 | * Software is furnished to do so, subject to the following conditions: 24 | * 25 | * The above copyright notice and this permission notice shall be included 26 | * in all copies or substantial portions of the Software. 27 | * 28 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 29 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 30 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 31 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 32 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 33 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 34 | * DEALINGS IN THE SOFTWARE. 35 | ****************************************************************************** 36 | * 37 | * $Log: shpdump.c,v $ 38 | * Revision 1.18 2011-07-24 03:05:14 fwarmerdam 39 | * use %.15g for formatting coordiantes in shpdump 40 | * 41 | * Revision 1.17 2010-07-01 07:33:04 fwarmerdam 42 | * do not crash in shpdump if null object returned 43 | * 44 | * Revision 1.16 2010-07-01 07:27:13 fwarmerdam 45 | * white space formatting adjustments 46 | * 47 | * Revision 1.15 2006-01-26 15:07:32 fwarmerdam 48 | * add bMeasureIsUsed flag from Craig Bruce: Bug 1249 49 | * 50 | * Revision 1.14 2005/02/11 17:17:46 fwarmerdam 51 | * added panPartStart[0] validation 52 | * 53 | * Revision 1.13 2004/09/26 20:09:35 fwarmerdam 54 | * avoid rcsid warnings 55 | * 56 | * Revision 1.12 2004/01/27 18:05:35 fwarmerdam 57 | * Added the -ho (header only) switch. 58 | * 59 | * Revision 1.11 2004/01/09 16:39:49 fwarmerdam 60 | * include standard include files 61 | * 62 | * Revision 1.10 2002/04/10 16:59:29 warmerda 63 | * added -validate switch 64 | * 65 | * Revision 1.9 2002/01/15 14:36:07 warmerda 66 | * updated email address 67 | * 68 | * Revision 1.8 2000/07/07 13:39:45 warmerda 69 | * removed unused variables, and added system include files 70 | * 71 | * Revision 1.7 1999/11/05 14:12:04 warmerda 72 | * updated license terms 73 | * 74 | * Revision 1.6 1998/12/03 15:48:48 warmerda 75 | * Added report of shapefile type, and total number of shapes. 76 | * 77 | * Revision 1.5 1998/11/09 20:57:36 warmerda 78 | * use SHPObject. 79 | * 80 | * Revision 1.4 1995/10/21 03:14:49 warmerda 81 | * Changed to use binary file access. 82 | * 83 | * Revision 1.3 1995/08/23 02:25:25 warmerda 84 | * Added support for bounds. 85 | * 86 | * Revision 1.2 1995/08/04 03:18:11 warmerda 87 | * Added header. 88 | * 89 | */ 90 | 91 | #include 92 | #include 93 | #include "shapefil.h" 94 | 95 | SHP_CVSID("$Id: shpdump.c,v 1.18 2011-07-24 03:05:14 fwarmerdam Exp $") 96 | 97 | int main( int argc, char ** argv ) 98 | 99 | { 100 | SHPHandle hSHP; 101 | int nShapeType, nEntities, i, iPart, bValidate = 0,nInvalidCount=0; 102 | int bHeaderOnly = 0; 103 | const char *pszPlus; 104 | double adfMinBound[4], adfMaxBound[4]; 105 | 106 | if( argc > 1 && strcmp(argv[1],"-validate") == 0 ) 107 | { 108 | bValidate = 1; 109 | argv++; 110 | argc--; 111 | } 112 | 113 | if( argc > 1 && strcmp(argv[1],"-ho") == 0 ) 114 | { 115 | bHeaderOnly = 1; 116 | argv++; 117 | argc--; 118 | } 119 | 120 | /* -------------------------------------------------------------------- */ 121 | /* Display a usage message. */ 122 | /* -------------------------------------------------------------------- */ 123 | if( argc != 2 ) 124 | { 125 | printf( "shpdump [-validate] [-ho] shp_file\n" ); 126 | exit( 1 ); 127 | } 128 | 129 | /* -------------------------------------------------------------------- */ 130 | /* Open the passed shapefile. */ 131 | /* -------------------------------------------------------------------- */ 132 | hSHP = SHPOpen( argv[1], "rb" ); 133 | 134 | if( hSHP == NULL ) 135 | { 136 | printf( "Unable to open:%s\n", argv[1] ); 137 | exit( 1 ); 138 | } 139 | 140 | /* -------------------------------------------------------------------- */ 141 | /* Print out the file bounds. */ 142 | /* -------------------------------------------------------------------- */ 143 | SHPGetInfo( hSHP, &nEntities, &nShapeType, adfMinBound, adfMaxBound ); 144 | 145 | printf( "Shapefile Type: %s # of Shapes: %d\n\n", 146 | SHPTypeName( nShapeType ), nEntities ); 147 | 148 | printf( "File Bounds: (%.15g,%.15g,%.15g,%.15g)\n" 149 | " to (%.15g,%.15g,%.15g,%.15g)\n", 150 | adfMinBound[0], 151 | adfMinBound[1], 152 | adfMinBound[2], 153 | adfMinBound[3], 154 | adfMaxBound[0], 155 | adfMaxBound[1], 156 | adfMaxBound[2], 157 | adfMaxBound[3] ); 158 | 159 | /* -------------------------------------------------------------------- */ 160 | /* Skim over the list of shapes, printing all the vertices. */ 161 | /* -------------------------------------------------------------------- */ 162 | for( i = 0; i < nEntities && !bHeaderOnly; i++ ) 163 | { 164 | int j; 165 | SHPObject *psShape; 166 | 167 | psShape = SHPReadObject( hSHP, i ); 168 | 169 | if( psShape == NULL ) 170 | { 171 | fprintf( stderr, 172 | "Unable to read shape %d, terminating object reading.\n", 173 | i ); 174 | break; 175 | } 176 | 177 | if( psShape->bMeasureIsUsed ) 178 | printf( "\nShape:%d (%s) nVertices=%d, nParts=%d\n" 179 | " Bounds:(%.15g,%.15g, %.15g, %.15g)\n" 180 | " to (%.15g,%.15g, %.15g, %.15g)\n", 181 | i, SHPTypeName(psShape->nSHPType), 182 | psShape->nVertices, psShape->nParts, 183 | psShape->dfXMin, psShape->dfYMin, 184 | psShape->dfZMin, psShape->dfMMin, 185 | psShape->dfXMax, psShape->dfYMax, 186 | psShape->dfZMax, psShape->dfMMax ); 187 | else 188 | printf( "\nShape:%d (%s) nVertices=%d, nParts=%d\n" 189 | " Bounds:(%.15g,%.15g, %.15g)\n" 190 | " to (%.15g,%.15g, %.15g)\n", 191 | i, SHPTypeName(psShape->nSHPType), 192 | psShape->nVertices, psShape->nParts, 193 | psShape->dfXMin, psShape->dfYMin, 194 | psShape->dfZMin, 195 | psShape->dfXMax, psShape->dfYMax, 196 | psShape->dfZMax ); 197 | 198 | if( psShape->nParts > 0 && psShape->panPartStart[0] != 0 ) 199 | { 200 | fprintf( stderr, "panPartStart[0] = %d, not zero as expected.\n", 201 | psShape->panPartStart[0] ); 202 | } 203 | 204 | for( j = 0, iPart = 1; j < psShape->nVertices; j++ ) 205 | { 206 | const char *pszPartType = ""; 207 | 208 | if( j == 0 && psShape->nParts > 0 ) 209 | pszPartType = SHPPartTypeName( psShape->panPartType[0] ); 210 | 211 | if( iPart < psShape->nParts 212 | && psShape->panPartStart[iPart] == j ) 213 | { 214 | pszPartType = SHPPartTypeName( psShape->panPartType[iPart] ); 215 | iPart++; 216 | pszPlus = "+"; 217 | } 218 | else 219 | pszPlus = " "; 220 | 221 | if( psShape->bMeasureIsUsed ) 222 | printf(" %s (%.15g,%.15g, %.15g, %.15g) %s \n", 223 | pszPlus, 224 | psShape->padfX[j], 225 | psShape->padfY[j], 226 | psShape->padfZ[j], 227 | psShape->padfM[j], 228 | pszPartType ); 229 | else 230 | printf(" %s (%.15g,%.15g, %.15g) %s \n", 231 | pszPlus, 232 | psShape->padfX[j], 233 | psShape->padfY[j], 234 | psShape->padfZ[j], 235 | pszPartType ); 236 | } 237 | 238 | if( bValidate ) 239 | { 240 | int nAltered = SHPRewindObject( hSHP, psShape ); 241 | 242 | if( nAltered > 0 ) 243 | { 244 | printf( " %d rings wound in the wrong direction.\n", 245 | nAltered ); 246 | nInvalidCount++; 247 | } 248 | } 249 | 250 | SHPDestroyObject( psShape ); 251 | } 252 | 253 | SHPClose( hSHP ); 254 | 255 | if( bValidate ) 256 | { 257 | printf( "%d object has invalid ring orderings.\n", nInvalidCount ); 258 | } 259 | 260 | #ifdef USE_DBMALLOC 261 | malloc_dump(2); 262 | #endif 263 | 264 | exit( 0 ); 265 | } 266 | -------------------------------------------------------------------------------- /Pods/shapelib/shprewind.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * $Id: shprewind.c,v 1.4 2004-09-26 20:09:35 fwarmerdam Exp $ 3 | * 4 | * Project: Shapelib 5 | * Purpose: Utility to validate and reset the winding order of rings in 6 | * polygon geometries to match the ordering required by spec. 7 | * Author: Frank Warmerdam, warmerdam@pobox.com 8 | * 9 | ****************************************************************************** 10 | * Copyright (c) 2002, Frank Warmerdam 11 | * 12 | * This software is available under the following "MIT Style" license, 13 | * or at the option of the licensee under the LGPL (see LICENSE.LGPL). This 14 | * option is discussed in more detail in shapelib.html. 15 | * 16 | * -- 17 | * 18 | * Permission is hereby granted, free of charge, to any person obtaining a 19 | * copy of this software and associated documentation files (the "Software"), 20 | * to deal in the Software without restriction, including without limitation 21 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 22 | * and/or sell copies of the Software, and to permit persons to whom the 23 | * Software is furnished to do so, subject to the following conditions: 24 | * 25 | * The above copyright notice and this permission notice shall be included 26 | * in all copies or substantial portions of the Software. 27 | * 28 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 29 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 30 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 31 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 32 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 33 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 34 | * DEALINGS IN THE SOFTWARE. 35 | ****************************************************************************** 36 | * 37 | * $Log: shprewind.c,v $ 38 | * Revision 1.4 2004-09-26 20:09:35 fwarmerdam 39 | * avoid rcsid warnings 40 | * 41 | * Revision 1.3 2004/01/09 16:39:49 fwarmerdam 42 | * include standard include files 43 | * 44 | * Revision 1.2 2002/04/10 17:23:11 warmerda 45 | * copy from source to destination now 46 | * 47 | * Revision 1.1 2002/04/10 16:56:36 warmerda 48 | * New 49 | * 50 | */ 51 | 52 | #include 53 | #include 54 | #include "shapefil.h" 55 | 56 | int main( int argc, char ** argv ) 57 | 58 | { 59 | SHPHandle hSHP, hSHPOut; 60 | int nShapeType, nEntities, i, nInvalidCount=0; 61 | double adfMinBound[4], adfMaxBound[4]; 62 | 63 | /* -------------------------------------------------------------------- */ 64 | /* Display a usage message. */ 65 | /* -------------------------------------------------------------------- */ 66 | if( argc != 3 ) 67 | { 68 | printf( "shprewind in_shp_file out_shp_file\n" ); 69 | exit( 1 ); 70 | } 71 | 72 | /* -------------------------------------------------------------------- */ 73 | /* Open the passed shapefile. */ 74 | /* -------------------------------------------------------------------- */ 75 | hSHP = SHPOpen( argv[1], "rb" ); 76 | 77 | if( hSHP == NULL ) 78 | { 79 | printf( "Unable to open:%s\n", argv[1] ); 80 | exit( 1 ); 81 | } 82 | 83 | SHPGetInfo( hSHP, &nEntities, &nShapeType, adfMinBound, adfMaxBound ); 84 | 85 | /* -------------------------------------------------------------------- */ 86 | /* Create output shapefile. */ 87 | /* -------------------------------------------------------------------- */ 88 | hSHPOut = SHPCreate( argv[2], nShapeType ); 89 | 90 | if( hSHPOut == NULL ) 91 | { 92 | printf( "Unable to create:%s\n", argv[2] ); 93 | exit( 1 ); 94 | } 95 | 96 | /* -------------------------------------------------------------------- */ 97 | /* Skim over the list of shapes, printing all the vertices. */ 98 | /* -------------------------------------------------------------------- */ 99 | for( i = 0; i < nEntities; i++ ) 100 | { 101 | SHPObject *psShape; 102 | 103 | psShape = SHPReadObject( hSHP, i ); 104 | if( SHPRewindObject( hSHP, psShape ) ) 105 | nInvalidCount++; 106 | SHPWriteObject( hSHPOut, -1, psShape ); 107 | SHPDestroyObject( psShape ); 108 | } 109 | 110 | SHPClose( hSHP ); 111 | SHPClose( hSHPOut ); 112 | 113 | printf( "%d objects rewound.\n", nInvalidCount ); 114 | 115 | exit( 0 ); 116 | } 117 | -------------------------------------------------------------------------------- /Pods/shapelib/shptest.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * $Id: shptest.c,v 1.7 2004-09-26 20:09:35 fwarmerdam Exp $ 3 | * 4 | * Project: Shapelib 5 | * Purpose: Application for generating sample Shapefiles of various types. 6 | * Used by the stream2.sh test script. 7 | * Author: Frank Warmerdam, warmerdam@pobox.com 8 | * 9 | ****************************************************************************** 10 | * Copyright (c) 1999, Frank Warmerdam 11 | * 12 | * This software is available under the following "MIT Style" license, 13 | * or at the option of the licensee under the LGPL (see LICENSE.LGPL). This 14 | * option is discussed in more detail in shapelib.html. 15 | * 16 | * -- 17 | * 18 | * Permission is hereby granted, free of charge, to any person obtaining a 19 | * copy of this software and associated documentation files (the "Software"), 20 | * to deal in the Software without restriction, including without limitation 21 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 22 | * and/or sell copies of the Software, and to permit persons to whom the 23 | * Software is furnished to do so, subject to the following conditions: 24 | * 25 | * The above copyright notice and this permission notice shall be included 26 | * in all copies or substantial portions of the Software. 27 | * 28 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 29 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 30 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 31 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 32 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 33 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 34 | * DEALINGS IN THE SOFTWARE. 35 | ****************************************************************************** 36 | * 37 | * $Log: shptest.c,v $ 38 | * Revision 1.7 2004-09-26 20:09:35 fwarmerdam 39 | * avoid rcsid warnings 40 | * 41 | * Revision 1.6 2002/01/15 14:36:07 warmerda 42 | * updated email address 43 | * 44 | * Revision 1.5 2001/06/22 02:18:20 warmerda 45 | * Added null shape support 46 | * 47 | * Revision 1.4 2000/07/07 13:39:45 warmerda 48 | * removed unused variables, and added system include files 49 | * 50 | * Revision 1.3 1999/11/05 14:12:05 warmerda 51 | * updated license terms 52 | * 53 | * Revision 1.2 1998/12/16 05:15:20 warmerda 54 | * Added support for writing multipatch. 55 | * 56 | * Revision 1.1 1998/11/09 20:18:42 warmerda 57 | * Initial revision 58 | * 59 | */ 60 | 61 | #include 62 | #include 63 | #include "shapefil.h" 64 | 65 | SHP_CVSID("$Id: shptest.c,v 1.7 2004-09-26 20:09:35 fwarmerdam Exp $") 66 | 67 | /************************************************************************/ 68 | /* Test_WritePoints() */ 69 | /* */ 70 | /* Write a small point file. */ 71 | /************************************************************************/ 72 | 73 | static void Test_WritePoints( int nSHPType, const char *pszFilename ) 74 | 75 | { 76 | SHPHandle hSHPHandle; 77 | SHPObject *psShape; 78 | double x, y, z, m; 79 | 80 | hSHPHandle = SHPCreate( pszFilename, nSHPType ); 81 | 82 | x = 1.0; 83 | y = 2.0; 84 | z = 3.0; 85 | m = 4.0; 86 | psShape = SHPCreateObject( nSHPType, -1, 0, NULL, NULL, 87 | 1, &x, &y, &z, &m ); 88 | SHPWriteObject( hSHPHandle, -1, psShape ); 89 | SHPDestroyObject( psShape ); 90 | 91 | x = 10.0; 92 | y = 20.0; 93 | z = 30.0; 94 | m = 40.0; 95 | psShape = SHPCreateObject( nSHPType, -1, 0, NULL, NULL, 96 | 1, &x, &y, &z, &m ); 97 | SHPWriteObject( hSHPHandle, -1, psShape ); 98 | SHPDestroyObject( psShape ); 99 | 100 | SHPClose( hSHPHandle ); 101 | } 102 | 103 | /************************************************************************/ 104 | /* Test_WriteMultiPoints() */ 105 | /* */ 106 | /* Write a small multipoint file. */ 107 | /************************************************************************/ 108 | 109 | static void Test_WriteMultiPoints( int nSHPType, const char *pszFilename ) 110 | 111 | { 112 | SHPHandle hSHPHandle; 113 | SHPObject *psShape; 114 | double x[4], y[4], z[4], m[4]; 115 | int i, iShape; 116 | 117 | hSHPHandle = SHPCreate( pszFilename, nSHPType ); 118 | 119 | for( iShape = 0; iShape < 3; iShape++ ) 120 | { 121 | for( i = 0; i < 4; i++ ) 122 | { 123 | x[i] = iShape * 10 + i + 1.15; 124 | y[i] = iShape * 10 + i + 2.25; 125 | z[i] = iShape * 10 + i + 3.35; 126 | m[i] = iShape * 10 + i + 4.45; 127 | } 128 | 129 | psShape = SHPCreateObject( nSHPType, -1, 0, NULL, NULL, 130 | 4, x, y, z, m ); 131 | SHPWriteObject( hSHPHandle, -1, psShape ); 132 | SHPDestroyObject( psShape ); 133 | } 134 | 135 | SHPClose( hSHPHandle ); 136 | } 137 | 138 | /************************************************************************/ 139 | /* Test_WriteArcPoly() */ 140 | /* */ 141 | /* Write a small arc or polygon file. */ 142 | /************************************************************************/ 143 | 144 | static void Test_WriteArcPoly( int nSHPType, const char *pszFilename ) 145 | 146 | { 147 | SHPHandle hSHPHandle; 148 | SHPObject *psShape; 149 | double x[100], y[100], z[100], m[100]; 150 | int anPartStart[100]; 151 | int anPartType[100], *panPartType; 152 | int i, iShape; 153 | 154 | hSHPHandle = SHPCreate( pszFilename, nSHPType ); 155 | 156 | if( nSHPType == SHPT_MULTIPATCH ) 157 | panPartType = anPartType; 158 | else 159 | panPartType = NULL; 160 | 161 | for( iShape = 0; iShape < 3; iShape++ ) 162 | { 163 | x[0] = 1.0; 164 | y[0] = 1.0+iShape*3; 165 | x[1] = 2.0; 166 | y[1] = 1.0+iShape*3; 167 | x[2] = 2.0; 168 | y[2] = 2.0+iShape*3; 169 | x[3] = 1.0; 170 | y[3] = 2.0+iShape*3; 171 | x[4] = 1.0; 172 | y[4] = 1.0+iShape*3; 173 | 174 | for( i = 0; i < 5; i++ ) 175 | { 176 | z[i] = iShape * 10 + i + 3.35; 177 | m[i] = iShape * 10 + i + 4.45; 178 | } 179 | 180 | psShape = SHPCreateObject( nSHPType, -1, 0, NULL, NULL, 181 | 5, x, y, z, m ); 182 | SHPWriteObject( hSHPHandle, -1, psShape ); 183 | SHPDestroyObject( psShape ); 184 | } 185 | 186 | /* -------------------------------------------------------------------- */ 187 | /* Do a multi part polygon (shape). We close it, and have two */ 188 | /* inner rings. */ 189 | /* -------------------------------------------------------------------- */ 190 | x[0] = 0.0; 191 | y[0] = 0.0; 192 | x[1] = 0; 193 | y[1] = 100; 194 | x[2] = 100; 195 | y[2] = 100; 196 | x[3] = 100; 197 | y[3] = 0; 198 | x[4] = 0; 199 | y[4] = 0; 200 | 201 | x[5] = 10; 202 | y[5] = 20; 203 | x[6] = 30; 204 | y[6] = 20; 205 | x[7] = 30; 206 | y[7] = 40; 207 | x[8] = 10; 208 | y[8] = 40; 209 | x[9] = 10; 210 | y[9] = 20; 211 | 212 | x[10] = 60; 213 | y[10] = 20; 214 | x[11] = 90; 215 | y[11] = 20; 216 | x[12] = 90; 217 | y[12] = 40; 218 | x[13] = 60; 219 | y[13] = 40; 220 | x[14] = 60; 221 | y[14] = 20; 222 | 223 | for( i = 0; i < 15; i++ ) 224 | { 225 | z[i] = i; 226 | m[i] = i*2; 227 | } 228 | 229 | anPartStart[0] = 0; 230 | anPartStart[1] = 5; 231 | anPartStart[2] = 10; 232 | 233 | anPartType[0] = SHPP_RING; 234 | anPartType[1] = SHPP_INNERRING; 235 | anPartType[2] = SHPP_INNERRING; 236 | 237 | psShape = SHPCreateObject( nSHPType, -1, 3, anPartStart, panPartType, 238 | 15, x, y, z, m ); 239 | SHPWriteObject( hSHPHandle, -1, psShape ); 240 | SHPDestroyObject( psShape ); 241 | 242 | 243 | SHPClose( hSHPHandle ); 244 | } 245 | 246 | /************************************************************************/ 247 | /* main() */ 248 | /************************************************************************/ 249 | int main( int argc, char ** argv ) 250 | 251 | { 252 | /* -------------------------------------------------------------------- */ 253 | /* Display a usage message. */ 254 | /* -------------------------------------------------------------------- */ 255 | if( argc != 2 ) 256 | { 257 | printf( "shptest test_number\n" ); 258 | exit( 1 ); 259 | } 260 | 261 | /* -------------------------------------------------------------------- */ 262 | /* Figure out which test to run. */ 263 | /* -------------------------------------------------------------------- */ 264 | 265 | if( atoi(argv[1]) == 0 ) 266 | Test_WritePoints( SHPT_NULL, "test0.shp" ); 267 | 268 | else if( atoi(argv[1]) == 1 ) 269 | Test_WritePoints( SHPT_POINT, "test1.shp" ); 270 | else if( atoi(argv[1]) == 2 ) 271 | Test_WritePoints( SHPT_POINTZ, "test2.shp" ); 272 | else if( atoi(argv[1]) == 3 ) 273 | Test_WritePoints( SHPT_POINTM, "test3.shp" ); 274 | 275 | else if( atoi(argv[1]) == 4 ) 276 | Test_WriteMultiPoints( SHPT_MULTIPOINT, "test4.shp" ); 277 | else if( atoi(argv[1]) == 5 ) 278 | Test_WriteMultiPoints( SHPT_MULTIPOINTZ, "test5.shp" ); 279 | else if( atoi(argv[1]) == 6 ) 280 | Test_WriteMultiPoints( SHPT_MULTIPOINTM, "test6.shp" ); 281 | 282 | else if( atoi(argv[1]) == 7 ) 283 | Test_WriteArcPoly( SHPT_ARC, "test7.shp" ); 284 | else if( atoi(argv[1]) == 8 ) 285 | Test_WriteArcPoly( SHPT_ARCZ, "test8.shp" ); 286 | else if( atoi(argv[1]) == 9 ) 287 | Test_WriteArcPoly( SHPT_ARCM, "test9.shp" ); 288 | 289 | else if( atoi(argv[1]) == 10 ) 290 | Test_WriteArcPoly( SHPT_POLYGON, "test10.shp" ); 291 | else if( atoi(argv[1]) == 11 ) 292 | Test_WriteArcPoly( SHPT_POLYGONZ, "test11.shp" ); 293 | else if( atoi(argv[1]) == 12 ) 294 | Test_WriteArcPoly( SHPT_POLYGONM, "test12.shp" ); 295 | 296 | else if( atoi(argv[1]) == 13 ) 297 | Test_WriteArcPoly( SHPT_MULTIPATCH, "test13.shp" ); 298 | else 299 | { 300 | printf( "Test `%s' not recognised.\n", argv[1] ); 301 | exit( 10 ); 302 | } 303 | 304 | #ifdef USE_DBMALLOC 305 | malloc_dump(2); 306 | #endif 307 | 308 | exit( 0 ); 309 | } 310 | -------------------------------------------------------------------------------- /Pods/shapelib/shptreedump.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * $Id: shptreedump.c,v 1.8 2005-01-03 22:30:13 fwarmerdam Exp $ 3 | * 4 | * Project: Shapelib 5 | * Purpose: Mainline for creating and dumping an ASCII representation of 6 | * a quadtree. 7 | * Author: Frank Warmerdam, warmerdam@pobox.com 8 | * 9 | ****************************************************************************** 10 | * Copyright (c) 1999, Frank Warmerdam 11 | * 12 | * This software is available under the following "MIT Style" license, 13 | * or at the option of the licensee under the LGPL (see LICENSE.LGPL). This 14 | * option is discussed in more detail in shapelib.html. 15 | * 16 | * -- 17 | * 18 | * Permission is hereby granted, free of charge, to any person obtaining a 19 | * copy of this software and associated documentation files (the "Software"), 20 | * to deal in the Software without restriction, including without limitation 21 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 22 | * and/or sell copies of the Software, and to permit persons to whom the 23 | * Software is furnished to do so, subject to the following conditions: 24 | * 25 | * The above copyright notice and this permission notice shall be included 26 | * in all copies or substantial portions of the Software. 27 | * 28 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 29 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 30 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 31 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 32 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 33 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 34 | * DEALINGS IN THE SOFTWARE. 35 | ****************************************************************************** 36 | * 37 | * $Log: shptreedump.c,v $ 38 | * Revision 1.8 2005-01-03 22:30:13 fwarmerdam 39 | * added support for saved quadtrees 40 | * 41 | * Revision 1.7 2002/04/10 16:59:12 warmerda 42 | * fixed email 43 | * 44 | * Revision 1.6 1999/11/05 14:12:05 warmerda 45 | * updated license terms 46 | * 47 | * Revision 1.5 1999/06/02 18:24:21 warmerda 48 | * added trimming code 49 | * 50 | * Revision 1.4 1999/06/02 17:56:12 warmerda 51 | * added quad'' subnode support for trees 52 | * 53 | * Revision 1.3 1999/05/18 19:13:13 warmerda 54 | * Use fabs() instead of abs(). 55 | * 56 | * Revision 1.2 1999/05/18 19:11:11 warmerda 57 | * Added example searching capability 58 | * 59 | * Revision 1.1 1999/05/18 17:49:20 warmerda 60 | * New 61 | * 62 | */ 63 | 64 | #include "shapefil.h" 65 | 66 | #include 67 | #include 68 | #include 69 | #include 70 | 71 | SHP_CVSID("$Id: shptreedump.c,v 1.8 2005-01-03 22:30:13 fwarmerdam Exp $") 72 | 73 | static void SHPTreeNodeDump( SHPTree *, SHPTreeNode *, const char *, int ); 74 | static void SHPTreeNodeSearchAndDump( SHPTree *, double *, double * ); 75 | 76 | /************************************************************************/ 77 | /* Usage() */ 78 | /************************************************************************/ 79 | 80 | static void Usage() 81 | 82 | { 83 | printf( "shptreedump [-maxdepth n] [-search xmin ymin xmax ymax]\n" 84 | " [-v] [-o indexfilename] [-i indexfilename]\n" 85 | " shp_file\n" ); 86 | exit( 1 ); 87 | } 88 | 89 | 90 | 91 | /************************************************************************/ 92 | /* main() */ 93 | /************************************************************************/ 94 | int main( int argc, char ** argv ) 95 | 96 | { 97 | SHPHandle hSHP; 98 | SHPTree *psTree; 99 | int nExpandShapes = 0; 100 | int nMaxDepth = 0; 101 | int bDoSearch = 0; 102 | double adfSearchMin[4], adfSearchMax[4]; 103 | const char *pszOutputIndexFilename = NULL; 104 | const char *pszInputIndexFilename = NULL; 105 | const char *pszTargetFile = NULL; 106 | 107 | /* -------------------------------------------------------------------- */ 108 | /* Consume flags. */ 109 | /* -------------------------------------------------------------------- */ 110 | while( argc > 1 ) 111 | { 112 | if( strcmp(argv[1],"-v") == 0 ) 113 | { 114 | nExpandShapes = 1; 115 | argv++; 116 | argc--; 117 | } 118 | else if( strcmp(argv[1],"-maxdepth") == 0 && argc > 2 ) 119 | { 120 | nMaxDepth = atoi(argv[2]); 121 | argv += 2; 122 | argc -= 2; 123 | } 124 | else if( strcmp(argv[1],"-o") == 0 && argc > 2 ) 125 | { 126 | pszOutputIndexFilename = argv[2]; 127 | argv += 2; 128 | argc -= 2; 129 | } 130 | else if( strcmp(argv[1],"-i") == 0 && argc > 2 ) 131 | { 132 | pszInputIndexFilename = argv[2]; 133 | argv += 2; 134 | argc -= 2; 135 | } 136 | else if( strcmp(argv[1],"-search") == 0 && argc > 5 ) 137 | { 138 | bDoSearch = 1; 139 | 140 | adfSearchMin[0] = atof(argv[2]); 141 | adfSearchMin[1] = atof(argv[3]); 142 | adfSearchMax[0] = atof(argv[4]); 143 | adfSearchMax[1] = atof(argv[5]); 144 | 145 | adfSearchMin[2] = adfSearchMax[2] = 0.0; 146 | adfSearchMin[3] = adfSearchMax[3] = 0.0; 147 | 148 | if( adfSearchMin[0] > adfSearchMax[0] 149 | || adfSearchMin[1] > adfSearchMax[1] ) 150 | { 151 | printf( "Min greater than max in search criteria.\n" ); 152 | Usage(); 153 | } 154 | 155 | argv += 5; 156 | argc -= 5; 157 | } 158 | else if( pszTargetFile == NULL ) 159 | { 160 | pszTargetFile = argv[1]; 161 | argv++; 162 | argc--; 163 | } 164 | else 165 | { 166 | printf( "Unrecognised argument: %s\n", argv[1] ); 167 | Usage(); 168 | } 169 | } 170 | 171 | /* -------------------------------------------------------------------- */ 172 | /* Do a search with an existing index file? */ 173 | /* -------------------------------------------------------------------- */ 174 | if( bDoSearch && pszInputIndexFilename != NULL ) 175 | { 176 | FILE *fp = fopen( pszInputIndexFilename, "rb" ); 177 | int *panResult, nResultCount = 0, iResult; 178 | 179 | if( fp == NULL ) 180 | { 181 | perror( pszInputIndexFilename ); 182 | exit( 1 ); 183 | } 184 | 185 | panResult = SHPSearchDiskTree( fp, adfSearchMin, adfSearchMax, 186 | &nResultCount ); 187 | 188 | printf( "Result: " ); 189 | for( iResult = 0; iResult < nResultCount; iResult++ ) 190 | printf( "%d ", panResult[iResult] ); 191 | printf( "\n" ); 192 | free( panResult ); 193 | 194 | fclose( fp ); 195 | 196 | exit( 0 ); 197 | } 198 | 199 | /* -------------------------------------------------------------------- */ 200 | /* Display a usage message. */ 201 | /* -------------------------------------------------------------------- */ 202 | if( pszTargetFile == NULL ) 203 | { 204 | Usage(); 205 | } 206 | 207 | /* -------------------------------------------------------------------- */ 208 | /* Open the passed shapefile. */ 209 | /* -------------------------------------------------------------------- */ 210 | hSHP = SHPOpen( pszTargetFile, "rb" ); 211 | 212 | if( hSHP == NULL ) 213 | { 214 | printf( "Unable to open:%s\n", pszTargetFile ); 215 | exit( 1 ); 216 | } 217 | 218 | /* -------------------------------------------------------------------- */ 219 | /* Build a quadtree structure for this file. */ 220 | /* -------------------------------------------------------------------- */ 221 | psTree = SHPCreateTree( hSHP, 2, nMaxDepth, NULL, NULL ); 222 | 223 | /* -------------------------------------------------------------------- */ 224 | /* Trim unused nodes from the tree. */ 225 | /* -------------------------------------------------------------------- */ 226 | SHPTreeTrimExtraNodes( psTree ); 227 | 228 | /* -------------------------------------------------------------------- */ 229 | /* Dump tree to .qix file. */ 230 | /* -------------------------------------------------------------------- */ 231 | if( pszOutputIndexFilename != NULL ) 232 | { 233 | SHPWriteTree( psTree, pszOutputIndexFilename ); 234 | } 235 | 236 | /* -------------------------------------------------------------------- */ 237 | /* Dump tree by recursive descent. */ 238 | /* -------------------------------------------------------------------- */ 239 | else if( !bDoSearch ) 240 | SHPTreeNodeDump( psTree, psTree->psRoot, "", nExpandShapes ); 241 | 242 | /* -------------------------------------------------------------------- */ 243 | /* or do a search instead. */ 244 | /* -------------------------------------------------------------------- */ 245 | else 246 | SHPTreeNodeSearchAndDump( psTree, adfSearchMin, adfSearchMax ); 247 | 248 | /* -------------------------------------------------------------------- */ 249 | /* cleanup */ 250 | /* -------------------------------------------------------------------- */ 251 | SHPDestroyTree( psTree ); 252 | 253 | SHPClose( hSHP ); 254 | 255 | #ifdef USE_DBMALLOC 256 | malloc_dump(2); 257 | #endif 258 | 259 | exit( 0 ); 260 | } 261 | 262 | /************************************************************************/ 263 | /* EmitCoordinate() */ 264 | /************************************************************************/ 265 | 266 | static void EmitCoordinate( double * padfCoord, int nDimension ) 267 | 268 | { 269 | const char *pszFormat; 270 | 271 | if( fabs(padfCoord[0]) < 180 && fabs(padfCoord[1]) < 180 ) 272 | pszFormat = "%.9f"; 273 | else 274 | pszFormat = "%.2f"; 275 | 276 | printf( pszFormat, padfCoord[0] ); 277 | printf( "," ); 278 | printf( pszFormat, padfCoord[1] ); 279 | 280 | if( nDimension > 2 ) 281 | { 282 | printf( "," ); 283 | printf( pszFormat, padfCoord[2] ); 284 | } 285 | if( nDimension > 3 ) 286 | { 287 | printf( "," ); 288 | printf( pszFormat, padfCoord[3] ); 289 | } 290 | } 291 | 292 | /************************************************************************/ 293 | /* EmitShape() */ 294 | /************************************************************************/ 295 | 296 | static void EmitShape( SHPObject * psObject, const char * pszPrefix, 297 | int nDimension ) 298 | 299 | { 300 | int i; 301 | 302 | printf( "%s( Shape\n", pszPrefix ); 303 | printf( "%s ShapeId = %d\n", pszPrefix, psObject->nShapeId ); 304 | 305 | printf( "%s Min = (", pszPrefix ); 306 | EmitCoordinate( &(psObject->dfXMin), nDimension ); 307 | printf( ")\n" ); 308 | 309 | printf( "%s Max = (", pszPrefix ); 310 | EmitCoordinate( &(psObject->dfXMax), nDimension ); 311 | printf( ")\n" ); 312 | 313 | for( i = 0; i < psObject->nVertices; i++ ) 314 | { 315 | double adfVertex[4]; 316 | 317 | printf( "%s Vertex[%d] = (", pszPrefix, i ); 318 | 319 | adfVertex[0] = psObject->padfX[i]; 320 | adfVertex[1] = psObject->padfY[i]; 321 | adfVertex[2] = psObject->padfZ[i]; 322 | adfVertex[3] = psObject->padfM[i]; 323 | 324 | EmitCoordinate( adfVertex, nDimension ); 325 | printf( ")\n" ); 326 | } 327 | printf( "%s)\n", pszPrefix ); 328 | } 329 | 330 | /************************************************************************/ 331 | /* SHPTreeNodeDump() */ 332 | /* */ 333 | /* Dump a tree node in a readable form. */ 334 | /************************************************************************/ 335 | 336 | static void SHPTreeNodeDump( SHPTree * psTree, 337 | SHPTreeNode * psTreeNode, 338 | const char * pszPrefix, 339 | int nExpandShapes ) 340 | 341 | { 342 | char szNextPrefix[150]; 343 | int i; 344 | 345 | strcpy( szNextPrefix, pszPrefix ); 346 | if( strlen(pszPrefix) < sizeof(szNextPrefix) - 3 ) 347 | strcat( szNextPrefix, " " ); 348 | 349 | printf( "%s( SHPTreeNode\n", pszPrefix ); 350 | 351 | /* -------------------------------------------------------------------- */ 352 | /* Emit the bounds. */ 353 | /* -------------------------------------------------------------------- */ 354 | printf( "%s Min = (", pszPrefix ); 355 | EmitCoordinate( psTreeNode->adfBoundsMin, psTree->nDimension ); 356 | printf( ")\n" ); 357 | 358 | printf( "%s Max = (", pszPrefix ); 359 | EmitCoordinate( psTreeNode->adfBoundsMax, psTree->nDimension ); 360 | printf( ")\n" ); 361 | 362 | /* -------------------------------------------------------------------- */ 363 | /* Emit the list of shapes on this node. */ 364 | /* -------------------------------------------------------------------- */ 365 | if( nExpandShapes ) 366 | { 367 | printf( "%s Shapes(%d):\n", pszPrefix, psTreeNode->nShapeCount ); 368 | for( i = 0; i < psTreeNode->nShapeCount; i++ ) 369 | { 370 | SHPObject *psObject; 371 | 372 | psObject = SHPReadObject( psTree->hSHP, 373 | psTreeNode->panShapeIds[i] ); 374 | assert( psObject != NULL ); 375 | if( psObject != NULL ) 376 | { 377 | EmitShape( psObject, szNextPrefix, psTree->nDimension ); 378 | } 379 | 380 | SHPDestroyObject( psObject ); 381 | } 382 | } 383 | else 384 | { 385 | printf( "%s Shapes(%d): ", pszPrefix, psTreeNode->nShapeCount ); 386 | for( i = 0; i < psTreeNode->nShapeCount; i++ ) 387 | { 388 | printf( "%d ", psTreeNode->panShapeIds[i] ); 389 | } 390 | printf( "\n" ); 391 | } 392 | 393 | /* -------------------------------------------------------------------- */ 394 | /* Emit subnodes. */ 395 | /* -------------------------------------------------------------------- */ 396 | for( i = 0; i < psTreeNode->nSubNodes; i++ ) 397 | { 398 | if( psTreeNode->apsSubNode[i] != NULL ) 399 | SHPTreeNodeDump( psTree, psTreeNode->apsSubNode[i], 400 | szNextPrefix, nExpandShapes ); 401 | } 402 | 403 | printf( "%s)\n", pszPrefix ); 404 | 405 | return; 406 | } 407 | 408 | /************************************************************************/ 409 | /* SHPTreeNodeSearchAndDump() */ 410 | /************************************************************************/ 411 | 412 | static void SHPTreeNodeSearchAndDump( SHPTree * hTree, 413 | double *padfBoundsMin, 414 | double *padfBoundsMax ) 415 | 416 | { 417 | int *panHits, nShapeCount, i; 418 | 419 | /* -------------------------------------------------------------------- */ 420 | /* Perform the search for likely candidates. These are shapes */ 421 | /* that fall into a tree node whose bounding box intersects our */ 422 | /* area of interest. */ 423 | /* -------------------------------------------------------------------- */ 424 | panHits = SHPTreeFindLikelyShapes( hTree, padfBoundsMin, padfBoundsMax, 425 | &nShapeCount ); 426 | 427 | /* -------------------------------------------------------------------- */ 428 | /* Read all of these shapes, and establish whether the shape's */ 429 | /* bounding box actually intersects the area of interest. Note */ 430 | /* that the bounding box could intersect the area of interest, */ 431 | /* and the shape itself still not cross it but we don't try to */ 432 | /* address that here. */ 433 | /* -------------------------------------------------------------------- */ 434 | for( i = 0; i < nShapeCount; i++ ) 435 | { 436 | SHPObject *psObject; 437 | 438 | psObject = SHPReadObject( hTree->hSHP, panHits[i] ); 439 | if( psObject == NULL ) 440 | continue; 441 | 442 | if( !SHPCheckBoundsOverlap( padfBoundsMin, padfBoundsMax, 443 | &(psObject->dfXMin), 444 | &(psObject->dfXMax), 445 | hTree->nDimension ) ) 446 | { 447 | printf( "Shape %d: not in area of interest, but fetched.\n", 448 | panHits[i] ); 449 | } 450 | else 451 | { 452 | printf( "Shape %d: appears to be in area of interest.\n", 453 | panHits[i] ); 454 | } 455 | 456 | SHPDestroyObject( psObject ); 457 | } 458 | 459 | if( nShapeCount == 0 ) 460 | printf( "No shapes found in search.\n" ); 461 | } 462 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Mapkit_ShapeFile 2 | ================ 3 | 4 |

5 | 6 | Mapkit_shapeFile_demo 7 |

8 | 9 | ##Overview 10 | 11 | Uses ESRI Shape Files to draw Overlays on MKMapViews 12 | 13 | ##Installation 14 | 15 | Pod install in root directory and use XCWorkspace 16 | 17 | ##Architecture 18 | 19 | ###ViewController+MapOverlay 20 | 21 | Interacts with the MKPoloygonRenderer to handle drawing of geospatial regions using defined fill color stroke color and line width 22 | 23 | ###GeoRegion 24 | 25 | Encapsulates geospatial data for a given georegion. Initializer handles parsing of SHPObject and storing shape data into Objective-C object. 26 | 27 | ###GeoRegionStack 28 | 29 | Handles iterating through colection of GeoRegion and providing an Array of geoRegion objects. 30 | -------------------------------------------------------------------------------- /assets/images/country.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altyus/Mapkit_ShapeFile/e81e3559997fea97e018ba6c73f4c643bd2eb28e/assets/images/country.png -------------------------------------------------------------------------------- /assets/images/mapkitshapefile.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altyus/Mapkit_ShapeFile/e81e3559997fea97e018ba6c73f4c643bd2eb28e/assets/images/mapkitshapefile.gif -------------------------------------------------------------------------------- /assets/images/state.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altyus/Mapkit_ShapeFile/e81e3559997fea97e018ba6c73f4c643bd2eb28e/assets/images/state.png -------------------------------------------------------------------------------- /assets/images/statepark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altyus/Mapkit_ShapeFile/e81e3559997fea97e018ba6c73f4c643bd2eb28e/assets/images/statepark.png --------------------------------------------------------------------------------