FileGDB API for linux 学习之七,数据的查询
2011-03-04 16:27
405 查看
FileGDB API Table类的Search函数支持简单的SELECT查询语句,其包含两种定义方式,分别是:
这个函数可以通过范围和属性两种方法进行过滤。
第二种定义方式:
Query例子提供了这两个函数的使用,大家可以参考一下这个例子。
Query例子程序使用的数据为一个点层数据,下面的例子是我自己写的,来访问面和线数据。由于FileGDB提供的函数提供给我们的是各种geometry对象的二进制buffer,并没有提供具体的对象,因此我们需要自己写程序将这些二进制buffer解析成点串坐标。
下面是显示多边形和线点串坐标的一段程序:
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }运行结果如下:
第一种定义方式为: long FileGDBAPI::Table::Search ( const std::wstring & subfields, const std::wstring & whereClause, Envelope envelope, bool recycling, EnumRows & rows ) Performs a spatial query (envelope intersects) on the table. Parameters: [in] subfields (Optional) The fields that should be fetched by the query's returned rows. Must include a comma delimited list of fields or a "*". Passing in blank will return a -2147220985 (INVALID_SQL) error. [in] whereClause (Optional) Attribute constraints to apply to the query. [in] envelope The spatial extent of the query. [in] recycling Indicates whether row memory should be recycled. [out] rows The results of the query. Returns: A long integer indicating whether the method finished successfully.
这个函数可以通过范围和属性两种方法进行过滤。
第二种定义方式:
long FileGDBAPI::Table::Search ( const std::wstring & subfields, const std::wstring & whereClause, bool recycling, EnumRows & rows ) Performs an attribute query on the table. Parameters: [in] subfields (Optional) The fields that should be fetched by the query's returned rows. Must include a comma delimited list of fields or a "*". A blank will return a -2147220985 (INVALID_SQL) error. [in] whereClause (Optional) Attribute constraints to apply to the query. [in] recycling Indicates whether row memory should be recycled. [out] rows The results of the query. Returns: A long integer indicating whether the method finished successfully.
这种方法不支持范围查询,只支持where字句查询。
需要注意的是:
如果过滤的时候不用where字句进行过滤,那么whereclause参数需要设置成L””,而不是L” “. 否则构建出来的SQL语句是错误的。
Query例子提供了这两个函数的使用,大家可以参考一下这个例子。
Query例子程序使用的数据为一个点层数据,下面的例子是我自己写的,来访问面和线数据。由于FileGDB提供的函数提供给我们的是各种geometry对象的二进制buffer,并没有提供具体的对象,因此我们需要自己写程序将这些二进制buffer解析成点串坐标。
下面是显示多边形和线点串坐标的一段程序:
#include <stdio.h> #include <tchar.h> #include <string> #include <iostream> #include <vector> #include <map> #include <atlbase.h> #define EXT_FILEGDB_API _declspec(dllimport) #pragma warning (disable : 4251) #include "Geodatabase.h" #include "GeodatabaseManagement.h" #include "Table.h" #include "Row.h" #include "Util.h" #include "commonlib.h" using namespace std; using namespace FileGDBAPI; Geodatabase geodatabase; int main() { // Create a new geodatabase in the current directory. long hr; // Re-open the geodatabase. if ((hr = OpenGeodatabase(L"../data/TestFileGDB.gdb", geodatabase)) != S_OK) { cout << "An error occurred while opening the geodatabase." << endl; cout << "Error code: " << hr << endl; return -1; } cout << "The geodatabase has been opened." << endl; Table table; if((hr = geodatabase.OpenTable(L"//Drainage//Catchment",table)) != S_OK) { cout << "An error occurred while open the table." << endl; cout << "Error code: " << hr <<endl; return -1; } EnumRows QueryRows; hr = table.Search(L"Shape",L"",true,QueryRows); //if ((hr = table.Search(L"Shape, NAME, Pop1996", L"TERM = 'City'", true, QueryRows)) != S_OK) if(S_OK != hr) { cout << "An error occurred while Searching the table." << endl; cout << "Error code: " << hr <<endl; return -1; } Row QueryRow; ShapeBuffer geometry; int i = 0; while(QueryRows.Next(QueryRow) == S_OK) { QueryRow.GetGeometry(geometry); GeometryObj* pGeometryObj = getgeometry(geometry.shapeBuffer); if(pGeometryObj) { for (i = 0; i < pGeometryObj->nVertixCount; i++) { cout << "{x= " << pGeometryObj->pfXY[i].x <<"y= "<<pGeometryObj->pfXY[i].y << " }"<< endl; }
releasegeometry(pGeometryObj); } } QueryRows.Close(); if((hr = geodatabase.CloseTable(table)) != S_OK) { cout << "An error occurred while closing the table." << endl; cout << "Error code: " << hr << endl; return -1; } if ((hr = CloseGeodatabase(geodatabase)) != S_OK) { cout << "An error occurred while closing the geodatabase." << endl; cout << "Error code: " << hr << endl; return -1; } return 0; }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }运行结果如下:
相关文章推荐
- FileGDB API for linux学习之八,空间数据解析库
- FileGDB API for linux 学习系列之四,XML Schema of Geodatabase
- FileGDB API for linux学习系列之三,检索目录树
- FileGDB API for linux 学习系列之二,编译Display例子程序
- FileGDB API for linux 学习系列之六,对象的创建
- FileGDB API for linux 学习系列之一,编译例子程序
- ArcGIS API for JavaScript 4.2学习笔记[23] 没有地图如何进行查询?【FindTask类的使用】
- ArcGIS API for JavaScript 4.2学习笔记[20] 使用缓冲区结合Query对象进行地震点查询【重温异步操作思想】
- ArcGIS API for iOS开发教程(五)数据查询
- ArcGIS API for JavaScript 4.2学习笔记[17] 官方第七章Searching(空间查询)概览与解释
- ArcGIS API For Flex(查询数据)
- ArcGIS API for JavaScript 4.2学习笔记[30] 点和线高程查询(第八章完结)
- ArcGIS API for JavaScript 4.2学习笔记[21] 对3D场景上的3D要素进行点击查询【Query类学习】
- ArcGIS api for javascript——查询没有地图的数据
- ArcGIS API for JavaScript 4.2学习笔记[25] 官方第八章Analysis(空间查询)概览与解释
- ArcGIS API for JavaScript 4.2学习笔记[9] 同一种视图不同数据(Map)同步
- ArcGIS API for JavaScript 4.2学习笔记[22] 使用【QueryTask类】进行空间查询 / 弹窗样式
- SQLServer\framework启动报异常:Module的类型初始值设定项引发异常 [转]QQ空间、新浪微博、腾讯微博等一键分享API链接代码 window下 mongodb快速安装 数据表查询所有子/父节点 C#学习笔记1
- Linux基础学习--查询数据man 后面的数字意义(1)
- arcgis api for javascript(一)使用自定义数据对FeatureLayer进行渲染