Some of our customers have very large parcel layers (~half a million features). What I’m attempting to do is query this layer however possible with an array of values to return the features associated with those values. In this case, our column is the parcel number.
I’ve tried a couple approaches. Doing a layer.QueryTools.ExecuteQuery() to retrieve a table of OBJECTID’s where I can then get the features from, and looping through the list of parcel numbers and doing an individual layer…QueryTools.GetFeaturesByColumnValue( ). Both seem to take an extremely long time.
Code for the former:
parcelLayer.Open();
String query = String.Format(
“SELECT OBJECTID FROM {0} WHERE {1} in (’{2}’)”
,
parcelLayer.Name,
ActiveSet.parcelFieldName,
String.Join(
"’, '"
,parcelList.ToArray()));
DataTable results = parcelLayer.QueryTools.ExecuteQuery( query );
Collection<string> ids =
new
Collection<
string
>();
foreach
(DataRow row
in
results.Rows)
{
ids.Add(DataTools.ToType<string>(row[
“OBJECTID”
]));
}
Collection<feature> features = parcelLayer.QueryTools.GetFeaturesByIds(ids, ReturningColumnsType.NoColumns);
foreach
( Feature f
in
features )
{
dynLayer.InternalFeatures.Add( f.Id, f );
}
return
;
Any suggestions as to how I can make this faster?
Also from what I’m reading, it looks like we can’t guarantee the feature Id will exist in the shapefile, so therefore this query may not even work. So how am I supposed to retrieve the features associate with this list of parcel numbers? Even if I return all columns, I don’t know of a way to instantiate or access the associated features with the rows from ExecuteQuery()
This is another solution, though even longer than the aforementioned query
Collection<
Feature
> features = parcelLayer.FeatureSource.GetAllFeatures(new List<
String
>() { ActiveSet.parcelFieldName });
foreach (Feature f in features)
{
if( ParcelNumbers.Contains( DataTools.ToType<
String
>(f.ColumnValues[ActiveSet.parcelFieldName] ) ) )
dynLayer.InternalFeatures.Add(f.Id, f);
}