MCPcopy Create free account
hub / github.com/PDAL/PDAL / SetupSchema

Method SetupSchema

plugins/pgpointcloud/io/PgWriter.cpp:184–300  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

182
183
184uint32_t PgWriter::SetupSchema(uint32_t srid)
185{
186
187 // If the user has specified a PCID they want to use,
188 // does it exist in the database?
189 std::ostringstream oss;
190 long schema_count;
191 if (m_pcid)
192 {
193 oss << "SELECT Count(pcid) FROM pointcloud_formats WHERE pcid = " <<
194 m_pcid;
195 std::string count_str = pg_query_once(m_session, oss.str());
196 if (count_str.empty())
197 throwError("Unable to count pcid's in table `pointcloud_formats`");
198 schema_count = atoi(count_str.c_str());
199 if (schema_count == 0)
200 throwError("Requested PCID '" + Utils::toString(m_pcid) +
201 "' does not exist in POINTCLOUD_FORMATS");
202 return m_pcid;
203 }
204
205 // Do we have any existing schemas in the POINTCLOUD_FORMATS table?
206 uint32_t pcid = 0;
207 oss.clear();
208 oss << "SELECT Count(pcid) FROM pointcloud_formats";
209 std::string schema_count_str = pg_query_once(m_session, oss.str());
210 if (schema_count_str.empty())
211 throwError("Unable to count pcid's in table 'pointcloud_formats'.");
212 schema_count = atoi(schema_count_str.c_str());
213 oss.str("");
214
215 // Create an XML output schema.
216 std::string compression;
217 /* If the writer specifies a compression, we should set that */
218 if (m_patch_compression_type == CompressionType::Dimensional)
219 compression = "dimensional";
220 else if (m_patch_compression_type == CompressionType::Lazperf)
221 compression = "laz";
222
223 Metadata metadata;
224 MetadataNode m = metadata.getNode();
225 m.add("compression", compression);
226
227 XMLSchema schema(dbDimTypes(), m);
228 std::string xml = schema.xml();
229
230 // Do any of the existing schemas match the one we want to use?
231 if (schema_count > 0)
232 {
233 oss.str("");
234 oss.clear();
235 oss << "SELECT pcid, schema FROM pointcloud_formats WHERE srid = " << srid;
236 PGresult *result = pg_query_result(m_session, oss.str());
237 for (int i = 0; i < PQntuples(result); ++i)
238 {
239 char *pcid_str = PQgetvalue(result, i, 0);
240 char *schema_str = PQgetvalue(result, i, 1);
241

Callers

nothing calls this directly

Calls 10

pg_query_onceFunction · 0.85
dbDimTypesFunction · 0.85
pg_query_resultFunction · 0.85
strMethod · 0.80
getNodeMethod · 0.80
xmlMethod · 0.80
toStringFunction · 0.50
emptyMethod · 0.45
clearMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected