Find Feature Geometry from an attribute query.

Developer
Apr 6, 2011 at 3:48 PM

What is the correct way to find the Geometry associated with a given row based on an attribute query?

 

Hi, I'm just getting back to DotSpatial development after a rather long break.  The code snippet below crashes at :

feature = fs.FeatureLookup[result[0]];

With the error: "The given key was not present in the dictionary."

So, I look at fs.FeatureLookup and it is in fact empty.   However, the feature set.DataTable.Select(sfilter) return the correct row.  And this row does in fact have a polygon geometry associated with it.

 

What is the correct way to find the Geometry associated with a given row based on an attribute query.

 

FeatureSet fs = (layer.DataSet as FeatureSet);

if (!fs.AttributesPopulated)
{
     fs.FillAttributes();
}

string sFilter = String.Format("[{0}]='{1}'", sFieldName, iLinkId);

DataRow[] result = fs.DataTable.Select(sFilter);

if (result.Length == 1)
{
    feature = fs.FeatureLookup[result[0]];
}

Editor
Apr 6, 2011 at 5:09 PM
keenedge wrote:

What is the correct way to find the Geometry associated with a given row based on an attribute query?

 

Hi, I'm just getting back to DotSpatial development after a rather long break.  The code snippet below crashes at :

feature = fs.FeatureLookup[result[0]];

With the error: "The given key was not present in the dictionary."

So, I look at fs.FeatureLookup and it is in fact empty.   However, the feature set.DataTable.Select(sfilter) return the correct row.  And this row does in fact have a polygon geometry associated with it.

 

What is the correct way to find the Geometry associated with a given row based on an attribute query.

 

 

FeatureSet fs = (layer.DataSet as FeatureSet);

if (!fs.AttributesPopulated)
{
     fs.FillAttributes();
}

string sFilter = String.Format("[{0}]='{1}'", sFieldName, iLinkId);

DataRow[] result = fs.DataTable.Select(sFilter);

if (result.Length == 1)
{
    feature = fs.FeatureLookup[result[0]];
}

 

Friend, have you try with the BasicGeometry of your FeatureLookup?

string sFilter = String.Format("[{0}]='{1}'", sFieldName, iLinkId);

DataRow[] result = fs.DataTable.Select(sFilter);

if (result.Length == 1)
{
    feature = fs.FeatureLookup[result[0]].BasicGeometry;
}

Hope it serves you!

Francisco J.
Developer
Apr 6, 2011 at 5:59 PM

Thanks for you help but that is not the problem here.

 

The queston is:  Why is the FeatureLookup Dictionary property empty when DataTable.Select returns one row.

May 25, 2011 at 10:13 AM

Hi keenedge, did you find the solution for this problem?

I often encounter the same situation. In most of cases reloding FeatureSet from file helps, but not always.

I would like to find proper solution for that...

Aug 24, 2014 at 1:23 PM
I also have this problem.Is thre any solutions?
Developer
Sep 10, 2014 at 7:45 AM
Edited Sep 10, 2014 at 7:45 AM
Please have a look at changeset 74994. This should solve your problem.