ThinkGeo.com    |     Documentation    |     Premium Support

GetBoundingBox and InMemoryFeatureSource

Hi all,


I'm trying to follow the demo of the bounding box, and I'm just not having any luck.  The problem occurs when I'm trying to create the InMemoryFeatureSource.  VS gives me an error stating 'An Item with the same key has already been added.'  I assumed this was an error on my part, but wasn't sure.  I started looking into the API, however, and I can't figure out the constructor for the InMemoryFeatureSource.  Why is the first IEnumberable<FeatureSourceColumn> needed?  Maybe I just don't understand the purpose of the class, but shouldn't the second list of <Features> take care of anything the first list would need?   Code follows, if it's of any use, though it's not working.


 


 



    public void GetBoundingBoxByInMemoryMarkerOverlay(InMemoryMarkerOverlay inMem)
    {
        if (inMem.Features.Count > 1)
        {
            Collection<Feature> features = new Collection<Feature>();
            foreach(string key in inMem.Features.Keys){
                features.Add(inMem.Features[key]);
            }
            InMemoryFeatureSource inMemSource = new InMemoryFeatureSource(new List<FeatureSourceColumn>(), features);
            inMemSource.Open();
            MainMap.CurrentExtent = inMemSource.GetBoundingBox();
            inMemSource.Close();
        }

    }



So, I figured out what I was doing wrong with the BoundingBox, so please disregard that part of the question.  As suspected, it was the fault of my code.  However, the other part of the post regarding the InMemoryFeatureSource I would greatly like to know more about.  Thanks again.



Dustin, 



InMemoryMarkerOverlay itself can get the BoudingBox very easily. Here is the code. 


  public void GetBoundingBoxByInMemoryMarkerOverlay(InMemoryMarkerOverlay inMem)
      {
            MainMap.CurrentExtent = inMem.FeatureSource.GetBoundingBox();
      }

Maybe you don’t need it now but still wants to let you know that in the feature, we only have the content of the tabular data, and the first parameter IEnumerable<featuresourcecolumn></featuresourcecolumn> provides the columns of the tabular data. Here is a sample which can make you easier to understand. 




// Create 2 columns, "Name" and "Population"
            Collection<FeatureSourceColumn> columns = new Collection<FeatureSourceColumn>();
            columns.Add(new FeatureSourceColumn("Name"));
            columns.Add(new FeatureSourceColumn("Population"));
            
            // Create the column fields for the feature "Lawrence"
            Dictionary<string, string> LawrenceColumns = new Dictionary<string,string>();
            LawrenceColumns.Add("Name", "Lawrence");
            LawrenceColumns.Add("Population", "81000");

            // Create the feature "Lawrence"
            Feature Lawrence = new Feature(new PointShape("Point(-95.253199 38.959902)"), LawrenceColumns);

            // Create the InMemoryFeatureSource
            InMemoryFeatureSource inMemoryFeatureSource = new InMemoryFeatureSource(columns, new Feature[] { Lawrence });




Let us know for more queries. 



Thanks, 



Ben