I'm porting an app from V2 to V4 and am a bit confused about how drawing and saving shapes now works.
Let's say I have 3 drop down menus. The first one allows me to draw a point, the second a line and the third a polygon.
In V2 I would create 3 shape files and corresponding layers, do a BeginEdit on the correct layer then CommitEdit when finished drawing.
On V4 I have to use TrackInteractiveOverlay. I have it quite happily drawing all 3 shape types on one layer but now want to save.
Do I have to have 3 overlays if I want to save to 3 different shape files? I can't see how this would work as to start drawing I simply say map.TrackOverlay.TrackMode = xx.
Also, how do I then load the shape files in the future and allow them to be edited?
Thanks for your post and questions. I think it depends on where you want to save. It is possible to save point, line and polygon into one InmemoryFeatureLayer while it is impossible to save them into one specified shape file because they are belonging to different types of shapes. According to the shape file specification, one shape file can only store one type of shapes, either in point or line or area. When you want to edit the shapes no matter they are stored in shape file or inmemory, just load it into EditIntertativeOverlay. Any more questions please feel free to let me know. Thanks. Yang
Let’s say I have 4 drop down menu’s. The first is bus stops and allows point to be drawn, the second is park benches and is points, the third is bridges and is lines and the last id bandstands and is polygons. Each of the 4 types needs to be saved into a different shape file on the hard disk.
In V2 it was easy. Each shape file was a separate layer. I just saved the layer and the shape file was updated.
I’m not sure what to do in v4. All 4 shapes will be drawn on the one layer. How do I save the shapes? I can iterate through all the shapes on the layer but how do I match them with the files they need to be stored in?
Thanks for your feedback. Why not use the WellKnownType to identify the feature type? Hope it helps. WellKnownType wellKnownType = basShape.GetWellKnownType();
Any more questions please feel free to ask. Thanks. Yale
Thanks for your post and feedback. I am sorry if I misunderstand anything. Let me make sure what we are going to achieve. Let us say we have 4 features in the InmemoryFetureLayer: Feture1---- AreaType. Feture2--- LineType Feture3--- PointType Feture4----LineType When we want to save those features into disk-based shape files, we have to save them into three files: a.shp ---- Polygon type b.shp---- Polyline type c.shp ---- point type
Then when a feature come in for save, we use the API GetWellKnownType to determine which file we will save it to. Anything unclear please feel free to let me know. Thanks. Yale
Thanks for your post and feedback. I do not think there is an existing API to determine a feature is already exists in a shape or not, the simplest way is to loop each feature in the shape to compare with the target feature ,while this will cause some performance issue if the shape contains too many features. This performance problem can be avoided by using some spatial query APIs like GetFeaturesInsideBoundingBox to get some candidate features first. Following code snippet shows you how to save a feature into an existing shape file, hope it helps.
ShapeFileFeatureLayer shapeFileLayer = new ShapeFileFeatureLayer(@"a.shp", ShapeFileReadWriteMode.ReadWrite); shapeFileLayer.Open(); try { shapeFileLayer.EditTools.BeginTransaction(); shapeFileLayer.EditTools.Add(feature); TransactionResult result = shapeFileLayer.EditTools.CommitTransaction(); } finally { shapeFileLayer.Close(); }
Any more questions please feel free to let me know. Thanks. Yang