本文整理汇总了C++中GeoDataDocument::addSchema方法的典型用法代码示例。如果您正苦于以下问题:C++ GeoDataDocument::addSchema方法的具体用法?C++ GeoDataDocument::addSchema怎么用?C++ GeoDataDocument::addSchema使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeoDataDocument
的用法示例。
在下文中一共展示了GeoDataDocument::addSchema方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fileinfo
GeoDataDocument *ShpRunner::parseFile(const QString &fileName, DocumentRole role, QString &error)
{
QFileInfo fileinfo( fileName );
if (fileinfo.suffix().compare(QLatin1String("shp"), Qt::CaseInsensitive) != 0) {
error = QStringLiteral("File %1 does not have a shp suffix").arg(fileName);
mDebug() << error;
return nullptr;
}
SHPHandle handle = SHPOpen( fileName.toStdString().c_str(), "rb" );
if ( !handle ) {
error = QStringLiteral("Failed to read %1").arg(fileName);
mDebug() << error;
return nullptr;
}
int entities;
int shapeType;
SHPGetInfo( handle, &entities, &shapeType, NULL, NULL );
mDebug() << " SHP info " << entities << " Entities "
<< shapeType << " Shape Type ";
DBFHandle dbfhandle;
dbfhandle = DBFOpen( fileName.toStdString().c_str(), "rb");
int nameField = DBFGetFieldIndex( dbfhandle, "Name" );
int noteField = DBFGetFieldIndex( dbfhandle, "Note" );
int mapColorField = DBFGetFieldIndex( dbfhandle, "mapcolor13" );
GeoDataDocument *document = new GeoDataDocument;
document->setDocumentRole( role );
if ( mapColorField != -1 ) {
GeoDataSchema schema;
schema.setId(QStringLiteral("default"));
GeoDataSimpleField simpleField;
simpleField.setName(QStringLiteral("mapcolor13"));
simpleField.setType( GeoDataSimpleField::Double );
schema.addSimpleField( simpleField );
document->addSchema( schema );
}
for ( int i=0; i< entities; ++i ) {
GeoDataPlacemark *placemark = 0;
placemark = new GeoDataPlacemark;
document->append( placemark );
SHPObject *shape = SHPReadObject( handle, i );
if (nameField != -1) {
const char* info = DBFReadStringAttribute( dbfhandle, i, nameField );
// TODO: defaults to utf-8 encoding, but could be also something else, optionally noted in a .cpg file
placemark->setName( info );
mDebug() << "name " << placemark->name();
}
if (noteField != -1) {
const char* note = DBFReadStringAttribute( dbfhandle, i, noteField );
// TODO: defaults to utf-8 encoding, see comment for name
placemark->setDescription( note );
mDebug() << "desc " << placemark->description();
}
double mapColor = DBFReadDoubleAttribute( dbfhandle, i, mapColorField );
if ( mapColor ) {
GeoDataStyle::Ptr style(new GeoDataStyle);
if ( mapColor >= 0 && mapColor <=255 ) {
quint8 colorIndex = quint8( mapColor );
style->polyStyle().setColorIndex( colorIndex );
}
else {
quint8 colorIndex = 0; // mapColor is undefined in this case
style->polyStyle().setColorIndex( colorIndex );
}
placemark->setStyle( style );
}
switch ( shapeType ) {
case SHPT_POINT: {
GeoDataPoint *point = new GeoDataPoint( *shape->padfX, *shape->padfY, 0, GeoDataCoordinates::Degree );
placemark->setGeometry( point );
mDebug() << "point " << placemark->name();
break;
}
case SHPT_MULTIPOINT: {
GeoDataMultiGeometry *geom = new GeoDataMultiGeometry;
for( int j=0; j<shape->nVertices; ++j ) {
geom->append( new GeoDataPoint( GeoDataCoordinates(
shape->padfX[j], shape->padfY[j],
0, GeoDataCoordinates::Degree ) ) );
}
placemark->setGeometry( geom );
mDebug() << "multipoint " << placemark->name();
break;
}
case SHPT_ARC: {
if ( shape->nParts != 1 ) {
GeoDataMultiGeometry *geom = new GeoDataMultiGeometry;
for( int j=0; j<shape->nParts; ++j ) {
GeoDataLineString *line = new GeoDataLineString;
int itEnd = (j + 1 < shape->nParts) ? shape->panPartStart[j+1] : shape->nVertices;
for( int k=shape->panPartStart[j]; k<itEnd; ++k ) {
//.........这里部分代码省略.........