Hi Ben,
please may a get an example (VisualBasic) to create new features in an existing dynamic layer.
I also would like to have an example to select and delete a feature in such a open layer.
Regards
Jörg
Hi Ben,
please may a get an example (VisualBasic) to create new features in an existing dynamic layer.
I also would like to have an example to select and delete a feature in such a open layer.
Regards
Jörg
Joerg,
We have already got an ideal sample. It’s in VB, showing how to create, edit, remove a feature and how to add it to a Dynamic Overlay. It’s within MapShapes ->DrawEditShapes along with the product, please have a look and let me know if you have any issues.
Thanks,
Ben
Hi Ben,
it is nice to use the example but this will not work on a postgreLayer. I have a going Save Subroutine for edited features, but the adding of new features is not possible. I give you both. My Save Subroutine and my adding a polygon Subroutine. Together they can't work.
regards Jörg
Protected Sub buttonDrawPolygon_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles buttonDrawPolygon.Click
If Map1.DynamicOverlay.Layers("EditLayer").IsVisible Then
Dim testlayer As PostgreSqlFeatureLayer = DirectCast(Map1.DynamicOverlay.Layers("EditLayer"), PostgreSqlFeatureLayer)
testlayer.Open()
Dim features As Collection(Of Feature) = testlayer.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns)
testlayer.Close()
Map1.EditOverlay.Features.Clear()
Map1.EditOverlay.TrackMode = TrackMode.Polygon
For Each Feature As Feature In features
Map1.EditOverlay.Features.Add(Feature.Id, Feature)
Next
Map1.DynamicOverlay.Layers("EditLayer").IsVisible = False
End If
End Sub
Public Sub SaveShapes(ByVal sender As Object, ByVal e As EventArgs)
If Not Map1.DynamicOverlay.Layers("EditLayer").IsVisible Then
'Dim testLayer As ShapeFileFeatureLayer = New ShapeFileFeatureLayer(MapPath("~/SampleData/Joerg/los.shp"), ShapeFileReadWriteMode.ReadWrite)
Dim connectString As String = "Server=geo-04;userId=postgres;Password=geodata;DataBase=schweiz;"
Dim los As New PostgreSqlFeatureLayer(connectString, "los", "gid")
los.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.StandardColors.Red, GeoColor.StandardColors.Red, 2)
'testLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Red, 1, True)
los.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
' Map1.DynamicOverlay.Layers.Add("test1", testLayer)
los.Open()
los.EditTools.BeginTransaction()
Dim features As Collection(Of Feature) = Map1.EditOverlay.Features
For Each feature As Feature In features
los.EditTools.Update(feature)
Next
los.EditTools.CommitTransaction()
los.Close()
Map1.EditOverlay.Features.Clear()
Map1.EditOverlay.TrackMode = TrackMode.None
Map1.DynamicOverlay.Layers("EditLayer").IsVisible = True
Map1.DynamicOverlay.Redraw()
End If
End Sub
Joerg
First, please make sure you are using the latest version (3.1.16) as we used to have some issue around editing features in the previous version.
We found a problem in the current version that when calling the method postGreFeatureSource.GetAllColumns(), it returns the Geometries column which might not supposed to be returned. This will lead to some problems also. So in this version, please do not get the geometries column using GetAllColumns() in PostgreLayer. Here we made a sample for you which works fine on my machine, please have a try.
Thanks,
Ben
490-PostgreEditSample.zip (14.9 KB)
Hi Ben,
thank you for your examples. The one subroutine saves very well the feature you produce (bounding box) in the other subroutine. May be I have today a bad day, but I am not able to change your example to my need.
I need to create new polygon features on my postgrelayer with the cursor.
Furthermore I want to select existing features in the layer and delete them or delete vertices of them.
May I ask you send me examples for that need.
Regards
Jörg
Joerg,
There is a tricky stuff for PostgreFeatureLayer, I have a bad day too until finally I figured it out after spending couples of hours on it. :-)
When we create a postgre layer, we need to setup a “featureIdColumn” which is very important that whenever you add a new feature to the layer, you MUST set that column otherwise new feature cannot be added. For example in the above demo, the featureIdColumn is set to “gid”, that means when I want to add a feature to the layer, I must set the “gid” value for that feature.
Here is how I create that layer,
Dim layer As New PostgreSqlFeatureLayer("Server=myServer;DataBase=myDataBase;UserId=userId;Password=password", "los", "gid")
So when I want to add a new feature, I need this
Dim feature As Feature = New Feature("POLYGON((1 1,5 1,5 5,1 5,1 1))")
feature.ColumnValues.Add("gid", "10")
layer.EditTools.Add(feature)
If we don't set the “gid” column, it will fail. If the “gid” cannot be converted to a interger like “abc”, it will fail. If the “gid” existed in the database, for example there is already one record exists in the feature source with the “gid” equals to “10” in the above sample, it will also fail. So when we add a feature, we should make sure we set a proper id for it, otherwise it just fail without any notifications. That is the reason you have no luck when drawing the feature on the map (they have no “gid” field) and then adding them to the layer.
I think a better solution might be that when adding a feature without a value in the id column, we just generate a new one automatically. I've add this to our tracking system and we will see what we can do to improve this. Thanks very much for pointing it out.
Thanks,
Ben
Hi Ben,
thank you much for your long work on my problem. Now I would like to have an example, how I can get the highest ID to add a new feature by the cursor or is there no chance to do such work on this version?
Regards Jörg
Joerg,
We don’t have a good way for this in the current version. You need to get all the existing features out and check what is the highest ID. We will consider all the postgre support issue and hopefully we can have a better solution in next version.
Thanks,
Ben