How to Get Shape Name

1.4k Views Asked by At

Using DotSpatial, if I open a Shapefile as an IFeatureSet, I can see a collection of shapes within the FeatureSet and these shapes have collections of attributes. But I can't see an obvious way of finding the name associated to the shape?

For example, if I have the following code:

var featureSet = Shapefile.Open("../../Ecuador/map.shp");

var rowCount = featureSet.NumRows();

for (var i = 0; i < rowCount; i++)
{
    var shape = featureSet.GetShape(i, true);
    var geometry = shape.ToGeometry();
}

If I debug into this code by putting a breakpoint on the Shape object I can see a collections of attributes. In the example I'm using, each shape has 12 attributes. I can see that one of these attributes is what I would consider to be the name of the shape (in this example I'm looking at the provinces of Ecuador), but I have no idea how to reliably pair which one of these attributes would be the shape name, in this case the name of the province.


Edit

Here is an example of the available attributes I can see for the first shape:

Image of available shape attributes

From a quick look, I'd say that the attribute at index 4 was the one I need, but how do I find this out programmatically?


Further Edit

It looks as though, through further poking about in the data that the labels for the attributes might be the DataTable Column names in the IFeatureSet:

Image of data table column values

Although... which of these would I pick programmatically if I wanted to import these shapes? Is the only way to allow the person doing the import to manually pick the correct one?

1

There are 1 best solutions below

0
On BEST ANSWER

I found a page called Importing Geographic Information Systems (GIS) data in Google Earth.

The process to import from a shapefile shows a screenshot where the user is asked to select the attribute that contains the names for the shapes, from a table of available attributes.

Image showing the selecting of the name field

It looks as though the task of attaching names to features is handled manually by the user.