WhirlyGlobe  1.1
A 3D interactive globe toolkit for ios
/Users/sjg/iPhone/WhirlyGlobe/WhirlyGlobeSrc/WhirlyGlobeLib/include/VectorDatabase.h
00001 /*
00002  *  VectorDatabase.h
00003  *  WhirlyGlobeLib
00004  *
00005  *  Created by Steve Gifford on 5/12/11.
00006  *  Copyright 2011 mousebird consulting
00007  *
00008  *  Licensed under the Apache License, Version 2.0 (the "License");
00009  *  you may not use this file except in compliance with the License.
00010  *  You may obtain a copy of the License at
00011  *  http://www.apache.org/licenses/LICENSE-2.0
00012  *
00013  *  Unless required by applicable law or agreed to in writing, software
00014  *  distributed under the License is distributed on an "AS IS" BASIS,
00015  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016  *  See the License for the specific language governing permissions and
00017  *  limitations under the License.
00018  *
00019  */
00020 
00021 #import <math.h>
00022 #import <set>
00023 #import <map>
00024 #import "VectorData.h"
00025 #import "sqlite3.h"
00026 
00027 namespace WhirlyGlobe
00028 {
00029     
00030 typedef std::set<unsigned int> UIntSet;
00031 
00037 class VectorDatabase
00038 {
00039 public:
00045     VectorDatabase(NSString *bundleDir,NSString *cacheDir,NSString *baseName,VectorReader *reader,const std::set<std::string> *indices,bool cache=false,bool autoload=false);
00046     ~VectorDatabase();
00047 
00050     void setAutoload(bool autoload);
00051     
00053     void setMemCache(bool memCache);
00054     
00056     void process();
00057     
00059     unsigned int numVectors();
00060     
00063     GeoMbr getMbr(unsigned int);
00064     
00071     VectorShapeRef getVector(unsigned int,bool withAttributes=true);
00072     
00074     void getVectorsWithinMbr(const GeoMbr &mbr,UIntSet &vecIds);
00075     
00079     void getMatchingVectors(NSString *query,UIntSet &vecIds);
00081     void getMatchingVectors(NSString *query,ShapeSet &shapes);
00082 
00085     void findArealsForPoint(const GeoCoord &coord,ShapeSet &shapes);
00086     
00087 protected:
00088     bool buildCaches(NSString *mbrCache,NSString *sqlDb);
00089     bool readCaches(NSString *mbrCache,NSString *sqlDb);
00090     
00091     VectorReader *reader;
00092     
00095     std::vector<GeoMbr> mbrs;
00096     
00098     bool vecCacheOn;
00099     std::map<unsigned int,VectorShapeRef> vecCache;
00100     
00102     bool autoloadOn;
00103     int autoloadWhere;
00104     
00106     sqlite3 *db;
00107 };
00108 
00109 }