1

I have an ITable i cast it to an IFeatureLayerDefinition after casting it to an ILayer then to an IFeatureLayer, then i used my IFeatureLayerDefinition to get only one IFeature using the IFeatureLayerDefinition.DefinitionExpression so when i add my ILayer to the Map and refresh it works but i couldn't zoom to it programmatically this is my code :

private void list_commune_SelectedIndexChanged(object sender, EventArgs e)
{
    if(table_commune==null) return;

    ILayer layer = (ILayer)table_commune;
    IFeatureLayer fl = (IFeatureLayer)layer;

    object selectedCommune = ((ComboBox)sender).SelectedItem ;
    object code_commune = null;

    if (!this.commune_dic.ContainsKey(selectedCommune)) 
        return;
    else 
        code_commune = this.commune_dic[selectedCommune];

    IFeatureLayerDefinition featureLayerDef = (IFeatureLayerDefinition)fl;
    featureLayerDef.DefinitionExpression = "NUM_COMMUNE = " + (code_commune);

    Map.AddLayer(layer);
    Map.Extent = Map.get_Layer(0).AreaOfInterest;
    Map.Refresh();
}

And this how my IFeature looks like when i added it to the Map : And this how my IFeature looks like when i added it to the Map

0

Well i've just found a solution, I create an IFeatureCursor and an IFeature and called IFeatureLayer.Search() to get the IFeatureCursor then called ICursor.NextFeature() to get the IFeature then set the Map.Extent to IFeature.Extent and it did work :)

private void list_commune_SelectedIndexChanged(object sender, EventArgs e)
{
    if(table_commune==null) return;

    ILayer layer = (ILayer)table_commune;
    IFeatureLayer fl = (IFeatureLayer)layer;

    object selectedCommune = ((ComboBox)sender).SelectedItem ;
    object code_commune = null;

    if (!this.commune_dic.ContainsKey(selectedCommune)) 
        return;
    else 
        code_commune = this.commune_dic[selectedCommune];

    IFeatureLayerDefinition featureLayerDef = (IFeatureLayerDefinition)fl;
    featureLayerDef.DefinitionExpression = "NUM_COMMUNE = " + (code_commune);


    IFeatureCursor cursor = fl.Search(null, false);
    IFeature feature = cursor.NextFeature();

    Map.AddLayer(layer);
    Map.Extent = feature.Extent;
    Map.Refresh();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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