• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ VFKReaderSQLite类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中VFKReaderSQLite的典型用法代码示例。如果您正苦于以下问题:C++ VFKReaderSQLite类的具体用法?C++ VFKReaderSQLite怎么用?C++ VFKReaderSQLite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了VFKReaderSQLite类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: failure

/*!
  \brief Get first found feature based on it's property
  
  \param column property name
  \param value property value
  \param bGeom True to check also geometry != NULL
    
  \return pointer to feature definition or NULL on failure (not found)
*/
VFKFeatureSQLite *VFKDataBlockSQLite::GetFeature(const char *column, GUIntBig value,
                                                 bool bGeom)
{
    int idx;
    CPLString osSQL;
    VFKReaderSQLite  *poReader;

    sqlite3_stmt *hStmt;
    
    poReader = (VFKReaderSQLite*) m_poReader;
    
    osSQL.Printf("SELECT %s from %s WHERE %s = " CPL_FRMT_GUIB,
                 FID_COLUMN, m_pszName, column, value);
    if (bGeom) {
        CPLString osColumn;
        
        osColumn.Printf(" AND %s IS NOT NULL", GEOM_COLUMN);
        osSQL += osColumn;
    }
    
    hStmt = poReader->PrepareStatement(osSQL.c_str());
    if (poReader->ExecuteSQL(hStmt) != OGRERR_NONE)
        return NULL;
    
    idx = sqlite3_column_int(hStmt, 0) - 1;
    sqlite3_finalize(hStmt);
    
    if (idx < 0 || idx >= m_nFeatureCount) // ? assert
        return NULL;

    return (VFKFeatureSQLite *) GetFeatureByIndex(idx);
}
开发者ID:drownedout,项目名称:datamap,代码行数:41,代码来源:vfkdatablocksqlite.cpp


示例2: UpdateVfkBlocks

/*!
  \brief Update VFK_DB_TABLE table

  \param nGeometries number of geometries to update
*/
void VFKDataBlockSQLite::UpdateVfkBlocks(int nGeometries) {
    int nFeatCount;
    CPLString osSQL;
    
    VFKReaderSQLite  *poReader;
    
    poReader = (VFKReaderSQLite*) m_poReader;

    /* update number of features in VFK_DB_TABLE table */    
    nFeatCount = (int)GetFeatureCount();
    if (nFeatCount > 0) {
        osSQL.Printf("UPDATE %s SET num_features = %d WHERE table_name = '%s'",
                     VFK_DB_TABLE, nFeatCount, m_pszName);
        poReader->ExecuteSQL(osSQL.c_str());
    }

    /* update number of geometries in VFK_DB_TABLE table */    
    if (nGeometries > 0) {
        CPLDebug("OGR-VFK", 
                 "VFKDataBlockSQLite::UpdateVfkBlocks(): name=%s -> "
                 "%d geometries saved to internal DB", m_pszName, nGeometries);
        
	osSQL.Printf("UPDATE %s SET num_geometries = %d WHERE table_name = '%s'",
		     VFK_DB_TABLE, nGeometries, m_pszName);
	poReader->ExecuteSQL(osSQL.c_str());
    }
}
开发者ID:drownedout,项目名称:datamap,代码行数:32,代码来源:vfkdatablocksqlite.cpp


示例3: GetFeatures

/*!
  \brief Get features based on properties
  
  \param column array of property names
  \param value array of property values
  \param num number of array items
  
  \return list of features
*/
VFKFeatureSQLiteList VFKDataBlockSQLite::GetFeatures(const char **column, GUIntBig *value, int num)
{
    int iRowId;
    CPLString osSQL, osItem;

    VFKReaderSQLite     *poReader;
    VFKFeatureSQLiteList fList;
    
    sqlite3_stmt *hStmt;
    
    poReader = (VFKReaderSQLite*) m_poReader;
    
    osSQL.Printf("SELECT rowid from %s WHERE ", m_pszName);
    for (int i = 0; i < num; i++) {
        if (i > 0)
            osItem.Printf(" OR %s = " CPL_FRMT_GUIB, column[i], value[i]);
        else
            osItem.Printf("%s = " CPL_FRMT_GUIB, column[i], value[i]);
        osSQL += osItem;
    }
    osSQL += " ORDER BY ";
    osSQL += FID_COLUMN;
    
    hStmt = poReader->PrepareStatement(osSQL.c_str());
    while (poReader->ExecuteSQL(hStmt) == OGRERR_NONE) {
        iRowId = sqlite3_column_int(hStmt, 0);
        fList.push_back((VFKFeatureSQLite *)GetFeatureByIndex(iRowId - 1));
    }
    
    return fList;
}
开发者ID:drownedout,项目名称:datamap,代码行数:40,代码来源:vfkdatablocksqlite.cpp


