Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is some code that I am using to try to get a working IFeatureLayer from a subset of data from a database table. The fourth line containing "fcWkspc.OpenFeatureQuery" throws and error complaining about an "The operation was attempted on an empty geometry.".

Should also mention that this code was lifted directly from ESRI documentation example code at the following link:

Can anyone tell me what I might be doing wrong?

// m_wkSpace2 is of type IWorkspace2
IFeatureWorkspace fcWkspc = (IFeatureWorkspace)m_wkSpace2;

IQueryDef qDef = fcWkspc.CreateQueryDef();

Def.Tables = "dbo.TABLE_NAME";
qDef.WhereClause = "Name1 = '" + var1 + "' AND Name2 = '" + var2 + "'";

IFeatureDataset featureDataset = fcWkspc.OpenFeatureQuery("MyJoin", qDef);
IFeatureClassContainer featureClassContainer = (IFeatureClassContainer)featureDataset;
IFeatureClass featureClass = featureClassContainer.get_ClassByName("MyJoin");

IFeatureLayer layerForMap = (IFeatureLayer)featureClass;
share|improve this question

I would first check to see if your where clause is valid and it does return data. Another suggestion would be to use the IFeatureLayerDefinition to setup a QueryDef since you are only using a single table - An example here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.