ArcSDE Java SDK obtains the number of elements of the element class FeatureCount

Source: Internet
Author: User

Some users have long reported that the ArcSDE SDK does not directly obtain the number of element elements. Users can only obtain the total number of elements through the basic query loop, because the development of SDE has not been viewed, I didn't care too much about it. I checked the help today, but there are still many ways to get this FeatureCount.
However, I write functions based on version data and non-version data, and the acquisition of version data is certainly common.
Related Environment:
ArcSDE SDK 10
Java SDK
Note: One element class name in my SDE is "conn"
For non-version data queries, you can directly use SQL statements to obtain them, which is very convenient.
[Python]
Public static void queryLayerFeatureCount (){
Try {
SeConnection conn = getConn ();
SeQuery query = new SeQuery (conn );
// Use the SQL statement directly. This condition is applicable only to non-arcsde versions.
String SQL = "select count (objectid) from conn ";
Query. prepareSql (SQL );
Query.exe cute ();
 
SeRow row = query. fetch ();
While (row! = Null)
{
System. out. println ("------ featureclass feature count -----------------");
System. out. println (row. getObject (0). toString ());
System. out. println ("--------------------------------------------------");
Row = query. fetch ();
}

} Catch (Exception ex ){
Ex. printStackTrace ();
}
}

However, if you use version editing, the above function will certainly not work, but I find that the statistics of a table can obtain RowCount.
[Python]
Public static void queryLayerVersionedFeatureCount ()
{
Try {
SeConnection conn = getConn ();
SeTable table = new SeTable (conn, "conn ");
SeColumnDefinition [] tableDef = table. describe ();
String [] cols = new String [tableDef. length];
For (int j = 0; j <cols. length; j ++)
{
Cols [j] = tableDef [j]. getName ();
}
SeSqlConstruct sqlCons = new SeSqlConstruct ("conn ");
SeQuery query = new SeQuery (conn, cols, sqlCons );

 
SeQueryInfo queryInfo = new SeQueryInfo ();
QueryInfo. setQueryType (SeQueryInfo. SE_QUERYTYPE_ATTRIBUTE_FIRST );
QueryInfo. setColumns (cols );
QueryInfo. setConstruct (sqlCons );

// Query. prepareQueryInfo (queryInfo );
// Query.exe cute ();

SeTable. SeTableStats stats = query. calculateTableStatistics ("*", SeTable. SeTableStats. SE_COUNT_STATS, queryInfo, 0 );
Int count = stats. getCount ();
System. out. println ("------ featureclass feature count -----------------");
System. out. println (count );
System. out. println ("--------------------------------------------------");



} Catch (Exception ex ){
Ex. printStackTrace ();
}
}
Do you see the annotated two lines of code? If added, the following error will be reported:
[Python]
ArcSDE Error Number:-52
Error Description: SHAPE/fid stream not finished, CAN't EXECUTE.
Extended Error Description:
It took me a lot of time.
Now, with the above example, you don't have to calculate the total number of elements in the element class by repeating the accumulative count of the element class.

The following code runs normally. You only need to modify the relevant parameters and send all the examples
[Python]
Package lish. test;
Import com. esri. sde. sdk. client .*;
Public class test {

Private static SeConnection conn = null;
 
Private static String server = "192.168.205.142 ";
Private static String instance = "5353 ";
Private static String database = "";
Private static String username = "sde ";
Private static String password = "sde ";
 
Private static SeConnection getConn (){
If (conn = null ){
Try {
Conn = new SeConnection (server, instance, database, username,
Password );
} Catch (SeException ex ){
Ex. printStackTrace ();
}

}

Return conn;
}
 
/**
* @ Param args
*/
Public static void main (String [] args ){

QueryLayerVersionedFeatureCount ();
}
Public static void queryLayerVersionedFeatureCount ()
{
Try {
SeConnection conn = getConn ();
SeTable table = new SeTable (conn, "conn ");
SeColumnDefinition [] tableDef = table. describe ();
String [] cols = new String [tableDef. length];
For (int j = 0; j <cols. length; j ++)
{
Cols [j] = tableDef [j]. getName ();
}
SeSqlConstruct sqlCons = new SeSqlConstruct ("conn ");
SeQuery query = new SeQuery (conn, cols, sqlCons );

 
SeQueryInfo queryInfo = new SeQueryInfo ();
QueryInfo. setQueryType (SeQueryInfo. SE_QUERYTYPE_ATTRIBUTE_FIRST );
QueryInfo. setColumns (cols );
QueryInfo. setConstruct (sqlCons );

// Query. prepareQueryInfo (queryInfo );
// Query.exe cute ();

SeTable. SeTableStats stats = query. calculateTableStatistics ("*", SeTable. SeTableStats. SE_COUNT_STATS, queryInfo, 0 );
Int count = stats. getCount ();
System. out. println ("------ featureclass feature count -----------------");
System. out. println (count );
System. out. println ("--------------------------------------------------");



} Catch (Exception ex ){
Ex. printStackTrace ();
}
}
Public static void queryLayerFeatureCount (){
Try {
SeConnection conn = getConn ();
SeQuery query = new SeQuery (conn );
// Use the SQL statement directly. This condition is applicable only to non-arcsde versions.
String SQL = "select count (objectid) from con ";
Query. prepareSql (SQL );
Query.exe cute ();
 
SeRow row = query. fetch ();
While (row! = Null)
{
System. out. println ("------ featureclass feature count -----------------");
System. out. println (row. getObject (0). toString ());
System. out. println ("--------------------------------------------------");
Row = query. fetch ();
}

} Catch (Exception ex ){
Ex. printStackTrace ();
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.