ThinkGeo.com    |     Documentation    |     Premium Support

Load Polygon String into Layer

Hello,


I am using the following to get the polygon description: GetWellKnownText().  Then I save the string to a datable.  My question is once I retrieve the polygon string, how do I create a dynamic layer (InMemoryFeatureLayer drawZoneLayer ) that represents that polygon?


   InMemoryFeatureLayer drawZoneLayer = (InMemoryFeatureLayer)Map1.DynamicOverlay.Layers["ZoneLayer"];

   drawZoneLayer.InternalFeatures.Clear();


   foreach(Feature features in Map1.EditOverlay.Features)

   {

    if(!drawZoneLayer.InternalFeatures.Contains(features.Id))

    {

     this._hdnPolygonString.Value = features.GetWellKnownText().ToString();

    }

   }


  protected void LoadPolygon()

  {

   ShapeFileFeatureSource featureSource = new ShapeFileFeatureSource(this._hdnPolygonString.Value);

   InMemoryFeatureLayer drawZoneLayer = (InMemoryFeatureLayer)Map1.DynamicOverlay.Layers["ZoneLayer"];


   // Load Polygon description here.


   Map1.DynamicOverlay.Redraw();

  }


Thanks, Steven



Steven, 
  
 You need to create a new Feature that represents the Polygon and then add that Feature to your InMemoryFeatureLayer. 
  
 
Feature feature = new Feature(WKT);
drawZoneLayer.InternalFeatures.Add(feature);
 
  
 Here are 2 suggestions for your code  
 1, GetWellKnownText() returns a string already, we do not need to add ToString() behind it 
 2, I’m not sure what does that ShapeFileFeatureSource for, but anyway, the parameter in the constructor is supposed to be the shapefile name, but not a WKT of a shape. 
  
 Hope that helps. :) 
  
 Thanks, 
  
 Ben