public static QueryResult featureCollection2QueryResult ( SimpleFeatureCollection featureCollection ) { List < AttributeDescriptor > attributeDescriptors = featureCollection . getSchema ( ) . getAttributeDescriptors ( ) ; QueryResult queryResult = new QueryResult ( ) ; int count = 0 ; for ( AttributeDescriptor attributeDescriptor : attributeDescriptors ) { if ( ! ( attributeDescriptor instanceof GeometryDescriptor ) ) { String fieldName = attributeDescriptor . getLocalName ( ) ; String type = attributeDescriptor . getType ( ) . getBinding ( ) . toString ( ) ; queryResult . names . add ( fieldName ) ; queryResult . types . add ( type ) ; count ++ ; } } SimpleFeatureIterator featureIterator = featureCollection . features ( ) ; while ( featureIterator . hasNext ( ) ) { SimpleFeature f = featureIterator . next ( ) ; Geometry geometry = ( Geometry ) f . getDefaultGeometry ( ) ; queryResult . geometries . add ( geometry ) ; Object [ ] dataRow = new Object [ count ] ; int index = 0 ; for ( AttributeDescriptor attributeDescriptor : attributeDescriptors ) { if ( ! ( attributeDescriptor instanceof GeometryDescriptor ) ) { String fieldName = attributeDescriptor . getLocalName ( ) ; Object attribute = f . getAttribute ( fieldName ) ; if ( attribute == null ) { attribute = "" ; } dataRow [ index ++ ] = attribute ; } } queryResult . data . add ( dataRow ) ; } return queryResult ; }
Utility to convert a featurecollection to a queryresult format .