# Layer.GetBoundingBox question

**URL:** <https://community.thinkgeo.com/t/layer-getboundingbox-question/348>\
**Category:** WinForms\
**Created:** [April 13, 2009, 10:06am UTC](https://community.thinkgeo.com/t/layer-getboundingbox-question/348 "2009-04-13T10:06:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ted](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@Ted](https://community.thinkgeo.com/u/Ted)\
**Post date:** [April 13, 2009, 10:06am UTC](https://community.thinkgeo.com/t/layer-getboundingbox-question/348/1 "2009-04-13T10:06:39Z")

</div>

I&nbsp;have&nbsp;a&nbsp;custom&nbsp;layer&nbsp;that&nbsp;derives&nbsp;from&nbsp;a&nbsp;FeatureLayer.&nbsp;&nbsp;&nbsp;I&nbsp;need&nbsp;to&nbsp;get&nbsp;the&nbsp;bounding&nbsp;box&nbsp;for&nbsp;this&nbsp;layer.&nbsp;&nbsp;&nbsp;I&nbsp;was&nbsp;expecting&nbsp;the&nbsp;following&nbsp;to&nbsp;work:

GrowerLayer.Open();

&nbsp;

RectangleShape&nbsp;r&nbsp;=&nbsp;GrowerLayer.GetBoundingBox();

GrowerLayer.Close();

&nbsp;

However,&nbsp;this&nbsp;throws&nbsp;an&nbsp;exception&nbsp;on&nbsp;the&nbsp;GetBoundingBox&nbsp;call,&nbsp;indicating&nbsp;that&nbsp;there&nbsp;is&nbsp;no&nbsp;bounding&nbsp;box&nbsp;for&nbsp;the&nbsp;layer.

I&nbsp;can&nbsp;execute&nbsp;the&nbsp;following,&nbsp;though,&nbsp;and&nbsp;I'm&nbsp;fine:

GrowerLayer.FeatureSource.Open();

RectangleShape&nbsp;r&nbsp;=&nbsp;GrowerLayer.FeatureSource.GetBoundingBox();

GrowerLayer.FeatureSource.Close();

I&nbsp;can&nbsp;override&nbsp;the&nbsp;Layer.GetBoundingBoxCore()&nbsp;method,&nbsp;but&nbsp;I&nbsp;was&nbsp;expecting&nbsp;the&nbsp;base&nbsp;FeatureLayer&nbsp;implementation&nbsp;to&nbsp;open&nbsp;my&nbsp;FeatureSource&nbsp;and&nbsp;get&nbsp;teh&nbsp;BoundingBox&nbsp;automatically.&nbsp;

Maybe&nbsp;the&nbsp;issue&nbsp;(if&nbsp;there&nbsp;is&nbsp;one)&nbsp;is&nbsp;in&nbsp;the&nbsp;HasBoundingBox&nbsp;implementation&nbsp;instead?&nbsp;&nbsp;&nbsp;I&nbsp;assume&nbsp;that's&nbsp;used&nbsp;inside&nbsp;the&nbsp;GetBoundingBox&nbsp;function,&nbsp;to&nbsp;determine&nbsp;if&nbsp;an&nbsp;error&nbsp;should&nbsp;be&nbsp;thrown.

Can&nbsp;you&nbsp;confirm&nbsp;that&nbsp;1)&nbsp;I&nbsp;have&nbsp;an&nbsp;error&nbsp;in&nbsp;my&nbsp;implementation,&nbsp;2)&nbsp;that&nbsp;this&nbsp;is&nbsp;behavior&nbsp;as&nbsp;designed,&nbsp;or&nbsp;3)&nbsp;it&nbsp;is&nbsp;a&nbsp;bug&nbsp;that&nbsp;will&nbsp;be&nbsp;addressed?

Thanks!

---

<div class="post-metadata">