示例4: DB

/*!
  \brief Save geometry to DB (as WKB)

  \param poGeom pointer to OGRGeometry to be saved
  \param iRowId row id to update

  \return OGRERR_NONE on success otherwise OGRERR_FAILURE
*/
OGRErr VFKDataBlockSQLite::SaveGeometryToDB(const OGRGeometry *poGeom, int iRowId)
{
    int        rc, nWKBLen;
    CPLString  osSQL;

    sqlite3_stmt *hStmt = NULL;

    VFKReaderSQLite *poReader = (VFKReaderSQLite*) m_poReader;

    if (poGeom) {
        nWKBLen = poGeom->WkbSize();
        GByte *pabyWKB = (GByte *) CPLMalloc(nWKBLen + 1);
        poGeom->exportToWkb(wkbNDR, pabyWKB);

        osSQL.Printf("UPDATE %s SET %s = ? WHERE rowid = %d",
                     m_pszName, GEOM_COLUMN, iRowId);
        hStmt = poReader->PrepareStatement(osSQL.c_str());

        rc = sqlite3_bind_blob(hStmt, 1, pabyWKB, nWKBLen, CPLFree);
        if (rc != SQLITE_OK) {
            sqlite3_finalize(hStmt);
            CPLError(CE_Failure, CPLE_AppDefined,
                     "Storing geometry in DB failed");
            return OGRERR_FAILURE;
        }
    }
    else { /* invalid */
        osSQL.Printf("UPDATE %s SET %s = NULL WHERE rowid = %d",
                     m_pszName, GEOM_COLUMN, iRowId);
        hStmt = poReader->PrepareStatement(osSQL.c_str());
    }

    return poReader->ExecuteSQL(hStmt); /* calls sqlite3_finalize() */
}
开发者ID:ryandavid,项目名称:rotobox,代码行数:42,代码来源:vfkdatablocksqlite.cpp


示例5: properties

/*!
  \brief Get first found feature based on it's properties (AND)

  \param column array of property names
  \param value array of property values
  \param num number of array items
  \param bGeom True to check also geometry != NULL

  \return pointer to feature definition or NULL on failure (not found)
*/
VFKFeatureSQLite *VFKDataBlockSQLite::GetFeature(const char **column, GUIntBig *value, int num,
                                                 bool bGeom)
{
    VFKReaderSQLite *poReader = (VFKReaderSQLite*) m_poReader;

    CPLString osSQL;
    osSQL.Printf("SELECT %s FROM %s WHERE ", FID_COLUMN, m_pszName);

    CPLString osItem;
    for( int i = 0; i < num; i++ )
    {
        if (i > 0)
            osItem.Printf(" AND %s = " CPL_FRMT_GUIB, column[i], value[i]);
        else
            osItem.Printf("%s = " CPL_FRMT_GUIB, column[i], value[i]);
        osSQL += osItem;
    }
    if( bGeom )
    {
        osItem.Printf(" AND %s IS NOT NULL", GEOM_COLUMN);
        osSQL += osItem;
    }

    sqlite3_stmt *hStmt = poReader->PrepareStatement(osSQL.c_str());
    if (poReader->ExecuteSQL(hStmt) != OGRERR_NONE)
        return NULL;

    int idx = sqlite3_column_int(hStmt, 0) - 1; /* rowid starts at 1 */
    sqlite3_finalize(hStmt);

    if (idx < 0 || idx >= m_nFeatureCount) // ? assert
        return NULL;

    return (VFKFeatureSQLite *) GetFeatureByIndex(idx);
}
开发者ID:ryandavid,项目名称:rotobox,代码行数:45,代码来源:vfkdatablocksqlite.cpp


