FileGDB API for linux 学习之七,数据的查询
分享
FileGDB API Table类的Search函数支持简单的SELECT查询语句,其包含两种定义方式,分别是:
第一种定义方式为:
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.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;
}
运行结果如下:
文章来源:http://blog.csdn.net/liufeng1980423/article/details/6223741[/i]
第一种定义方式为:
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.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;
}
运行结果如下:
文章来源:http://blog.csdn.net/liufeng1980423/article/details/6223741[/i]
0 个评论
推荐内容
相关问题
- 作为Desktop用户对数据的获取比较乏力,可能缺了哪些知识?
- 有谁知道哪里可以免费获取各省市地图数据呢,包括详细的shape文件数据
- 有栅格数据a(大数据),小数据b,怎么从a中扣掉b,得到a数据剩下的部分?栅格能裁剪取反吗?
- 在windows server2008 R2 64位中安装了portal 10.5 设置好托管arcgis server站点,并用data store为托管数据库,发布数据出错
- cityengine怎么导入arcgis的shp数据,对shp数据有什么要求
- ArcGIS数据库数据逐图幅裁剪
- ArcGis打开图层后显示unknown units,想要define一个投影坐标系,但数据大小似乎不一致
- 基于ArcGIS的CAD数据向GIS数据转换方法
- 如何统计shp点数据落在栅格不同区间的个数?
- 镶嵌数据集 Add Rasters
- Linux下如何将ArcGIS Server的服务端口改为80