libspatialindex API Reference  (git-trunk)
Utility.cc
Go to the documentation of this file.
1 /******************************************************************************
2  * Project: libsidx - A C API wrapper around libspatialindex
3  * Purpose: C++ object declarations to implement utilities.
4  * Author: Howard Butler, hobu.inc@gmail.com
5  ******************************************************************************
6  * Copyright (c) 2009, Howard Butler
7  *
8  * All rights reserved.
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a
11  * copy of this software and associated documentation files (the "Software"),
12  * to deal in the Software without restriction, including without limitation
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  * and/or sell copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included
18  * in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  * DEALINGS IN THE SOFTWARE.
27 ******************************************************************************/
28 
30 
32 {
34 
35  Tools::Variant var;
36 
37  // Rtree defaults
38 
40  var.m_val.dblVal = 0.7;
41  ps->setProperty("FillFactor", var);
42 
44  var.m_val.ulVal = 100;
45  ps->setProperty("IndexCapacity", var);
46 
48  var.m_val.ulVal = 100;
49  ps->setProperty("LeafCapacity", var);
50 
53  ps->setProperty("TreeVariant", var);
54 
55  // var.m_varType = Tools::VT_LONGLONG;
56  // var.m_val.llVal = 0;
57  // ps->setProperty("IndexIdentifier", var);
58 
60  var.m_val.ulVal = 32;
61  ps->setProperty("NearMinimumOverlapFactor", var);
62 
64  var.m_val.dblVal = 0.4;
65  ps->setProperty("SplitDistributionFactor", var);
66 
68  var.m_val.dblVal = 0.3;
69  ps->setProperty("ReinsertFactor", var);
70 
72  var.m_val.ulVal = 2;
73  ps->setProperty("Dimension", var);
74 
76  var.m_val.bVal = true;
77  ps->setProperty("EnsureTightMBRs", var);
78 
80  var.m_val.ulVal = 100;
81  ps->setProperty("IndexPoolCapacity", var);
82 
84  var.m_val.ulVal = 100;
85  ps->setProperty("LeafPoolCapacity", var);
86 
88  var.m_val.ulVal = 1000;
89  ps->setProperty("RegionPoolCapacity", var);
90 
92  var.m_val.ulVal = 500;
93  ps->setProperty("PointPoolCapacity", var);
94 
95  // horizon for TPRTree
97  var.m_val.dblVal = 20.0;
98  ps->setProperty("Horizon", var);
99 
100  // Buffering defaults
102  var.m_val.ulVal = 10;
103  ps->setProperty("Capacity", var);
104 
106  var.m_val.bVal = false;
107  ps->setProperty("WriteThrough", var);
108 
109  // Disk Storage Manager defaults
111  var.m_val.bVal = true;
112  ps->setProperty("Overwrite", var);
113 
115  var.m_val.pcVal = const_cast<char*>("");
116  ps->setProperty("FileName", var);
117 
119  var.m_val.ulVal = 4096;
120  ps->setProperty("PageSize", var);
121 
123  var.m_val.llVal = 0;
124  ps->setProperty("ResultSetLimit", var);
125 
126  // Our custom properties related to whether
127  // or not we are using a disk or memory storage manager
128 
130  var.m_val.ulVal = RT_Disk;
131  ps->setProperty("IndexStorageType", var);
132 
134  var.m_val.ulVal = RT_RTree;
135  ps->setProperty("IndexType", var);
136 
138  var.m_val.pcVal = const_cast<char*>("dat");
139  ps->setProperty("FileNameDat", var);
140 
142  var.m_val.pcVal = const_cast<char*>("idx");
143  ps->setProperty("FileNameIdx", var);
144 
145  // Custom storage manager properties
147  var.m_val.pcVal = 0;
148  ps->setProperty("CustomStorageCallbacksSize", var);
149 
151  var.m_val.pcVal = 0;
152  ps->setProperty("CustomStorageCallbacks", var);
153 
154  return ps;
155 }
156 
157 void Page_ResultSet_Ids(IdVisitor& visitor, int64_t** ids, int64_t nStart, int64_t nResultLimit, uint64_t* nResults)
158 {
159  int64_t nResultCount;
160 
161  nResultCount = visitor.GetResultCount();
162 
163  if (nResultLimit == 0)
164  {
165  // no offset paging
166  nResultLimit = nResultCount;
167  nStart = 0;
168  }
169  else
170  {
171  if ((nResultCount - (nStart + nResultLimit)) < 0)
172  {
173  // not enough results to fill nResultCount
174  nStart = (std::min)(nStart, nResultCount);
175  nResultCount = nStart + (std::min)(nResultLimit, nResultCount - nStart);
176  }
177  else
178  {
179  nResultCount = (std::min)(nResultCount, nStart + nResultLimit);
180  }
181  }
182 
183  *ids = (int64_t*) malloc (nResultLimit * sizeof(int64_t));
184 
185  std::vector<uint64_t>& results = visitor.GetResults();
186 
187  for (int64_t i = nStart; i < nResultCount; ++i)
188  {
189  (*ids)[i - nStart] = results[i];
190  }
191 
192  *nResults = nResultCount - nStart;
193 }
194 
195 void Page_ResultSet_Obj(ObjVisitor& visitor, IndexItemH** items, int64_t nStart, int64_t nResultLimit, uint64_t* nResults)
196 {
197  int64_t nResultCount;
198 
199  nResultCount = visitor.GetResultCount();
200 
201  if (nResultLimit == 0)
202  {
203  // no offset paging
204  nResultLimit = nResultCount;
205  nStart = 0;
206  }
207  else
208  {
209  if ((nResultCount - (nStart + nResultLimit)) < 0)
210  {
211  // not enough results to fill nResultCount
212  nStart = (std::min)(nStart, nResultCount);
213  nResultCount = nStart + (std::min)(nResultLimit, nResultCount - nStart);
214  }
215  else
216  {
217  nResultCount = (std::min)(nResultCount, nStart + nResultLimit);
218  }
219  }
220 
221  *items = (IndexItemH*) malloc (nResultLimit * sizeof(SpatialIndex::IData*));
222 
223  std::vector<SpatialIndex::IData*>& results = visitor.GetResults();
224 
225  // copy the Items into the newly allocated item array
226  // we need to make sure to copy the actual Item instead
227  // of just the pointers, as the visitor will nuke them
228  // upon ~
229  for (int64_t i = nStart; i < nResultCount; ++i)
230  {
231  SpatialIndex::IData* result =results[i];
232  (*items)[i - nStart] = (IndexItemH)dynamic_cast<SpatialIndex::IData*>(result->clone());
233  }
234  *nResults = nResultCount - nStart;
235 }
std::vector< uint64_t > & GetResults()
Definition: IdVisitor.h:45
VariantType m_varType
Definition: Tools.h:277
uint64_t GetResultCount() const
Definition: IdVisitor.h:44
uint32_t ulVal
Definition: Tools.h:289
void setProperty(std::string property, Variant const &v)
Definition: Tools.cc:354
char * pcVal
Definition: Tools.h:292
uint8_t bVal
Definition: Tools.h:284
std::vector< SpatialIndex::IData * > & GetResults()
Definition: ObjVisitor.h:45
union Tools::Variant::@0 m_val
int64_t llVal
Definition: Tools.h:283
virtual IObject * clone()=0
void Page_ResultSet_Obj(ObjVisitor &visitor, IndexItemH **items, int64_t nStart, int64_t nResultLimit, uint64_t *nResults)
Definition: Utility.cc:195
Tools::PropertySet * GetDefaults()
Definition: Utility.cc:31
class SIDX_DLL PropertySet
Definition: Tools.h:298
int32_t lVal
Definition: Tools.h:282
double dblVal
Definition: Tools.h:286
uint64_t GetResultCount() const
Definition: ObjVisitor.h:44
void Page_ResultSet_Ids(IdVisitor &visitor, int64_t **ids, int64_t nStart, int64_t nResultLimit, uint64_t *nResults)
Definition: Utility.cc:157
struct SpatialIndex_IData * IndexItemH
Definition: sidx_config.h:107