Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SegmentNetwork.py invalid expression (SelectLayerByAttribute) #300

Open
Yorkshirepuddnz opened this issue Apr 23, 2020 · 4 comments
Open
Labels
help wanted Requests from analysts and BRAT users to help solve specific problems or find work-arounds.

Comments

@Yorkshirepuddnz
Copy link

Hi guys,
I'm pretty new to this sorry if I've missed anything out
I'm trying to run the SegmentNetwork.py script for a stream network in the UK. As such it doesn't have the NHD network attributes. I've added an "FCODE" column to the polyline attribute table and populated this with "46006" since the network represents perennial streams only.

I'm running the script in the python window in ArcMap 10.6.1 and get the following traceback:

Runtime error Traceback (most recent call last): File "", line 171, in File "", line 31, in main File "f:\desktop10.6\arcpy\arcpy\management.py", line 7742, in SelectLayerByAttribute raise e ExecuteError: ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute).

Any hints would be greatly appreciated,
Many thanks,
Gabe
BRAT issues

@mhallerud
Copy link
Contributor

@Yorkshirepuddnz Apologies for the super late response, unfortunately it's really difficult to tell what is going on with this error without your dataset. If you haven't figured it out already, I would first try saving the intermediate before the line that fails, running the selection in ArcMap, and then dropping the output of the selection through the rest of the code.

@joewheaton joewheaton added the help wanted Requests from analysts and BRAT users to help solve specific problems or find work-arounds. label May 21, 2020
@joewheaton
Copy link
Contributor

Good suggestion @mhallerud. @Yorkshirepuddnz there is a UK adaptation of BRAT that was just published by Hugh Graham (see post here in sqlBRAT repo). pyBRAT is a research-grade series of scripts that was pretty unapologetically written for a workflow with nationally available US Data. That said, it has been modified to work with Canadian datasets, UK datasets, and more bespoke US data. None of those have been done (yet) as professional-grade tools to make an easy to use GIS user interface. Conceptually, there is nothing stopping you from applying BRAT, it is just recognizing what the scripts and tools to apply them can and can't do.

You're getting stuck at a step that is simply selecting the part of your drainage network you want to use (here a perennial selection) and then will attempt to segment it. Your troubleshooting step seems reasonable (i.e. fudge data to add that piece it is looking for). You could also try to push this past this by attempting to just manually produce what this step does and move to next step, or adjusting that script in what its looking for.

I haven't used @h-a-graham 's code, but his UK adaptation of BRAT is in this repo. Alternatively, you could take a look at what he does for dealing with UK data. Paper just came out too.

@h-a-graham
Copy link

@Yorkshirepuddnz it looks like you may need to use 'FTYPE' rather than 'FCODE' for the extra US based column. My understanding is that the USGS data considers ephemeral stream which are filtered out from line 43 in the script here: segmentNetwork.py

quer = """ "FTYPE" = 428 OR "FTYPE" = 420 OR "FTYPE" = 566""" - @joewheaton @mhallerud I presume these codes are those to be filtered out so setting a column named 'FTYPE' to any other number will keep the features?

AS Joe says, pyBRAT is designed for the US but can be adapted for the uk.

The UK version has a similar script to split a stream network here: script
But this doesn't use arcpy but geopandas and shapely which do not come as standard with the arc python build...

PS. a more userfirendly better documented version of the UK BDC repo that Joe shared will be coming out soon.

@Yorkshirepuddnz
Copy link
Author

Hi all,
Thanks so much for getting back to me I'll look into your suggestions
best wishes,
Gabe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Requests from analysts and BRAT users to help solve specific problems or find work-arounds.
Projects
None yet
Development

No branches or pull requests

4 participants