== Query Features with a filter == This page describes how to use the MaestroAPI from the [wiki:maestro MapGuide Maestro] project in your own application. This sample shows how to read geometry features from a !FeatureSource using MaestroAPI. (C#) {{{ #!text/x-csharp using OSGeo.MapGuide.MaestroAPI; ... //Read the setup, either from QueryString, Form, Cookies or hardcoded values string username = Request.Params("USERNAME") == null ? "Anonymous" : Request.Params("USERNAME"); string password = Request.Params("PASSWORD") == null ? "" : Request.Params("PASSWORD"); string layout = Request.Params("LAYOUT") == null ? "Library://MyLayout.WebLayout" : Request.Params("LAYOUT"); string locale = Request.Params("LOCALE") == null ? "en" : Request.Params("LOCALE"); string sessionid = Request.Params("SESSION"); //Variables that should be replaced string serverUrl = "http://localhost/mapguide/mapagent/mapagent.fcgi"; string featureSourceId = "Library://my data source.FeatureSource"; string classname = "Default:Test"; string filter = "ID = 5 AND Y LIKE 'test*'"; //Setup connection Uri host = new Uri(serverUrl); ServerConnectionI con; //Either use session id or explicit credentials if (string.IsNullOrEmpty(sessionid)) con = new HttpServerConnection(host, username , password, locale, true); else con = new HttpServerConnection(host, sessionid, true); //Get the featuresource FeatureSource fs = con.GetFeatureSource(featureSourceId); FeatureSourceDescription desc = fs.DescribeSource(classname); //Find the geometry column FeatureSetColumn geometryColumn = null; foreach(FeatureSetColumn col in desc.Schemas[0].Columns) if (col.Type == MaestroAPI.Utility.GeometryType) geometryColumn = col; //TODO: If there are more than one? //Add any extra columns that you need string[] columns = new string[] { geometryColumn.Name }; //Prepare a list List features = new List(); //Execute the query using (FeatureSetReader rd = fs.SelectFeatures(classname, filter, columns)) while (rd.Read()) features.Add(rd.Row[geometryColumn.Name] as Topology.IO.Geometry.IGeometry); //The list "features" is now a list of all geometry found by applying the filter. }}}