ThinkGeo.com    |     Documentation    |     Premium Support

How to make a saved polygon editable

Hi Yale,


I have no problem in saving and displaying the saved polyzon as shown in the following code. My problem is: after showing the saved polygon, i cannot apply the "Track&Edit Shape" functionality of MapSuite 4.0 to edit the polygon.Could you tell me which statement should be added  in the t label1_Click below to achieve the edit goal?


Thanks a lot for your guidance.


Franklin


void trackOverlay_TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e) 



PolygonShape polygonShape = (PolygonShape)e.TrackShape; 



Collection<dbfcolumn></dbfcolumn> dbfColumns = new Collection<dbfcolumn></dbfcolumn>(); 

dbfColumns.Add(new DbfColumn("POLYID", DbfColumnType.String, 10, 0)); 

dbfColumns.Add(new DbfColumn("NAME", DbfColumnType.String, 10, 0)); 

Feature editFeature = new Feature((PolygonShape)e.TrackShape); // I am not sure how to do this properly. 

editFeature.ColumnValues.Add("Name", "Yale"); // as suggested 





ShapeFileFeatureLayer.CreateShapeFile(ShapeFileType.Polygon, @"C:\testOnload\testLoad.shp", dbfColumns, Encoding.UTF8, OverwriteMode.DoNotOverwrite); 



ShapeFileFeatureLayer shapeFileFetureLayer = new ShapeFileFeatureLayer(@"C:\testOnload\testLoad.shp", ShapeFileReadWriteMode.ReadWrite); 

try 



shapeFileFetureLayer.Open(); 

shapeFileFetureLayer.EditTools.BeginTransaction(); 

shapeFileFetureLayer.EditTools.Add(polygonShape); 

TransactionResult result = shapeFileFetureLayer.EditTools.CommitTransaction(); 



finally 



shapeFileFetureLayer.Close(); 







// The code below is used to display the saved shape.

private void label1_Click(object sender, EventArgs e) 



winformsMap1.MapUnit = GeographyUnit.DecimalDegree; 

ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"C:\testOnload\testLoad.shp"); 



worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(100, GeoColor.SimpleColors.Black)); 



worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; 



LayerOverlay layerOverlay = new LayerOverlay(); 



// Add the shapefile layer to the layer overlay 

layerOverlay.Layers.Add(worldLayer); 





winformsMap1.Overlays.Add(layerOverlay); 



winformsMap1.Refresh(); 







 


 


 



Fraklin,


Thanks for your post and sample code. Try following code, hope it helps.

// The code below is used to display the saved shape.
        private void label1_Click(object sender, EventArgs e)
        {
            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
            ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"C:\testOnload\testLoad.shp");
 
            worldLayer.Open();
            Collection<Feature> allFeatures = worldLayer.QueryTools.GetAllFeatures(ReturningColumnsType.NoColumns);
 
            winformsMap1.TrackOverlay.TrackMode = TrackMode.None;
            foreach (Feature feature in allFeatures)
            {
                winformsMap1.EditOverlay.EditShapesLayer.InternalFeatures.Add(feature);
            }
            winformsMap1.EditOverlay.CalculateAllControlPoints();
            winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear();
 
       
            worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(100, GeoColor.SimpleColors.Black));
 
            worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
 
            LayerOverlay layerOverlay = new LayerOverlay();
 
            // Add the shapefile layer to the layer overlay 
            layerOverlay.Layers.Add(worldLayer);
 
 
            winformsMap1.Overlays.Add(layerOverlay);
 
            winformsMap1.Refresh();
 
        } 

 
Any more questions please feel free to let me know.
Thanks.
Yale

Yale, 
  
    Applying the method suggested, the saved polygon appears immediately in edit mode after clicking the load button;and the edit mode works fine. Thanks. 
 What changes will be in the code if the saved polygon is displayed as a normal polygon (as if it is first created) and the polygon will appear in the edit mode only after clicking the "Edit" button? 
 Thanks a lot for your help. You are a real pro. 
  
 Franklin

Franklin, 
  
 Thanks for your post and feedback. 
  
 If we do not add the saved polygon into the EditShapeLayer in the EditOverlay, then it will not be in EditMode, and we add it into a normal InmemoryFeatureLayer, then it will be displayed as a normal polygon. 
  
 If I am not clear, please feel free to let me know. 
  
 Thanks. 
  
 Yale