Select to view content in your preferred language

Reading shapefile with C# EasyGIS

3492
6
11-23-2020 01:56 AM
MattiasWesterberg
Occasional Contributor

I am trying to read a shapefile using EasyGIS with C#.

My code seems to work except for the last row were i call the GetRecord method.

The exception i get is:

System.ArgumentException: 'fieldIndex must be <= DBFRecordHeader.NumFields and >=0'

What am i doing wrong?

 

string path = System.IO.Directory.GetCurrentDirectory();
EGIS.ShapeFileLib.ShapeFile shapeFile = new EGIS.ShapeFileLib.ShapeFile();
shapeFile.LoadFromFile(path + "\\CD_VIC_06_imr.shp");
string[] record = shapeFile.GetRecords(shapeFile.RenderSettings.FieldIndex);

 

Thank you!

0 Kudos
6 Replies
ManishPatel
Esri Contributor

Hi @MattiasWesterberg ,

 

I would debug and verify through the breakpoints if the shapefile was able to read and load through the path.

Also, while in debug mode you might check if the

shapeFile.RenderSettings.FieldIndex

returns the desired value.

 

Cheers,

Manish

Cheers,
Manish
MattiasWesterberg
Occasional Contributor

shapeFile.RenderSettings.FieldIndex is -1.
What could be the reason for that?

0 Kudos
MattiasWesterberg
Occasional Contributor
shapeFile.RenderSettings.FieldIndex is -1.
What could be the reason for that?
0 Kudos
ManishPatel
Esri Contributor

@MattiasWesterberg ,

If no FieldName is set or FieldName is not in the DBF file Field index returns -1.

When you debug does the shapeFile contain any values, if not then you might want to check the path for the shapefile. You can try to to hard code the path to the shapefile and try if it is able to read that.

 

Cheers,

Manish

Cheers,
Manish
MattiasWesterberg
Occasional Contributor

Thanks.

Do you know how i can get the coordinates?

0 Kudos
MattiasWesterberg
Occasional Contributor

How do i get the long and lat values?

0 Kudos