class="java" name="code">public void sdeTest(String cqlPredicate,String refGeo){ Map map = new HashMap(); map.put( "dbtype", "arcsde" ); map.put( "server", "127.0.0.1" ); map.put( "port", "5151" ); map.put( "instance", "sde" ); map.put( "user", "test" ); map.put( "password", "test" ); DataStore dataStore = null; try { dataStore = DataStoreFinder.getDataStore(map); String typeName = "TEST_PG"; SimpleFeatureType schema = dataStore.getSchema(typeName); String geometryAttributeName = schema.getGeometryDescriptor() .getLocalName(); FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints()); List<Filter> match = new ArrayList<Filter>(); if(cqlPredicate!=null){//属性查询条件 like a='1' and b='2' Filter filter1 = CQL.toFilter(cqlPredicate); match.add(filter1); } if(refGeo!=null){//空间查询条件 refGeo 是标准的WKT字符串 Filter filter2 = ff.contains(ff.property(geometryAttributeName), ff .literal(refGeo)); match.add(filter2); } Transaction transaction = new DefaultTransaction(); Filter filter = ff.and(match);//属性空间联合查询 Query query = new Query(typeName, filter); // query.setStartIndex(new Integer(4)); // query.setMaxFeatures(2); SortBy[] sortBy = new SortBy[1]; //sortBy[0] = ff.sort("NAME", SortOrder.DESCENDING ); sortBy[0] = ff.sort("ZZJGDM", SortOrder.ASCENDING ); query.setSortBy(sortBy); FeatureReader reader = dataStore.getFeatureReader(query, transaction); while (reader.hasNext()) { Feature feature = reader.next(); Iterator iterator = feature.getProperties().iterator(); while (iterator.hasNext()) { Property property = (Property) iterator.next(); // if(!property.getName().getLocalPart().equalsIgnoreCase(geometryAttributeName)) System.out.print(property.getName() + "=" + property.getValue()+"\t"); String colName = property.getName().getLocalPart(); } System.out.println(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (CQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ if(dataStore!=null) dataStore.dispose(); } }