ThinkGeo.com    |     Documentation    |     Premium Support

Displaying a PolygonShape feature in the FeatureSource.GetFeaturesInsideBoundingBoxCore override

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


 


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




    service_area
    
        
            service_area_id
            area_name
            minim_long_nbr
            minim_lat_nbr
            maxim_long_nbr
            maxim_lat_nbr
        
    
    
        
            428
            West Palm Beach
            -80.17157
            26.78963
            -79.95124
            26.93378
        
    
    


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



 


 


{


 


protected override Collection<Feature> GetFeaturesInsideBoundingBoxCore(RectangleShape boundingBox, 

IEnumerable<string> returningColumnNames)Collection<Feature> returnFeatures = new Collection<Feature>();

 


try

{


 


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


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

 


{


 


 


 


 


 


 


 


 


 


pointShapes.Add(


pointShapes.Add(


pointShapes.Add(


pointShapes.Add(


pointShapes.Add(


 


 


polygonShape.Id = service_area_id +


 


 


{


 


{


feature.ColumnValues.Add(dc.ColumnName,


}


}


returnFeatures.Add(feature);


rectangleShape.Id = polygonShape.Id +


feature = rectangleShape.GetFeature();


 


{


 


{


feature.ColumnValues.Add(dc.ColumnName,


}


}


returnFeatures.Add(feature);


 


pointShape.Id = service_area_id +


feature = pointShape.GetFeature();


 


{


 


{


feature.ColumnValues.Add(dc.ColumnName,


}


}


returnFeatures.Add(feature);


}


}


 


{


 


}


 


boundingBox.ToString()));


 


}


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>();new Vertex(rectangleShape.UpperLeftPoint));new Vertex(rectangleShape.UpperRightPoint));new Vertex(rectangleShape.LowerLeftPoint));new Vertex(rectangleShape.LowerRightPoint));new Vertex(es.Center));RingShape ringShape = new RingShape(pointShapes);PolygonShape polygonShape = new PolygonShape(ringShape);"x";Feature feature = polygonShape.GetFeature();foreach(DataColumn dc in dt.Columns)if (!dr.IsNull(dc))Convert.ToString(dr[dc]));"y";foreach(DataColumn dc in dt.Columns)if (!dr.IsNull(dc))Convert.ToString(dr[dc]));PointShape pointShape = new PointShape(minim_long_nbr, minim_lat_nbr);"z";foreach (DataColumn dc in dt.Columns)if (!dr.IsNull(dc))Convert.ToString(dr[dc]));catch(Exception ex)Debug.WriteLine(ex.ToString());Debug.WriteLine(String.Format("Found {0} items in {1} bounding box", returnFeatures.Count, return returnFeatures; 


 


 


 


 



Well, the source code didn’t come over cleanly, so I am going to try again: 
  
   
 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;  
 } 
 


Gregory, 
  
 Your code of creating a Polygon Shape is fine. Can you try printing out the WellKnowText of every feature at the end of the GetFeaturesInsideBoundingBoxCore() to make sure there are nothing strange there. The code should be like this 
 
  Collection<Feature> returnFeatures = new Collection<Feature>();

            foreach (Feature feature in returnFeatures)
            {
                Debug.WriteLine(feature.GetWellKnownText());
            }
 
 and the WKT of a Polygon should be similar like  
 “POLYGON((0 30,0 20,0 10,0 40,0 30))” 
  
 If that part is fine, maybe something wrong with the render part, can you show me how you render the polygons, and can you change the map’s current extent to one of the polygon’s bounding box so we can make sure the polygon is inside the viewport. Also make sure the ApplyUntilZoomLevel is from ZoomLevel01 to ZoomLevel20 so it has no chance to be invisible just because zoomlevels.  
  
 Let me know what you find. 
  
 Thanks, 
  
 Ben