POST
|
Best I could do was create a dummy survey with links to all the surveys I need. Lol.
... View more
09-07-2023
07:02 AM
|
0
|
0
|
471
|
POST
|
Thanks David, that was it. I swear I tried every combination of moving the 'counter++' and 'return' statement around to try and make this work before posting on here. Never thought to put the 'counter++' in the list. I knew someone would take a look at it and see what's wrong, so I appreciate you taking the time. I'll mark your answer as correct. For those looking at this in posterity, there were a few minor additional adjustments I had to make to get it 100%, so here's the final code (These were issues in my original post): Line 5 | Limited the number of fields to just 'OBJECTID' and 'assetNodeTo' instead of '*' Line 6 | There was a missing comma in the filter statement. Line 10 | Should be: numToNodes, not numToNode. Line 35 | Should be: "result": $feature.assetID. This will return the existing Asset ID instead of the OBJECTID of one of the lines. I should also note that this will only work for lines with 2 vertices. If you have more than two, the updated line will be reduced to 2, so it will return a straight line. This isn't ideal in some circumstances and I'll update this when I work in some code for lines with >2 vertices. var pointGeometryX = Text(Geometry($feature).x);
var pointGeometryY = Text(Geometry($feature).y);
var pointID = $feature.assetID;
var lineImport = FeatureSetbyName($datastore, "LineLayer", ['OBJECTID','assetNodeTo'], true);
var lineFilter = filter(lineImport, "assetNodeTo = @pointID"); //Filter Line Layer to just the To Nodes that join to the moved point, Join is based on Asset ID (point.assetID=line.assetNodeTo)
var AddList = [];
var counter = 0;
var numToNodes = Count(lineFilter);
if (numToNodes > 0) {
for (var i in lineFilter) {
var LineGeomPaths = Geometry(i).paths;
var fromNodeGeom = LineGeomPaths[0][0]; //Get From Nodes XY Coordinates
var fromNodeGeomX = Text(fromNodeGeom.x);
var fromNodeGeomY = Text(fromNodeGeom.y);
var polylineJSON = { //Build Polyline layer with new To Node (New moved point geometry), keep same From Node
"paths": [[
[fromNodeGeomX, fromNodeGeomY, 0],
[pointGeometryX, pointGeometryY, 0]
]],
"spatialReference": {
"wkid":2249
}
};
var polyFinal = Polyline(polylineJSON)
AddList[counter++] = {
"OBJECTID": i.OBJECTID,
"geometry": polyFinal
};
}
return {
"result": $feature.assetID,
"edit": [{
"className": "LineLayer",
"updates": AddList
}]
}
} else {
return $feature.assetID
}
... View more
03-17-2023
04:05 AM
|
1
|
0
|
459
|
POST
|
No it's not, I edited to make it more understandable to a wider audience. I already caught a couple things and I'm editing it now. Generally speaking, it does in fact work, it just doesn't edit more than 1 line.
... View more
03-16-2023
11:54 AM
|
0
|
0
|
497
|
POST
|
Hi Everyone, I'm trying to edit a line feature class when a To Node point is moved. The arcade attribute rule I wrote works, but it only moves 1 line that has a matching ID. It seems like it is the first OBJECTID the script encounters. For some reason, the rest of the lines aren't moving. Does anyone see anything in this code that could be preventing that? var pointGeometryX = Text(Geometry($feature).x) //X Coordinate of Point to Be Moved
var pointGeometryY = Text(Geometry($feature).y) //Y Coordinate of Point to Be Moved
var pointID = $feature.assetID //Asset ID of Point to be Moved
var lineImport = FeatureSetbyName($datastore, "LineLayer",['*'],true) //Line Layer to be moved based on new location of Point
var lineFilter = filter(lineImport "assetNodeTo = @pointID") //Filter Line Layer to just the To Nodes that join to the moved point, Join is based on Asset ID (point.assetID=line.assetNodeTo)
var AddList = [] //Create empty list
var counter = 0 //Set counter
var numToNodes= Count(lineFilter) //Get Count of Filtered data
if (numToNodes > 0) { //If there are 1 or more To Nodes, execute loop
for (var i in lineFilter) { //Loop through all rows in filtered data
var LineGeomPaths = Geometry(i).paths ;//Get Geometry of Line Layer
var fromNodeGeom = LineGeomPaths[0][0]; //Get From Nodes XY Coordinates
var fromNodeGeomX = Text(fromNodeGeom.x); //Get Text From Node X
var fromNodeGeomY = Text(fromNodeGeom.y); // Get Text From Node Y
var polylineJSON = { "paths": [[[fromNodeGeomX,fromNodeGeomY,0],[pointGeometryX,pointGeometryY,0]]],"spatialReference": {"wkid":2249}}; //Build Polyline layer with new To Node (New moved point geometry), keep same From Node
var polyFinal=Polyline(polylineJSON)// Build Polyline
AddList[counter] = {'OBJECTID': i.OBJECTID,'geometry': polyFinal}; //Add to List
}
}
counter++
}
return {'result': i.OBJECTID,'edit': [{'className': 'LineLayer','updates': AddList}]}//Return edit statement
else { return $feature.assetID} //If no To Nodes, overwrite the assetID with current value and exit loop
... View more
03-16-2023
11:39 AM
|
0
|
5
|
523
|
DOC
|
I wasn't able to get this going with multiple records. I ended up running the script every minute and there are only 7 or 8 a day so the likelihood of multiple features being entered within that time period is very minimal (not to mention with this particular map, it's not apocalyptic if it does happen). I think in the future I will need to take another look at it. If you work it out in the meantime, please post it here. I did end up being able to send emails to 4 different people based on a Department field, and have multiple other fields appear formatted in the email. This script has been incredibly useful.
... View more
04-30-2018
05:06 AM
|
0
|
0
|
17198
|
POST
|
Neil, I just finished creating a model which symbolizes SMH Inspections based on when the inspection was entered into the related table. It is based on a field in the SMH Feature, exactly like what Randy was talking about above, but joined to the Inspection Table and run using a Python script in Windows Task Scheduler. I populate that field with a "Yes" to indicate it was inspected within the last month (Green Diamond), which is hidden and not editable by field staff. When a month elapses, the yes will change back to <Null> and the symbology will change back to a Red Diamond. This is the basic outline: The first 4 tools clear any of the existing "Yes"(s) in the Feature Class and allow it to be populated with the most recent data. You then join the SMH Inspection FC and the Inspection Table. You MUST make the FC a Table View first however, or the tool will not run when called in Python. The Inspection Table must be made into a Query Table so you can pull the records within the last month. Here's what that looks like: Make sure to enter in the time you want in the Expression. I will ultimately use the 'created_date' field. This will pull all records in the last 30 days. Then Join to the FC Table View and keep only matching records. Field Calculate the designated field in the FC with a value (Yes for me) Remove the Join. In order to get this to run automatically, open IDLE and enter the following: import arcpy
#Copy Toolbox Path Properties>Location
arcpy.ImportToolbox("C:\Users\USER NAME\AppData\Roaming\ESRI\Desktop10.5\ArcCatalog\DATABASE NAME.sde\TOOLBOX NAME (do not include .tbx)")
#Copy FC Path Properties>Name, You must assign an Alias to the Toolbox
arcpy.ToolboxALIAS.ModelName("C:\Users\USER NAME\AppData\Roaming\ESRI\Desktop10.5\ArcCatalog\DATABASE NAME.sde\FEATURE CLASS NAME")
#This is the first parameter at the beginning of the model
#You may need to change the backslashes to forward slashes
print "Completed"
Run at your convenience with Windows Task Scheduler. I know this is more than what you want so you can definitely eliminate the time part of it if you just want to see that it was inspected at some point. I just put this all together since others may find it useful and I literally just finished it so it's still fresh in my mind. Fred
... View more
03-22-2018
12:19 PM
|
0
|
0
|
583
|
DOC
|
Actually, I do have another question. I am returning the text, but it is formatted with brackets and commas etc. ( This is in the email) I managed to format it using the following code, but it only returns 1 record. def newList():
mergelist = zip(Address, Street, Department)
for c1,c2,c3 in mergelist:
return '{} {} {}\n'.format(c1, c2, c3)
FROM = 'REDACTED'
TO = ['REDACTED']
SUBJECT = 'New GIS Feature Added'
TEXT = "Features with Addresses at" + str(newList()) + " " + "\n\nwere added to the DPW GIS layer"
Ideally, I'd like it do tabulate all the records that are appended to the lists in a readable format in the email: 62 Burford Avenue Water 26 Central Street Sewer 115 Elm Street Operations I understand the formatting part, I just don't know why it isn't returning all the records in the list. Thanks again.
... View more
01-16-2018
09:03 AM
|
0
|
0
|
17197
|
DOC
|
Awesome Jake, that worked. Thanks. That was the last hurdle I had to implementing this. I'll post a more lengthy post on other issues I had that other people may find useful that aren't in this thread when I have a minute.
... View more
01-02-2018
06:47 AM
|
0
|
0
|
17196
|
DOC
|
Thanks Jake. I believe that is what I have as it is. Here is the whole thing, with sensitive parts redacted. I put it together piecemeal based on feedback in this thread as well as the previous thread. import urllib2, json, urllib, datetime, time, smtplib
from datetime import timedelta
Department = []
oidList = []
Street = []
Address = []
URL = 'REDACTED'
params = {'f': 'pjson', 'where': "1=1", 'outfields' : 'OBJECTID, created_date, Department, Street, Address', 'returnGeometry' : 'false'}
req = urllib2.Request(URL, urllib.urlencode(params))
response = urllib2.urlopen(req)
data = json.load(response)
for feat in data['features']:
createDate = feat['attributes']['created_date']
createDate = int(str(createDate)[0:-3])
t = datetime.datetime.now() - timedelta(hours=24)
t = time.mktime(t.timetuple())
if createDate > t:
Department.append(feat['attributes']['Department'])
oidList.append(feat['attributes']['OBJECTID'])
Street.append(feat['attributes']['Street'])
Address.append(feat['attributes']['Address'])
mergelist = zip(Address, Street, Department)
FROM = 'REDACTED'
TO = ['REDACTED']
SUBJECT = 'New GIS Feature Added'
TEXT = "Features with Addresses at" + " " + str(mergelist) + " " + "were added to the DPW GIS layer"
message =""" 'Subject: New GIS Feature Added'.format(SUBJECT, TEXT)
From: %s
To: %s
Subject: %s
%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
gmailPwd = 'REDACTED'
if len(oidList) > 0:
smtpObj = smtplib.SMTP(host='smtp.gmail.com', port= 587)
smtpObj.starttls()
smtpObj.login(FROM, gmailPwd)
smtpObj.sendmail(FROM, TO, message)
print "Successfully sent email"
smtpObj.quit()
else:
print "No new data found"
I get this in the body of my email: Thanks, Fred
... View more
12-27-2017
07:48 AM
|
0
|
0
|
17196
|
DOC
|
@Jake Skinner Thanks for providing this script and following up with issues, it's all been very helpful. One question I have is how to remove the 'u' from the beginning of the strings that are returned in the SMTP email. I do not want the OBJECTIDs to show up in the email so I am not targeting that list in the script. Instead, I'd like the email to return the addresses of the newly added features, which I managed to do. However the string that is returned has a 'u' in front of all strings that are listed in the email. Any idea on how to get rid of this? Thanks, Fred
... View more
12-22-2017
09:30 AM
|
0
|
0
|
17195
|
Title | Kudos | Posted |
---|---|---|
1 | 03-17-2023 04:05 AM |
Online Status |
Offline
|
Date Last Visited |
10-20-2023
07:41 AM
|