|
POST
|
I am trying to populate the new created point with X, Y coordinates but i have not been successful. The fields it needs to populate on the point feature class is "Point_X" and "Pont_Y". it seems as only "Point_Y" is the only one that gets populated. I also need to take two fields from the parcels ("SiteStreet" & StreetType") and combine them to populate a field from on the point feature layer (StreetName) i am unsure on how to do that. #import modules
import arcpy
"""
tool box parameters
point param = feature set
targetpoint = featurelayer
parcel = featurelayer
"""
arcpy.env.qualifiedFieldNames = False
point = arcpy.GetParameterAsText(0) #point boolen
targetpoint = "CCAP1" #target point feature class
parcel = "parcels" #target feature class
parcel_lyr = 'parcel_lyr'
for prow in arcpy.da.SearchCursor(point,'SHAPE@XY'):
x,y = prow[0]
del prow
point1 = arcpy.Point(x, y)
ptGeometry = arcpy.PointGeometry(point1)
CC_list = []
with arcpy.da.SearchCursor(targetpoint, ["AddressID"]) as cursor:
for row in cursor:
try:
if "CC" in row[0]:
CC_list.append(int(row[0].strip("CC")))
except TypeError:
pass
del cursor
CC_list.sort()
AddressID = CC_list[-1] + 1
AddressID = 'CC' + str(AddressID)
arcpy.MakeFeatureLayer_management(parcel,parcel_lyr)
arcpy.SelectLayerByLocation_management(parcel_lyr,"INTERSECT",ptGeometry)
fldList = ['ACCOUNT','OwnerName','SiteAddres','SiteNum','siteNumSfx','Predir','SiteStreet', 'StreetType', 'Postdir', 'SiteCity', 'SiteZip']
fldDict ={}
if int(arcpy.GetCount_management(parcel_lyr).getOutput(0))==1:
for parrow in arcpy.da.SearchCursor(parcel_lyr,fldList):
for x in range(len(fldList)):
fldDict[fldList ]=parrow
del parrow
fldAttList = []
for x in range(len(fldList)):
fldAttList.append(fldDict[fldList ])
manualFields = ["SiteState","FacltyType", "StructType","GIS_STEW", "UpdateBy","Verified", "Status", "StructCat", "APA_CODE","AddressID", "POINT_X", "POINT_Y"]
for fld in manualFields:
fldList.append(fld)
fixedAtts = ["ID","Single Family Home","Primary, Private","CanyonCo", "TA", "Yes, GRM, TA","Active","Residential","1110", AddressID, x, y]
for att in fixedAtts:
fldAttList.append(att)
fldAttList.append(point1)
fldtuple = (fldAttList)
fldList.append( 'SHAPE@XY')
tprow = arcpy.da.InsertCursor(targetpoint, fldList)
tprow.insertRow(fldtuple)
del tprow
... View more
07-20-2015
01:26 PM
|
0
|
20
|
6850
|
|
POST
|
That is the weirdest thing. I added the "POINT_X", "POINT_Y" and x,y to the same lines as you did but i got an error but now that i copied and pasted what you have i got it to work, kind of for some weird reason i have "10" in the "POINT_x" field. I know that is not correct. also the point feature class has a field called "StreetName" that i need populate from two fields from the parcels and they are "SiteStreet" & StreetType". as far as my other quesitons, would you like me to start a different post? you mentioned using a else statement below so if there was more or less than 1, could you show how this works with the current code?, so i could click on multiple parcels to create new address points? this would be handy of i need to create multiple points for new subdivisions. can you also attach a copy of the model that you use for please.
... View more
07-20-2015
10:36 AM
|
0
|
3
|
786
|
|
POST
|
list of fields from parcels that i need to transfer to point feature that are the same fields as the point feature class. ACCOUNT, SiteAddres, SiteNum, SiteNumbSfx, Predir, Predir, SiteStreet, StreetType, Postdir, SiteCity, SiteZip, OwnerName, SubName. The point feature class has a field called "StreetName" that i need populate from two fields from the parcels and they are "SiteStreet" & StreetType". I also need to populate the fields called "AddressID" (unique Identifier) I currently have this working with the code below. the only thing that i need to do is populate the fields "POINT_X" and "POINT_Y" with x,y coordinates. Thanks for the explanation of the code i was about to ask if you can explain it. I don't quiet understand the loops and python dictiionarys, and going field list and populating the dictionary with the field name and the matching attribute. you mentioned using a else statement below so if there was more or less than 1, could you show how this works with the current code?, so i could click on multiple parcels to create new address points? this would be handy of i need to create multiple points for new subdivisions. can you also attach a copy of the model that you use for please. #import modules
import arcpy
"""
tool box parameters
point param = feature set
targetpoint = featurelayer
parcel = featurelayer
"""
arcpy.env.qualifiedFieldNames = False
point = arcpy.GetParameterAsText(0) #point boolen
targetpoint = "CCAP1" #target point feature class
parcel = "parcels" #target feature class
parcel_lyr = 'parcel_lyr'
for prow in arcpy.da.SearchCursor(point,'SHAPE@XY'):
x,y = prow[0]
del prow
point1 = arcpy.Point(x, y)
ptGeometry = arcpy.PointGeometry(point1)
CC_list = []
with arcpy.da.SearchCursor(targetpoint, ["AddressID"]) as cursor:
for row in cursor:
try:
if "CC" in row[0]:
CC_list.append(int(row[0].strip("CC")))
except TypeError:
pass
del cursor
CC_list.sort()
AddressID = CC_list[-1] + 1
AddressID = 'CC' + str(AddressID)
arcpy.MakeFeatureLayer_management(parcel,parcel_lyr)
arcpy.SelectLayerByLocation_management(parcel_lyr,"INTERSECT",ptGeometry)
fldList = ['ACCOUNT','OwnerName','SiteAddres','SiteNum','siteNumSfx','Predir','SiteStreet', 'StreetType', 'Postdir', 'SiteCity', 'SiteZip']
fldDict ={}
if int(arcpy.GetCount_management(parcel_lyr).getOutput(0))==1:
for parrow in arcpy.da.SearchCursor(parcel_lyr,fldList):
for x in range(len(fldList)):
fldDict[fldList ]=parrow
del parrow
fldAttList = []
for x in range(len(fldList)):
fldAttList.append(fldDict[fldList ])
manualFields = ["SiteState","FacltyType", "StructType","GIS_STEW", "UpdateBy","Verified", "Status", "StructCat", "APA_CODE","AddressID"]
for fld in manualFields:
fldList.append(fld)
fixedAtts = ["ID","Single Family Home","Primary, Private","CanyonCo", "TA", "Yes, GRM, TA","Active","Residential","1110",AddressID, ]
for att in fixedAtts:
fldAttList.append(att)
fldAttList.append(point1)
fldtuple = (fldAttList)
fldList.append( 'SHAPE@XY')
tprow = arcpy.da.InsertCursor(targetpoint,fldList)
tprow.insertRow(fldtuple)
del tprow
... View more
07-20-2015
08:41 AM
|
0
|
1
|
1652
|
|
POST
|
Sorry to keep bugging but i just noticed that the code doesn't populate the AddressID, POINT_X, POINT_Y fields. I tried to include into your code but i am unable to work. I also need to populate field "StreetName" on the point from the Parcels, but the Parcels has the two fields SiteStreet & StreetType. I need to take the two fields SiteStreet & StreetType from the parcels and insert them together into the StreetName of the point. #import modules
import arcpy
"""
tool box parameters
point param = feature set
targetpoint = featurelayer
parcel = featurelayer
"""
point = arcpy.GetParameterAsText(0) #point boolen
targetpoint = "Test1" #target point feature class
parcel = "TaxParcels" #target feature class
parcel_lyr = 'parcel_lyr'
for prow in arcpy.da.SearchCursor(point,'SHAPE@XY'):
x,y = prow[0]
del prow
point1 = arcpy.Point(x, y)
ptGeometry = arcpy.PointGeometry(point1)
CC_list = []
with arcpy.da.SearchCursor(fc, ["AddressID"]) as cursor:
for row in cursor:
try:
if "CC" in row[0]:
CC_list.append(int(row[0].strip("CC")))
except TypeError:
pass
del cursor
CC_list.sort()
AddressID = CC_list[-1] + 1
AddressID = 'CC' + str(AddressID)
arcpy.MakeFeatureLayer_management(parcel,parcel_lyr)
arcpy.SelectLayerByLocation_management(parcel_lyr,"INTERSECT",ptGeometry)
fldList = ['ACCOUNT','OWNERNAME','SiteAddres','SiteNum','SiteNumSfx','Predir','SiteStreet', 'StreetType', 'Postdir', 'SiteCity', 'SiteZip', 'OwnerName']
fldDict ={}
if int(arcpy.GetCount_management(parcel_lyr).getOutput(0))==1:
for parrow in arcpy.da.SearchCursor(parcel_lyr,fldList):
for x in range(len(fldList)):
fldDict[fldList ]=parrow
del parrow
fldAttList = []
for x in range(len(fldList)):
fldAttList.append(fldDict[fldList ])
manualFields = ["FacltyType", "StructType", "Verified", "Status", "StructCat", "APA_CODE"]
for fld in manualFields:
fldList.append(fld)
fixedAtts = ["Single Family Home","Primary, Private","Yes, GRM, TA","Active","Residential","1110"]
for att in fixedAtts:
fldAttList.append(att)
fldAttList.append(point1)
otherFields = ["X_Coord", "Y_Coord", "SHAPE@XY", "ADDRESSID"]
for oth in otherFields:
fldAttList.append(point1)
fldtuple = (fldAttList)
fldList.append( 'SHAPE@XY')
tprow = arcpy.da.InsertCursor(targetpoint,fldList)
tprow.insertRow(fldtuple)
del tprow
... View more
07-17-2015
01:58 PM
|
0
|
8
|
1652
|
|
POST
|
Wes, that worked awesome for creating a point and updating the points attributes! but i am having trouble putting and uncertain on how to implementing the arcpy.da.update cursor into the point dictionary. I need to be able to add the manualFields into the point. Thanks for you help Wes manualFields = ["FacltyType", "StructType", "Verified", "Status", "StructCat", "APA_CODE", "ACCOUNT", 'SiteStreet', 'SHAPE@X', 'SHAPE@Y']
with arcpy.da.UpdateCursor(ptGeometry, manualFields) as rows:
for row in rows:
row[0] = ("Single Family Home")
row[1] = ("Primary, Private")
row[2] = ("Yes, GRM, TA")
row[3] = ("Active")
row[4] = ("Residential")
row[5] = ("1110")
rows.updateRow(row)
... View more
07-17-2015
09:03 AM
|
0
|
10
|
1652
|
|
DOC
|
I am not sure what you mean by "and change something". what would one change?
... View more
07-16-2015
04:39 PM
|
0
|
0
|
6830
|
|
POST
|
Thank you for the reply. I am trying to implement your suggestions but i come up with a fail. current code. import arcpy
from arcpy import env
# Allow overwrite
arcpy.env.overwriteOutput = True
arcpy.env.qualifiedFieldNames = False
arcpy.env.workspace = r"Database Servers\DSD15_SQLEXPRESS.gds\TwoWay (VERSION:dbo.DEFAULT)"
# Script user input parameters
fc = "TEST"
polygonLayer = "parcels"
poly = "ACCOUNT"#
Pnt = "Account"#
input = arcpy.GetParameterAsText(0)
rows = arcpy.SearchCursor(input)
for row in rows:
geom = row.Shape
X = geom.centroid.X
Y = geom.centroid.Y
del rows
# Create point
inPoint = arcpy.PointGeometry(arcpy.Point(X,Y))
#Select parcel within selected Address Points
arcpy.SelectLayerByLocation_management(polygonLayer, "INTERSECT", inPoint)
# Make a layer from the feature class
arcpy.MakeFeatureLayer_management(fc, "Par")
# define the field list from the parcels
sourceFieldsList = ["ACCOUNT", poly,"SiteAddres",'SiteNum', 'SiteStreet','SiteNumSfx','Predir','SiteStreet', 'StreetType', 'Postdir', 'SiteCity', 'SiteZIP', 'OwnerName']
# populate the dictionary will all selected polygons
valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor("Par", sourceFieldsList)}
# define the field list to the points
updateFieldsList = ["Account", Pnt,"SiteAddres", 'SiteNum', 'SiteStreet', 'SiteNumSfx','Predir','SiteStreet', 'StreetType', 'Postdir', 'SiteCity', 'SiteZip', 'OwnerName']
arcpy.da.UpdateCursor(inPoint, updateFieldsList)
for updateRow in updateRows:
keyValue = updateRow[0]
if keyValue in valueDict:
for n in range (1,len(sourceFieldsList)):
updateRow = valueDict[keyValue][n-1]
updateRows.updateRow(updateRow)
rowInserter = arcpy.da.InsertCursor(fc, updateFieldsList)
arcpy.da.UpdateCursor(fc, updateFieldsList)
for row in rows:
row[0] = ("Single Family Home")
row[1] = ("Primary, Private")
row[2] = ("Yes, GRM, TA")
row[3] = ("Active")
row[4] = ("Residential")
row[5] = ("1110")
rows.updateRow(row)
rowInserter.insertRow(row)
arcpy.RefreshActiveView()
... View more
07-16-2015
03:33 PM
|
0
|
1
|
1652
|
|
POST
|
I am working on a add-on button that i would like to be able to click on a parcel and create a point where i click and i need the new populate with the Parcels attributes. I currently have two scripts that work, one creates the point and the other does spatial join and populates the selected point with the tax parcels attributes but the point has to already be there and selected. I need to be able to combine the two scripts into one. I think my biggest problem is that i don't know how to select the point once it's created to be able to spatial join and update the point with the Parcels attributes. I would gratefully appreciate any help on combining these two. My initial try was to use the sort to get the highest AddressID which was created in the first script (CC_list.sort()) and then was going to use selecLayerByLocation to select the parcel to do the spatial join with the point but nothing is selected. for row in sorted(arcpy.da.SearchCursor(fc, ["OBJECTID", "AddressID"]),reverse=True):
mostRecentOID=row[0]
mostRecentAddressID=row[1]
break
#Select parcel within selected Address Points
arcpy.SelectLayerByLocation_management(polygonLayer, "INTERSECT", pointGeom) Create point script import arcpy
from arcpy import env
import time
import datetime
# Allow overwrite
arcpy.env.overwriteOutput = True
arcpy.env.qualifiedFieldNames = False
arcpy.env.workspace = r"Database Servers\DSD15_SQLEXPRESS.gds\TwoWay (VERSION:dbo.DEFAULT)"
# Script user input parameters
#pointLayer = "TEST.DBO.CCAPTEST" #pointlayer
fc = "TEST"
# Start an edit session. Must provide the workspace.
edit = arcpy.da.Editor(arcpy.env.workspace)
# Edit session is started without an undo/redo stack for versioned data
# (for second argument, use False for unversioned data)
edit.startEditing(True)
# Start an edit operation
edit.startOperation()
input = arcpy.GetParameterAsText(0)
rows = arcpy.SearchCursor(input)
for row in rows:
geom = row.Shape
X = geom.centroid.X
Y = geom.centroid.Y
del rows
CC_list = []
with arcpy.da.SearchCursor(fc, ["AddressID"]) as cursor:
for row in cursor:
try:
if "CC" in row[0]:
CC_list.append(int(row[0].strip("CC")))
except TypeError:
pass
del cursor
CC_list.sort()
AddressID = CC_list[-1] + 1
AddressID = 'CC' + str(AddressID)
pointGeom = arcpy.PointGeometry(arcpy.Point(X, Y))
row_values = [(X, Y, (X, Y), AddressID)]
cursor = arcpy.da.InsertCursor(fc, ["POINT_X", "POINT_Y", "SHAPE@XY", "AddressID"])
for row in row_values:
cursor.insertRow(row)
#del cursor
# Stop the edit operation.
edit.stopOperation()
# Stop the edit session and save the changes
edit.stopEditing(True)
arcpy.RefreshActiveView() Spatial join Update point attributes script. # Import arcpy module
import arcpy
# Allow overwrite
arcpy.env.overwriteOutput = True
# Script user input parameters
polygonLayer = "Taxparcels"
pointLayer = "TEST" #Point Layer
arcpy.env.workspace = r"Database Servers\DSD15_SQLEXPRESS.gds\TwoWay (VERSION:dbo.DEFAULT)"
poly = "ACCOUNT_1"
Pnt = "Account"
sjpoints = "In_memory\sjpoints"
parcelsCount = int(arcpy.GetCount_management(pointLayer).getOutput(0))
dsc = arcpy.Describe(pointLayer)
selection_set = dsc.FIDSet
if len(selection_set) == 0:
print "There are no features selected"
elif parcelsCount >= 1:
#Run the Spatial Join tool, using the defaults for the join operation and join type
arcpy.SpatialJoin_analysis(pointLayer, polygonLayer, sjpoints)
# define the field list from the spatial join
sourceFieldsList = ["TARGET_FID", poly,"ACCOUNT_1","SiteAddres_1",'SiteNum_1', 'SiteStreet_1','SiteNumSfx_1','Predir_1','SiteStreet_1', 'StreetType_1', 'Postdir_1', 'SiteCity_1', 'SiteZIP_1', 'OwnerName_1']
# define the field list to the original points
updateFieldsList = ["OID@", Pnt,"Account","SiteAddres", 'SiteNum', 'StreetName', 'SiteNumSfx','Predir','SiteStreet', 'StreetType', 'Postdir', 'SiteCity', 'SiteZip', 'OwnerName']
# Start an edit session. Must provide the workspace.
edit = arcpy.da.Editor(arcpy.env.workspace)
# Edit session is started without an undo/redo stack for versioned data
# (for second argument, use False for unversioned data)
edit.startEditing(True)
# Start an edit operation
edit.startOperation()
manualFields = ["FacltyType", "StructType", "Verified", "Status", "StructCat", "APA_CODE", "ACCOUNT", 'SiteStreet']
with arcpy.da.UpdateCursor(pointLayer, manualFields) as rows:
for row in rows:
row[0] = ("Single Family Home")
row[1] = ("Primary, Private")
row[2] = ("Yes, GRM, TA")
row[3] = ("Active")
row[4] = ("Residential")
row[5] = ("1110")
rows.updateRow(row)
del row
del rows
# populate the dictionary from the polygon
valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sjpoints, sourceFieldsList)}
with arcpy.da.UpdateCursor(pointLayer, updateFieldsList) as updateRows:
for updateRow in updateRows:
keyValue = updateRow[0]
if keyValue in valueDict:
for n in range (1,len(sourceFieldsList)):
updateRow = valueDict[keyValue][n-1]
updateRows.updateRow(updateRow)
# Stop the edit operation.
edit.stopOperation()
# Stop the edit session and save the changes
edit.stopEditing(True)
arcpy.RefreshActiveView()
#arcpy.Delete_management(sjpoints)
... View more
07-16-2015
01:12 PM
|
0
|
15
|
5628
|
|
DOC
|
What is the best way to upgrade to a new version with out having to re-create and relink your layers in e-search widget? replacing the eSearch folder in stemap/widgets makes you redo the widget and takes time. Awesome widget!
... View more
07-10-2015
02:16 PM
|
0
|
0
|
6830
|
|
POST
|
Richard, I recreated the database and re-ran the code and it ran fine. some how the address point database got corrupted. Now if the address point did not an have attribute in the "Account" field this would not work because there is nothing to match with the Parcels "ACCOUNT" attribute. So would a spatial join work in a situation where the address point does not have an attribute in the "Account" field. Thanks for your help!
... View more
07-09-2015
11:16 AM
|
0
|
1
|
1025
|
|
POST
|
Richard, i was getting the ArcMap drawing errors the request operation is invalid on a close state. I removed the "with" from line 39 and replaced with the edit = arcpy.da.Editor(arcpy.env.workspace) edit.startEditing and edit.startOperation and i did not the the close state error. I did notice that for some address point the attributes were updated with the same attributes. I have attached a picture of two parcels that have different "ACCOUNT" & "siteNum number from each other. I select the point on south parcel and run the code and seems to run fine but then i select the address point of the parcel above and it populates with the info from the south parcel.. weird
... View more
07-09-2015
10:21 AM
|
0
|
3
|
1025
|
|
POST
|
Richard thanks for the awesome feedback and suggestions. in this situation how would i go about getting syntax to get errors reported and automated closure of the session? I have tried your code you posted but nothing happens the FC selected point doesn't get any updated attributes and there is no error.
... View more
07-09-2015
08:20 AM
|
0
|
5
|
1915
|
|
POST
|
It must be FireFox, i just posted an update to my code and worked . I remove some unnecessary lines.
... View more
07-08-2015
03:26 PM
|
0
|
1
|
1915
|
|
POST
|
That's usually how post code too, but for some reason it mess it up. Maybe it's firefox....
... View more
07-08-2015
03:22 PM
|
0
|
0
|
1915
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-27-2022 11:37 AM | |
| 1 | 10-31-2023 10:16 AM | |
| 1 | 02-16-2023 01:50 PM | |
| 1 | 08-11-2021 11:13 AM | |
| 1 | 01-06-2021 10:45 AM |
| Online Status |
Offline
|
| Date Last Visited |
09-10-2024
10:42 AM
|