POST
|
my labels seem to be grouped around one feature, cant figure out why Im using Arcmap 10.6.1
... View more
08-23-2019
09:00 AM
|
0
|
1
|
251
|
POST
|
I was QAQC'g my code results and found unexpected values. My code queries point and polygon layers looking for how many negative test result are gathered before a positive. for grid in grids:
dates = []
arcpy.SelectLayerByLocation_management("cwdpts4Anlys", "WITHIN", grid.shape, "", "NEW_SELECTION")
positives = arcpy.SearchCursor("cwdpts4Anlys",' "PRION_DETECTED" = 1 ' , "", "SAMPLEDATE" )
for positive in positives:
dates.append(positive.SAMPLEDATE)
earliest = min(dates)
grid.setValue("FrstPosDte", earliest)
posYear = earliest.year
print posYear
negDates = []
arcpy.SelectLayerByLocation_management("cwdpts4Anlys", "WITHIN", grid.shape,"", "NEW_SELECTION")
negatives = arcpy.SearchCursor("cwdpts4Anlys",' "PRION_DETECTED" = 0 ', "", "SAMPLEDATE")
for negative in negatives:
negDates.append(negative.SAMPLEDATE)
if negDates:
earliestNeg = min(negDates)
print earliestNeg
grid.setValue("FrstNegDte", earliestNeg)
where = "EXTRACT(YEAR from {0}) <= {1}".format(arcpy.AddFieldDelimiters("cwdpts4Anlys", "SAMPLEDATE"), posYear)
arcpy.SelectLayerByAttribute_management("cwdpts4Anlys", "SUBSET_SELECTION", where)
result = int(arcpy.GetCount_management("cwdpts4Anlys").getOutput(0))
print result
grid.setValue("NgPriorPs", result)
else:
grid.setValue("NgPriorPs", 0)
grids.updateRow(grid)
It appears when checking the values for negatives prior to positive that the getCount includes the earliest positive (or it is always one more than expected. Why? Do I need to physically clear the selection before making the second "New_Selection" Thanks, Alicia
... View more
06-19-2014
11:23 AM
|
0
|
0
|
667
|
POST
|
Perfect! Thank You. I will read a little more about the formatting on my own. Alicia
... View more
05-19-2014
11:25 AM
|
0
|
0
|
228
|
POST
|
Hello, Still working with a grid, trying to count the number of negative s after the first positive. Everything seems to be working as expected, except my count is always zero. Sample output: [datetime.datetime(2009, 3, 24, 0, 0), datetime.datetime(2009, 3, 24, 0, 0), datetime.datetime(2010, 3, 31, 0, 0), datetime.datetime(2010, 3, 31, 0, 0), datetime.datetime(2011, 3, 22, 0, 0)] 2009-03-24 00:00:00 0 [datetime.datetime(2007, 11, 19, 0, 0)] 2007-11-19 00:00:00 0 [datetime.datetime(2008, 4, 2, 0, 0), datetime.datetime(2010, 4, 14, 0, 0)] 2008-04-02 00:00:00 0 [datetime.datetime(2005, 9, 14, 0, 0), datetime.datetime(2006, 3, 31, 0, 0), datetime.datetime(2006, 4, 12, 0, 0), datetime.datetime(2010, 4, 1, 0, 0), datetime.datetime(2010, 4, 1, 0, 0), datetime.datetime(2011, 3, 22, 0, 0), datetime.datetime(2011, 3, 22, 0, 0), datetime.datetime(2011, 3, 25, 0, 0), datetime.datetime(2011, 4, 13, 0, 0), datetime.datetime(2011, 4, 14, 0, 0)] 2005-09-14 00:00:00 0 [datetime.datetime(2011, 4, 14, 0, 0)] 2011-04-14 00:00:00 0 for grid in grids: dates = [] arcpy.SelectLayerByLocation_management("cwdpts4Anlys", "WITHIN", grid.shape, "", "NEW_SELECTION") positives = arcpy.SearchCursor("cwdpts4Anlys",' "ELISALYMPHNODE" = \'Positive\' ' , "", "SAMPLE_DATE" ) for positive in positives: dates.append(positive.SAMPLE_DATE) print dates earliest = min(dates) print earliest arcpy.SelectLayerByLocation_management("cwdpts4Anlys", "WITHIN", grid.shape,"", "NEW_SELECTION") arcpy.SelectLayerByAttribute_management("cwdpts4Anlys", "SUBSET_SELECTION", ' "ELISALYMPHNODE" = \'Negative\' ') arcpy.SelectLayerByAttribute_management("cwdpts4Anlys","SUBSET_SELECTION",'"SAMPLE_DATE" <= date.earliest ' ) result = int(arcpy.GetCount_management("cwdpts4Anlys").getOutput(0)) print result [\Code] I have tried several different formats in the SelectLayerByAttribute line including .....date earliest and........ earliest, but the return is always the same. thanks again Alicia
... View more
05-19-2014
07:48 AM
|
0
|
2
|
560
|
POST
|
positives = arcpy.SearchCursor("cwdpts4Anlys",' "ELISALYMPHNODE" = \'Positive\' ' , "", "SAMPLE_ DATE" ')
I think you have an extra single quote at the end. You single quote for the expression ends at the end of the 2nd parameter, then I see no single quote for the one on the end to go with. SHould be like this I believe.
positives = arcpy.SearchCursor("cwdpts4Anlys",' "ELISALYMPHNODE" = \'Positive\' ' , "", "SAMPLE_ DATE" )
And yes, syntax errors are the devil. I missed that! Thanks
... View more
05-17-2014
09:07 AM
|
0
|
0
|
326
|
POST
|
positives = arcpy.SearchCursor("cwdpts4Anlys",' "ELISALYMPHNODE" = \'Positive\' ' , "", "SAMPLE_ DATE" '
Just a quick note: you have it as "SAMPLE_ DATE", not "SAMPLE_DATE". It could just be a copy/paste into the forum post editor, but you may want to take a quick look at your source code to verify this isn't the problem. I think your right, but I am also curious about how the date format is maintained. When I set up the "dates" list, what is the format of the list? Thanks, Alicia
... View more
05-17-2014
09:06 AM
|
0
|
0
|
326
|
POST
|
Good Afternoon ArcPy Wizards! I would love some input on my code. I am trying to capture the earliest positive in a grid and then count the negative sample that were required before the positive. The Code: for grid in grids: dates = [] arcpy.SelectLayerByLocation_management("cwdpts4Anlys", "WITHIN", grid.shape, "NEW_SELECTION") positives = arcpy.SearchCursor("cwdpts4Anlys",' "ELISALYMPHNODE" = \'Positive\' ' , "", "SAMPLE_ DATE" ') for positive in positives: dates.append(row[0]) earliest = min(dates) arcpy.SelectLayerByLocation_management("cwdpts4Anlys", "WITHIN", grid.shape, "NEW_SELECTION") arcpy.SelectLayerByAttribute_management("cwdpts4Anlys", "SUBSET_SELECTION", ' "ELISALYMPHNODE" = \'Negative\' ') arcpy.SelectLayerByAttribute_management("cwdpts4Anlys","SUBSET_SELECTION",'"SAMPLE_DATE" <= date earliest ' ) negatives = int(arcpy.GetCount_management("cwdpts4Anlys").getOutput(0)) grid.setValue('NegPrior2Pos', negatives) grids.updateRow(grid) I get a syntax error at positives = arcpy.SearchCursor("cwdpts4Anlys",' "ELISALYMPHNODE" = \'Positive\' ' , "", "SAMPLE_ DATE" ') Ive tried adding the keyword date before "SAMPLE_DATE" and many other ways. Thanks! Alicia
... View more
05-16-2014
12:23 PM
|
0
|
4
|
888
|
POST
|
I am just now incorporating this. I am all but positive this is the answer I was needing. Thanks! I did test and this does solve the endless loop, but I do not want to say that this code is perfect yet. I am still working on the iterative selection which is not working as expected. Thanks!!!
... View more
03-26-2014
11:21 AM
|
0
|
0
|
629
|
POST
|
Can anyone break this line down? int(arcpy.GetCount_management(tempLayer).getOutput(0)) I saw this used in a for loop, and wonder if I should go this direction, because I can not make this loop work as it is.
... View more
03-26-2014
10:11 AM
|
0
|
0
|
629
|
POST
|
That problem seems to be related to the first couple lines: arcpy.MakeFeatureLayer_management("wtlnd4Anlys", "in_memory\\wtlnd4Units")
wtlnd4Units = "in_memory\\wtlnd4Anlys" You output to "in_memory\\wtlnd4Units", but the wtlnd4Units string is "in_memory\\wtlnd4Anlys" From what I can tell from your script those should be the same strings. Thanks let me try that as well!!! I need a break from this code for a little while obviously. I did not see it! Thanks Alicia
... View more
03-11-2014
11:54 AM
|
0
|
0
|
629
|
POST
|
#Create "in_memory" feture class for processing
#
arcpy.MakeFeatureLayer_management("wtlnd4Anlys", "in_memory\\wtlnd4Units")
wtlnd4Units = "in_memory\\wtlnd4Anlys"
#Loop through wetlands and select the adjacent polys populate WtlndUnitID and UnitArea
#
wtlndRow = arcpy.SearchCursor("wtlnd4Anlys")
wtlndUnitID = 0
for row in wtlndRow:
if row.WtlndUnitID is None:
totalArea = 0
wtlndUnitID += 1
arcpy.MakeFeatureLayer_management("wtlnd4Anlys", "in_memory\\adjWtlnd")
adjWtlnd = "in_memory\\adjWtlnd"
arcpy.SelectLayerByLocation_management(adjWtlnd,"SHARE_A_LINE_SEGMENT_WITH",row.shape, "", "NEW_SELECTION")
numPolys = 1
count = 0
while numPolys != count:
numPolys = arcpy.GetCount_management(adjWtlnd)
arcpy.SelectLayerByLocation_management(adjWtlnd,"SHARE_A_LINE_SEGMENT_WITH", wtlnd4Units,"", "ADD_TO_SELECTION")
count = arcpy.GetCount_management(adjWtlnd)
I made changes, but now I receive an error at :
arcpy.SelectLayerByLocation_management(adjWtlnd,"SHARE_A_LINE_SEGMENT_WITH", wtlnd4Units,"", "ADD_TO_SELECTION")
ERROR 000732: Selecting Features: Dataset in_memory\wtlnd4Anlys does not exist or is not supported It seems it will take the in_memory: adjWtlnd but wont accept the second in_memory. But Im not really sure. Thanks for your help! Alicia
... View more
03-11-2014
10:42 AM
|
0
|
0
|
629
|
POST
|
for row in wtlndRow: if row.WtlndUnitID is None: totalArea = 0 wtlndUnitID += 1 adjWtlnd = arcpy.MakeFeatureLayer_management(wtlnd4Units, "in_memory\\adjWtlnd") arcpy.SelectLayerByLocation_management(adjWtlnd,"SHARE_A_LINE_SEGMENT_WITH",row.shape, "", "NEW_SELECTION") numPolys = 1 count = 0 while numPolys != count: numPolys = arcpy.GetCount_management(adjWtlnd) arcpy.SelectLayerByLocation_management(adjWtlnd,"SHARE_A_LINE_SEGMENT_WITH", wtlnd4Units,"", "ADD_TO_SELECTION") count = arcpy.GetCount_management(adjWtlnd) Cant figure out why this wont evaluate to true. Thanks! Alicia
... View more
03-11-2014
09:20 AM
|
0
|
9
|
970
|
POST
|
Have you figured this out yet. I have a similar issue. I would like to use a mosaic dataset and an input selection to clip or mask. The original data would be to larger to process on it's own? I would like to use python to do all the processing. thanks alicia
... View more
02-06-2014
06:45 PM
|
0
|
0
|
416
|
POST
|
Can you post an example of the table your are selecting from? This a standard attribute from the NWI table which is in a geodatabase. [ATTACH=CONFIG]31190[/ATTACH] The Pic is small so I attached a better image also. I did get the last, most recent, code to run on my desktop and laptop.
... View more
02-06-2014
10:54 AM
|
0
|
0
|
353
|
POST
|
When I had the entire selection in one line of code
arcpy.SelectLayerByAttribute_management("wtlnd4Analysis", "NEW_SELECTION", ' "WETLAND_TYPE" = \'RIVERINE\' AND "ATTRIBUTE" LIKE \'%H%\' OR "WETLAND_TYPE" = \'LAKE\' AND "ATTRIBUTE" LIKE \'%UBH%\' ')
I loaded this into the python window and I never saw the selection change. It would be obvious, because there are several very large river that would be removed. I tried adding () around where clause and still nothing changed. Today I run this on on my desktop at work instead of my laptop and it doesnt even work as I step through. I get an empty selection no mater what? Im stumped. Thanks Alicia Back working on laptop, and this works thus far:
arcpy.MakeFeatureLayer_management(wtlndPath, "wtlnd4Anlys_lyr")
arcpy.SelectLayerByAttribute_management("wtlnd4Anlys_lyr", "NEW_SELECTION", ' "ATTRIBUTE" LIKE \'R%H%\' OR "ATTRIBUTE" LIKE \'L%UBH%\' ')
arcpy.SelectLayerByAttribute_management("wtlnd4Anlys_lyr", "SWITCH_SELECTION")
... View more
02-03-2014
11:06 AM
|
0
|
0
|
354
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|