|
POST
|
Hi all, I'm hoping someone can help me a problem I can't figure out. Below is my code. I keep getting a RuntimeError: cannot open 'file I'm writing to' using a arcpy.da.InsertCursor. It keeps locking for some reason, I do not have arc open when running (running it from PyCharm), and it will write to the file thousands of times... I am writing line segments to a feature class and it will do it thousands of times, but then seemingly randomly say it can't access it. I have run it many times and it get's locked up in different places each time. The only info I can find is that people need to close their cursors, but all my cursors (both search and insert cursors) are closed after each use. I'm not sure what else to do. Any ideas? Description of what code is trying to do below if that is helpful at all as well as a screen shot of the error. import arcpy
# Set environments / workspace. Workspace should point to a gdb that has all the effort point feature classes
arcpy.env.workspace = r"C:\Users\bhodge\Dropbox (New England Aquarium)\MonumentsWork\MonumentSpeciesDiversity\DataFromBob\DerivedData.gdb"
arcpy.env.overwriteOutput = True
# This is the input points
fc = r"C:\Users\bhodge\Dropbox (New England Aquarium)\MonumentsWork\MonumentSpeciesDiversity\DataFromBob\DerivedData.gdb\EffortPoints_Prj_TEST_B"
# This is the output lines
sr = arcpy.Describe(fc).spatialReference
outputFC = arcpy.management.CreateFeatureclass(r"C:\Users\bhodge\Dropbox (New England Aquarium)\MonumentsWork\MonumentSpeciesDiversity\DataFromBob\DerivedData.gdb", "EffortLines_TEST", "POLYLINE", "", "DISABLED", "DISABLED", sr)
# Add desired fields to outputFC
arcpy.AddField_management(outputFC, "MONTH", "TEXT")
arcpy.AddField_management(outputFC, "YEAR", "SHORT")
arcpy.AddField_management(outputFC, "FILEID", "TEXT")
arcpy.AddField_management(outputFC, "EVENTNO", "LONG")
# Make a feature Layer of the input points to work off. This layer is temporary and will not persist after session ends unless saved
arcpy.MakeFeatureLayer_management(fc, "fc_lyr")
# Sort the table by fileid and eventno and create a new fc called fc_sort
sort_fields = [["FILEID", "ASCENDING"], ["EVENTNO", "ASCENDING"]]
fc_Sorted = arcpy.Sort_management("fc_lyr", "fc_sort", sort_fields)
# Create the search cursor
fields = ['FILEID', 'beauf_num', 'LEGTYPE', 'LEGSTAGE', 'vis_num', 'olviz_num', 'alt_num', 'LAND', 'MONTH', 'YEAR', "EVENTNO", "SHAPE@"]
with arcpy.da.SearchCursor(fc_Sorted, fields) as cur1:
for row in cur1:
# Name variables and assign values starting on first record of table
fileid1 = row[0]
beaufort = row[1]
legtype = row[2]
legstage = row[3]
visiblty = row[4]
oldvis = row[5]
alt = row[6]
land = row[7]
month = row[8]
year = row[9]
eventno = row[10]
# Get the geometry of the point for that record
geom1 = row[11].getPart()
# Go to the next row, get the fileid and geometry
next_row = cur1.next()
fileid2 = next_row[0]
land2 = next_row[7]
geom2 = next_row[11].getPart()
# Create an Array
array = arcpy.Array()
# Test the parameters to see if it should be on-effort
if ((fileid1 == fileid2) and (beaufort != None and beaufort <= 4) and ((visiblty != None and visiblty >= 2) or (oldvis == 1)) and \
(land != 1 and land2 != 1) and (alt != None and alt <= 366) and \
(not legtype == '0') and \
(not (legtype == '7' and legstage == ' ')) and \
(not (legtype == '9' and legstage == ' ')) and \
(not (legtype == '5' and legstage == ' '))):
array.add(geom1)
array.add(geom2)
polyline = arcpy.Polyline(array, sr)
with arcpy.da.InsertCursor(outputFC, ['SHAPE@', "MONTH", "YEAR", "FILEID", "EVENTNO"]) as insertCursor1:
insertCursor1.insertRow([polyline, month, year, fileid1, eventno])
del insertCursor1
array.removeAll()
else:
pass
del cur1
print("first with loop completed")
with arcpy.da.SearchCursor(fc_Sorted, fields) as cur2:
cur2.next()
for row in cur2:
# Name variables and assign values starting on first record of table
fileid1 = row[0]
beaufort = row[1]
legtype = row[2]
legstage = row[3]
visiblty = row[4]
oldvis = row[5]
alt = row[6]
land = row[7]
month = row[8]
year = row[9]
eventno = row[10]
# Get the geometry of the point for that record
geom1 = row[11].getPart()
# Go to the next row, get the fileid and geometry
next_row = cur2.next()
fileid2 = next_row[0]
land2 = next_row[7]
geom2 = next_row[11].getPart()
# Create an Array
array = arcpy.Array()
# Test the parameters to see if it should be on-effort
if ((fileid1 == fileid2) and (beaufort != None and beaufort <= 4) and ((visiblty != None and visiblty >= 2) or (oldvis == 1)) and \
(land != 1 and land2 != 1) and (alt != None and alt <= 366) and \
(not legtype == '0') and \
(not (legtype == '7' and legstage == ' ')) and \
(not (legtype == '9' and legstage == ' ')) and \
(not (legtype == '5' and legstage == ' '))):
array.add(geom1)
array.add(geom2)
polyline = arcpy.Polyline(array, sr)
with arcpy.da.InsertCursor(outputFC, ['SHAPE@', "MONTH", "YEAR", "FILEID", "EVENTNO"]) as insertCursor2:
insertCursor2.insertRow([polyline, month, year, fileid1, eventno])
del insertCursor2
array.removeAll()
else:
pass
del cur2
print("Done") This is the Error I get, but this changes depending on the run. Sometimes it's in in insertCursor1 sometimes in insertCursor2 depending on how far it get's that run. "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe" "C:/Users/bhodge/Dropbox (New England Aquarium)/MonumentsWork/MonumentSpeciesDiversity/MonumentsPython/Trackline_Fields.py"
Traceback (most recent call last):
File "C:/Users/bhodge/Dropbox (New England Aquarium)/MonumentsWork/MonumentSpeciesDiversity/MonumentsPython/Trackline_Fields.py", line 59, in <module>
with arcpy.da.InsertCursor(outputFC, ['SHAPE@', "MONTH", "YEAR", "FILEID", "EVENTNO"]) as insertCursor1:
RuntimeError: cannot open 'C:\Users\bhodge\Dropbox (New England Aquarium)\MonumentsWork\MonumentSpeciesDiversity\DataFromBob\DerivedData.gdb\EffortLines_TEST'
Process finished with exit code 1 Code description: Basically I'm running through a point table, looking at variables in the first row, and some in the next row and if those parameters meet my requirements, I draw a line to connect the points and save that to a featureclass I created along with some variables I need attached to those line segments. I run through two searchCursors because of how I need to access the first and second line, it skips one iteration, (basically the first one compares points 1&2, 3&4, etc.) so I run it through a second searchCursor accessing the opposites (comparing 2&3, 4&5, etc.). It's somehow locking the file I'm trying to write to in the insertCursor, but it does so randomly and I don't know why or how to fix it. Thanks in advance for any suggestions!
... View more
09-17-2020
08:59 AM
|
0
|
14
|
7985
|
|
POST
|
My goodneess you've saved my sanity! Yes, this worked, thank you so much!!!
... View more
07-28-2020
07:20 AM
|
0
|
0
|
3551
|
|
POST
|
Hi Dan, thanks so much for your reply and thanks for pointing me to the code formatting info. This was my first time posting code in a forum and I simply copied and pasted not knowing there was another way. I think I understand what you are suggesting, and it was the original way I tried to complete this task. Below, I tried to create a polyline from an array, shoot it into an empty list (below called featureList), then use the CopyFeatures_management to create an output feature class from the featureList list, however, that did not work either. Below is that attempt. You may notice this is slightly different than my original post (there is an additional 'if' statement testing variables and determine if it should draw a polyline), however, I took all that out trying to simplify things until I figured out how to get any line to actually draw. Is this what you were thinking? Or did I misinterpret your suggestion? import arcpy
# Set environments / workspace. Workspace will be a parameter in tool. This parameter should point to a gdb that has all the effort point feature classes
arcpy.env.workspace = r"C:\Users\bhodge\Dropbox (New England Aquarium)\MonumentsWork\MonumentSpeciesDiversity\DataProcessing\MichelleCData.gdb"
arcpy.env.overwriteOutput = True
featureList = []
# Set where the output featureclass will go
fc = r"C:\Users\bhodge\Dropbox (New England Aquarium)\MonumentsWork\MonumentSpeciesDiversity\DataProcessing\MichelleCData.gdb\SurveyPointsUTM19_TestSet_Short_6"
# Make a feature Layer to work off
arcpy.MakeFeatureLayer_management(fc, "fc_lyr")
# Sort the table by fileid and eventno and create a new fc called fc_sort
sort_fields = [["FILEID", "ASCENDING"], ["EVENTNO", "ASCENDING"]]
fc_Sorted = arcpy.Sort_management("fc_lyr", "fc_sort", sort_fields)
# Create the search cursor
fields = ['FILEID', 'BEAUFORT', 'LEGTYPE', 'LEGSTAGE', 'VISIBLTY', 'MONTH', 'YEAR', "SHAPE@"]
with arcpy.da.SearchCursor(fc_Sorted, fields) as cur:
for row in cur:
# Name variables and assign values starting on first record of table
fileid1 = row[0]
beaufort = row[1]
legtype = row[2]
legstage = row[3]
visiblty = row[4]
month = row[5]
year = row[6]
# Get the geometry of the point for that record
geom1 = row[7].getPart()
# Go to next record and name variables and assign values
next(cur)
fileid2 = row[0]
geom2 = row[7].getPart()
array = arcpy.Array()
if ((fileid1 == fileid2) and (beaufort != None and beaufort <= 4) and (visiblty != None and visiblty >= 2)) and \
(not legtype == '0') and \
(not (legtype == '7' and legstage == ' ')) and \
(not (legtype == '9' and legstage == ' ')) and \
(not (legtype == '5' and legstage == ' ')):
array.add(geom1)
array.add(geom2)
polyline = arcpy.Polyline(array, arcpy.SpatialReference(26919))
featureList.append(polyline)
array.removeAll()
else:
pass
del cur
outputLines = arcpy.CopyFeatures_management(featureList, r"C:\Users\bhodge\Dropbox (New England Aquarium)\MonumentsWork\MonumentSpeciesDiversity\DataProcessing\MichelleCData.gdb\OnEffortLines6")
... View more
07-27-2020
02:01 PM
|
0
|
0
|
3551
|
|
POST
|
I'm going crazy and hoping someone can help. I'm trying to bring in a point feature class, go row by row (using a .da.searchcursor), add two points into an array, and create a polyline from them. Then use an da.update cursor to add that line segment into a line feature class. Then go to the next row and do the same until I have made a number of line segments from the point features. I have tried this a ton of different ways, all with the same result, an updated line feature class that has the added rows, but NO lines draw and the length field for all segments are 0. I've altered this to just run the points and add the points to a new point feature and that works just fine. This code has also been updated to incorporate the .da.cursors (I have similar code running off the old cursors that work, i'm just trying to update it and the .polyline is not working right). Does anyone have any ideas or things to try? I'm going crazy. TIA! import arcpy
# Set environments / workspace. Workspace will be a parameter in tool. This parameter should point to a gdb that has all the effort point feature classes
arcpy.env.workspace = r"C:\Users\bhodge\Dropbox (New England Aquarium)\MonumentsWork\MonumentSpeciesDiversity\DataProcessing\MichelleCData.gdb"
arcpy.env.overwriteOutput = True
# input point fc
fc = r"C:\Users\bhodge\Dropbox (New England Aquarium)\MonumentsWork\MonumentSpeciesDiversity\DataProcessing\MichelleCData.gdb\SurveyPointsUTM19_TestSet_Short_6"
arcpy.MakeFeatureLayer_management(fc, "fc_lyr")
# Sort the table by fileid and eventno and create a new fc called fc_sort
sort_fields = [["FILEID", "ASCENDING"], ["EVENTNO", "ASCENDING"]]
fc_Sorted = arcpy.Sort_management("fc_lyr", "fc_sort", sort_fields)
# Create the search cursor
fields = ["SHAPE@"]
with arcpy.da.SearchCursor(fc_Sorted, fields) as cur:
for row in cur:
geom1 = row[0].getPart()
cur.next()
geom2 = row[0].getPart()
array = arcpy.Array()
array.add(geom1)
array.add(geom2)
polyline = arcpy.Polyline(array, arcpy.SpatialReference(26919))
with arcpy.da.InsertCursor(r"C:\Users\bhodge\Dropbox (New England Aquarium)\MonumentsWork\MonumentSpeciesDiversity\DataProcessing\MichelleCData.gdb\OnEffortLinesTEST", 'SHAPE@') as insertCursor:
insertCursor.insertRow([polyline])
array.removeAll()
del insertCursor
del cur The result is all the points used draw and are correct (the fc_Sorted /fc_sort), and the line feature class seems to updated in that rows are added, but no lines draw and the Length field is 0.
... View more
07-27-2020
10:12 AM
|
0
|
4
|
3638
|
|
POST
|
I am considering using the Web App Developer Java Script API to develop a custom app vs using ESRI's templates. Due to project funding, after app completion we don't have continuous funding to keep the app 'up to date', so we want the app to last as long as possible before needing any additional work. When using ESRI's templates and keeping it hosted on ArcGIS online organizational account, when new versions of js are released, they are automatically updated and kept running smoothly. However, when you create a custom app (developer) using the API, you need to host elsewhere (not arcgis online) and as js versions start to get outdated, the app, or parts of it, may begin to stop working properly (at least that is what I have heard happens). I am new to thinking about moving more towards the developer side of thing (instead of the out-of-the box templates), but what I want to build is not available through the current Web App Builder options, so I'm wondering if it's worth it for me to try and figure out how to make a custom app with the developer edition. I am curious as to what the expected time frame is for a custom developed app to last before it needs an overhaul to continue to run smoothly (1 year, 5 years, etc.)? I would appreciate any thoughts or experience on this. Thanks in advance to taking the time to consider this.
... View more
01-14-2020
11:16 AM
|
0
|
0
|
742
|
|
POST
|
This has happened to me on a number of occasions and I had to spend a lot of time recreating data after files were ruined by this. I always make backup files when doing any editing, but I never thought I'd need to make backup files of any file I want to just simply delete a field from. Frustrating.
... View more
12-17-2019
12:09 PM
|
0
|
0
|
1615
|
|
POST
|
Hi, I've recently developed a dashboard through my arcgis online account that I would like to post/embed on a website to share with the public. From what I can find, it seems as if you can only share dashboards with people who (1) have the dashboard application installed on their computer, and (2) have an arcgis online account. Does anyone know if there is any way for others to view your dashboard? I would like to be able to share my webmap (just like you can share/embed a webmap you develop in arcgis online), with the public via a website, but I would like them to be able to view all the widgets included in the dashboard as well. Is this possible? Or will it be in the future? Thanks!
... View more
05-07-2013
11:20 AM
|
0
|
0
|
635
|
|
POST
|
Eric, I emailed you with my data. Thank you for taking a look at this! jevans02, thanks so much for your reply. I have heard of a double kriging process, but haven't dove too deep into it. I will look at it more closely now, thanks for attaching the paper. I have been trying to figure out the zero-inflated negative binomial mixture model sometimes used to deal with this, but I will also look at the ZIP model you referenced. And thanks again for sending a reference! I appreciate it!
... View more
01-04-2012
05:37 AM
|
0
|
0
|
3448
|
|
POST
|
Hi, Thank you for your response. Generally, yes. The data is of whale sightings, and there are areas where the whales are seen most often (and where the highest survey effort is), so there are generally a couple pockets where the values are high, surrounded by a lot of 0's. The values are of numbers of whales accounting for the level of survey effort. So there are ares where there is at least some effort, but no whales sighted. These are most likely false 0's, meaning that those aren't necessarily areas where there are 0 whales there, but at the time of the survey, no whales were seen there. I'm also working on other models that might deal with this issue, however, my overall goal is to created an interpolated surface of whale distribution, which is why I'm trying to figure out how to make my data appropriate to use a krigging method. Thanks for your help on this, Brooke
... View more
01-03-2012
09:01 AM
|
0
|
0
|
3448
|
|
POST
|
Hi, I am having an issue with attempting to use krigging on a dataset I have. My data is not normally distributed and it is seriously 0 inflated. I want to normalize it in order to use krigging, but because I have 0 values, my only option is to use a Normal Score transformation using simple krigging, however, even that doesn't seem to be helping much. Is there any suggestions anyone can give me to normalize my data, or other interpolation options that might be better suited to my data? Thank you in advance for your help. Brooke
... View more
01-03-2012
06:32 AM
|
0
|
10
|
6282
|
|
POST
|
If anyone else is having this issue, I managed to get if fixed. I had been working in WGS84 with my points all in decimal degrees. I tried putting everything into a projection and updated the geometry (updated the lat/long) and re-ran the script and the lines are now falling right on the points. I don't know why it wasn't working in WGS84 (I don't understand why it matters), but this is working so I'm happy:.)
... View more
06-01-2011
09:55 AM
|
0
|
0
|
470
|
|
POST
|
I have a script that basically has an input point table, runs through a search cursor testing rows using an if statement. If the statement is true, I want to use those points to create a polyline. That part of the script is... [this is just a small section of it, but the script isn't the problem]. Basically this is just to show that I'm using the row.shape and the .getPart() to retrieve info from the table. featureList = [] geom = row.shape array1 = geom.getPart() array.add(array1) polyline = arcpy.Polyline(array) array.removeAll() featureList.append(polyline) My script runs fine, but I noticed if I zoom way in, my lines weren't exactly meeting my points. They were off anywhere from < 1 meter to about 10 meters. I then went back and looked at what the .getPart was retrieving and I noticed that it was adding significant digits onto the lat/long locations of the points. So where in my original table the longitude was -68.95, the .getPart would result in -68.9499999999999. Same with my latitude, the original value was 43.900002 and the .getPart would result in 43.900001526. I tried looking at the original point input table to see if perhaps there were more significant digits there that weren't being displayed in the table and also looked at the .dbf table that was used to create the original point table for the same thing, but it's not the case. I can't figure out why it is adding these significant digits and slightly changing the location. Has anyone else had this issue or know what could be causing this problem? Thank you in advance for any help! This is driving me crazy!
... View more
05-31-2011
01:18 PM
|
0
|
1
|
759
|
|
POST
|
Hi, I have created a model that has two iterators. One that iterates through a set of feature classes, and another that iterates through unique filed values. Because model builder only allows one iterator per model, I had to use a sub-model in my model for one of the iterators. The sub-model iterates through the feature classes, then I have that model linked within my other model to then iterate through unique field values. Basically, what I want it for all the feature classes in my feature dataset to then be broken down by all the unique values in a specified field. The problem is when I run the model, the feature class iterator sub-model only iterates through one of the feature classes, then runs the field iterator and then stops (saying it's complete). Does anyone know why it doesn't continue to iterate through all my feature classes and have any suggestions on how to fix it so it does? Thanks!
... View more
12-10-2010
07:14 AM
|
0
|
0
|
2006
|
|
POST
|
Hi Eric, Thanks for getting back to me. You are correct in that the pattern is not as distinct as my last post. The data in my last post was evenly distributed and there were a lot more points closer together, so I think the pattern was more dramatic. Here my point dataset is a bit more sparse and not evenly distributed, and at that scale I think it was a bit hard to see. I have attached a new pdf that is zoomed in more and shows the dots a bit better. There are two screen shots, and one includes the point dataset used for the interpolation. As you can see, it looks as though the dots on the raster are forming at where the points are. Also, while I have you here and sense you're a GA product engineer, I was wondering if you knew of any materials that go into depth on GA, in particular determining which method/parameter/model/transformation etc. to use. I have read the GA tutorial provided by ESRI, but it doesn't go into detail on each of the parameter options for the different interpolation methods. I usually find myself using what others have used in similar situations, or just guessing and trying different options until I find something that works, but when I'm writing up a report/paper, it's nice to have reasons why I chose certain parameters. If there are any materials, books, etc. that you think would be useful, I would greatly appreciate any recommendations. Thanks Eric! Brooke
... View more
10-15-2010
06:13 AM
|
0
|
0
|
801
|
|
POST
|
I wrote in a few weeks ago about dotted pattern in my interpolated raster in geostatistical analyst. I was able to fix it using a different model type. I am now using a different dataset and am seeing the same pattern (see attachment), but this time choosing a different model type does not rectify the problem. The pattern seems to occur from my point dataset used for the interpolation. No matter which model type I use, the pattern still occurs. Does anyone have any ideas on how I can fix this? Thanks, Brooke
... View more
10-14-2010
09:24 AM
|
0
|
3
|
2705
|
| Title | Kudos | Posted |
|---|---|---|
| 2 | 02-16-2021 01:04 PM | |
| 1 | 02-17-2021 11:11 AM | |
| 1 | 01-04-2021 08:30 AM | |
| 1 | 09-29-2020 11:12 AM |
| Online Status |
Offline
|
| Date Last Visited |
08-04-2022
01:16 PM
|