By using the QueryFilter I am getting some features based on the query and I am placing that feature names in a listbox. When the user selects a particular name in the listbox that feature has to be zoomed to in the map.
Below is my code:
IQueryFilter pQueryFilter = new QueryFilterClass();
pQueryFilter.WhereClause = textBox1.Text + textBox2.Text;
ICursor pCursor = pFeatureClass.Search(pQueryFilter, true) as ICursor;
IRow pRow = pCursor.NextRow();
while (pRow != null)
{
listBox2.Items.Add(pRow.get_Value(9).ToString());
pRow = pCursor.NextRow();
}
Here is what I tried:
IActiveView pActiveView = pMxDocument.ActiveView;
IGeometry pGeometry = pFeature.Shape;
IEnvelope pEnvelope = pGeometry.Envelope;
pActiveView.Extent = pEnvelope.Expand(1.2, 1.2, true);
But I am unable to zoom.
-
so feature is not selected in the map.right?vinayan– vinayan2013年01月10日 07:59:11 +00:00Commented Jan 10, 2013 at 7:59
-
Do you want to select the feature and highlight it or just zoom the map?Emi– Emi2013年01月10日 08:36:58 +00:00Commented Jan 10, 2013 at 8:36
-
I want to zoom that feature which i selected in ListBoxJagadesh– Jagadesh2013年01月10日 08:39:27 +00:00Commented Jan 10, 2013 at 8:39
-
@Jagadesh - please post where you are going wrong..vinayan– vinayan2013年01月10日 10:09:53 +00:00Commented Jan 10, 2013 at 10:09
-
@Jagadesh I added some comment in my answer. may be you missed it. you need to pass false in the expand method's third argument and you have to refresh arcmap's active view. For experimental please use pEnvelope.Expand(10, 10, false);Emi– Emi2013年01月10日 11:10:21 +00:00Commented Jan 10, 2013 at 11:10
4 Answers 4
This is not tested.
public void ZoomTo(IGeometry geometry)
{
IMxDocument doc = (IMxDocument)ArcMap.Application.Document;
IMap map = (IMap)doc.FocusMap;
IActiveView pActiveView = (IActiveView)map;
IEnvelope pEnvelope;
if (geometry is IPoint)
{
IEnvelope currentEnv = pActiveView.Extent;
IPoint point = (IPoint)geometry;
currentEnv.CenterAt(point);
pActiveView.Extent = currentEnv;
map.MapScale = 100; //to set the scale to 1:100
}
else
{
pEnvelope = geometry.Envelope;
pEnvelope.Expand(1.2, 1.2, true);
pActiveView.Extent = pEnvelope;
}
pActiveView.Refresh();
}
-
Now i want to zoom to some collection of features where all are point features then how to work with it.Jagadesh– Jagadesh2013年01月16日 12:09:00 +00:00Commented Jan 16, 2013 at 12:09
-
check snipplr.com/view/48443vinayan– vinayan2013年01月16日 12:32:19 +00:00Commented Jan 16, 2013 at 12:32
-
1If the geometry coordinate system is geographic and geometry type isn't point, then pEnvelope.Expand(1.2, 1.2, true); will zoom to a very big extent.Farid Cheraghi– Farid Cheraghi2015年05月02日 14:19:23 +00:00Commented May 2, 2015 at 14:19
Try the following (assuming names are unique):
- Store the feature reference returned by pFeatureClass.Search(pQueryFilter, true).NextFeature() in a hashtable (data structure is not important), with key=name & value=actual feature object
- On the selection changed event for the list, call
pActiveView.Extent=(hashtable[SelectedListItem] as IFeature).Extent - This should zoomt to the feature (but wont select it upon zooming)
-
I slightly changed my code instead of ICursor i have taken IFeatureCursor from that i am getting IFeature i tried but its not zooming to the featureJagadesh– Jagadesh2013年01月10日 08:51:51 +00:00Commented Jan 10, 2013 at 8:51
-
I saw that, any specific reason for it...do you intend to re-use it later?ujjwalesri– ujjwalesri2013年01月10日 08:52:58 +00:00Commented Jan 10, 2013 at 8:52
-
if the Geometry is an IPoint, it may not zoom..you might have to apply a buffer i think..vinayan– vinayan2013年01月10日 08:55:07 +00:00Commented Jan 10, 2013 at 8:55
-
You could store the feature reference directly in the ListView using its ListViewItem.Tag property. Just be sure to use a non-recycling cursor.blah238– blah2382013年01月10日 08:56:15 +00:00Commented Jan 10, 2013 at 8:56
-
@vinayan yes it is point feature how to zoom nowJagadesh– Jagadesh2013年01月10日 09:10:27 +00:00Commented Jan 10, 2013 at 9:10
You could also use the IHookActions
interface for this, e.g.:
hookActions.DoAction(feature.Shape, esriHookActions.esriHookActionsZoom)
See also this sample: Using HookActions in custom commands
-
HookAction is the only method to zoom ? because i am beginner and not aware of hookactionsJagadesh– Jagadesh2013年01月10日 09:28:14 +00:00Commented Jan 10, 2013 at 9:28
-
2There are at least 3 ways to skin this cat... I am just offering one more.blah238– blah2382013年01月10日 09:34:45 +00:00Commented Jan 10, 2013 at 9:34
-
This is only applicable to ArcEngine and no the DesktopFarid Cheraghi– Farid Cheraghi2015年05月02日 14:20:51 +00:00Commented May 2, 2015 at 14:20
-
@FaridCher Are you sure? I remember testing it with ArcMap and it worked fine.blah238– blah2382015年05月04日 19:52:12 +00:00Commented May 4, 2015 at 19:52
-
I haven't tested this with Desktop. But If you open IHookActions documentation (your own link), you will only see Arc Engine under Product Availability!Farid Cheraghi– Farid Cheraghi2015年05月04日 21:26:11 +00:00Commented May 4, 2015 at 21:26
you just have to find out which feature the user selected.
ADDITION: May be for point feature the extent is so small that map can not zoom that much. So you need to make an envelope of that point and expand it as much as the map needs.
For point features:
IGeometry pointGeo = selectedFeature.Shape;
IEnvelope envelope = pointGeo.Envelop;
envelope.Expand(10,10,false);
map.ActiveView.Extent = envelope;
map.ActiveView.Refresh();
see more fore IEnvelope.Expand Method. This should work.
-
I want to zoom that feature in Map at minimum map scaleJagadesh– Jagadesh2013年01月10日 08:56:35 +00:00Commented Jan 10, 2013 at 8:56
-
@Jagadesh what do you mean by "minimum map scale"? Also, no such requirement was not stated up front (a bit unfair).blah238– blah2382013年01月10日 08:58:12 +00:00Commented Jan 10, 2013 at 8:58
-
For a particular Layer in a Map there are huge amount of Features placed. By querying particular fields i want to zoom that particular feature which user selected.Jagadesh– Jagadesh2013年01月10日 09:04:06 +00:00Commented Jan 10, 2013 at 9:04
-
Okay... so you want to zoom to a feature. We got that part. What do you mean by "minimum map scale" is there a minimum scale level (e.g. 1:1200) that you don't want to automatically zoom below?blah238– blah2382013年01月10日 09:04:59 +00:00Commented Jan 10, 2013 at 9:04
-
(e.g. 1:2) so that we can see only that featureJagadesh– Jagadesh2013年01月10日 09:07:50 +00:00Commented Jan 10, 2013 at 9:07