box - 'NoneType' object has no attribute 'index' while exporting HEC-RAS

0 votes
105 views
asked Jun 21 by Loren Amelang

I've progressed past several more bugs in other software, and I'm back to RiverGIS, and apparently ready to export my HEC-RAS file. But I get this:

AttributeError: 'NoneType' object has no attribute 'index'

I found http://q2a.rivergis.com/153/error-python-code-creating-import-file?show=153#q153

"As a workaround, you could create a dummy 1D reach with 2 xsections to enable the export to SDF."

But I'm still learning the 1D process. As far as I know I have pure 1D CrossSections. But I just noticed the CrossSections are in the "PROFILES" shapefiles that SAGA made. My RiverGIS XSCutLines layer has no data.

So I used Database -> Import Layers...  and selected my PROFILES file. The QGIS "Show feature count" option still shows '0' for XSCutLines, but now it draws my cutlines on the map. And the export works! At least it makes a big file with appropriate-looking data in it:

#This file is generated by RiverGIS, a QGIS plugin (http://rivergis.com)
BEGIN HEADER:
   DTM TYPE: GRID
   DTM:
   STREAM LAYER: rivergis@127.0.0.1/ridge1/StreamCenterlines
   NUMBER OF REACHES: 3
   CROSS-SECTION LAYER: rivergis@127.0.0.1/ridge1/XSCutLines
   NUMBER OF CROSS-SECTIONS: 1435
   MAP PROJECTION:
   PROJECTION ZONE:
   DATUM:
   VERTICAL DATUM:
   BEGIN SPATIAL EXTENT:
      XMIN: 6182619.17887215
      YMIN: 2218322.56405207
      XMAX: 6220726.92902117
      YMAX: 2252061.87504029
   END SPATIAL EXTENT:
      UNITS: FEET
END HEADER:

So I guess I've answered my own question. Guess I'll leave this here in case it might help someone else... 

Still, how can an empty data file cause Python to not know the properties of a "box"?

\rivergis\ras_gis_import.py
...

   def spatial_extent(self):
        qry = 'SELECT ST_Extent(geom) FROM "{0}"."XSCutLines";'
        qry = qry.format(self.schema)
        box = self.rgis.rdb.run_query(qry, fetch=True)[0][0]
        box_min = box[box.index('(')+1:box.index(',')].split()
        box_max = box[box.index(',')+1:box.index(')')].split()
        ext = 'XMIN: {0}\n      YMIN: {1}\n      XMAX: {2}\n      YMAX: {3}\n   '
        se = ext.format(box_min[0], box_min[1], box_max[0], box_max[1])
        if self.rgis.DEBUG:
            self.rgis.addInfo(se)
        return se

The only other place I see "box" is here (only the text would copy):

\rivergis\__pycache__\ras_gis_import.cpython-36.pyc
...
Nz/SELECT ST_Extent(geom) FROM "{0}"."XSCutLines";T)
z=XMIN: {0}
      YMIN: {1}
      XMAX: {2}
      YMAX: {3}
      boxZbox_minZbox_max

I know barely enough Python to be dangerous...  But the current message looks like "box" needs to be defined somewhere, and it isn't. Except really it appears the problem is an empty input line, not an undefined variable...  Maybe the routine could check for my empty data file and put up a more helpful message?

1 Answer

0 votes
answered Jun 21 by rpasiok (3,601 points)
Please, do not use the SAGA tool (Cross Profile) to create your cross-sections. You do not need profiles... you only need lines with cross-sections location. Create some test cross-sections manually, starting from left bank side, and let us know if that works.
commented Jun 29 by Loren Amelang
Today I can't get any stationing in my output files with any cutlines. See:
http://q2a.rivergis.com/522/line_locate_point-isnt-point-again

Is there some better tool to generate lots of cutlines? I'm not sure how many I really need, but I'm guessing over 700 at the moment...  Not likely to happen manually!
commented Jun 29 by Loren Amelang
See http://q2a.rivergis.com/522/line_locate_point-isnt-point-again for the solution to the missing stationing issue.
Welcome to RiverGIS Q&A, where you can ask questions and receive answers from other members of the community.

Visit rivergis.com for documentation and general info about the QGIS plugin.
...