示例6: failure

/*!
  \brief Get feature by FID

  Modifies next feature id.

  \param nFID feature id

  \return pointer to feature definition or NULL on failure (not found)
*/
IVFKFeature *VFKDataBlockSQLite::GetFeature(GIntBig nFID)
{
    if (m_nFeatureCount < 0) {
        m_poReader->ReadDataRecords(this);
    }

    if (nFID < 1 || nFID > m_nFeatureCount)
        return NULL;

    if( m_bGeometryPerBlock && !m_bGeometry )
    {
        LoadGeometry();
    }

    VFKReaderSQLite *poReader = (VFKReaderSQLite*) m_poReader;

    CPLString osSQL;
    osSQL.Printf("SELECT rowid FROM %s WHERE %s = " CPL_FRMT_GIB,
                 m_pszName, FID_COLUMN, nFID);
    if (EQUAL(m_pszName, "SBP")) {
        osSQL += " AND PORADOVE_CISLO_BODU = 1";
    }
    sqlite3_stmt *hStmt = poReader->PrepareStatement(osSQL.c_str());

    int rowId = -1;
    if (poReader->ExecuteSQL(hStmt) == OGRERR_NONE) {
        rowId = sqlite3_column_int(hStmt, 0);
    }
    sqlite3_finalize(hStmt);

    return GetFeatureByIndex(rowId - 1);
}
开发者ID:ryandavid,项目名称:rotobox,代码行数:41,代码来源:vfkdatablocksqlite.cpp


示例7: geometry

/*!
  \brief Load geometry (point layers)

  \return number of invalid features
*/
int VFKDataBlockSQLite::LoadGeometryPoint()
{
    int   nInvalid, rowId, nGeometries;
    bool  bSkipInvalid;
    /* long iFID; */
    double x, y;

    CPLString     osSQL;
    sqlite3_stmt *hStmt;

    VFKFeatureSQLite *poFeature;
    VFKReaderSQLite  *poReader;

    nInvalid  = nGeometries = 0;
    poReader  = (VFKReaderSQLite*) m_poReader;

    if (LoadGeometryFromDB()) /* try to load geometry from DB */
	return 0;

    bSkipInvalid = EQUAL(m_pszName, "OB") || EQUAL(m_pszName, "OP") || EQUAL(m_pszName, "OBBP");
    osSQL.Printf("SELECT SOURADNICE_Y,SOURADNICE_X,%s,rowid FROM %s",
                 FID_COLUMN, m_pszName);
    hStmt = poReader->PrepareStatement(osSQL.c_str());

    if (poReader->IsSpatial())
	poReader->ExecuteSQL("BEGIN");

    while(poReader->ExecuteSQL(hStmt) == OGRERR_NONE) {
        /* read values */
        x = -1.0 * sqlite3_column_double(hStmt, 0); /* S-JTSK coordinate system expected */
        y = -1.0 * sqlite3_column_double(hStmt, 1);
#ifdef DEBUG
	const long iFID = sqlite3_column_double(hStmt, 2);
#endif
	rowId = sqlite3_column_int(hStmt, 3);

        poFeature = (VFKFeatureSQLite *) GetFeatureByIndex(rowId - 1);
        CPLAssert(NULL != poFeature && poFeature->GetFID() == iFID);

        /* create geometry */
	OGRPoint pt(x, y);
        if (!poFeature->SetGeometry(&pt)) {
            nInvalid++;
            continue;
        }

	/* store also geometry in DB */
	if (poReader->IsSpatial() &&
	    SaveGeometryToDB(&pt, rowId) != OGRERR_FAILURE)
	    nGeometries++;
    }
    
    /* update number of geometries in VFK_DB_TABLE table */
    UpdateVfkBlocks(nGeometries);

    if (poReader->IsSpatial())
	poReader->ExecuteSQL("COMMIT");
    
    return bSkipInvalid ? 0 : nInvalid;
}
开发者ID:drownedout,项目名称:datamap,代码行数:65,代码来源:vfkdatablocksqlite.cpp


示例8: id

