Changes between Initial Version and Version 1 of maestro/MaestroAPI/samples/QueryFeatureSource


Ignore:
Timestamp:
01/15/10 00:38:11 (15 years ago)
Author:
ksgeograf
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • maestro/MaestroAPI/samples/QueryFeatureSource

    v1 v1  
     1
     2== Query Features with a filter ==
     3This page describes how to use the MaestroAPI from the [wiki:maestro MapGuide Maestro] project in your own application.
     4
     5This sample shows how to read geometry features from a !FeatureSource using MaestroAPI.
     6
     7(C#)
     8{{{
     9using OSGeo.MapGuide.MaestroAPI;
     10...
     11
     12//Read the setup, either from QueryString, Form, Cookies or hardcoded values
     13string username = Request.Params("USERNAME") == null ? "Anonymous" : Request.Params("USERNAME");
     14string password = Request.Params("PASSWORD") == null ? "" : Request.Params("PASSWORD");
     15string layout = Request.Params("LAYOUT") == null ? "Library://MyLayout.WebLayout" : Request.Params("LAYOUT");
     16string locale = Request.Params("LOCALE") == null ? "en" : Request.Params("LOCALE");
     17string sessionid = Request.Params("SESSION");
     18
     19
     20//Variables that should be replaced
     21string serverUrl = "http://localhost/mapguide/mapagent/mapagent.fcgi";
     22string featureSourceId = "Library://my data source.FeatureSource";
     23string classname = "Default:Test";
     24string filter = "ID = 5 AND Y LIKE 'test*'";
     25
     26//Setup connection
     27Uri host = new Uri(serverUrl);
     28ServerConnectionI con;
     29
     30//Either use session id or explicit credentials
     31if (string.IsNullOrEmpty(sessionid))
     32    con = new HttpServerConnection(host, username , password, locale, true);
     33else
     34    con = new HttpServerConnection(host, sessionid, true);
     35
     36//Get the featuresource
     37FeatureSource fs = con.GetFeatureSource(featureSourceId);
     38FeatureSourceDescription desc = fs.DescribeSource(classname);
     39
     40//Find the geometry column
     41FeatureSetColumn geometryColumn = null;
     42foreach(FeatureSetColumn col in desc.Schemas[0].Columns)
     43    if (col.Type == MaestroAPI.Utility.GeometryType)
     44        geometryColumn = col; //TODO: If there are more than one?
     45
     46//Add any extra columns that you need
     47string[] columns = new string[] { geometryColumn.Name };
     48
     49//Prepare a list
     50List<Topology.IO.Geometry.IGeometry> features = new List<Topology.IO.Geometry.IGeometry>();
     51
     52//Execute the query
     53using (FeatureSetReader rd = fs.SelectFeatures(classname, filter, columns))
     54    while (rd.Read())
     55        features.Add(rd.Row[geometryColumn.Name] as Topology.IO.Geometry.IGeometry);
     56
     57//The list "features" is now a list of all geometry found by applying the filter.
     58}}}
     59
     60