2

I want to find the object that is part of the polygon and displaying it in a separate listbox.

Example

I have two layers with polygons, the first polygon (Red) is the polygon in which you want to search for features. The second polygon layer (Green) is the polygon that you want to display in the listbox when you enter the first polygon.

A yellow marked polygon that should not be affected because it is included in the first (red) polygon not completely I have little experience in this, I would like at least part of the implementation code of this At the same time I have to choose from the listbox layer with a polygon (Green)

 public void button1_Click(object sender, EventArgs e)
        {
Tool1 dbconnect = new Tool1();


 IFeatureLayer pfeaturelayer = (IFeatureLayer)mxDocument.ActiveView.FocusMap.Layer[0];
                    IDataset pDS = (IDataset)pfeaturelayer.FeatureClass;
                    WellManagerPolygon wl = new WellManagerPolygon(pDS.Workspace);
                    Well pWell = wl.GetWellByIDPolygon(Convert.ToString(textBox2.Text), Convert.ToString(comboBox1.Text));


                    int mRange = Convert.ToInt32(textBox1.Text);
                    // range of x meters
                    ITopologicalOperator pTopo = (ITopologicalOperator)pWell.PolygonLocation;



                    IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pDS.Workspace;
                    pWorkspaceEdit.StartEditing(true);
                    pWorkspaceEdit.StartEditOperation();

                    IFeatureWorkspace pWorkspace = (IFeatureWorkspace)pWorkspaceEdit;

                    IFeatureClass pWellRangeFC = pWorkspace.OpenFeatureClass("WellRange");
                    IFeature pFeature = pWellRangeFC.CreateFeature();


                    pFeature.set_Value(pFeature.Fields.FindField("WELLIDRANGE"), Convert.ToInt32(textBox2.Text));
                    pFeature.set_Value(pFeature.Fields.FindField("RANGE"), Convert.ToInt32(textBox1.Text));

                    pFeature.Shape = BarsRange;
                    pFeature.Store();



                    mxDocument.UpdateContents();
                    mxDocument.ActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeography, null, null);

                    pWorkspaceEdit.StopEditing(true);
                    pWorkspaceEdit.StopEditOperation();
2

You can go about it this way:

//loop through your red features
var search_red = red_feature_class.Search(null, true);
IFeature red_feature;
while((red_feature = search_red.NextFeature()) != null)
{
    //build a query using the red feature's geometry
    ISpatialFilter filter = new SpatialFilter();
    filter.Geometry = red_feature.Shape;

    //this will find any feature contained contained in the red polygon
    filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;

    //use false if you need to cache the feature object itself 
    var search_green = green_feature_class.Search(filter, true); 

    IFeature green_feature;
    while((green_feature = search_green.NextFeature()) != null)
    {
        //do whatever you want to the green feature here
    }
}

If you have tons of these to search for, a Spatial Join may better suit the problem.

  • how can I now display green features in the listbox? – user140079 Apr 11 at 17:20
  • I added your code to my question, can you see I did everything right? – user140079 Apr 11 at 17:27
  • If you're going to keep the entire IFeature object around you should use 'false' in this call: pGreen.Search(filter, true). – danielm Apr 11 at 20:42
  • For how you display the features in the listbox, you could add the OID or some other field value to the listbox. – danielm Apr 11 at 20:43
  • ,[For how you display the features in the listbox, you could add the OID or some other field value to the listbox] I don't know how to do it, or what you mean. – user140079 Apr 11 at 20:48

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.