This project is read-only.

Two fields, Same Name

Feb 20, 2013 at 3:31 PM
I took over a project from a coworker who left the company. His knowledge of GIS was fair but he missed some rules about shapefiles. In particular he creates two fields in a shapefile with the same name. I'm surprised MW allows this and doesn't thrown an exception.

Now my problem is that I want to update the labeling to he 4.8 labeling engine. When I generate my labels like so
sf.Labels.Generate("[Start Poin]", MapWinGIS.tkLabelPositioning.lpFirstSegment, True)
Well since there are two fields with that name it uses the first one it finds. But I need to use the second one. I don't want to change too much of the code as other routines could depend on the structure of the shapefile. Is there anything I can do to work around this?

Feb 21, 2013 at 9:46 AM
The only option you have is to rename one of the fields. Renaming the second field will make sense because it will never be used anyway.
I don't know if it is no longer possible to add duplicate field names with the latest version. It was certainly possible with older versions.

Feb 21, 2013 at 11:16 AM
I've reproduced this behavior with the current SVN version.
I've submitted an issue report about it at

Feb 21, 2013 at 7:53 PM
The creation of the shapefile is done via the MW4.8 Framework. But the MW application does request that one of the fields be renamed. Is that done in memory or does that get committed to the shapefile?

I'm thinking more of what I should do here. Many of his routines base their labeling on field index. That can easily change so wanted to be more clever and use the field name and employ the new labeling engine. I think if in other parts he uses the field index that will not change for the time being as I'm not changing that. If I change the field name to something proper then I will have to change the second field. As you said if I change the first field then that could change which field gets chosen. Changing the second field will not matter because if they have the same name then calling it by name will never chose the second field.