# Updating a feature's shape dynamically?

**URL:** <https://community.thinkgeo.com/t/updating-a-features-shape-dynamically/570>\
**Category:** WinForms\
**Created:** [July 28, 2009, 6:57pm UTC](https://community.thinkgeo.com/t/updating-a-features-shape-dynamically/570 "2009-07-28T18:57:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmccrillis](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/ed655f/32.png) [@jmccrillis](https://community.thinkgeo.com/u/jmccrillis)\
**Post date:** [July 28, 2009, 6:57pm UTC](https://community.thinkgeo.com/t/updating-a-features-shape-dynamically/570/1 "2009-07-28T18:57:13Z")

</div>

I'm&nbsp;attempting&nbsp;to&nbsp;update&nbsp;a&nbsp;lot&nbsp;of&nbsp;features&nbsp;on&nbsp;my&nbsp;map&nbsp;as&nbsp;new&nbsp;data&nbsp;comes&nbsp;in,&nbsp;hopefully&nbsp;in&nbsp;the&nbsp;most&nbsp;efficient&nbsp;manner&nbsp;I&nbsp;can&nbsp;find.&nbsp;I&nbsp;looked&nbsp;at&nbsp;the&nbsp;example&nbsp;of&nbsp;the&nbsp;moving&nbsp;plane&nbsp;and&nbsp;came&nbsp;up&nbsp;with&nbsp;the&nbsp;code&nbsp;below.&nbsp;I'm&nbsp;attempting&nbsp;to&nbsp;get&nbsp;the&nbsp;RectangleShape&nbsp;associated&nbsp;with&nbsp;the&nbsp;feature&nbsp;and&nbsp;change&nbsp;it's&nbsp;height&nbsp;based&nbsp;on&nbsp;the&nbsp;new&nbsp;data.&nbsp;The&nbsp;feature&nbsp;is&nbsp;found&nbsp;by&nbsp;the&nbsp;query,&nbsp;but&nbsp;the&nbsp;returned&nbsp;RectangleShape&nbsp;is&nbsp;null.

&nbsp;

`             //redraw the noise display            InMemoryFeatureLayer receiversLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("ReceiversLayer");            Overlay ReceiversOverlay = winformsMap1.Overlays["ReceiversOverlay"];            String[] columns = { "SerialNumber", "Noise" };            // Lock the overlay while we update the points            ReceiversOverlay.Lock.EnterWriteLock();            try            {                foreach (ReceiverUnit r in receivers.Values)                {                    receiversLayer.Open();                    Feature f = receiversLayer.QueryTools.GetFeatureById(r.SerialNumber, columns);                    receiversLayer.Close();                    RectangleShape rectShape = f.GetShape() as RectangleShape; // why is this null?                    rectShape.UpperLeftPoint.Y = r.LatLong.Y + r.Noise*.01;                                                                                         f.ColumnValues["Noise"] = r.Noise.ToString();                    receiversLayer.Open();                    receiversLayer.EditTools.BeginTransaction();                    //receiversLayer.EditTools.Update(f);                    receiversLayer.EditTools.Update(rectShape);                    receiversLayer.EditTools.CommitTransaction();                    receiversLayer.Close();                }            }            finally {                // Release the lock on the overlay                ReceiversOverlay.Lock.ExitWriteLock();            }            winformsMap1.Refresh();        }  `

Apparently&nbsp;I'm&nbsp;doing&nbsp;this&nbsp;wrong,&nbsp;but&nbsp;I&nbsp;don't&nbsp;find&nbsp;any&nbsp;other&nbsp;examples&nbsp;of&nbsp;doing&nbsp;this.&nbsp;I&nbsp;have&nbsp;tried&nbsp;clearing&nbsp;&nbsp;the&nbsp;features&nbsp;in&nbsp;the&nbsp;layer&nbsp;and&nbsp;creating&nbsp;new&nbsp;ones,&nbsp;which&nbsp;works,&nbsp;but&nbsp;at&nbsp;only&nbsp;100&nbsp;points,&nbsp;the&nbsp;updating&nbsp;is&nbsp;erratic,&nbsp;rather&nbsp;than&nbsp;smooth,&nbsp;and&nbsp;sometimes&nbsp;stops&nbsp;for&nbsp;a&nbsp;short&nbsp;moment.&nbsp;I&nbsp;will&nbsp;have&nbsp;many&nbsp;more&nbsp;than&nbsp;100&nbsp;points,&nbsp;so&nbsp;I'm&nbsp;looking&nbsp;at&nbsp;other&nbsp;methods.

Thanks&nbsp;for&nbsp;any&nbsp;help,

Janene

Wireless&nbsp;Seismic

---

<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:** [July 28, 2009, 8:35pm UTC](https://community.thinkgeo.com/t/updating-a-features-shape-dynamically/570/2 "2009-07-28T20:35:22Z")

</div>

&nbsp;

Hi&nbsp;Janene,  
&nbsp;  
Thanks&nbsp;for&nbsp;your&nbsp;post!  
&nbsp;  
There&nbsp;are&nbsp;some&nbsp;errors&nbsp;in&nbsp;your&nbsp;code,&nbsp;and&nbsp;I&nbsp;also&nbsp;have&nbsp;some&nbsp;ideas&nbsp;to&nbsp;improve&nbsp;the&nbsp;performance&nbsp;of&nbsp;your&nbsp;application.  
&nbsp;  
First&nbsp;of&nbsp;all,&nbsp;you&nbsp;can&nbsp;not&nbsp;get&nbsp;a&nbsp;RectangleShape&nbsp;from&nbsp;a&nbsp;feature;&nbsp;the&nbsp;RectangleShape&nbsp;is&nbsp;processed&nbsp;as&nbsp;PolygonShape&nbsp;when&nbsp;stored&nbsp;in&nbsp;a&nbsp;feature.&nbsp;That&nbsp;is&nbsp;why&nbsp;the&nbsp;returned&nbsp;RectangleShape&nbsp;is&nbsp;null.&nbsp;The&nbsp;code&nbsp;should&nbsp;be&nbsp;like&nbsp;this:  
&nbsp;  
  
`RectangleShape rectShape = f.GetBoundingBox();`  
&nbsp;  
Second,&nbsp;you&nbsp;don’t&nbsp;need&nbsp;to&nbsp;use&nbsp;the&nbsp;QueryTools&nbsp;and&nbsp;EditTools&nbsp;for&nbsp;an&nbsp;InMemoryFeatureLayer,&nbsp;just&nbsp;use&nbsp;the&nbsp;feature’s&nbsp;id&nbsp;to&nbsp;index&nbsp;the&nbsp;InternalFeatures&nbsp;in&nbsp;it.&nbsp;Your&nbsp;code&nbsp;could&nbsp;be&nbsp;like&nbsp;this:  
&nbsp;  
When&nbsp;you&nbsp;add&nbsp;some&nbsp;feature&nbsp;to&nbsp;the&nbsp;InMemoryFeatureLayer,&nbsp;you&nbsp;can&nbsp;add&nbsp;the&nbsp;id&nbsp;as&nbsp;an&nbsp;index&nbsp;(in&nbsp;your&nbsp;application,&nbsp;the&nbsp;feature’s&nbsp;id&nbsp;should&nbsp;be&nbsp;same&nbsp;to&nbsp;SerialNumber):  
&nbsp;  
  
`receiversLayer.InternalFeatures.Add(f.Id, f);`  
&nbsp;  
Then&nbsp;you&nbsp;can&nbsp;query&nbsp;a&nbsp;feature&nbsp;by&nbsp;the&nbsp;indexed&nbsp;id:  
&nbsp;  
  
`Feature f = receiversLayer.InternalFeatures[r.SerialNumber];`  
&nbsp;  
You&nbsp;also&nbsp;can&nbsp;edit&nbsp;a&nbsp;feature&nbsp;like&nbsp;this:  
&nbsp;  
  
`receiversLayer.InternalFeatures[r.SerialNumber] = new Feature(rectShape);`  
&nbsp;  
You&nbsp;can&nbsp;have&nbsp;a&nbsp;try&nbsp;with&nbsp;these&nbsp;codes&nbsp;and&nbsp;hope&nbsp;this&nbsp;can&nbsp;help&nbsp;you.  
&nbsp;  
Any&nbsp;more&nbsp;questions&nbsp;please&nbsp;let&nbsp;me&nbsp;know.  
&nbsp;  
Thanks,  
&nbsp;  
sun

---

<div class="post-metadata">

**Author:** ![jmccrillis](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/ed655f/32.png) [@jmccrillis](https://community.thinkgeo.com/u/jmccrillis)\
**Post date:** [July 29, 2009, 1:20pm UTC](https://community.thinkgeo.com/t/updating-a-features-shape-dynamically/570/3 "2009-07-29T13:20:09Z")

</div>

Thank&nbsp;you,&nbsp;Sun,&nbsp;I've&nbsp;put&nbsp;these&nbsp;changes&nbsp;in&nbsp;and&nbsp;now&nbsp;it&nbsp;does&nbsp;work.&nbsp;  
  
  
  
Unfortunately,&nbsp;it's&nbsp;far&nbsp;too&nbsp;slow&nbsp;for&nbsp;what&nbsp;I&nbsp;need.&nbsp;When&nbsp;I&nbsp;increased&nbsp;my&nbsp;number&nbsp;of&nbsp;points&nbsp;(receivers)&nbsp;to&nbsp;10,000,&nbsp;the&nbsp;display&nbsp;locked&nbsp;up.&nbsp;Eventually&nbsp;I&nbsp;will&nbsp;need&nbsp;the&nbsp;ability&nbsp;to&nbsp;have&nbsp;up&nbsp;to&nbsp;60K-100K&nbsp;points.  
  
  
  
The&nbsp;behavior&nbsp;I&nbsp;need&nbsp;is&nbsp;to&nbsp;be&nbsp;able&nbsp;to&nbsp;update/change&nbsp;the&nbsp;shape&nbsp;and&nbsp;color&nbsp;of&nbsp;each&nbsp;point&nbsp;as&nbsp;new&nbsp;data&nbsp;comes&nbsp;in,&nbsp;at&nbsp;about&nbsp;4&nbsp;times&nbsp;per&nbsp;second.&nbsp;I&nbsp;need&nbsp;the&nbsp;points&nbsp;to&nbsp;update&nbsp;in&nbsp;groups&nbsp;or&nbsp;individually,&nbsp;rather&nbsp;than&nbsp;the&nbsp;entire&nbsp;map&nbsp;at&nbsp;once.&nbsp;  
  
  
  
Any&nbsp;help&nbsp;with&nbsp;setting&nbsp;this&nbsp;up&nbsp;to&nbsp;be&nbsp;as&nbsp;efficient&nbsp;and&nbsp;fast&nbsp;as&nbsp;it&nbsp;can&nbsp;be&nbsp;would&nbsp;be&nbsp;helpful,&nbsp;and&nbsp;is&nbsp;part&nbsp;of&nbsp;my&nbsp;product&nbsp;evaluation&nbsp;criteria.&nbsp;  
  
  
  
Here's&nbsp;my&nbsp;current&nbsp;version.&nbsp;I've&nbsp;played&nbsp;around&nbsp;with&nbsp;where&nbsp;to&nbsp;put&nbsp;the&nbsp;layer&nbsp;open&nbsp;and&nbsp;close,&nbsp;the&nbsp;lock&nbsp;and&nbsp;unlock,&nbsp;etc.&nbsp;  
  
  
  
Janene  
  
  
  
&nbsp;

`            InMemoryFeatureLayer receiversLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("ReceiversLayer");            Overlay ReceiversOverlay = winformsMap1.Overlays["ReceiversOverlay"];            try            {                // Lock the overlay while we update the points                ReceiversOverlay.Lock.EnterWriteLock();                receiversLayer.Open();                foreach (ReceiverUnit r in receivers.Values)                {                    Feature f = receiversLayer.InternalFeatures[r.SerialNumber];                    RectangleShape rectShape = f.GetBoundingBox();                     rectShape.UpperLeftPoint.Y = r.LatLong.Y + r.Noise*.01;                                                                                         Feature newFeat = new Feature(rectShape);                    newFeat.ColumnValues["SerialNumber"] = r.SerialNumber;                    newFeat.ColumnValues["Noise"] = r.Noise.ToString();                    receiversLayer.InternalFeatures[r.SerialNumber] = newFeat;                }            } catch (Exception ex) {                Console.WriteLine(ex.StackTrace);            } finally {                    // Release the lock on the overlay                    receiversLayer.Close();                      ReceiversOverlay.Lock.ExitWriteLock();                    winformsMap1.Refresh();                        }`

---

<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:** [July 30, 2009, 2:01am UTC](https://community.thinkgeo.com/t/updating-a-features-shape-dynamically/570/4 "2009-07-30T02:01:35Z")

</div>

Janene,

So&nbsp;you&nbsp;mean&nbsp;you&nbsp;just&nbsp;want&nbsp;to&nbsp;update/change&nbsp;the&nbsp;shape&nbsp;and&nbsp;color&nbsp;for&nbsp;a&nbsp;few&nbsp;features&nbsp;when&nbsp;new&nbsp;data&nbsp;comes&nbsp;in?&nbsp;I&nbsp;think&nbsp;you&nbsp;can&nbsp;change&nbsp;the&nbsp;current&nbsp;extent&nbsp;to&nbsp;a&nbsp;small&nbsp;bounding&nbsp;box&nbsp;which&nbsp;just&nbsp;contains&nbsp;the&nbsp;modified&nbsp;features&nbsp;when&nbsp;you&nbsp;need&nbsp;to&nbsp;refresh&nbsp;the&nbsp;map.&nbsp;  
&nbsp;  
In&nbsp;addition,&nbsp;you’d&nbsp;better&nbsp;try&nbsp;the&nbsp;IndexedInMemoryFeatureLayer&nbsp;instead&nbsp;of&nbsp;InMemoryFeatureLayer&nbsp;when&nbsp;the&nbsp;count&nbsp;of&nbsp;points&nbsp;is&nbsp;larger&nbsp;than&nbsp;10000,&nbsp;because&nbsp;it&nbsp;can&nbsp;improve&nbsp;the&nbsp;performance&nbsp;of&nbsp;finding&nbsp;the&nbsp;features&nbsp;to&nbsp;be&nbsp;drawn.&nbsp;You&nbsp;can&nbsp;find&nbsp;the&nbsp;code&nbsp;and&nbsp;get&nbsp;more&nbsp;information&nbsp;in&nbsp;the&nbsp;following&nbsp;link:  
&nbsp;  
[gis.thinkgeo.com/Support/Dis...fault.aspx](http://gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/16/aft/5266/afv/topic/Default.aspx)  
&nbsp;  
Any&nbsp;more&nbsp;questions&nbsp;please&nbsp;let&nbsp;me&nbsp;know.  
&nbsp;  
Thanks,  
&nbsp;  
Sun

---

<div class="post-metadata">

**Author:** ![jmccrillis](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/ed655f/32.png) [@jmccrillis](https://community.thinkgeo.com/u/jmccrillis)\
**Post date:** [July 30, 2009, 9:47am UTC](https://community.thinkgeo.com/t/updating-a-features-shape-dynamically/570/5 "2009-07-30T09:47:53Z")

</div>

Hi&nbsp;Sun,

I&nbsp;will&nbsp;need&nbsp;to&nbsp;change&nbsp;groups&nbsp;of&nbsp;features&nbsp;as&nbsp;the&nbsp;data&nbsp;comes&nbsp;in,&nbsp;probably&nbsp;100-200&nbsp;at&nbsp;a&nbsp;time,&nbsp;not&nbsp;just&nbsp;a&nbsp;few,&nbsp;but&nbsp;not&nbsp;the&nbsp;whole&nbsp;display&nbsp;of&nbsp;tens&nbsp;of&nbsp;thousands.

I&nbsp;was&nbsp;confused&nbsp;in&nbsp;the&nbsp;code&nbsp;that,&nbsp;while&nbsp;I&nbsp;wanted&nbsp;to&nbsp;edit&nbsp;the&nbsp;features&nbsp;only,&nbsp;I&nbsp;had&nbsp;to&nbsp;create&nbsp;new&nbsp;ones&nbsp;with&nbsp;the&nbsp;new&nbsp;rectangle,&nbsp;and&nbsp;then&nbsp;also&nbsp;had&nbsp;to&nbsp;add&nbsp;the&nbsp;custom&nbsp;data&nbsp;to&nbsp;the&nbsp;new&nbsp;features&nbsp;as&nbsp;well&nbsp;-&nbsp;this&nbsp;is&nbsp;a&nbsp;replace,&nbsp;not&nbsp;an&nbsp;edit,&nbsp;and&nbsp;as&nbsp;such&nbsp;is&nbsp;probably&nbsp;slower&nbsp;than&nbsp;it&nbsp;needs&nbsp;to&nbsp;be.&nbsp;

I&nbsp;will&nbsp;look&nbsp;at&nbsp;the&nbsp;Indexed&nbsp;version,&nbsp;thanks.&nbsp;

Janene

---

<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:** [July 30, 2009, 9:09pm UTC](https://community.thinkgeo.com/t/updating-a-features-shape-dynamically/570/6 "2009-07-30T21:09:53Z")

</div>

Janene,

I&nbsp;made&nbsp;a&nbsp;sample&nbsp;which&nbsp;is&nbsp;using&nbsp;the&nbsp;IndexedInMemoryFeatureLayer&nbsp;and&nbsp;update&nbsp;around&nbsp;100&nbsp;points&nbsp;(I&nbsp;create&nbsp;a&nbsp;random&nbsp;bounding&nbsp;box&nbsp;to&nbsp;get&nbsp;points&nbsp;from&nbsp;the&nbsp;tens&nbsp;of&nbsp;thousands&nbsp;points)&nbsp;each&nbsp;time.&nbsp;You&nbsp;can&nbsp;get&nbsp;the&nbsp;sample&nbsp;from&nbsp;the&nbsp;attachment&nbsp;and&nbsp;take&nbsp;a&nbsp;look.  
&nbsp;  
About&nbsp;the&nbsp;feature&nbsp;editing,&nbsp;as&nbsp;the&nbsp;feature&nbsp;is&nbsp;a&nbsp;structure&nbsp;and&nbsp;is&nbsp;value&nbsp;type,&nbsp;so&nbsp;edit&nbsp;a&nbsp;feature&nbsp;is&nbsp;just&nbsp;create&nbsp;a&nbsp;new&nbsp;instance&nbsp;to&nbsp;replace&nbsp;the&nbsp;original&nbsp;one.&nbsp;  
&nbsp;  
Please&nbsp;let&nbsp;me&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;any&nbsp;more&nbsp;questions.  
&nbsp;  
Thanks,  
&nbsp;  
sun&nbsp;&nbsp;  
  
[979-Post6047Demo.zip](https://community.thinkgeo.com/uploads/default/original/2X/9/9e9deb30bd62b7847fdb3a8b872da446a387216a.zip) (12.8 KB)