/*!
  \brief Update feature id (see SBP)

  \param iFID feature id to set up
  \param rowId list of rows to update
*/
void VFKDataBlockSQLite::UpdateFID(GIntBig iFID, std::vector<int> rowId)
{
    CPLString osSQL, osValue;
    VFKReaderSQLite *poReader = (VFKReaderSQLite*) m_poReader;

    /* update number of geometries in VFK_DB_TABLE table */
    osSQL.Printf("UPDATE %s SET %s = " CPL_FRMT_GIB " WHERE rowid IN (",
                 m_pszName, FID_COLUMN, iFID);
    for (size_t i = 0; i < rowId.size(); i++) {
        if (i > 0)
            osValue.Printf(",%d", rowId[i]);
        else
            osValue.Printf("%d", rowId[i]);
        osSQL += osValue;
    }
    osSQL += ")";

    poReader->ExecuteSQL(osSQL.c_str());
}
开发者ID:ryandavid,项目名称:rotobox,代码行数:25,代码来源:vfkdatablocksqlite.cpp


示例9: LoadGeometryFromDB

/*!
  \brief Load geometry from DB

  \return TRUE geometry successfully loaded otherwise FALSE
*/
bool VFKDataBlockSQLite::LoadGeometryFromDB()
{
    int nInvalid, nGeometries, nGeometriesCount, nBytes, rowId;
#ifdef DEBUG
    long iFID;
#endif
    bool bSkipInvalid;

    CPLString osSQL;

    OGRGeometry      *poGeometry;

    VFKFeatureSQLite *poFeature;
    VFKReaderSQLite  *poReader;

    sqlite3_stmt *hStmt;

    poReader = (VFKReaderSQLite*) m_poReader;

    if (!poReader->IsSpatial())   /* check if DB is spatial */
	return FALSE;

    osSQL.Printf("SELECT num_geometries FROM %s WHERE table_name = '%s'",
		 VFK_DB_TABLE, m_pszName);
    hStmt = poReader->PrepareStatement(osSQL.c_str());
    if (poReader->ExecuteSQL(hStmt) != OGRERR_NONE)
        return FALSE;
    nGeometries = sqlite3_column_int(hStmt, 0);
    sqlite3_finalize(hStmt);
    
    if (nGeometries < 1)
	return FALSE;
    
    bSkipInvalid = EQUAL(m_pszName, "OB") || EQUAL(m_pszName, "OP") || EQUAL(m_pszName, "OBBP");

    /* load geometry from DB */
    nInvalid = nGeometriesCount = 0;
    osSQL.Printf("SELECT %s,rowid,%s FROM %s ",
		 GEOM_COLUMN, FID_COLUMN, m_pszName);
    if (EQUAL(m_pszName, "SBP"))
	osSQL += "WHERE PORADOVE_CISLO_BODU = 1 ";
    osSQL += "ORDER BY ";
    osSQL += FID_COLUMN;
    hStmt = poReader->PrepareStatement(osSQL.c_str());

    rowId = 0;
    while(poReader->ExecuteSQL(hStmt) == OGRERR_NONE) {
        rowId++; // =sqlite3_column_int(hStmt, 1);
#ifdef DEBUG
        iFID =
#endif
            sqlite3_column_double(hStmt, 2);

        poFeature = (VFKFeatureSQLite *) GetFeatureByIndex(rowId - 1);
        CPLAssert(NULL != poFeature && poFeature->GetFID() == iFID);

        // read geometry from DB
	nBytes = sqlite3_column_bytes(hStmt, 0);
	if (nBytes > 0 &&
	    OGRGeometryFactory::createFromWkb((GByte*) sqlite3_column_blob(hStmt, 0),
					      NULL, &poGeometry, nBytes) == OGRERR_NONE) {
	    nGeometriesCount++;
	    if (!poFeature->SetGeometry(poGeometry)) {
		nInvalid++;
	    }
	    delete poGeometry;
	}
	else {
	    nInvalid++;
	}
    }

    CPLDebug("OGR-VFK", "%s: %d geometries loaded from DB",
	     m_pszName, nGeometriesCount);

    if (nGeometriesCount != nGeometries) {
	CPLError(CE_Warning, CPLE_AppDefined, 
                 "%s: %d geometries loaded (should be %d)",
		 m_pszName, nGeometriesCount, nGeometries);
    }

    if (nInvalid > 0 && !bSkipInvalid) {
	CPLError(CE_Warning, CPLE_AppDefined, 
                 "%s: %d features with invalid or empty geometry",
		 m_pszName, nInvalid);
    }

    return TRUE;
}
开发者ID:drownedout,项目名称:datamap,代码行数:94,代码来源:vfkdatablocksqlite.cpp


