Пример #1
0
std::string sosicon::ConverterSosi2psql::
getSrid( ISosiElement* sosiTree ) {

    // Path: .HODE/..TRANSPAR/...KOORDSYS
    ISosiElement* head = 0, * transpar = 0, * coordsys = 0;

    sosi::SosiElementSearch srcHead( sosi::sosi_element_head );
    sosi::SosiElementSearch srcTranspar( sosi::sosi_element_transpar );
    sosi::SosiElementSearch srcCoordsys( sosi::sosi_element_coordsys );

    if( sosiTree->getChild( srcHead ) ) {
        head = srcHead.element();
    }
    if( head && head->getChild( srcTranspar ) ) {
        transpar = srcTranspar.element();
    }
    if( transpar && transpar->getChild( srcCoordsys ) ) {
        coordsys = srcCoordsys.element();
    }

    std::string srid;

    if( coordsys ) {
        std::stringstream ss;
        ss << coordsys->getData();
        int sysCode;
        ss >> sysCode;
        sosi::SosiTranslationTable tt;
        sosi::CoordSys cs = tt.sysCodeToCoordSys( sysCode );
        srid = cs.srid();
        std::cout << "Coordinate system: " << cs.displayString() << "\n";
    }
    else {
Пример #2
0
void sosicon::ConverterSosi2psql::
extractData( ISosiElement* parent,
             FieldsList& hdr,
             std::map<std::string,std::string>*& row ) {

    sosi::SosiElementSearch srcData;
    while( parent->getChild( srcData ) ) {

        ISosiElement* dataElement = srcData.element();

        extractData( dataElement, hdr, row );

        std::string fieldName = utils::toFieldname( dataElement->getName() );
        std::string data = dataElement->getData();
        
        if( data.empty() ) {
            continue;
        }

        if( hdr.find( fieldName ) == hdr.end() ) {
            hdr[ fieldName ] = Field( data );
        }
        else {
          hdr[ fieldName ].expand( data );
        }

        if( row ) {
            ( *row )[ fieldName ] = data;
        }
    }
}
Пример #3
0
void sosicon::ConverterSosiStat::
printElementData( ISosiElement* e, sosi::SosiElementSearch src, int padding ) {
    while( e->getChild( src ) ) {
        ISosiElement* child = src.element();
        if( !child->getData().empty() ) {
            std::string label = child->getName();
            label.resize( padding, '.' );
            std::cout << " " << label << ": " << child->getData() << "\n";
        }
    }
}
Пример #4
0
void sosicon::ConverterSosiStat::
run() {
    for( std::vector<std::string>::iterator f = mCmd->mSourceFiles.begin(); f != mCmd->mSourceFiles.end(); f++ ) {
        std::cout << "\nGenerating statistics for " << *f << "\n";
        Parser p;
        char ln[ 1024 ];
        std::ifstream ifs( ( *f ).c_str() );
        int c = 0;
        while( !ifs.eof() ) {
            c++;
            if( mCmd->mIsTtyOut && ( c % 100 ) == 0 ) {
                std::cout << "\rParsing " << c << " lines...";
            }
            memset( ln, 0x00, sizeof ln );
            ifs.getline( ln, sizeof ln );
            p.ragelParseSosiLine( ln );
        }
        std::cout << "\n" << c << " lines in file   \n\n";
        p.complete();
        ifs.close();

        ISosiElement* root = p.getRootElement();
        makeStat( root );

        sosi::SosiElementSearch srcHead( sosi::sosi_element_head );
        if( root->getChild( srcHead ) ) {
            sosi::SosiElementSearch srcHeadItem;
            
            printTableHeader( "SOSI HEADER", "VALUE", 22 );
            printElementData( srcHead.element(), sosi::SosiElementSearch(), 22 );
            std::cout << "\n\n";
            
            sosi::SosiElementSearch srcTranspar( sosi::sosi_element_transpar );
            if( srcHead.element()->getChild( srcTranspar ) ) {
                sosi::SosiElementSearch srcTransparItem;
                printTableHeader( "SOSI HEADER/TRANSPAR", "VALUE", 22 );
                printElementData( srcTranspar.element(), sosi::SosiElementSearch(), 22 );
                std::cout << "\n\n";
            }
        }

        printTableHeader( "SOSI ELEMENT", "COUNT", 30 );
        printListContent( mGeoTypes, 30 );
        std::cout << "\n\n";

        printTableHeader( "OBJTYPE", "COUNT", 30 );
        printListContent( mObjTypes, 30 );
        std::cout << "\n\n";

    }
}
Пример #5
0
void sosicon::sosi::SosiNorthEast::
initHeadMember( ISosiHeadMember& headMember, ElementType type ) {
    if( !headMember.initialized() ) {
        SosiElementSearch head( sosi_element_head );
        SosiElementSearch transpar( sosi_element_transpar );
        SosiElementSearch target( type );
        ISosiElement* root = mSosiElement->getRoot();
        if( root->getChild( head ) &&
            head.element()->getChild( transpar ) &&
            transpar.element()->getChild( target ) )
        {
            headMember.init( target.element() );
        }
    }
}
Пример #6
0
void sosicon::shape::Shapefile::
extractDbfFields( ISosiElement* sosi, DbfRecord& rec ) {

    std::string field;
    std::string data;
    ISosiElement* child = 0;
    sosi::SosiElementSearch src;

    while( sosi->getChild( src ) ) {
        child = src.element();
        if( child->getType() != sosi::sosi_element_ne ) {
            data = utils::trim( child->getData() );
            saveToDbf( rec, child->getName(), data );
            extractDbfFields( child, rec );
        }
    }
}
Пример #7
0
int sosicon::shape::Shapefile::
build( ISosiElement* sosiTree, std::string objType, sosi::ElementType geomType ) {

    int count = 0;

    mSosiTree = sosiTree;

    ISosiElement* sosi = 0;
    sosi::SosiElementSearch src;
    ShapeType shapeTypeEquivalent = shape_type_none;

    std::vector<std::string>& f = mFilterSosiId;
    while( sosiTree->getChild( src ) ) {

        sosi = src.element();

        if(
            ( objType.empty() || objType == sosi->getObjType() ) &&
            ( f.size() == 0 || std::find( f.begin(), f.end(), sosi->getSerial() ) != f.end() )
          )
        {

            if( sosi->getType() == geomType ) {
                shapeTypeEquivalent = getShapeEquivalent( sosi->getType() );
                buildShpElement( sosi, shapeTypeEquivalent );
                insertDbfRecord( sosi );
                ++count;
            }
        }
    }
    if( count > 0 ) {

        buildShpHeader( shapeTypeEquivalent );

        buildDbf(); // database (attributes table)
        buildShx(); // index

    }

    return count;
}