linkagescape / linkage-mapper

ArcGIS tools to automate mapping and prioritization of wildlife habitat corridors
https://circuitscape.org/linkagemapper/
GNU General Public License v3.0
39 stars 12 forks source link

Addressing Issue #14 - Arcpy.da Cursors #92

Closed NatMills closed 5 years ago

NatMills commented 5 years ago

See https://github.com/linkagescape/linkage-mapper/issues/14 for details.

dkav commented 5 years ago

@NatMills you are merging back in some old code with this commit. You should make your changes to a current version of the file.

To the cursor changes, there is more to addressing this issue than simply inserting .da. For example the following code:

        irows = arcpy.InsertCursor(cpair_tbl)
        for nrow in cores_product:
            outputrow = irows.newRow()
            outputrow.setValue(FR_COL, int(nrow[0]))
            outputrow.setValue(TO_COL, int(nrow[1]))
            irows.insertRow(outputrow)

    return cpair_tbl

    except Exception:
        raise
    finally:
        if srows:
            del srows
        if outputrow:
            del outputrow
        if irows:
            del irows

could be replaced with:

        with arcpy.da.InsertCursor(cpair_tbl, [FR_COL, TO_COL]) as irows:
            for nrow in cores_product:
                irows.insertRow(int(nrow[0]), int(nrow[1]))

        return cpair_tbl

    except Exception:
        raise

Finally, I started to implement this improvement myself through out the code base, but haven't made much progress. The example give above is from one of the updates I made earlier this year. I am hopeful that I will have time to finish the task in September (integrating it with other changes I have made), that is unless you are planning on taking on this before I restart?

johngallo commented 5 years ago

Hi @dkav and @NatMills,

Thanks Darren for reviewing that PR!

I'll take the blame for Nat not updating the most current file.

Nat, from what I gather from your workflow system, a way to do this in the future is to make a branch in GitKraken called something like update_cursor, and then, when that branch is in your repository, copy that repository over into your workspace and name the whole repository something like update-cursor_branch, then do all your changes there, and testing, then when you are ready, make sure your repository is set to that branch, and copy over your updated files, or even the whole repository if you like. GitKraken will know which ones have been updated. Then, when you do the pull request, and if many changes to the develop code have been made since you made the cursoral branch, Git will account for that accordingly. (e.g. delete the lines of code for clipping to bounding geometery). If one of those other changes made was on the same lines of code, the issue will be raised, asking you for how to resolve the conflict. If that happens, let Darren and I know.

Regarding Darren's question, my suggestion is to say you'll circle back to the question after you finish issue #89, and if he is ready to work on it before you get back to him that it is all his. That is my opinion at least.

Thanks Fellas!

John