question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can i remove a point on a layer and in the datatable?

See original GitHub issue

Hi guys, I have a point layer, where i can add point on this layer with id, values etc… These values are in the datatable too, how can i delete a point on the map with a simple button or by clicking on the point which delete the point values in the datatable and the point symbol on the map. I tried pointF.RemoveShapeAt(idOfThePoint) but it did’nt work. Thank for your help !

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jany-tenajcommented, Oct 11, 2017

Check whether the feature you deleted has a FID that is not -1 if you remove the feature after reopening the project.

Please also check whether the Features have been initialized before you select the feature you want to remove.

If your layer is in IndexMode the feature gets created from the vertices and can’t be found inside DataSet.Features so it can’t be removed.

As far as I remember I run the following code on layers after reopening projects to make sure I can use them afterwards without errors.

if (!fLayer.DataSet.AttributesPopulated) fLayer.DataSet.FillAttributes();
fLayer.DataSet.IndexMode = false;
1reaction
jany-tenajcommented, Jan 24, 2017

You might solve this in two ways.

  1. Don’t add the point before the user has left the dialog.
                     if ((pointmouseClick))
                        {
                            frmValid f = new frmValid();
                            f.Show(); //if this is a form you might use ShowDialog to make sure the form is closed before you continue

                            if (Passerrelle.pass.ann) //add the point only if the user didn't click cancel
                            {
                                GeoAPI.Geometries.Coordinate coord = map1.PixelToProj(e.Location);
                                NetTopologySuite.Geometries.Point point = new NetTopologySuite.Geometries.Point(coord);

                                IFeature currentFeature = pointF.AddFeature(point);
                                pointID = pointID + 1; //don't use this to find the pointID, it could differ from the actual pointID of your currentFeature

                                currentFeature.DataRow["Référence"] = fichier + Passerrelle.pass.reff;
                                currentFeature.DataRow["Date"] = auj;
                                currentFeature.DataRow["hmoy"] = Passerrelle.pass.hmoy;

                            }
                            map1.Refresh();
                            map1.ResetBuffer();
                            map1.FunctionMode = FunctionMode.Pan;
                            map1.Cursor = Cursors.Default;
                            pointmouseClick = false; 
                        }
  1. Call the code I posted in my first answer to clean the lists:
                     if ((pointmouseClick))
                        {
                            frmValid f = new frmValid();
                            f.Show();
                            
                            GeoAPI.Geometries.Coordinate coord = map1.PixelToProj(e.Location);
                            NetTopologySuite.Geometries.Point point = new NetTopologySuite.Geometries.Point(coord);

                            IFeature currentFeature = pointF.AddFeature(point);
                            pointID = pointID + 1;
                            
                            if (Passerrelle.pass.ann == false)
                            {
                                pointF.Features.Remove(currentFeature); // remove currentFeature directly, you can't be sure that your pointID belongs to currentFeature

                                pointF.UpdateExtent(); //update the extent of the existing features
                                pointF.InitializeVertices(); //updates the vertex array so it no longer contains the delete feature vertices
                                pointLayer.AssignFastDrawnStates(); //updates the FastDrawn states
                            }
                            else
                            {
                                currentFeature.DataRow["Référence"] = fichier + Passerrelle.pass.reff;
                                currentFeature.DataRow["Date"] = auj;
                                currentFeature.DataRow["hmoy"] = Passerrelle.pass.hmoy;

                            }
                            map1.Refresh();
                            map1.ResetBuffer();
                            map1.FunctionMode = FunctionMode.Pan;
                            map1.Cursor = Cursors.Default;
                            pointmouseClick = false; 
                        }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove columns from DataTable in C# - Stack Overflow
To remove all columns after the one you want, below code should work. It will remove at index 10 (remember Columns are 0...
Read more >
Removing a data source from a data table
On the authoring bar, click Data canvas . · Make sure the data table of interest is selected. · In the data canvas,...
Read more >
Also, can't create second table after remove()/destroy()
I would like to be able to create a second table after removing/destroying the first table. The flow is Map Selection > Ajax...
Read more >
Deleting records in a table—ArcMap | Documentation
Right-click the table or layer in the table of contents and choose Open Attribute Table. Select the records you want to delete. Press...
Read more >
Why can I not duplicate a data table column.
If you imported the points from a spreadsheet it would be simpler to delete the layer, make the headers of the columns identical...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found