Class that represents features on a FeatureLayer.
Object Model
Syntax
Example
The following example performs a query on a point layer, including a request for feature geometry. The query returns a FeatureTable. We first find the geometry column in the table. Then we loop through the features and retrieve the city's point (technically the first point in the Multipoint collection of the feature). We add the point to a separate point collection. At this point we could use the points in a new query or display. The code assumes a pre-existing MapView object.
C# | Copy Code |
---|
FeatureLayer theLayer = (FeatureLayer)mapView.Layers.FindByName("Cities");
// Set up query on the Cities layer
Filter queryFilter = new Filter(new Envelope(0, 30, 10, 40));
QueryParameters queryParams = new QueryParameters(queryFilter);
queryParams.ReturnGeometries = true;
// Perform query, get FeatureTable as result
FeatureTable queryResults = theLayer.Query(queryParams);
// Find the Geometry column in the results FeatureTable
string geometryColumn = String.Empty;
foreach (DataColumn col in queryResults.Columns)
{
if (col.DataType == typeof(ESRI.ArcGIS.ADF.IMS.Geometry.Geometry))
geometryColumn = col.ColumnName;
}
PointCollection pointColl = new PointCollection();
Multipoint featureMultiPt;
ESRI.ArcGIS.ADF.IMS.Geometry.Point pt;
if (geometryColumn != String.Empty)
{
// Retrieve the geometry (point) for each city, add to point collection
foreach (DataRow featureRow in queryResults.Rows)
{
featureMultiPt = (ESRI.ArcGIS.ADF.IMS.Geometry.Multipoint)featureRow[geometryColumn];
pt = featureMultiPt.Points[0];
pointColl.Add(pt);
}
}
// Do something with the point collection
int numPoints = pointColl.Count; |
Visual Basic | Copy Code |
---|
Dim theLayer As FeatureLayer = CType(mapView.Layers.FindByName("Cities"), FeatureLayer)
' Set up query on the Cities layer
Dim queryFilter As New Filter(New Envelope(0, 30, 10, 40))
Dim queryParams As New QueryParameters(queryFilter)
queryParams.ReturnGeometries = True
' Perform query, get FeatureTable as result
Dim queryResults As FeatureTable = theLayer.Query(queryParams)
' Find the Geometry column in the results FeatureTable
Dim geometryColumn As String = String.Empty
For Each col As DataColumn In queryResults.Columns
If col.DataType Is GetType(ESRI.ArcGIS.ADF.IMS.Geometry.Geometry) Then
geometryColumn = col.ColumnName
End If
Next
Dim pointColl As New PointCollection()
Dim featureMultiPt As Multipoint
Dim pt As ESRI.ArcGIS.ADF.IMS.Geometry.Point
If geometryColumn <> String.Empty Then
' Retrieve the geometry (point) for each city, add to point collection
For Each featureRow As DataRow In queryResults.Rows
featureMultiPt = CType(featureRow(geometryColumn), ESRI.ArcGIS.ADF.IMS.Geometry.Multipoint)
pt = featureMultiPt.Points(0)
pointColl.Add(pt)
Next
End If
' Do something with the point collection
Dim numPoints As Integer = pointColl.Count |
Remarks
Requirements
Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family
See Also