相关文章推荐

I am getting the error "System.InvalidCastException:'Unable to cast object of type 'ArcGIS.Core.Data.Field' to type  'System.IConvertible'. I am pretty sure this worked for me before, but I got this error when I applied it to the "Shape_Area" field. If anyone encountered the same problem, how did you resolve it? Thanks!

 Field areaField = modelSoilsDef.GetFields().FirstOrDefault(x => x.Name.Contains("Shape_Area"));
                        var Area = Convert.ToDouble(areaField);

Hi,

First, you don't need use Linq to find field.

Field areaField = modelSoilsDef.FindField("Shape_Area");

To find spatial fields like area or length don't use strings like "Shape_Area". Name of spatial field could depend on database type. Use ArcGIS Pro SDK for these fields:

string areaFieldName = modelSoilsDef.GetAreaField();

And the last thing. As I understand you want to read row value of field "Shape_Area". Your code could look like this:

var Area =  Convert.ToDouble(row[modelSoilsDef.GetAreaField()]);

If you want to read more than one row:

string areaFieldName = modelSoilsDef.GetAreaField();
// inside row cursor
var Area =  Convert.ToDouble(row[areaFieldName]);

Hi,

First, you don't need use Linq to find field.

Field areaField = modelSoilsDef.FindField("Shape_Area");

To find spatial fields like area or length don't use strings like "Shape_Area". Name of spatial field could depend on database type. Use ArcGIS Pro SDK for these fields:

string areaFieldName = modelSoilsDef.GetAreaField();

And the last thing. As I understand you want to read row value of field "Shape_Area". Your code could look like this:

var Area =  Convert.ToDouble(row[modelSoilsDef.GetAreaField()]);

If you want to read more than one row:

string areaFieldName = modelSoilsDef.GetAreaField();
// inside row cursor
var Area =  Convert.ToDouble(row[areaFieldName]);

 
推荐文章