@@ -84,7 +84,7 @@ def deletable(self):
8484 """Return whether dataset can be deleted."""
8585 return self .__deletable
8686
87- def index (self , bbox , client_srid , filterexpr , filter_geom ):
87+ def index (self , bbox , client_srid , filterexpr , filter_geom , filter_fields ):
8888 """Find features inside bounding box.
8989
9090 :param list[float] bbox: Bounding box as [<minx>,<miny>,<maxx>,<maxy>]
@@ -93,11 +93,16 @@ def index(self, bbox, client_srid, filterexpr, filter_geom):
9393 :param (sql, params) filterexpr: A filter expression as a tuple
9494 (sql_expr, bind_params)
9595 :param str filter_geom: JSON serialized GeoJSON geometry
96+ :param list[string] filter_fields: Field names to return
9697 """
9798 srid = client_srid or self .srid
9899
99100 own_attributes , join_attributes = self .__extract_join_attributes ()
100101
102+ if filter_fields :
103+ own_attributes = [attr for attr in own_attributes if attr in filter_fields or attr == self .primary_key ]
104+ join_attributes = [attr for attr in join_attributes if attr in filter_fields ]
105+
101106 # build query SQL
102107
103108 # select id and permitted attributes
@@ -146,13 +151,15 @@ def index(self, bbox, client_srid, filterexpr, filter_geom):
146151 if where_clauses :
147152 where_clause = "WHERE (" + ") AND (" .join (where_clauses ) + ")"
148153
149- geom_sql = self .geom_column_sql (srid , with_bbox = False )
150- if self .geometry_column :
151- # select overall extent
152- geom_sql += (
153- ', ST_Extent(%s) OVER () AS _overall_bbox_' %
154- self .transform_geom_sql ('"{geom}"' , self .srid , srid )
155- )
154+ geom_sql = ""
155+ if not filter_fields or "geometry" in filter_fields :
156+ geom_sql = self .geom_column_sql (srid , with_bbox = False )
157+ if self .geometry_column :
158+ # select overall extent
159+ geom_sql += (
160+ ', ST_Extent(%s) OVER () AS _overall_bbox_' %
161+ self .transform_geom_sql ('"{geom}"' , self .srid , srid )
162+ )
156163
157164 sql = sql_text (("""
158165 SELECT {columns}%s
@@ -179,7 +186,7 @@ def index(self, bbox, client_srid, filterexpr, filter_geom):
179186 join_attribute_values = self .__query_join_attributes (join_attributes , attribute_values )
180187 attribute_values .update (join_attribute_values )
181188
182- features .append (self .feature_from_query (attribute_values , srid ))
189+ features .append (self .feature_from_query (attribute_values , srid , filter_fields ))
183190 if '_overall_bbox_' in row :
184191 overall_bbox = row ['_overall_bbox_' ]
185192
@@ -1060,14 +1067,16 @@ def transform_geom_sql(self, geom_sql, geom_srid, target_srid):
10601067
10611068 return geom_sql
10621069
1063- def feature_from_query (self , row , client_srid ):
1070+ def feature_from_query (self , row , client_srid , filter_fields = None ):
10641071 """Build GeoJSON Feature from query result row.
10651072
10661073 :param obj row: Row result from query
10671074 :param int client_srid: Client SRID or None for dataset SRID
10681075 """
10691076 props = OrderedDict ()
10701077 for attr in self .attributes :
1078+ if filter_fields and not attr in filter_fields :
1079+ continue
10711080 # Omit hidden fields
10721081 if self .fields .get (attr , {}).get ('constraints' , {}).get ('hidden' , False ) == True :
10731082 continue
@@ -1085,7 +1094,7 @@ def feature_from_query(self, row, client_srid):
10851094 geometry = None
10861095 crs = None
10871096 bbox = None
1088- if self .geometry_column :
1097+ if self .geometry_column and ( not filter_fields or "geometry" in filter_fields ) :
10891098 if row ['json_geom' ] is not None :
10901099 geometry = json .loads (row ['json_geom' ])
10911100 else :
0 commit comments