Wechat: yu389741| Email: gisdqy@163.com

Shop:https://www.giserdqy.com/shop

GeoTools&ArcSDE JDK


使用GeoTools查询ArcSDE数据.


public List<Map<String,Object>> queryByWhere(final String where,SeLayer sdeLyr,ISession sdeSession)
{
try
{
final String lyrName = sdeLyr.getName();
final String geoColName = sdeLyr.getSpatialColumn();

SeTable table = sdeSession.getTable(lyrName);
SeColumnDefinition[] tableDef = sdeSession.describe(table);
final String[] cols1 = new String[tableDef.length];
for (int i = 0; i < tableDef.length; i++)
{
cols[i] = tableDef[i].getName();
}
final String[] cols =cols1;
final Command<List<Map<String,Object>>> queryCmd = new Command<List<Map<String,Object>>>() {
@Override
public List<Map<String,Object>> execute(ISession session, SeConnection connection) throws SeException,IOException {
ArrayList<Map<String, Object>> results = new java.util.ArrayList<Map<String,Object>>();
SeSqlConstruct sqlCons = new SeSqlConstruct(lyrName);//构建空间查询表达式
final SeQuery query = new SeQuery(connection, cols, sqlCons);
query.prepareQuery();
query.execute();
SeRow row = query.fetch();//使用Session对象根据查询的结果获取查询的每一条记录
while(row!=null)//循环处理每一行查询出来的数据
{
Map<String,Object> result = new java.util.HashMap<String,Object>();
for(int i=0;i<cols.length;i++)
{
if(geoColName.compareToIgnoreCase(cols[i])==0)
{
try {
SeShape seShape = (SeShape)row.getShape(i).clone();
result.put(geoColName, seShape);
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
}
else
{
Object obj = row.getObject(i);
result.put(cols[i], obj);
}
}
results.add(result);
row = query.fetch();
}
return results;
}
};
return sdeSession.issue(queryCmd);
}
catch(Exception ex)
{
ex.printStackTrace();
logger.log(Level.ERROR, ex);
}
return new java.util.ArrayList<Map<String,Object>>();
}

转载自:https://blog.csdn.net/vgsgis/article/details/83531013