# Displaying a PolygonShape feature in the FeatureSource.GetFeaturesInsideBoundingBoxCore override

**URL:** <https://community.thinkgeo.com/t/displaying-a-polygonshape-feature-in-the-featuresource-getfeaturesinsideboundingboxcore-override/275>\
**Category:** WinForms\
**Created:** [March 10, 2009, 3:01pm UTC](https://community.thinkgeo.com/t/displaying-a-polygonshape-feature-in-the-featuresource-getfeaturesinsideboundingboxcore-override/275 "2009-03-10T15:01:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregory](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@Gregory](https://community.thinkgeo.com/u/Gregory)\
**Post date:** [March 10, 2009, 3:01pm UTC](https://community.thinkgeo.com/t/displaying-a-polygonshape-feature-in-the-featuresource-getfeaturesinsideboundingboxcore-override/275/1 "2009-03-10T15:01:55Z")

</div>

I&nbsp;have&nbsp;created&nbsp;a&nbsp;FeatureSource.GetFeaturesInsideBoundingBoxCore&nbsp;override&nbsp;using&nbsp;the&nbsp;ExtendingMapSuiteFeatureSource&nbsp;sample&nbsp;solution.&nbsp;I&nbsp;can&nbsp;create&nbsp;features&nbsp;from&nbsp;PointShapes&nbsp;and&nbsp;from&nbsp;RectangleShapes,&nbsp;but&nbsp;the&nbsp;features&nbsp;I&nbsp;create&nbsp;from&nbsp;PolygonShapes&nbsp;do&nbsp;not&nbsp;display.&nbsp;

&nbsp;

For&nbsp;the&nbsp;sake&nbsp;of&nbsp;argument,&nbsp;I&nbsp;use&nbsp;the&nbsp;same&nbsp;records&nbsp;from&nbsp;the&nbsp;database&nbsp;to&nbsp;create&nbsp;the&nbsp;PointShape,&nbsp;RectangleShape&nbsp;and&nbsp;PolygonShape&nbsp;features.&nbsp;The&nbsp;data&nbsp;looks&nbsp;like&nbsp;so:

&nbsp;&nbsp;&nbsp;&nbsp; **service\_area**  
&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp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sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-79.95124  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;26.93378  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;

My&nbsp;code&nbsp;appears&nbsp;below.&nbsp;The&nbsp;same&nbsp;record&nbsp;is&nbsp;used&nbsp;to&nbsp;create&nbsp;the&nbsp;polygon,&nbsp;rectangle&nbsp;and&nbsp;point.&nbsp;I&nbsp;can&nbsp;comment&nbsp;out&nbsp;the&nbsp;code&nbsp;blocks&nbsp;one&nbsp;at&nbsp;a&nbsp;time,&nbsp;to&nbsp;demonstrate&nbsp;that&nbsp;features&nbsp;display&nbsp;in&nbsp;the&nbsp;map&nbsp;only&nbsp;for&nbsp;the&nbsp;point&nbsp;and&nbsp;rectangle,&nbsp;and&nbsp;not&nbsp;the&nbsp;polygon.&nbsp;I&nbsp;am&nbsp;sure&nbsp;the&nbsp;problem&nbsp;lies&nbsp;with&nbsp;the&nbsp;way&nbsp;I&nbsp;declare&nbsp;the&nbsp;vertices&nbsp;and&nbsp;construct&nbsp;the&nbsp;polygon&nbsp;from&nbsp;them,&nbsp;but&nbsp;can&nbsp;not&nbsp;be&nbsp;sure.&nbsp;Your&nbsp;advice&nbsp;is&nbsp;appreciated.

&nbsp;

&nbsp;

{

&nbsp;

protected&nbsp;override&nbsp;Collection\<Feature\>&nbsp;GetFeaturesInsideBoundingBoxCore(RectangleShape&nbsp;boundingBox,&nbsp;  
  
IEnumerable\<string\>&nbsp;returningColumnNames)Collection\<Feature\>&nbsp;returnFeatures&nbsp;=&nbsp;new&nbsp;Collection\<Feature\>();

&nbsp;

try

{

&nbsp;

boundingBox.UpperLeftPoint.Y,&nbsp;boundingBox.LowerRightPoint.Y);

DataTable&nbsp;dt&nbsp;=&nbsp;Data.Regions.GetRegions(boundingBox.LowerRightPoint.X,&nbsp;boundingBox.UpperLeftPoint.X,

&nbsp;

{

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

pointShapes.Add(

pointShapes.Add(

pointShapes.Add(

pointShapes.Add(

pointShapes.Add(

&nbsp;

&nbsp;

polygonShape.Id&nbsp;=&nbsp;service\_area\_id&nbsp;+

&nbsp;

&nbsp;

{

&nbsp;

{

feature.ColumnValues.Add(dc.ColumnName,

}

}

returnFeatures.Add(feature);

rectangleShape.Id&nbsp;=&nbsp;polygonShape.Id&nbsp;+

feature&nbsp;=&nbsp;rectangleShape.GetFeature();

&nbsp;

{

&nbsp;

{

feature.ColumnValues.Add(dc.ColumnName,

}

}

returnFeatures.Add(feature);

&nbsp;

pointShape.Id&nbsp;=&nbsp;service\_area\_id&nbsp;+

feature&nbsp;=&nbsp;pointShape.GetFeature();

&nbsp;

{

&nbsp;

{

feature.ColumnValues.Add(dc.ColumnName,

}

}

returnFeatures.Add(feature);

}

}

&nbsp;

{

&nbsp;

}

&nbsp;

boundingBox.ToString()));

&nbsp;

}

foreach(DataRow&nbsp;dr&nbsp;in&nbsp;dt.Rows)double&nbsp;minim\_long\_nbr&nbsp;=&nbsp;Convert.ToDouble(dr["minim\_long\_nbr"]);double&nbsp;maxim\_long\_nbr&nbsp;=&nbsp;Convert.ToDouble(dr["maxim\_long\_nbr"]);double&nbsp;minim\_lat\_nbr&nbsp;=&nbsp;Convert.ToDouble(dr["minim\_lat\_nbr"]);double&nbsp;maxim\_lat\_nbr&nbsp;=&nbsp;Convert.ToDouble(dr["maxim\_lat\_nbr"]);string&nbsp;service\_area\_id&nbsp;=&nbsp;Convert.ToString(dr["service\_area\_id"]);string&nbsp;area\_name&nbsp;=&nbsp;Convert.ToString(dr["area\_name"]);EllipseShape&nbsp;es&nbsp;=&nbsp;new&nbsp;EllipseShape(new&nbsp;PointShape(minim\_long\_nbr,&nbsp;minim\_lat\_nbr),&nbsp;400,&nbsp;GeographyUnit.DecimalDegree,&nbsp;DistanceUnit.Feet);RectangleShape&nbsp;rectangleShape&nbsp;=&nbsp;es.GetBoundingBox();List\<Vertex\>&nbsp;pointShapes&nbsp;=&nbsp;new&nbsp;List\<Vertex\>();new&nbsp;Vertex(rectangleShape.UpperLeftPoint));new&nbsp;Vertex(rectangleShape.UpperRightPoint));new&nbsp;Vertex(rectangleShape.LowerLeftPoint));new&nbsp;Vertex(rectangleShape.LowerRightPoint));new&nbsp;Vertex(es.Center));RingShape&nbsp;ringShape&nbsp;=&nbsp;new&nbsp;RingShape(pointShapes);PolygonShape&nbsp;polygonShape&nbsp;=&nbsp;new&nbsp;PolygonShape(ringShape);"x";Feature&nbsp;feature&nbsp;=&nbsp;polygonShape.GetFeature();foreach(DataColumn&nbsp;dc&nbsp;in&nbsp;dt.Columns)if&nbsp;(!dr.IsNull(dc))Convert.ToString(dr[dc]));"y";foreach(DataColumn&nbsp;dc&nbsp;in&nbsp;dt.Columns)if&nbsp;(!dr.IsNull(dc))Convert.ToString(dr[dc]));PointShape&nbsp;pointShape&nbsp;=&nbsp;new&nbsp;PointShape(minim\_long\_nbr,&nbsp;minim\_lat\_nbr);"z";foreach&nbsp;(DataColumn&nbsp;dc&nbsp;in&nbsp;dt.Columns)if&nbsp;(!dr.IsNull(dc))Convert.ToString(dr[dc]));catch(Exception&nbsp;ex)Debug.WriteLine(ex.ToString());Debug.WriteLine(String.Format("Found&nbsp;{0}&nbsp;items&nbsp;in&nbsp;{1}&nbsp;bounding&nbsp;box",&nbsp;returnFeatures.Count,&nbsp;return&nbsp;returnFeatures;&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![Gregory](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@Gregory](https://community.thinkgeo.com/u/Gregory)\
**Post date:** [March 10, 2009, 3:10pm UTC](https://community.thinkgeo.com/t/displaying-a-polygonshape-feature-in-the-featuresource-getfeaturesinsideboundingboxcore-override/275/2 "2009-03-10T15:10:57Z")

</div>

Well,&nbsp;the&nbsp;source&nbsp;code&nbsp;didn’t&nbsp;come&nbsp;over&nbsp;cleanly,&nbsp;so&nbsp;I&nbsp;am&nbsp;going&nbsp;to&nbsp;try&nbsp;again:&nbsp;  
&nbsp;&nbsp;  
&nbsp;`   protected override Collection<Feature> GetFeaturesInsideBoundingBoxCore(RectangleShape boundingBox,       IEnumerable<string> returningColumnNames)    {        Collection<Feature> returnFeatures = new Collection<Feature>();      try        {            DataTable dt = Data.Regions.GetRegions(boundingBox.LowerRightPoint.X, boundingBox.UpperLeftPoint.X,              boundingBox.UpperLeftPoint.Y, boundingBox.LowerRightPoint.Y);            foreach(DataRow dr in dt.Rows)          {              double minim_long_nbr = Convert.ToDouble(dr[“minim_long_nbr”]);              double maxim_long_nbr = Convert.ToDouble(dr[“maxim_long_nbr”]);              double minim_lat_nbr = Convert.ToDouble(dr[“minim_lat_nbr”]);              double maxim_lat_nbr = Convert.ToDouble(dr[“maxim_lat_nbr”]);              string service_area_id = Convert.ToString(dr[“service_area_id”]);                string area_name = Convert.ToString(dr[“area_name”]);                EllipseShape es = new EllipseShape(new PointShape(minim_long_nbr, minim_lat_nbr), 400,                   GeographyUnit.DecimalDegree, DistanceUnit.Feet);                RectangleShape rectangleShape = es.GetBoundingBox();                List<Vertex> pointShapes = new List<Vertex>();                pointShapes.Add(new Vertex(rectangleShape.UpperLeftPoint));              pointShapes.Add(new Vertex(rectangleShape.UpperRightPoint));              pointShapes.Add(new Vertex(rectangleShape.LowerLeftPoint));              pointShapes.Add(new Vertex(rectangleShape.LowerRightPoint));              pointShapes.Add(new Vertex(es.Center));                RingShape ringShape = new RingShape(pointShapes);              PolygonShape polygonShape = new PolygonShape(ringShape);              polygonShape.Id = service_area_id + “x”;                Feature feature = polygonShape.GetFeature();                foreach(DataColumn dc in dt.Columns)              {                  if (!dr.IsNull(dc))                  {                      feature.ColumnValues.Add(dc.ColumnName, Convert.ToString(dr[dc]));                  }              }                returnFeatures.Add(feature);                rectangleShape.Id = polygonShape.Id + “y”;              feature = rectangleShape.GetFeature();                foreach(DataColumn dc in dt.Columns)              {                  if (!dr.IsNull(dc))                  {                      feature.ColumnValues.Add(dc.ColumnName, Convert.ToString(dr[dc]));                  }              }                returnFeatures.Add(feature);                PointShape pointShape = new PointShape(minim_long_nbr, minim_lat_nbr);              pointShape.Id = service_area_id + “z”;              feature = pointShape.GetFeature();                foreach (DataColumn dc in dt.Columns)              {                  if (!dr.IsNull(dc))                  {                      feature.ColumnValues.Add(dc.ColumnName, Convert.ToString(dr[dc]));                  }              }                returnFeatures.Add(feature);          }      }      catch(Exception ex)      {          Debug.WriteLine(ex.ToString());      }      Debug.WriteLine(String.Format(“Found {0} items in {1} bounding box”, returnFeatures.Count,           boundingBox.ToString()));      return returnFeatures;   }  `

---

<div class="post-metadata">

**Author:** ![Ben](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ben/32/25720_2.png) [@Ben](https://community.thinkgeo.com/u/Ben)\
**Post date:** [March 11, 2009, 2:50am UTC](https://community.thinkgeo.com/t/displaying-a-polygonshape-feature-in-the-featuresource-getfeaturesinsideboundingboxcore-override/275/3 "2009-03-11T02:50:25Z")

</div>

Gregory,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Your&nbsp;code&nbsp;of&nbsp;creating&nbsp;a&nbsp;Polygon&nbsp;Shape&nbsp;is&nbsp;fine.&nbsp;Can&nbsp;you&nbsp;try&nbsp;printing&nbsp;out&nbsp;the&nbsp;WellKnowText&nbsp;of&nbsp;every&nbsp;feature&nbsp;at&nbsp;the&nbsp;end&nbsp;of&nbsp;the&nbsp;GetFeaturesInsideBoundingBoxCore()&nbsp;to&nbsp;make&nbsp;sure&nbsp;there&nbsp;are&nbsp;nothing&nbsp;strange&nbsp;there.&nbsp;The&nbsp;code&nbsp;should&nbsp;be&nbsp;like&nbsp;this&nbsp;  
&nbsp;`  Collection<Feature> returnFeatures = new Collection<Feature>();            foreach (Feature feature in returnFeatures)            {                Debug.WriteLine(feature.GetWellKnownText());            }`&nbsp;  
&nbsp;and&nbsp;the&nbsp;WKT&nbsp;of&nbsp;a&nbsp;Polygon&nbsp;should&nbsp;be&nbsp;similar&nbsp;like&nbsp;&nbsp;  
&nbsp;“POLYGON((0&nbsp;30,0&nbsp;20,0&nbsp;10,0&nbsp;40,0&nbsp;30))”&nbsp;  
&nbsp;&nbsp;  
&nbsp;If&nbsp;that&nbsp;part&nbsp;is&nbsp;fine,&nbsp;maybe&nbsp;something&nbsp;wrong&nbsp;with&nbsp;the&nbsp;render&nbsp;part,&nbsp;can&nbsp;you&nbsp;show&nbsp;me&nbsp;how&nbsp;you&nbsp;render&nbsp;the&nbsp;polygons,&nbsp;and&nbsp;can&nbsp;you&nbsp;change&nbsp;the&nbsp;map’s&nbsp;current&nbsp;extent&nbsp;to&nbsp;one&nbsp;of&nbsp;the&nbsp;polygon’s&nbsp;bounding&nbsp;box&nbsp;so&nbsp;we&nbsp;can&nbsp;make&nbsp;sure&nbsp;the&nbsp;polygon&nbsp;is&nbsp;inside&nbsp;the&nbsp;viewport.&nbsp;Also&nbsp;make&nbsp;sure&nbsp;the&nbsp;ApplyUntilZoomLevel&nbsp;is&nbsp;from&nbsp;ZoomLevel01&nbsp;to&nbsp;ZoomLevel20&nbsp;so&nbsp;it&nbsp;has&nbsp;no&nbsp;chance&nbsp;to&nbsp;be&nbsp;invisible&nbsp;just&nbsp;because&nbsp;zoomlevels.&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;Let&nbsp;me&nbsp;know&nbsp;what&nbsp;you&nbsp;find.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Ben
