阅读:1414回复:0
ArcSDE C-API 开发:读取属性数据
<P>完整代码:</P>
<P >SE_CONNECTION Connection;</P> <P >SE_STREAM Stream;</P> <P >SE_SQL_CONSTRUCT *sqlc</P> <P >SE_ERROR Connect_error;</P> <P >LONG rc, population;</P> <P >SHORT num_cols;</P> <P >LFLOAT area;</P> <P >CHAR *server, *instance, *database, *user, *passwd;</P> <P >CHAR **attrs, *name;</P> <P > </P> <P >/* Connect to ArcSDE */</P> <P >rc = <a href="mk:@MSITStore:E:\应用软件\ArcSDE8.3\SDEHelp.chm::/CAPI_functions/functions/SE_connection_create.htm" target="_blank" >SE_connection_create</A></P> <P >(server, instance, database, user, passwd, ;Connect_error,<BR> ;Connection);</P> <P >/* See Error handling section for check_error function code. */</P> <P >check_error(Connection, NULL, rc, "SE_connection_create");</P> <P > </P> <P >/* Create a stream for the query */</P> <P >rc = <a href="mk:@MSITStore:E:\应用软件\ArcSDE8.3\SDEHelp.chm::/CAPI_functions/functions/SE_stream_create.htm" target="_blank" >SE_stream_create</A> (Connection, ;Stream);</P> <P >check_error(Connection, NULL, rc, "SE_stream_create");</P> <P > </P> <P >/* Allocate an SE_SQL_CONSTRUCT */</P> <P >rc = <a href="mk:@MSITStore:E:\应用软件\ArcSDE8.3\SDEHelp.chm::/CAPI_functions/functions/SE_sql_construct_alloc.htm" target="_blank" >SE_sql_construct_alloc</A> (1, ;sqlc);</P> <P >check_error(Connection, NULL, rc, "SE_sql_construct_alloc");</P> <P > </P> <P >/* Fill in the details of the SQL query */</P> <P >sqlc->where = malloc(20);</P> <P >sqlc->num_tables = 1;</P> <P >strcpy (sqlc->tables[0], "cities");</P> <P >strcpy (sqlc->where, "population < 10000");</P> <P > </P> <P >/* Define the number and names of the table columns to be returned */</P> <P >num_cols = 3;</P> <P >attrs = (CHAR **) malloc (num_cols * sizeof(CHAR *));</P> <P >attrs[0] = "city_name";</P> <P >attrs[1] = "area";</P> <P >attrs[2] = "population";</P> <P > </P> <P >/* Define the stream query */</P> <P >rc = <a href="mk:@MSITStore:E:\应用软件\ArcSDE8.3\SDEHelp.chm::/CAPI_functions/functions/SE_stream_query.htm" target="_blank" >SE_stream_query</A> (Stream, num_cols, attrs, sqlc);</P> <P >check_error(NULL, Stream, rc, "SE_stream_query");</P> <P > </P> <P >rc = <a href="mk:@MSITStore:E:\应用软件\ArcSDE8.3\SDEHelp.chm::/CAPI_functions/functions/SE_stream_execute.htm" target="_blank" >SE_stream_execute</A> (Stream);</P> <P >/* Iterate over the results */</P> <P >while (rc == SE_SUCCESS)</P> <P >{</P> <P > rc = <a href="mk:@MSITStore:E:\应用软件\ArcSDE8.3\SDEHelp.chm::/CAPI_functions/functions/SE_stream_fetch.htm" target="_blank" >SE_stream_fetch</A> (Stream);</P> <P > if (rc == SE_SUCCESS)</P> <P > {</P> <P > rc = SE_stream_get_string (Stream,1,name);</P> <P > check_error(NULL, Stream, rc, "SE_stream_get_string");</P> <P > </P> <P > rc = <a href="mk:@MSITStore:E:\应用软件\ArcSDE8.3\SDEHelp.chm::/CAPI_functions/functions/SE_stream_get_double.htm" target="_blank" >SE_stream_get_double</A> (Stream,2,;area);</P> <P > check_error(NULL, Stream, rc, "SE_stream_get_double");</P> <P > </P> <P > rc = <a href="mk:@MSITStore:E:\应用软件\ArcSDE8.3\SDEHelp.chm::/CAPI_functions/functions/SE_stream_get_double.htm" target="_blank" >SE_stream_get_integer</A> (Stream,3,;population);</P> <P > check_error(NULL, Stream, rc, "SE_stream_get_integer");</P> <P > </P> <P > /* Now do something with the name, area and population */</P> <P > }</P> <P >}</P> <P > </P> <P >/* Release the stream when it is no longer needed */</P> <P >rc = <a href="mk:@MSITStore:E:\应用软件\ArcSDE8.3\SDEHelp.chm::/CAPI_functions/functions/SE_stream_free.htm" target="_blank" >SE_stream_free</A> (Stream);</P> <P >free (attrs);</P> <P >free (sqlc->where);</P> <P ><a href="mk:@MSITStore:E:\应用软件\ArcSDE8.3\SDEHelp.chm::/CAPI_functions/functions/SE_sql_construct_free.htm" target="_blank" ><!--kadov_tag{{<spaces>}}--> <!--kadov_tag{{</spaces>}}-->SE_sql_construct_free</A> (sqlc);</P> <P > </P> <P >/* Disconnect from ArcSDE */</P> <P ><a href="mk:@MSITStore:E:\应用软件\ArcSDE8.3\SDEHelp.chm::/CAPI_functions/functions/SE_connection_free.htm" target="_blank" ><!--kadov_tag{{<spaces>}}--> <!--kadov_tag{{</spaces>}}-->SE_connection_free</A> (Connection);</P> |
|
|