**Author:** ![Ted](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@Ted](https://community.thinkgeo.com/u/Ted)\
**Post date:** [April 13, 2009, 10:22am UTC](https://community.thinkgeo.com/t/layer-getboundingbox-question/348/2 "2009-04-13T10:22:21Z")

</div>

More&nbsp;info:&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;must&nbsp;override&nbsp;the&nbsp;Layer.HasBoundingBoxCore&nbsp;method&nbsp;in&nbsp;order&nbsp;to&nbsp;get&nbsp;past&nbsp;the&nbsp;Layer.GetBoundingBox&nbsp;check&nbsp;to&nbsp;determine&nbsp;that&nbsp;a&nbsp;bounding&nbsp;box&nbsp;&nbsp;is&nbsp;present.&nbsp;&nbsp;&nbsp;And,&nbsp;after&nbsp;doing&nbsp;that&nbsp;and&nbsp;overriding&nbsp;the&nbsp;Layer.GetBoundingBoxCore&nbsp;method,&nbsp;I&nbsp;get&nbsp;the&nbsp;expected&nbsp;results.&nbsp;&nbsp;&nbsp;&nbsp;If&nbsp;I&nbsp;don’t&nbsp;override&nbsp;the&nbsp;Layer.GetBoundingBoxCore&nbsp;method,&nbsp;then&nbsp;I&nbsp;get&nbsp;an&nbsp;error&nbsp;about&nbsp;the&nbsp;Layer&nbsp;not&nbsp;being&nbsp;open&nbsp;when&nbsp;I&nbsp;call&nbsp;GetBoundingBox.&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;I’m&nbsp;not&nbsp;sure&nbsp;how&nbsp;it&nbsp;is&nbsp;all&nbsp;supposed&nbsp;to&nbsp;work,&nbsp;but&nbsp;I&nbsp;don’t&nbsp;think&nbsp;it&nbsp;is&nbsp;working&nbsp;write.&nbsp;&nbsp;&nbsp;&nbsp;It&nbsp;is&nbsp;not&nbsp;a&nbsp;show-stopper,&nbsp;though.&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;And,&nbsp;be&nbsp;aware&nbsp;that&nbsp;I’m&nbsp;using&nbsp;the&nbsp;updated&nbsp;DLL’s&nbsp;from&nbsp;last&nbsp;week.

---

<div class="post-metadata">

**Author:** ![David](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@David](https://community.thinkgeo.com/u/David)\
**Post date:** [April 13, 2009, 10:30am UTC](https://community.thinkgeo.com/t/layer-getboundingbox-question/348/3 "2009-04-13T10:30:40Z")

</div>

Ted,&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;I&nbsp;am&nbsp;pretty&nbsp;sure&nbsp;what&nbsp;you&nbsp;are&nbsp;seeing&nbsp;is&nbsp;designed&nbsp;behavior,&nbsp;at&nbsp;least&nbsp;as&nbsp;per&nbsp;your&nbsp;first&nbsp;post.&nbsp;&nbsp;The&nbsp;reason&nbsp;is&nbsp;that&nbsp;there&nbsp;are&nbsp;some&nbsp;FeatureSources&nbsp;where&nbsp;it&nbsp;is&nbsp;not&nbsp;possible&nbsp;to&nbsp;calculate&nbsp;the&nbsp;bounding&nbsp;box&nbsp;or&nbsp;calculating&nbsp;it&nbsp;would&nbsp;take&nbsp;along&nbsp;time.&nbsp;&nbsp;Because&nbsp;of&nbsp;this&nbsp;we&nbsp;did&nbsp;not&nbsp;make&nbsp;the&nbsp;GetBoundingBoxCore&nbsp;a&nbsp;required&nbsp;abstract&nbsp;method.&nbsp;&nbsp;We&nbsp;did&nbsp;however&nbsp;want&nbsp;to&nbsp;note&nbsp;which&nbsp;FeatureSources&nbsp;do&nbsp;have&nbsp;this&nbsp;ability&nbsp;so&nbsp;we&nbsp;can&nbsp;take&nbsp;advantage&nbsp;of&nbsp;it&nbsp;in&nbsp;our&nbsp;drawing&nbsp;routines.&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;The&nbsp;pattern&nbsp;we&nbsp;use&nbsp;for&nbsp;optional&nbsp;Core&nbsp;methods&nbsp;that&nbsp;we&nbsp;want&nbsp;to&nbsp;support&nbsp;but&nbsp;not&nbsp;force&nbsp;you&nbsp;to&nbsp;implement&nbsp;is&nbsp;to&nbsp;have&nbsp;a&nbsp;concrete&nbsp;method&nbsp;like&nbsp;GetBoudningBox&nbsp;which&nbsp;checks&nbsp;another&nbsp;method&nbsp;like&nbsp;HasBoundingBox.&nbsp;&nbsp;The&nbsp;default&nbsp;for&nbsp;HasBoundingBox&nbsp;is&nbsp;false&nbsp;but&nbsp;it&nbsp;its&nbsp;getter&nbsp;is&nbsp;virtual&nbsp;and&nbsp;can&nbsp;be&nbsp;overridden.&nbsp;&nbsp;This&nbsp;gives&nbsp;you&nbsp;a&nbsp;way&nbsp;to&nbsp;check&nbsp;if&nbsp;the&nbsp;functionality&nbsp;is&nbsp;implemented&nbsp;before&nbsp;you&nbsp;try&nbsp;and&nbsp;call&nbsp;it.&nbsp;&nbsp;This&nbsp;is&nbsp;the&nbsp;same&nbsp;pattern&nbsp;that&nbsp;they&nbsp;use&nbsp;for&nbsp;Stream&nbsp;when&nbsp;they&nbsp;added&nbsp;Async&nbsp;Streams.&nbsp;&nbsp;It&nbsp;is&nbsp;a&nbsp;Microsoft&nbsp;pattern&nbsp;usually&nbsp;used&nbsp;when&nbsp;adding&nbsp;new&nbsp;functions&nbsp;to&nbsp;existing&nbsp;abstract&nbsp;classes&nbsp;where&nbsp;you&nbsp;do&nbsp;not&nbsp;want&nbsp;to&nbsp;break&nbsp;compatibility,&nbsp;or&nbsp;where&nbsp;you&nbsp;want&nbsp;the&nbsp;functionality&nbsp;to&nbsp;be&nbsp;optional.&nbsp;  
&nbsp;&nbsp;  
&nbsp;More&nbsp;to&nbsp;the&nbsp;point&nbsp;if&nbsp;you&nbsp;have&nbsp;a&nbsp;layer&nbsp;or&nbsp;feature&nbsp;source&nbsp;that&nbsp;you&nbsp;want&nbsp;to&nbsp;support&nbsp;the&nbsp;bounding&nbsp;box&nbsp;then&nbsp;you&nbsp;need&nbsp;to&nbsp;override&nbsp;the&nbsp;GetBoundigBoxCore&nbsp;and&nbsp;also&nbsp;the&nbsp;HasBoundingBox&nbsp;and&nbsp;have&nbsp;it&nbsp;return&nbsp;true&nbsp;otherwise&nbsp;we&nbsp;throw&nbsp;the&nbsp;error.&nbsp;&nbsp;&nbsp;The&nbsp;error&nbsp;is&nbsp;to&nbsp;let&nbsp;you&nbsp;know&nbsp;that&nbsp;this&nbsp;is&nbsp;not&nbsp;supported&nbsp;and&nbsp;to&nbsp;check&nbsp;the&nbsp;HasBoundingBox&nbsp;property.&nbsp;  
&nbsp;&nbsp;  
&nbsp;In&nbsp;the&nbsp;case&nbsp;you&nbsp;just&nbsp;mentioned&nbsp;where&nbsp;you&nbsp;override&nbsp;the&nbsp;HasBoundingBox&nbsp;and&nbsp;not&nbsp;the&nbsp;GetBoundignBoxCode&nbsp;then&nbsp;I&nbsp;am&nbsp;sure&nbsp;it&nbsp;was&nbsp;going&nbsp;to&nbsp;throw&nbsp;an&nbsp;error&nbsp;but&nbsp;not&nbsp;sure&nbsp;the&nbsp;error&nbsp;you&nbsp;reported&nbsp;was&nbsp;the&nbsp;right&nbsp;one.&nbsp;&nbsp;You&nbsp;need&nbsp;to&nbsp;override&nbsp;them&nbsp;in&nbsp;pairs.&nbsp;  
&nbsp;&nbsp;  
&nbsp;David

---

<div class="post-metadata">

**Author:** ![Ted](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@Ted](https://community.thinkgeo.com/u/Ted)\
**Post date:** [April 13, 2009, 10:42am UTC](https://community.thinkgeo.com/t/layer-getboundingbox-question/348/4 "2009-04-13T10:42:25Z")

</div>

Ahhhhhh…&nbsp;&nbsp;&nbsp;So&nbsp;Has\*&nbsp;is&nbsp;not&nbsp;a&nbsp;test&nbsp;of&nbsp;whether&nbsp;a&nbsp;specific&nbsp;instance&nbsp;of&nbsp;data&nbsp;has&nbsp;the&nbsp;specified&nbsp;content…&nbsp;it&nbsp;is&nbsp;an&nbsp;indication&nbsp;of&nbsp;whether&nbsp;the&nbsp;impmlementation&nbsp;supports&nbsp;the&nbsp;function.&nbsp;&nbsp;&nbsp;&nbsp;That&nbsp;is&nbsp;a&nbsp;piece&nbsp;of&nbsp;info&nbsp;that&nbsp;will&nbsp;be&nbsp;very&nbsp;useful&nbsp;to&nbsp;know&nbsp;moving&nbsp;forward&nbsp;:)&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks!

---

<div class="post-metadata">

**Author:** ![David](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@David](https://community.thinkgeo.com/u/David)\
**Post date:** [April 13, 2009, 10:55am UTC](https://community.thinkgeo.com/t/layer-getboundingbox-question/348/5 "2009-04-13T10:55:27Z")

</div>

Ted,&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;Yea&nbsp;we&nbsp;try&nbsp;and&nbsp;use&nbsp;‘Has’&nbsp;where&nbsp;it&nbsp;makes&nbsp;sense&nbsp;for&nbsp;properties&nbsp;and&nbsp;‘Can’&nbsp;for&nbsp;methods.&nbsp;&nbsp;GetBoudingBox&nbsp;is&nbsp;a&nbsp;strange&nbsp;one&nbsp;because&nbsp;it&nbsp;should&nbsp;usually&nbsp;be&nbsp;a&nbsp;property&nbsp;because&nbsp;a&nbsp;bounding&nbsp;box&nbsp;is&nbsp;an&nbsp;attribute&nbsp;of&nbsp;a&nbsp;FeatureSource&nbsp;however&nbsp;there&nbsp;is&nbsp;a&nbsp;rule&nbsp;to&nbsp;never&nbsp;make&nbsp;properties&nbsp;something&nbsp;that&nbsp;will&nbsp;ever&nbsp;take&nbsp;longer&nbsp;than&nbsp;a&nbsp;field&nbsp;access.&nbsp;&nbsp;This&nbsp;mean&nbsp;if&nbsp;you&nbsp;have&nbsp;to&nbsp;do&nbsp;any&nbsp;heavy&nbsp;computing&nbsp;then&nbsp;this&nbsp;should&nbsp;never&nbsp;be&nbsp;a&nbsp;property.&nbsp;&nbsp;Properties&nbsp;should&nbsp;return&nbsp;lightning&nbsp;fast&nbsp;and&nbsp;it&nbsp;is&nbsp;what&nbsp;people&nbsp;expect.&nbsp;&nbsp;If&nbsp;you&nbsp;have&nbsp;something&nbsp;that&nbsp;needs&nbsp;calculation&nbsp;that&nbsp;could&nbsp;take&nbsp;some&nbsp;time&nbsp;then&nbsp;it&nbsp;is&nbsp;recommended&nbsp;you&nbsp;use&nbsp;a&nbsp;method&nbsp;and&nbsp;put&nbsp;‘Get’&nbsp;in&nbsp;front&nbsp;of&nbsp;the&nbsp;name&nbsp;you&nbsp;would&nbsp;have&nbsp;used&nbsp;if&nbsp;it&nbsp;were&nbsp;a&nbsp;property.&nbsp;&nbsp;The&nbsp;‘Get’&nbsp;part&nbsp;makes&nbsp;it&nbsp;like&nbsp;a&nbsp;verb&nbsp;so&nbsp;it&nbsp;fits&nbsp;as&nbsp;a&nbsp;method,&nbsp;you&nbsp;know&nbsp;action&nbsp;type&nbsp;of&nbsp;things.&nbsp;&nbsp;If&nbsp;it&nbsp;were&nbsp;a&nbsp;straight&nbsp;method&nbsp;then&nbsp;we&nbsp;would&nbsp;have&nbsp;used&nbsp;‘Can’&nbsp;as&nbsp;the&nbsp;prefix.&nbsp;&nbsp;Maybe&nbsp;that&nbsp;is&nbsp;what&nbsp;is&nbsp;should&nbsp;have&nbsp;been,&nbsp;we&nbsp;were&nbsp;caught&nbsp;in&nbsp;a&nbsp;strange&nbsp;spot&nbsp;that&nbsp;the&nbsp;rules&nbsp;didn’t&nbsp;cover&nbsp;so&nbsp;we&nbsp;went&nbsp;with&nbsp;the&nbsp;property&nbsp;style&nbsp;since&nbsp;it&nbsp;is&nbsp;in&nbsp;spirit&nbsp;a&nbsp;property&nbsp;type&nbsp;thing.&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;David

---

<div class="post-metadata">

**Author:** ![David](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@David](https://community.thinkgeo.com/u/David)\
**Post date:** [April 13, 2009, 11:02am UTC](https://community.thinkgeo.com/t/layer-getboundingbox-question/348/6 "2009-04-13T11:02:21Z")

</div>

Ted,&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;We&nbsp;actually&nbsp;discussed&nbsp;‘Supports’&nbsp;as&nbsp;a&nbsp;prefix&nbsp;and&nbsp;had&nbsp;a&nbsp;big&nbsp;argument&nbsp;about&nbsp;it.&nbsp;&nbsp;The&nbsp;reason&nbsp;we&nbsp;didn’t&nbsp;go&nbsp;with&nbsp;it&nbsp;was&nbsp;we&nbsp;could&nbsp;not&nbsp;find&nbsp;any&nbsp;Microsoft&nbsp;examples&nbsp;of&nbsp;it.&nbsp;&nbsp;On&nbsp;the&nbsp;flip&nbsp;side&nbsp;we&nbsp;could&nbsp;find&nbsp;lots&nbsp;of&nbsp;Has&nbsp;and&nbsp;Can&nbsp;examples.&nbsp;&nbsp;Maybe&nbsp;Microsoft&nbsp;got&nbsp;this&nbsp;wrong.&nbsp;:-)&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;will&nbsp;tell&nbsp;you&nbsp;that&nbsp;designing&nbsp;an&nbsp;extensible&nbsp;API&nbsp;is&nbsp;a&nbsp;really&nbsp;tough&nbsp;job.&nbsp;&nbsp;There&nbsp;are&nbsp;a&nbsp;mountain&nbsp;of&nbsp;rules&nbsp;and&nbsp;I&nbsp;can&nbsp;tell&nbsp;you&nbsp;every&nbsp;API&nbsp;in&nbsp;the&nbsp;Core&nbsp;has&nbsp;a&nbsp;purpose&nbsp;and&nbsp;was&nbsp;designed&nbsp;to&nbsp;be&nbsp;in&nbsp;compliance&nbsp;with&nbsp;the&nbsp;design&nbsp;guidelines&nbsp;as&nbsp;to&nbsp;the&nbsp;best&nbsp;of&nbsp;our&nbsp;abilities.&nbsp;&nbsp;That&nbsp;is&nbsp;not&nbsp;to&nbsp;say&nbsp;we&nbsp;didn’t&nbsp;screw&nbsp;some&nbsp;things&nbsp;up&nbsp;but&nbsp;I&nbsp;personally&nbsp;sat&nbsp;through&nbsp;more&nbsp;reviews&nbsp;where&nbsp;we&nbsp;just&nbsp;went&nbsp;over&nbsp;API&nbsp;guidelines&nbsp;then&nbsp;I&nbsp;care&nbsp;to&nbsp;remember.&nbsp;&nbsp;What&nbsp;is&nbsp;crazy&nbsp;is&nbsp;that&nbsp;even&nbsp;on&nbsp;the&nbsp;50th&nbsp;review&nbsp;you&nbsp;can&nbsp;always&nbsp;find&nbsp;something.&nbsp;&nbsp;It&nbsp;is&nbsp;very&nbsp;hard&nbsp;to&nbsp;enforce&nbsp;a&nbsp;huge&nbsp;number&nbsp;of&nbsp;rules&nbsp;on&nbsp;a&nbsp;large&nbsp;API.&nbsp;&nbsp;Ok,&nbsp;I&nbsp;will&nbsp;get&nbsp;of&nbsp;my&nbsp;soap&nbsp;box&nbsp;now.&nbsp;  
&nbsp;&nbsp;  
&nbsp;David
