Select to view content in your preferred language

Create graphic objects from spatialquery result features and add these to the arcmap

932
3
12-19-2013 01:28 AM
cynthiasinha
Emerging Contributor
Hello Experts,

Hey , i am new to arcobject so need a help... I have to display those points on arcmap that lies inside the envelope.I am explainingwhat i have done so far. I have one point feature class say featureclass having (lat/lon)detail.I opened it  and used one ARCGIS Snippet i.e. GetActiveviewFromArcmap() and constructed one envelope as mentioned below-:




Iactiveview pactiveview=GetActiveviewFromArcmap(m_application);
Ienvelope penvelope=new EnvelopeClass();
penvelope=pactiveview.extent;
penvelope.QueryCoord(out minx, out miny,out maxX,out maxY);

Ispatialfilter sp=New IspatialfilterClass();
sp.geometry=penvelope;
sp.geometryfield=featureclass.shapefieldname;
sp.spatialrel=esrispatialrelenum.esrispatialrelIntersects;


Ifeaturecursor fc=featureclass.Search(sp,false);

IgraphicContainer pgc;
Ielement pElement;
pElement=new MarkerElementClass();
Ipoint ppoint=new PointClass();

Ifeature feature=featurecursor.NextFeature();

while(feature!=null)
{double x=Convert.ToDouble(feature.get_value(featureclass.fields.findfield("LAT")));
double y=Convert.ToDouble(feature.get_value(featureclass.fields.findfield("LON")));
ppoint.PutCoord(x,y);
pElement.Geometry=ppoint;
ppoint.AddElement(pElement,0);
pActiveview.Refresh();
featurecursor.NextFeature();}



The problem is it is  displaying  only one graphic object(point) on arcmap though there are 19 features satisfying the spatial query.I want that when i click the tool all features (point)/graphic object display on map at once.


Thanks in advance
0 Kudos
3 Replies
LeoDonahue
Deactivated User
You need this inside your while loop, at the end.

feature=featurecursor.NextFeature();
0 Kudos
cynthiasinha
Emerging Contributor
Hey i tried it but still the same output.
Is there any problem with graphic container or retrieving of spatial query result.I believe i have used the right approach but not able to understand why m not getting the expected result??
0 Kudos
NeilClemmons
Honored Contributor
It looks to me that your problem is that you're using the same element instance over and over inside your loop.  You need to create a new element with each loop iteration.
0 Kudos