# Moving feature, CenterAt & Projection

**URL:** <https://community.thinkgeo.com/t/moving-feature-centerat-projection/452>\
**Category:** WinForms\
**Created:** [June 1, 2009, 6:08pm UTC](https://community.thinkgeo.com/t/moving-feature-centerat-projection/452 "2009-06-01T18:08:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/p/b2d939/32.png) [@Patrick](https://community.thinkgeo.com/u/Patrick)\
**Post date:** [June 1, 2009, 6:08pm UTC](https://community.thinkgeo.com/t/moving-feature-centerat-projection/452/1 "2009-06-01T18:08:00Z")

</div>

Dear&nbsp;all,

Since&nbsp;I&nbsp;migrated&nbsp;from&nbsp;3.0.199&nbsp;to&nbsp;3.0.307&nbsp;I'm&nbsp;no&nbsp;longer&nbsp;able&nbsp;to&nbsp;move&nbsp;dynamic&nbsp;feature&nbsp;&&nbsp;center&nbsp;on&nbsp;a&nbsp;feature&nbsp;in&nbsp;combinaison&nbsp;with&nbsp;projection.

I'm&nbsp;using&nbsp;the&nbsp;same&nbsp;projection&nbsp;for&nbsp;a&nbsp;ShapeFileFeatureLayer&nbsp;and&nbsp;a&nbsp;InMemoryFeatureLayer:  
  
p&nbsp;=&nbsp;new&nbsp;Proj4Projection(Proj4Projection.GetEpsgParametersString&nbsp;(4326),&nbsp;Proj4Projection.GetGoogleMapParametersString());&nbsp;

Then&nbsp;I&nbsp;add&nbsp;some&nbsp;features&nbsp;on&nbsp;the&nbsp;InMemoryFeatureLayer&nbsp;with&nbsp;WGS84&nbsp;coord;&nbsp;features&nbsp;are&nbsp;correctly&nbsp;shown&nbsp;on&nbsp;the&nbsp;map.

The&nbsp;issue&nbsp;is&nbsp;when&nbsp;I&nbsp;try&nbsp;to&nbsp;center&nbsp;on&nbsp;that&nbsp;feature;&nbsp;the&nbsp;map&nbsp;is&nbsp;in&nbsp;fact&nbsp;centered&nbsp;to&nbsp;(0,0);&nbsp;this&nbsp;worked&nbsp;with&nbsp;3.0.199;&nbsp;here&nbsp;is&nbsp;my&nbsp;code:

feature&nbsp;=&nbsp;m\_DynamicLayer.InternalFeatures[featureKey];  
  
MainMap.CenterAt(feature);  
  
MainMap.Refresh();

Also,&nbsp;when&nbsp;I&nbsp;try&nbsp;to&nbsp;move&nbsp;that&nbsp;feature&nbsp;to&nbsp;another&nbsp;WGS84&nbsp;coord,&nbsp;the&nbsp;feature&nbsp;is&nbsp;moved&nbsp;to&nbsp;(0,0);&nbsp;again&nbsp;this&nbsp;worked&nbsp;in&nbsp;3.0.199&nbsp;and&nbsp;work&nbsp;if&nbsp;I&nbsp;do&nbsp;not&nbsp;use&nbsp;projection:

&nbsp;

DynamicOverlay.Lock.EnterWriteLock();  
  
PointShape&nbsp;pointShape&nbsp;=&nbsp;m\_DynamicLayer.InternalFeatures[featureKey].GetShape()&nbsp;as&nbsp;PointShape;  
  
pointShape.X&nbsp;=&nbsp;x;  
  
pointShape.Y&nbsp;=&nbsp;y;  
  
pointShape.Id&nbsp;=&nbsp;featureKey;  
  
m\_DynamicLayer.Open();  
  
m\_DynamicLayer.EditTools.BeginTransaction();  
  
m\_DynamicLayer.EditTools.Update(pointShape);  
  
m\_DynamicLayer.EditTools.CommitTransaction();  
  
m\_DynamicLayer.Close();  
  
DynamicOverlay.Lock.ExitWriteLock();  
  
MainMap.Refresh();

Any&nbsp;help&nbsp;is&nbsp;more&nbsp;than&nbsp;welcome.

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [June 2, 2009, 1:34am UTC](https://community.thinkgeo.com/t/moving-feature-centerat-projection/452/2 "2009-06-02T01:34:58Z")

</div>

Patrick,

&nbsp;  
I&nbsp;understand&nbsp;what&nbsp;is&nbsp;going&nbsp;on&nbsp;in&nbsp;your&nbsp;code&nbsp;and&nbsp;found&nbsp;that&nbsp;you&nbsp;made&nbsp;two&nbsp;minor&nbsp;mistakes:  
1)&nbsp;The&nbsp;passed&nbsp;in&nbsp;“feature”&nbsp;parameter&nbsp;in&nbsp;the&nbsp;CenterAt&nbsp;API&nbsp;should&nbsp;be&nbsp;a&nbsp;“projected”&nbsp;feature,&nbsp;so&nbsp;we&nbsp;need&nbsp;to&nbsp;project&nbsp;it&nbsp;before&nbsp;we&nbsp;passed&nbsp;it&nbsp;in.  
&nbsp;  
2)&nbsp;When&nbsp;we&nbsp;update&nbsp;a&nbsp;pointShape,&nbsp;we&nbsp;should&nbsp;project&nbsp;it&nbsp;too&nbsp;before&nbsp;we&nbsp;updated.  
&nbsp;  
So&nbsp;just&nbsp;try&nbsp;that.  
&nbsp;  
Following&nbsp;is&nbsp;my&nbsp;sample&nbsp;code,&nbsp;just&nbsp;take&nbsp;a&nbsp;reference.  
&nbsp;  
`  InMemoryFeatureLayer dynamicLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("DynamicLayer");            Projection projection = dynamicLayer.FeatureSource.Projection;            projection.Open();            winformsMap1.CenterAt(projection.ConvertToExternalProjection(dynamicLayer.InternalFeatures[0]));            winformsMap1.Refresh(); also:            InMemoryFeatureLayer dynamicLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("DynamicLayer");            winformsMap1.Overlays[1].Lock.EnterWriteLock();            try            {                PointShape pointShape = (PointShape)dynamicLayer.InternalFeatures[0].GetShape();                pointShape.Id = dynamicLayer.InternalFeatures[0].Id;                pointShape.X = -90;                pointShape.Y = -60;                Projection projection = dynamicLayer.FeatureSource.Projection;                projection.Open();                PointShape projectedPointShape = (PointShapeprojection.ConvertToExternalProjection(pointShape);                projectedPointShape.Id = pointShape.Id;                 dynamicLayer.Open();                dynamicLayer.EditTools.BeginTransaction();                dynamicLayer.EditTools.Update(projectedPointShape);                dynamicLayer.EditTools.CommitTransaction();                dynamicLayer.Close();            }            finally            {                winformsMap1.Overlays[1].Lock.ExitWriteLock();            }            winformsMap1.Refresh();`  
&nbsp;  
Let&nbsp;me&nbsp;know&nbsp;if&nbsp;any&nbsp;another&nbsp;problem.  
&nbsp;  
Yale

---

<div class="post-metadata">

**Author:** ![Patrick](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/p/b2d939/32.png) [@Patrick](https://community.thinkgeo.com/u/Patrick)\
**Post date:** [June 2, 2009, 2:25am UTC](https://community.thinkgeo.com/t/moving-feature-centerat-projection/452/3 "2009-06-02T02:25:50Z")

</div>

Yale,

Thank&nbsp;you&nbsp;for&nbsp;your&nbsp;code,&nbsp;it&nbsp;works&nbsp;...&nbsp;however,&nbsp;I&nbsp;feel&nbsp;it's&nbsp;a&nbsp;strange&nbsp;behaviour.

How&nbsp;can&nbsp;you&nbsp;explain&nbsp;that&nbsp;we&nbsp;need&nbsp;to&nbsp;use&nbsp;internal&nbsp;proj&nbsp;coord&nbsp;to&nbsp;add&nbsp;feature&nbsp;and&nbsp;external&nbsp;proj&nbsp;coord&nbsp;to&nbsp;move&nbsp;them?

Same&nbsp;for&nbsp;centerat;&nbsp;while&nbsp;I&nbsp;understand&nbsp;that&nbsp;centerat(point)&nbsp;can&nbsp;be&nbsp;a&nbsp;internal&nbsp;or&nbsp;external&nbsp;projection;&nbsp;I&nbsp;feel&nbsp;that&nbsp;centerat(feature)&nbsp;should&nbsp;handle&nbsp;the&nbsp;projection.

Regards

Patrick.

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [June 2, 2009, 3:06am UTC](https://community.thinkgeo.com/t/moving-feature-centerat-projection/452/4 "2009-06-02T03:06:58Z")

</div>

Patrick,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;reply.&nbsp;  
&nbsp;&nbsp;  
&nbsp;The&nbsp;reason&nbsp;we&nbsp;use&nbsp;internal&nbsp;projection&nbsp;when&nbsp;we&nbsp;add&nbsp;feature&nbsp;to&nbsp;InMemoryFeatureLayer&nbsp;is&nbsp;that&nbsp;all&nbsp;the&nbsp;features&nbsp;in&nbsp;it&nbsp;should&nbsp;be&nbsp;internal&nbsp;data&nbsp;and&nbsp;when&nbsp;we&nbsp;draw&nbsp;it&nbsp;we&nbsp;will&nbsp;project&nbsp;it&nbsp;to&nbsp;external&nbsp;features&nbsp;just&nbsp;before&nbsp;drawing&nbsp;or&nbsp;spatial&nbsp;querying&nbsp;etc.&nbsp;  
&nbsp;&nbsp;  
&nbsp;The&nbsp;reason&nbsp;we&nbsp;use&nbsp;external&nbsp;data&nbsp;when&nbsp;we&nbsp;update&nbsp;is&nbsp;that&nbsp;we&nbsp;use&nbsp;the&nbsp;EditTools&nbsp;to&nbsp;update&nbsp;features&nbsp;which&nbsp;will&nbsp;not&nbsp;handle&nbsp;the&nbsp;projection,&nbsp;still&nbsp;I&nbsp;think&nbsp;if&nbsp;we&nbsp;can&nbsp;handle&nbsp;it&nbsp;would&nbsp;be&nbsp;nice.&nbsp;  
&nbsp;&nbsp;  
&nbsp;The&nbsp;reason&nbsp;we&nbsp;did&nbsp;not&nbsp;handle&nbsp;the&nbsp;projection&nbsp;in&nbsp;CenterAt&nbsp;is&nbsp;that&nbsp;the&nbsp;projection&nbsp;object&nbsp;is&nbsp;just&nbsp;a&nbsp;property&nbsp;for&nbsp;a&nbsp;layer&nbsp;,&nbsp;not&nbsp;a&nbsp;&nbsp;property&nbsp;of&nbsp;MapControl.&nbsp;  
&nbsp;&nbsp;  
&nbsp;If&nbsp;any&nbsp;more&nbsp;further&nbsp;questions,&nbsp;just&nbsp;let&nbsp;me&nbsp;know.&nbsp;  
&nbsp;Thanks.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Yale.&nbsp;
