I tried running it with the value converted to integer and I still get the same error.
The following link has an archive with the reference shapefiles and the modified shapefiles
Field Conversion
Only the dbf file is modified by typecasting the code_ess field for all records.
Conversion using pyshp
library
Source code for conversion
def read_contents(r):
# Get Fields and Records
fields = r.fields
records = [record.as_dict() for record in r.records()]
# Change CODE_ess field type
fields.pop(0)
fields.pop()
fields.append(['CODE_ess', 'N', 7, 0])
# Typecast existing records CODE_ess field to int
for record in records:
record['CODE_ess'] = int(record['CODE_ess'])
return (fields, records)
def write_contents(w, fields, records):
# Add fields
fnames = []
for field in fields:
fnames.append(field[0])
w.field(field[0], field[1], field[2], field[3])
# Add records
for record in records:
w.record(record[fnames[0]], record[fnames[1]],
record[fnames[2]], record[fnames[3]],
record[fnames[4]], record[fnames[5]],
record[fnames[6]], record[fnames[7]],
record[fnames[8]], record[fnames[9]])
for dbf in glob.glob(join(path['shapefiles'], "*.dbf")):
r = shapefile.Reader(dbf)
fields, records = read_contents(r)
r = r.close()
w = shapefile.Writer(dbf=dbf)
write_contents(w, fields, records)
w.close()
Field Types Comparison
Last Element in list should be different.
According to pyshp docs (…github.com/GeospatialPython/pyshp#reading-records), before code_ess
is a string, and after is an integer
# Before
[('DeletionFlag', 'C', 1, 0), ['ID', 'C', 24, 0], ['CODE_TFV', 'C', 9, 0], ['TFV', 'C', 61, 0], ['TFV_G11', 'C', 34, 0], ['ESSENCE', 'C', 26, 0], ['SURF', 'N', 11, 4], ['code_tfv_2', 'C', 254, 0], ['Nomenc_CES', 'C', 254, 0], ['Nom_nomenc', 'C', 254, 0], ['CODE_ess', 'C', 254, 0]]
# After
[('DeletionFlag', 'C', 1, 0), ['ID', 'C', 24, 0], ['CODE_TFV', 'C', 9, 0], ['TFV', 'C', 61, 0], ['TFV_G11', 'C', 34, 0], ['ESSENCE', 'C', 26, 0], ['SURF', 'N', 11, 4], ['code_tfv_2', 'C', 254, 0], ['Nomenc_CES', 'C', 254, 0], ['Nom_nomenc', 'C', 254, 0], ['CODE_ess', 'N', 7, 0]]
Using QGIS to observe field type
Error - Training Output (Conda 7.1.0rc1)
2020-03-04 13:59:03 (INFO) TrainImagesClassifier: Default RAM limit for OTB is 256 MB
2020-03-04 13:59:03 (INFO) TrainImagesClassifier: GDAL maximum cache size is 396 MB
2020-03-04 13:59:03 (INFO) TrainImagesClassifier: OTB will use at most 8 threads
2020-03-04 13:59:03 (INFO) TrainImagesClassifier: Polygon analysis...
2020-03-04 13:59:03 (INFO) TrainImagesClassifier: Elevation management: setting default height above ellipsoid to 0 meters
2020-03-04 13:59:03 (INFO): Estimated memory for full processing: 27592.9MB (avail.: 256 MB), optimal image partitioning: 108 blocks
2020-03-04 13:59:03 (INFO): Estimation will be performed in 109 blocks of 10980x101 pixels
Analyze polygons...: 100% [**************************************************] (40s)
2020-03-04 13:59:44 (INFO) TrainImagesClassifier: Sampling rates...
2020-03-04 13:59:44 (INFO) TrainImagesClassifier: Sampling strategy : fit the number of samples based on the smallest class
2020-03-04 13:59:44 (INFO) TrainImagesClassifier: Sampling rates for image 1 : className requiredSamples totalSamples rate
1111100 183 1321599 0.000138469
1113100 183 1730 0.10578
1114111 183 85373 0.00214353
1115000 183 12527 0.0146084
1116000 183 97413 0.0018786
1117000 183 55220 0.00331402
1125000 183 3691622 4.95717e-05
1130000 183 96827 0.00188997
1211000 183 817767 0.00022378
1213000 183 12432 0.0147201
1216000 183 183 1
1225000 183 15952 0.0114719
1230000 183 288 0.635417
1381100 183 563297 0.000324873
1390000 183 7329 0.0249693
2000000 183 142900 0.00128062
4000000 183 95736 0.00191151
5000000 183 5963 0.0306893
2020-03-04 13:59:44 (INFO) TrainImagesClassifier: Sample selection...
2020-03-04 13:59:44 (INFO) TrainImagesClassifier: Elevation management: setting default height above ellipsoid to 0 meters
2020-03-04 13:59:44 (INFO) TrainImagesClassifier: Sampling strategy : set number of samples for each class
2020-03-04 13:59:44 (INFO) TrainImagesClassifier: Sampling rates : className requiredSamples totalSamples rate
1111100 183 1321599 0.000138469
1113100 183 1730 0.10578
1114111 183 85373 0.00214353
1115000 183 12527 0.0146084
1116000 183 97413 0.0018786
1117000 183 55220 0.00331402
1125000 183 3691622 4.95717e-05
1130000 183 96827 0.00188997
1211000 183 817767 0.00022378
1213000 183 12432 0.0147201
1216000 183 183 1
1225000 183 15952 0.0114719
1230000 183 288 0.635417
1381100 183 563297 0.000324873
1390000 183 7329 0.0249693
2000000 183 142900 0.00128062
4000000 183 95736 0.00191151
5000000 183 5963 0.0306893
2020-03-04 13:59:44 (INFO): Estimated memory for full processing: 27592.9MB (avail.: 256 MB), optimal image partitioning: 108 blocks
2020-03-04 13:59:44 (INFO): Estimation will be performed in 121 blocks of 1056x1056 pixels
Selecting positions with periodic sampler...: 100% [**************************************************] (1m 05s)
2020-03-04 14:00:49 (INFO) TrainImagesClassifier: Sample extraction...
2020-03-04 14:01:27 (INFO): Estimated memory for full processing: 41390MB (avail.: 256 MB), optimal image partitioning: 162 blocks
2020-03-04 14:01:27 (INFO): Estimation will be performed in 162 blocks of 10980x68 pixels
Extracting sample values...: 100% [**************************************************] (3m 13s)
2020-03-04 14:04:40 (INFO) TrainImagesClassifier: Model training...
2020-03-04 14:04:40 (INFO) TrainImagesClassifier: Reading vector file 1/1
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-17-f517d1d44ee0> in <module>
18 app.SetParameterString("io.out", join(path['stacked'], "model.rf"))
19
---> 20 app.ExecuteAndWriteOutput()
~/anaconda3/envs/orfeo/lib/otb/python/otbApplication.py in ExecuteAndWriteOutput(self)
2799
2800 def ExecuteAndWriteOutput(self):
-> 2801 return _otbApplication.Application_ExecuteAndWriteOutput(self)
2802
2803 def ConnectImage(self, arg2, app, out):
RuntimeError: stod