|
POST
|
You want something like the readline method. Here is the basics, not a full version, but you get the idea...
with open("foo.csv", "r") as f:
f.readline() # get rid of the first line
# this section goes in a loop
f.readline() #discard newline
lineOne = f.readline() # first line with a value
x = float(lineOne.split(",")[2])
lineTwo = f.readline()
x += (float(lineTwo.split(",")[2]))/2 # this is your value
# do something
... View more
04-30-2014
09:36 AM
|
0
|
0
|
741
|
|
POST
|
Do the feature classes have the same name? Do they have different spatial references? Either will cause the tool to fail.
... View more
04-30-2014
06:11 AM
|
0
|
0
|
1475
|
|
POST
|
Is the polygon layer set to selectable (4th icon at the top of the TOC)?
... View more
04-30-2014
05:26 AM
|
0
|
0
|
2167
|
|
POST
|
You don't want Copy, you want Append or Merge. Copy makes a new feature class, and you already have the destination feature class. If you want to replace the destination, delete the destination first and use copy, or delete features and append.
... View more
04-30-2014
05:17 AM
|
0
|
0
|
1475
|
|
POST
|
Not sure what to tell you. Worked for me. Are you importing arcpy? Jake, your method works, but is looping through the table n times in the inner loop the best way to go? The latest reply mentioned using a SearchCursor without the with...as statement, but I cannot get that to work either (error returns 'Cursor' object has no attribute 'Asset_ID' when I run the SearchCursor code:
... View more
04-30-2014
04:27 AM
|
0
|
0
|
2914
|
|
POST
|
Do you have any Nulls or empty fields in the Asset_ID field? Maybe add an if statement checking for them before appending to the list. What version of Arc are you running? You may want to modify the SearchCursor arguments to include just the Asset_ID field as well, and make sure someone else isn't accessing the data and putting a lock on it. Or maybe lstIds.append(row.getValue("Asset_ID")). I use arcpy.da, which is a slightly different syntax. The with...as syntax just provides for automatic garbage collection, so you don't have to manually delete rows or row. Maybe the version in your setup doesn't support with for a SearchCursor, so you could try going back to your original syntax. for that. In that case, consider wrapping it in a try/except block. This is actually what I'd try first. The with...as expects an __exit__ attribute, so if it's not there you'll get this error.
au = "Assets_Unprocessed"
fld = "Asset_ID"
lstIds = []
auRows = arcpy.SearchCursor(au)
for row in auRows:
lstIds.append(auRows.Asset_ID)
del auRows
del row
try:
aRows = arcpy.UpdateCursor("Assets")
for row in aRows:
if row.Processed == "N" and row.Asset_ID in lstIds:
row.Processed = "Y"
aRows.update(row)
except Exception as e:
print e.message
#do whatever
del aRows
del row
... View more
04-29-2014
09:01 AM
|
0
|
0
|
2914
|
|
POST
|
You don't show where you're looping through Asset_Unprocessed. Unless the actual value of Asset_ID is the string "Asset_Unprocessed.Asset_ID", no matches will be found. This isn't an error in the coding; it's doing exactly what it's told to do. If what you want is to update Assets if there is a match in the ID fields of the two tables, one solution would be to first run a SearchCursor on Assets_Unprocessed and populate a list with all that table's ids. Then run an UpdateCursor on Assets and check if the id value is in the list. Or, if the tables are joined as Jake asks, instead, change your code to check row.Assets_Unprocessed.Asset_ID, or whatever field name the join gave it. However, this wouldn't catch instances where Assets_Unprocessed.Asset_ID wasn't in the row for the matching id, if there are any. Yet another way would be to run the UpdateCursor in a nested loop in a SearchCursor loop, but I think I read somewhere that ESRI discourages nested cursors. Something like (untested):
au = "Assets_Unprocessed"
lstIds = []
# with... syntax automaticalyy deletes auRows, row
with arcpy.SearchCursor(au) as auRows:
for row in auRows:
lstIds.append(auRows.Asset_ID)
with arcpy.UpdateCursor("Assets") as aRows:
for row in aRows:
if row.Processed == "N" and row.Asset_ID in lstIds:
row.Processed = "Y"
arows.update(row)
... View more
04-29-2014
04:27 AM
|
0
|
0
|
2914
|
|
POST
|
One thing to be careful of when using linear referencing over a whole road length - 911 may require segments broken at intersections. This is for emergency dispatch. We had to break all our lines at intersections at my old job for this reason. Maybe this isn't a requirement for all 911 systems, but it was for ours.
... View more
04-28-2014
12:12 PM
|
0
|
0
|
3249
|
|
POST
|
If your set of PLSS data has the T, R, S... in separate columns, and your other table has them joined, you could just split the joined values and run a query on that, e.g. "Twp = newlist[0] and Rng = newlist[1] and Sec = newlist[2]..." and so on. Even easier would be to make a new field in the first, PLSS, dataset and run a field calculation to concatenate your separate values, then join like James recommends above.
... View more
04-28-2014
10:53 AM
|
0
|
0
|
1024
|
|
POST
|
Are you familiar with modulus division? It gives you the remainder. You want to check if PM % 1 = 0. That will be true for whole numbers, such as 11 % 1 == 0. 11.5 % 1 will equal 0.5. (This is python notation). It's a little more complicated if PM is a float or double datatype, because there you'll have to check if the value is very close to 0, rather than equaling 0, but the principle is the same. If PM is text, there's an even simpler way, but I'm guessing it's numeric. So in label expressions, you want something like this (in vbscript):
Function FindLabel ( [PM] )
if [PM] mod 1 = 0 then
FindLabel = [PM]
end if
End Function
... View more
04-23-2014
12:12 PM
|
0
|
0
|
1545
|
|
POST
|
Python doesn't recognize 'Null'. Instead, use None. Also, the proper way to check is 'is None', or 'is not None'. Without quotes, of course.
... View more
04-22-2014
06:29 AM
|
0
|
0
|
1584
|
|
POST
|
You might want to set your distance_height through multiplier variables outside of the for loop to save the overhead of setting them each trip through the loop. Might only be a negligible performance hit, but good practice to avoid it if not needed.
... View more
04-10-2014
11:01 AM
|
0
|
0
|
5353
|
|
POST
|
You could also use the python csv module to write the file out.
... View more
04-10-2014
08:14 AM
|
0
|
0
|
1969
|
|
POST
|
Alternatively to using the cursor, you could just make a field in each feature classes that was the flight height multiplied by the float value you are using, then just use that field value as the value for the buffer, so you are using the field name as input instead of a number. Oh, sure, if you want to do it the easy way! 🙂 You could still use the looping concept to add and calculate the new field to each feature class.
... View more
04-09-2014
11:04 AM
|
0
|
0
|
5353
|
| Title | Kudos | Posted |
|---|---|---|
| 6 | 08-22-2019 07:41 AM | |
| 1 | 05-05-2014 04:30 AM | |
| 1 | 08-15-2018 06:23 AM | |
| 3 | 08-06-2018 07:31 AM | |
| 1 | 03-30-2012 08:38 AM |
| Online Status |
Offline
|
| Date Last Visited |
12-12-2021
01:00 PM
|