示例10: SetGeometryLineString

/*!
  \brief Set geometry for linestrings

  \param poLine VFK feature
  \param oOGRLine line geometry
  \param[in,out] bValid TRUE when feature's geometry is valid
  \param[in,out] rowIdFeat list of row ids which forms linestring
  \param[in,out] nGeometries number of features with valid geometry
*/
bool VFKDataBlockSQLite::SetGeometryLineString(VFKFeatureSQLite *poLine, OGRLineString *oOGRLine,
                                               bool& bValid, const char *ftype,
                                               std::vector<int>& rowIdFeat, int& nGeometries)
{
    int              npoints;
    VFKReaderSQLite *poReader;

    poReader  = (VFKReaderSQLite*) m_poReader;

    oOGRLine->setCoordinateDimension(2); /* force 2D */

    /* check also VFK validity */
    if (bValid) {
        /* Feature types
           
           - '3'    - line       (2 points)
           - '4'    - linestring (at least 2 points)
           - '11'   - curve      (at least 2 points)
           - '15'   - circle     (3 points)
           - '15 r' - circle     (center point & radius)
           - '16'   - arc        (3 points)
        */

        npoints = oOGRLine->getNumPoints();
        if (EQUAL(ftype, "3") && npoints > 2) {
            /* be less pedantic, just inform user about data
             * inconsistency

               bValid = FALSE;
            */
            CPLDebug("OGR-VFK", 
                     "Line (fid=" CPL_FRMT_GIB ") defined by more than two vertices",
                     poLine->GetFID());
        }
        else if (EQUAL(ftype, "11") && npoints < 2) { 
            bValid = FALSE;
            CPLError(CE_Warning, CPLE_AppDefined, 
                     "Curve (fid=" CPL_FRMT_GIB ") defined by less than two vertices",
                     poLine->GetFID());
        }
        else if (EQUAL(ftype, "15") && npoints != 3) {
            bValid = FALSE;
            CPLError(CE_Warning, CPLE_AppDefined, 
                     "Circle (fid=" CPL_FRMT_GIB ") defined by invalid number of vertices (%d)",
                     poLine->GetFID(), oOGRLine->getNumPoints());
        }
        else if (strlen(ftype) > 2 && EQUALN(ftype, "15", 2) && npoints != 1) {
            bValid = FALSE;
            CPLError(CE_Warning, CPLE_AppDefined, 
                     "Circle (fid=" CPL_FRMT_GIB ") defined by invalid number of vertices (%d)",
                     poLine->GetFID(), oOGRLine->getNumPoints());
        }
        else if (EQUAL(ftype, "16") && npoints != 3) {
            bValid = FALSE;
            CPLError(CE_Warning, CPLE_AppDefined, 
                     "Arc (fid=" CPL_FRMT_GIB ") defined by invalid number of vertices (%d)",
                     poLine->GetFID(), oOGRLine->getNumPoints());
        }
    }

    /* set geometry (NULL for invalid features) */
    if (bValid) {
        if (!poLine->SetGeometry(oOGRLine, ftype)) {
            bValid = FALSE;
        }
    }
    else {
        poLine->SetGeometry(NULL);
    }
    
    /* update fid column */
    UpdateFID(poLine->GetFID(), rowIdFeat);        
    
    /* store also geometry in DB */
    CPLAssert(0 != rowIdFeat.size());
    if (bValid && poReader->IsSpatial() &&
        SaveGeometryToDB(bValid ? poLine->GetGeometry() : NULL,
                         rowIdFeat[0]) != OGRERR_FAILURE)
        nGeometries++;

    rowIdFeat.clear();
    oOGRLine->empty(); /* restore line */

    return bValid;
}
开发者ID:drownedout,项目名称:datamap,代码行数:94,代码来源:vfkdatablocksqlite.cpp



注:本文中的VFKReaderSQLite类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ VFSNode类代码示例发布时间:2022-05-31
下一篇:
C++ VECTOR3类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap