Yale,
I am not so clear what sort of event handler can accomplish the purpose of saving a polygon which is modified by the Track-Shape button functionality. How will the desktop API detect the end of the editing process?
Thanks.
Franklin
Yale,
I am not so clear what sort of event handler can accomplish the purpose of saving a polygon which is modified by the Track-Shape button functionality. How will the desktop API detect the end of the editing process?
Thanks.
Franklin
Franklin,
Thanks for your post and questions.
We have several types of edit operations in our edit system, that is Drag/Resize/Rotate/Vertex(Add,Remove,Move), so you can find following events related which type of operation you are doing against in the EditOverlay of MapControl.
winformsMap1.EditOverlay.FeatureDragged
winformsMap1.EditOverlay.FeatureResized
winformsMap1.EditOverlay.FeatureRotated
winformsMap1.EditOverlay.VertexAdded
winformsMap1.EditOverlay.VertexMoved
winformsMap1.EditOverlay.VertexRemoved
Any more questions please feel free to let me know.
Thanks.
Yale
Hi Yale,
Suppose I have created several polygons on a map and want to save all these shapse into database by clicking the save button.
In order to do so, I need
1.) create a polygon layer
2.) add these shapes as features into the layer
I am not clear about the syntax for creating such a polygon layer. Could you please shed light on this by a short example? Thanks.
Franklin
Franklin,
Thanks for your post and question.
I hope I did not mistake anything. We probably can use the InmemoryFeatureLayer to hold that polygon features, which is the simplest way to do this.
Any more questions please do not hesitate to let me know.
Thanks.
Yale
Yale,
OK, once InmemoryFeatureLayer is instantiated, we can use it to call InternalFeature.add("Polygon1", Feature(…))
1.) how would the application find out the number of Polygons drawn before the save button is clicked?
2.) how am I going to add all the polygon features via the InternalFeature.add (…)? (the syntax?)
3.) how am I going to use FindFeatureLayer to get the vertexis of each of the polygon feature?
Thanks.
Franklin
Franklin,
Thanks for your post and questions.
1) If you are using the track system of the map control to create those polygons, then all the polygons are stored in the TrackShapeLayer. So you can get the count by using the following statement:
int count = winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Count;
2) I am not sure what is the real problem is and I thought you have shown me the answer at the begging of the previous post.
3) FindFeatureLayer only find the target feature layer, it cannot get the vertices out for the polygons. Try the following steps:
Step1: Use the API find feature layer to get the target layer and convert it into InmemoryFeatureLayer.
Step2: Loop each feature and get shape for it and convert it to polygon.
Step3: Get the vertices of out ring and each inner rings; I think that is the vertices we need.
Any more questions please do not hesitate to let me know.
Thanks.
Yale
Yale,
If the TrackShapeLayer keeps all the drawn polygons already, it seems that "internal feature add" step above can be skipped. Thanks for the guidance.
Regards,
Franklin
Yale,
I am not sure how to get the drawn polygons kept at TrackShapeLayer. Is there a way of converting TrackShapeLayer to InMemoryFeatureLayer?
Can you show a example of getting feature from InMemoryFeatureLayer?
Thanks a lot.
Franklin
Franklin,
TrackShapeLayer is a InMemoryFeatureLayer, that means TrackShapeLayer’s type is InMemoryFeatureLayer, all features are stored at InternalFeatures property which is a GeoCollection you can get feature from it.
Please let us know if you have more question.
Thanks
James
Hi James,
Is it possible to get IEnumerable PolygonShape
<polygonshape></polygonshape>
from the InternalFeatures property? I don't know how to do it syntically.
Have you got a clue on this?
Thanks.
Franklin
Franklin,
Yes, each Feature has a shape, you can use feauture.GetShape() and convert to PolygonShape, if you’re not sure if it is PolygonShape or not, you can check shape.GetWellKnowType().
Thanks
James
James,
Thanks. I have tried what you said as version 2 of the CovertPolygonLayerToZones method attached.
Still the multipolygonshape instance created doesn't contain the polygon drawn on the application map and same exception occurs.
My questions are
1.) Does the TrackShapeLayer automatically save the feature (i.e. a polygon) drawn on the map?
2.) What goes wrong in the code specifically?
3.) How to construct the multipolygonShape instance correctly, which should contain the polygon or polygons drawn on the map?
Thanks a lot.
Franklin
FeatureLayerProblem.txt (3.29 KB)
Franklin,
Thanks for your detail information.
Your sample code can not compiled and has some logic problem I don't think you can run it, maybe it's not your really code, but still give me some information that can solve your problem.
First, at trackOverlay_TrackEnded, you add layer with the same key for each time, so that when you track the second polygon it will throw exception "An item with the same key has already been added.".
Second, I don't know how this code works?
"IEnumerable allPolygons = polygLayer.FeatureSource .GetAllFeatures(ReturningColumnsType.AllColumns) .OfType (); "
My code can get the MultipolygonShape: IEnumerable<Feature> allFeatures = polygLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.NoColumns);
Collection<PolygonShape> allPolygons = new Collection<PolygonShape>();
foreach (Feature feature in allFeatures)
{
allPolygons.Add((PolygonShape)feature.GetShape());
}
MultipolygonShape mpolyg = new MultipolygonShape(allPolygons);
I think right now you have already found the answers for your three questions.
Please let me know if you still can not fix it.
Thanks
James