This project is read-only.

Meaning and usage of AttributeTable

Jan 25, 2012 at 4:47 PM

Can someone educate me? When I create a new point shape file and add features, the datatable gets updated as expected, but the AttributeTable stays empty. Therefore, I cannot use lyr.Dataset.NumRows to see if the table is empty, I need to use lyr.Dataset.Datatable.Rows.Count.

Why are there essentially two datatables assigned to the featureset? When adding features, am I supposed to add records to both?



Jan 25, 2012 at 5:18 PM

I am trying to perform a simple operation on a point shape file, like .Features.RemoveAt(i). When I do so on a point shape file I create myself using New FeatureSet(DotSpatial.Topology.FeatureType.Point), the object is a featureset. When I save that shapefile and reload it, the object is a PointShapeFile (thus the AttributeTable question above). 

Just to get this thing working, I tried creating my new shapefile using New PointShapeFile, and populating the features and datatable myself. When I do a Save, I get exceptions regarding the FID column already existing.

Anyway, my code seems to be working at the moment using my original method (create as featureset, open as pointshapefile) as long as I use .datatable.rows.count for both.

It is just a bit confusing.

Jan 25, 2012 at 5:38 PM

If all you are wanting to do is manipulate a shapefile (i.e. not in the context of a MapLayer) you might want to look at the ShapeFileFeatureSource objects.  I use those a lot to add/delete/modify features in shapefiles.  It works well for very large shapefiles where you don't want to read everything into memory and may be faster for cases where you only want to manipulate a few features.