ArcSDE C-API 开发:读取属性数据

来源:互联网 发布:怎么设置淘宝店铺基础 编辑:程序博客网 时间:2024/05/14 03:47

很难得看到的Arcsde C API的sample,连官方网站上都是提供的java的,特此收录,转自http://www.gispower.org/article/arcgis/ao/2007/1113/0711132158575H3JBA9K9D4202D084ED.htm

 

 

SE_CONNECTION Connection;

SE_STREAM Stream;

SE_SQL_CONSTRUCT *sqlc

SE_ERROR Connect_error;

LONG rc, population;

SHORT num_cols;

LFLOAT area;

CHAR *server, *instance, *database, *user, *passwd;

CHAR **attrs, *name;

 

/* Connect to ArcSDE */

rc = SE_connection_create

(server, instance, database, user, passwd, &Connect_error, &Connection);

/* See Error handling section for check_error function code. */

check_error(Connection, NULL, rc, "SE_connection_create");

 

/* Create a stream for the query */

rc = SE_stream_create (Connection, &Stream);

check_error(Connection, NULL, rc, "SE_stream_create");

 

/* Allocate an SE_SQL_CONSTRUCT */

rc = SE_sql_construct_alloc (1, &sqlc);

check_error(Connection, NULL, rc, "SE_sql_construct_alloc");

 

/* Fill in the details of the SQL query */

sqlc->where = malloc(20);

sqlc->num_tables = 1;

strcpy (sqlc->tables[0], "cities");

strcpy (sqlc->where, "population < 10000");

 

/* Define the number and names of the table columns to be returned */

num_cols = 3;

attrs = (CHAR **) malloc (num_cols * sizeof(CHAR *));

attrs[0] = "city_name";

attrs[1] = "area";

attrs[2] = "population";

 

/* Define the stream query */

rc = SE_stream_query (Stream, num_cols, attrs, sqlc);

check_error(NULL, Stream, rc, "SE_stream_query");

 

rc = SE_stream_execute (Stream);

/* Iterate over the results */

while (rc == SE_SUCCESS)

{

rc = SE_stream_fetch (Stream);

if (rc == SE_SUCCESS)

{

rc = SE_stream_get_string (Stream,1,name);

check_error(NULL, Stream, rc, "SE_stream_get_string");

 

rc = SE_stream_get_double (Stream,2,&area);

check_error(NULL, Stream, rc, "SE_stream_get_double");

 

rc = SE_stream_get_integer (Stream,3,&population);

check_error(NULL, Stream, rc, "SE_stream_get_integer");

 

/* Now do something with the name, area and population */

}

}

 

/* Release the stream when it is no longer needed */

rc = SE_stream_free (Stream);

free (attrs);

free (sqlc->where);

undefined undefined undefined undefinedSE_sql_construct_free (sqlc);

 

/* Disconnect from ArcSDE */

undefined undefined undefined undefinedSE_connection_free (Connection);