4

Related to When are field calculator scripting questions on topic? and various comments on that Meta question (and many Main questions since) I think it is clear that we do not have consensus on where the line should be drawn between pure Python (better researched/asked at Stack Overflow) and Python functionality that is core to modern GIS (on-topic for here).

Where would you draw that line?

  • 4
    python needs to have an element of geographical features or relation of attributes to geometry. Not a python coder so can this can get into grey areas of pure python code. – Mapperz Oct 20 '15 at 13:32
  • 4
    I've answered a fair share of questions that fall into this category. I think part of the problem is that some authors do not understand enough to know that what they are asking a 'pure' python question. Another thing to keep in mind is that we'd need to ensure questions on SO aren't getting closed or moved here simply because GIS is mentioned in the question. – Evil Genius Oct 27 '15 at 16:12
9

Another excellent example of why defining the line for 'pure' Python questions is going to be difficult: Using variable in SelectByAttribute_management.

At the lowest level possible, it is purely a Python syntax issue.

However, the error given would indicate an error outside of Python, within the ArcGIS API:

Runtime error Traceback (most recent call last): File "", line 1, in File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 6435, in SelectLayerByAttribute raise e ExecuteError: ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute).

If you look up this error message you'll find:

The SQL expression is invalid.

It takes knowledge of both ArcGIS and Python to understand what the problem is and what the solution should be.

Now, the question is, should I answer this? It's actually fairly simple, and I've already spent more time creating this answer than it would have taken to do that.
I could also vote to close it as off-topic. But, given the fact that I've already taken the time to read and understand the question, and I know a solution, am I really improving this community by voting to close this question?

At the very least, I believe trying to define what is 'pure' Python is going to be a moving target, and something this community will struggle with on an on-going basis.

  • In this case, and more or less as a side issue, when I get a chance I'll go looking for Jason's "thread" (mentioned in the self-answer) and probably close it as a duplicate. – PolyGeo Nov 17 '15 at 20:30
  • @PolyGeo Agreed. The self answer either wasn't posted when I was looking at that question, or I simply didn't see it when I saw it in the review queue...if I had, I would have suggested the same. – Evil Genius Nov 17 '15 at 23:45
  • One day I hope to find time to look at all the gis.stackexchange.com/questions/tagged/error-000358 Q&As, expand the oldest one to cover the subsequent variants, and then roll them all up into duplicates of that earliest then canonical Q&A. – PolyGeo Nov 19 '15 at 0:06
  • In answer to the question in your answer: yes - I think you would be "improving this community by voting to close this question" especially if it is as a duplicate of an earlier Q&A that represented the same issue, rather than providing what is effectively the same answer once again. By doing so your effort will feed into the self-assembling FAQ for Select By Attribute. No one seemed to suggest that this question was off-topic i.e. there were no comments to that effect. – PolyGeo Dec 13 '15 at 23:09
  • 1
    @PolyGeo I'm not questioning that it's a duplicate, and should be closed for that reason. I brought it up as an example of a question that should be considered 'pure Python,' and to illustrate how fuzzy that line between Python and GIS will be...this question is entitled 'Where is the line between Python and GIS?' is it not? – Evil Genius Dec 13 '15 at 23:38
  • Your example is not one which I am thinking should be off-topic as more Python than GIS. I think it is a GIS question that has already been frequently asked, and answered. If I have closed any questions like this is being more suited to Stack Overflow than Geographic Information Systems I would like to review those decisions. Going back to the original question, if it was the first time such a question had appeared on GIS SE, would you close it as being more suited to Stack Overflow? I certainly would not. – PolyGeo Dec 15 '15 at 5:22
  • @PolyGeo When I said 'should be considered', it really should have been 'could be considered.' To answer your question, no I wouldn't have voted to close it as off topic. This particular question deals with string formatting, which you can find tons of questions about on SO. My point is: if a question could be on Stack Overflow in a more general format, does that mean it should be off topic here? I don't think we can be that general. – Evil Genius Dec 15 '15 at 12:50
  • Any spatial Python library question could be on Stack Overflow but I consider them more on-topic here. Any Python library question without a spatial component is off-topic here but on-topic there. – PolyGeo Dec 15 '15 at 13:15
0

https://gis.stackexchange.com/questions/177203/how-to-define-empty-raster-object-with-arcpy is a question that I think falls squarely on the Python side of the line despite mentioning ArcPy in the title.

The relevant code presented was:

for x in range(1,13):
    days_in_month = monthrange(2013,x)[1]
    for y in range(days_in_month):
       raster_sum+=rasters[count]

and the error was:

Runtime error 
Traceback (most recent call last):
  File "<string>", line 4, in <module>
NameError: name 'raster_sum' is not defined

There is no evidence for the ArcPy (or any other GIS) site package having been imported prior to, or being used by, what we are shown.

To get the same error thrown by raster_sum+=rasters[count] I can use this piece of pure Python code:

count = 0
rasters = [1,2,3]
raster_sum+=rasters[count]
0

I'll provide an answer based on an example question that has since been deleted by the Community user: https://gis.stackexchange.com/questions/167074/using-a-text-file-to-create-shapefile-with-attributes.

It was:

I'm using this with Python and Arcpy

Before I begin to code, I was wondering if it was possible to take a .txt file, and extract the first line as the field values, and extract the next lines of coordinates as extents.

An exmaple of the .txt file is like this:

1867-Jan-01 Field value  Field Value  Field Value Field Value  Field Value
  52N  62W
  42N  52W
  32N  42W
  22N  32W
  12N  22W
  11N  12W
  10N  13W

I would have a shapefile already created and all I would need to do is create the polygon files using the coordinates and populate the attribute table with values above it.

Is this a possibility using Python and Arcpy, and what direction should I take it?

This question from Main contains two questions. The second question (creating geometries using ArcPy) is clearly on-topic (but probably a duplicate) while the first question is about how to read lines from a text file using Python.

I voted to put the question on hold because the asker had not included a code snippet to show what they had tried and where they were stuck. However, if they had included a code snippet and that was about how to read lines from a text file using Python, rather than the geometry part, then I would still have voted to put it on hold as being better researched/asked at Stack Overflow.

If the question ceases to be about how to read lines from a text file using Python and becomes only about creating geometries using ArcPy then I will consider it to be highly on-topic for GIS SE and be ready to provide an answer or cite a duplicate.

  • 2
    This example raises an important aspect too. We have quite a few good python coders here. We do not have all that many super amazing all-world "Wow! I didn't know you could to that!" python coders hanging out here. We have a few of those, but SO is really the place to find them, and that is the main reason to move pure python questions over to SO. – blord-castillo Dec 17 '15 at 14:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .