|
POST
|
Hi Joshua, Thanks for answering. Sadly, this did not actually work for me. I still have the issue of selecting all centroids that distance from all wells - and OBJECTID is indeed numeric. What other ways might I implement this, if you don't mind? This is the full code I am using. I'm basically trying to compare last names of well owners and nearby centroids to see if there is a match. import arcpy
arcpy.env.overwriteOutput = 1
# define a workspace
arcpy.env.workspace = r"C:\Users\tmc18\Desktop\comp_orps\NYS_Wells.gdb"
# Define input files
orps09 = r"C:\Users\tmc18\Desktop\comp_orps\centroids\madirps_point1.shp"
wells = r"C:\Users\tmc18\Desktop\comp_orps\NYS_Wells.gdb\Madison_DEC_Well_Logs_3_14_14_MASTER_COPY1"
# Make a feature layer
arcpy.MakeFeatureLayer_management(orps09, "orps09_FL")
arcpy.MakeFeatureLayer_management(wells, "wells1")
wells1 = "wells1"
# Create dictionary of last names of all well owners
well_owners = {}
rows = arcpy.da.SearchCursor(wells1, ["OBJECTID", "owner_last"])
for row in rows:
well_owners[row[0]] = [row[1]]
del row,rows
# Create search cursor which will iterate through wells
with arcpy.da.SearchCursor(wells1, ["OBJECTID"]) as cursor:
for row in cursor:
# set well owner name for this record
owner = well_owners[row[0]]
# select by attribute
arcpy.SelectLayerByAttribute_management(wells1,"NEW_SELECTION","OBJECTID = {}".format(row[0]))
# select by location
arcpy.SelectLayerByLocation_management("orps09_FL", "WITHIN_A_DISTANCE", wells, "0.5 kilometers", "NEW_SELECTION")
# Create dictionary of last names of selected orps
orps_owners = {}
rows = arcpy.da.SearchCursor("orps09_FL", ["FID", "owner_last"])
for row in rows:
orps_owners[row[0]] = [row[1]]
del row,rows
# create search cursor which will iterate through selected orps owners
with arcpy.da.SearchCursor("orps09_FL", ["FID"]) as orpscur:
for row in orpscur:
# set orps owner name
orpsowner = orps_owners[row[0]]
if owner != orpsowner:
print owner, orpsowner
continue
else:
with arcpy.da.UpdateCursor(wells, ["match"]) as cur:
for row in cur:
row[0] = "YES"
cur.updateRow(row)
del cur
continue
... View more
01-06-2015
11:10 AM
|
0
|
2
|
3347
|
|
POST
|
Hi Jake, Thank you, that solved that little hangup. The lock issue was my own fault, it was because I made my cursor an update cursor which locked the table I was trying to select features from. Thanks again for your help!
... View more
01-06-2015
08:44 AM
|
0
|
0
|
765
|
|
POST
|
Hi folks, I'm trying to use a search cursor to iterate through a table and select the nearest centroids to the feature in the cursor, but when I try this instead of only selecting the centroids nearest the point in the cursor, it instead selects all of the centroids that distance from all of the points, then iterates to the next feature and selects all of them again. Is it possible to make the SelectLayerByLocation_management function only select features based on a single point at a time? Here's the code I'm using:
# Create search cursor which will iterate through wells, selecting all centroids within a distance
with arcpy.da.SearchCursor(wells, ["OBJECTID"]) as cursor:
for row in cursor:
# select by location
arcpy.SelectLayerByLocation_management("orps09_FL", "WITHIN_A_DISTANCE", wells, "0.5 kilometers", "NEW_SELECTION") Thanks in advance, Tom
... View more
01-06-2015
07:46 AM
|
1
|
4
|
12841
|
|
POST
|
Hey folks, Pretty new to GIS and scripting (in any language) and I'm trying to write a program that will, basically: 1) look at a point that represents an unverified well location 2) search for all centroids within a certain distance and select them 3) compare the last name of the well owner with the last name of all selected centroid owners 4) if there is a match between any, put "yes" in a "match" column Here are the issues I'm having: 1) the arcpy.SelectLayerByLocation function requires a feature layer input. I added a line in my script that makes my centroid data into a feature layer, which actually creates a layer in my table of contents, and when I fix an error and try to run the script again, it stops almost immediately saying that the feature layer already exists. If I take it out of the script, then the feature layer is undefined for later. My supervisor (who has a good amount of GIS experience) says something is happening weirdly there and is unsure why. 2) lock issues. Every time I try to run it and it gets past the feature layer part, I get this error: Runtime error Traceback (most recent call last): File "<string>", line 17, in <module> File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6618, in SelectLayerByLocation raise e ExecuteError: ERROR 999999: Error executing function. Cannot acquire a lock. Cannot acquire a lock. Item not found in this collection. Failed to execute (SelectLayerByLocation). Can anyone point me in the right direction here? Here is the code I've written import arcpy
# define a workspace
arcpy.env.workspace = r"C:\Users\tmc18\Desktop\comp_orps\NYS_Wells.gdb"
# Define input files
orps = r"C:\Users\tmc18\Desktop\comp_orps\centroids\madirps_point1.shp"
wells = r"C:\Users\tmc18\Desktop\comp_orps\NYS_Wells.gdb\Madison_DEC_Well_Logs_3_14_14_MASTER_COPY1"
arcpy.MakeFeatureLayer_management(orps, "orpsFL")
# Create well update cursor, will compare the "owner_last" field value of the well used to select nearby centroids to the "owner_last"
# field of centroid data.
with arcpy.da.UpdateCursor(wells, ["match", "owner_last"]) as cursor:
for row in cursor:
# select by location
arcpy.SelectLayerByLocation_management("orpsFL", "WITHIN_A_DISTANCE", wells, "0.5 kilometers", "new_selection")
# create orps name cursor
orps_match = arcpy.da.SearchCursor("orpsFL", ["owner_last"])
# if the uppercase string value of the well owner's last name != the centroid, then the orps_match cursor will move to the next
# centroid name and try that one.
if str([row[1] for row in cursor]).upper != str([row[0] for row in orps_match]).upper:
orps_match.next
# but if they do match, we get a "yes" in the match column
else:
row[0] = "YES"
cursor.updateRow(row)
continue Thanks in advance!
... View more
12-31-2014
09:45 AM
|
0
|
2
|
5361
|
|
POST
|
Hi folks, I feel like there's a very simple answer to this because no matter how much I searched I couldn't find one, however I'm pretty much brand new to gdb's, have mostly just used shapefiles up until now and I'm having trouble getting python to access the table of/a shapefile within a geodatabase. Here is the script I'm writing currently, can someone give me some direction here? import arcpy
# Set workspace
arcpy.env.workspace = "C:\Users\tmc18\Desktop\comp_orps\NYS_Wells.gdb"
# Define input feature layer & wells
orps09 = "C:\Users\tmc18\Desktop\comp_orps\centroids\madirps_point_Layer.lyr"
wells = "C:\Users\tmc18\Desktop\comp_orps\NYS_Wells.gdb\Madison_DEC_Well_Logs_3_14_14_MASTER_COPY.dbf"
wellshp = "C:\Users\tmc18\Desktop\comp_orps\NYS_Wells.gdb\Madison_DEC_Well_Logs_3_14_14_MASTER_COPY.shp"
# Define fields cursors will require
county = "County"
# Create search cursor
with arcpy.da.SearchCursor(wells, [county]) as cursor:
for row in cursor:
if county == "MADISON":
arcpy.SelectLayerByLocation_management(orps09, [within_a_distance, "1 km", add_to_selection])
cursor.next(row)
else:
continue I'm getting errors because within the gdb, the dbf and shapefiles don't exist. Since I see them there in ArcCatalog I thought it might work anyways, but obviously that is not the case. Many thanks in advance for your help, Tom
... View more
12-30-2014
08:35 AM
|
0
|
6
|
8457
|
|
POST
|
Thank you again my friend. I unfortunately did not relate "vertex" and "point" in my head; though it does make sense that the tools that work with verticies would also work for a point. Your help is much appreciated!
... View more
10-01-2014
12:32 PM
|
0
|
1
|
1827
|
|
POST
|
I'm wondering if there is a way to move a point feature to a specifc lat/long location. I am aware of the "move" tool in the edit bar, but it's only relational - it moves the point a certain distance relative to where it is, and besides, the units are in "x and y" distances and I have no idea what grid that's referencing in terms of my map, nor even how to find out. If I try to move a point by (+1, +1), for example, then it moves it fully out of the county I'm working on. It's really quite annoying, not to mention time consuming to determine the proper location that a point should be in, and then have to mark said spot, pan back to the point and then zoom out, drag and drop and then zoom in for finer placement. I'm really hoping there is an easier way. Thanks, Tom
... View more
10-01-2014
12:13 PM
|
0
|
4
|
5226
|
|
POST
|
Hi folks. This is a really basic question, I know, but I can't for the life of me figure it out. I accidentally added a callout with the go to XY tool and cannot remove it. I have searched all over online and in the ArcGIS help page and haven't found anything. Anyone know how to do this? Thanks in advance, Tom
... View more
10-01-2014
11:53 AM
|
1
|
6
|
25244
|
|
POST
|
Basically just trying to get python to concatenate a couple of field values into a link, specifically to get it to make a complete link to the image mate online using tax id and swis code found in said table. Here's my code: *disclaimer* I have very little experience coding... import arcpy parcel = "(address to my file here)" image = "http://property.tompkins-co.org/IMO/propdetail.aspx?swis=" mate = "&printkey=" swis = "SWIS" sbl = "PRINTKEY" link = "link" with arcpy.da.UpdateCursor(parcel, [swis, sbl, link]) as cursor: for row in cursor: row[2] == image.string() + row[0] + mate.string() + row[1] cursor.updateRow(row) print "finished" I keep getting the error: Runtime error Traceback (most recent call last): File "<string>", line 11, in <module> and then a runtime error saying it can't access the file I'm trying to get it to access. Is my code OK, and it just can't access the file? Or is my code incorrect as well? Thanks in advance, Tom
... View more
09-17-2014
11:45 AM
|
0
|
2
|
1491
|
|
POST
|
Hi Xander, I actually already have DEM's of the county in question. I am rather new to GIS and was unsure of how to go about this. I downloaded the DEM's online, converted them to raster and then did a raster to point shapefile. Currently I also have a full raster image (converted from the ~30 DEM's I downloaded and mosaic'd together) of the county. Can I perform the extract values to points on that raster image? Thanks for your advice, Tom
... View more
08-12-2014
05:56 AM
|
0
|
1
|
1122
|
|
POST
|
Hi folks. I want to join a layer of elevation points (~47 million of them for this given county) to a layer of features (~1700) that I want to know the elevation of. Is there a way to speed this process up or just generally make it less awful? My machine has 8gb of ram and 3+ ghz of processing power and it got through less than 1/6 of the points in about an hour. Do I just need to brute force it and let it run for a day? Thanks in advance, Tom
... View more
08-12-2014
05:26 AM
|
0
|
3
|
1767
|
|
POST
|
Ian, Using [-1] totally fixed the problem; I didn't realize that was an option. Thank you! I will have to do some spot checking, but that's fine. this has already saved me time. I'd like to sincerely thank both you and Florian- you've helped TREMENDOUSLY.
... View more
07-23-2014
11:32 AM
|
0
|
1
|
1632
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-01-2014 11:53 AM | |
| 1 | 01-06-2015 07:46 AM | |
| 1 | 07-22-2014 09:28 AM | |
| 2 | 07-22-2014 12:39 PM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:23 AM
|