|
POST
|
My python script calculates only the value of the immediate previous record instead of calculating the values of all preceding records before that particular record. The example (the image) below is the undesired output; While the image below here is what i want to achieve; This is my python script i used; import arcpy
from arcpy import da
CensusBldForm = "CensusBldForm"
Calculated_EA1=0
with arcpy.da.UpdateCursor(CensusBldForm, ["OBJECTID", "EstimatedPopulationinEA", "Calculated_EA"]) as cursor:
for row in cursor:
Calculated_EA2 = row[1]
row[2] = (Calculated_EA1 + Calculated_EA2)
Calculated_EA1 = Calculated_EA2
cursor.updateRow(row) Kindly assist me with the above please.
... View more
04-26-2016
11:29 AM
|
0
|
15
|
1601
|
|
POST
|
My python script calculates only the value of the immediate previous record instead of calculating the values of all preceding records before that particular record. The example (the image) below is the undesired output; While the image below here is what i want to achieve; This is my python script i used; import arcpy
from arcpy import da
CensusBldForm = "CensusBldForm"
Calculated_EA1=0
with arcpy.da.UpdateCursor(CensusBldForm, ["OBJECTID", "EstimatedPopulationinEA", "Calculated_EA"]) as cursor:
for row in cursor:
Calculated_EA2 = row[1]
row[2] = (Calculated_EA1 + Calculated_EA2)
Calculated_EA1 = Calculated_EA2
cursor.updateRow(row) Kindly assist me with the above please.
... View more
04-26-2016
11:26 AM
|
0
|
10
|
3961
|
|
POST
|
Thank you very much for your response, can you kindly relate the script above to feature layers instead as i can't really relate them as needed. Thanks
... View more
04-26-2016
12:38 AM
|
0
|
0
|
1601
|
|
POST
|
Excel wont work as we intend to use the form in ArcGIS Online?
... View more
04-18-2016
02:23 AM
|
0
|
18
|
1601
|
|
POST
|
Thanks for your views, the threshold is for any population value that falls between 450 - 500, now if the population for a particular row adds up to 503 - the population value of the next row would be (503 - 500) + the absolute population value of that row, likewise if the population for a particular row adds up to 498, then the population value of the next row would automatically start from the absolute population value of that row as nothing would be added to the absolute population value for that particular row.
... View more
04-18-2016
02:22 AM
|
0
|
0
|
3207
|
|
POST
|
Thanks for your reponse(s), what i want to achieve is to get the sum total of values from a field called population, but i really don't want the final sum, what i need is to get the sum as you loop through the rows (that's the population value) i.e if row 1 = 23 (row 1 would be 23 as there's no other row/record before row1) row 2 = 30 (row 2 would be 30 + the value in row 1) row 3 = 22 (row 3 would be 22 + the value in row 2), till you reach the last row. I also want to add a constraint whereby if the sum of the population values in the rows becomes 500, the next row's value would start from zero or the difference that makes the 500 from the previous row. Thanks
... View more
04-17-2016
04:57 AM
|
0
|
2
|
3207
|
|
POST
|
I need to automatically calculate a field based on values from previous rows? I need to automatically calculate a field based on values from previous rows such that once the total of all the previous rows is greater than 450 and less than 500, the next row starts counting from 0 or the balance of what made the previous row greater than 500. The script below just calculates the sum of the cities point that falls within the county, I want something that would make the value of a row (i.e. row2) the addition of the value of row1 + value of row2 and so on till when it gets to 500, where it starts from 1 again. Kindly help me please. cities = "Cities"
counties = "Counties"
destField= "URBPOP"
env.workspace = "C:\Users\KUNLE\Documents\ArcGIS\Default.gdb"
env.overwriteOutput = True
fldList = arcpy.ListFields(counties)
msg = "\nFields in " + counties + ":"
arcpy.AddMessage(msg)
for aFld in fldList:
msg = " - " + aFld.name
arcpy.AddMessage(msg)
fieldPresent = False
for aFld in fldList:
if aFld.name == destField:
fieldPresent = True
if not fieldPresent:
arcpy.AddField_management(counties,destField,"DOUBLE")
msg = "\nNew Field " + destField + " created in " + counties
arcpy.AddMessage(msg)
arcpy.MakeFeatureLayer_management(cities, "cities_feat")
list = []
rows = arcpy.SearchCursor("Counties")
for row in rows:
OID = row.getValue("POP")
list.append(OID)
maxOID = list[-1]
del row, rows
x = 1
while x <= maxOID:
list2 = []
arcpy.MakeFeatureLayer_management(counties, "counties_feat", "OBJECTID = " + str(x))
arcpy.SelectLayerByLocation_management("cities_feat", "WITHIN", "counties_feat")
rows = arcpy.SearchCursor("cities_feat")
for row in rows:
pop = row.getValue("POPULATION")
list2.append(pop)
sumlist = sum(list2)
rows2 = arcpy.UpdateCursor("counties_feat")
for row2 in rows2:
row2.URBPOP = sumlist
rows2.updateRow(row2)
#msg = " - " + row2.POP + " - " + "Urban Population: " + str(sumlist)
#arcpy.AddMessage(msg)
x += 1
del row, rows, row2, rows2
arcpy.Delete_management("counties_feat")
arcpy.Delete_management("cities_feat")
... View more
04-13-2016
02:07 AM
|
0
|
0
|
1316
|
|
POST
|
I need to automatically calculate a field based on values from previous rows?I need to automatically calculate a field based on values from previous rows such that once the total of all the previous rows is greater than 450 and less than 500, the next row starts counting from 0 or the balance of what made the previous row greater than 500. The script below just calculates the sum of the cities point that falls within the county, I want something that would make the value of a row (i.e. row2) the addition of the value of row1 + value of row2 and so on till when it gets to 500, where it starts from 1 again. Kindly help me please.
... View more
04-13-2016
01:59 AM
|
0
|
28
|
12051
|
|
POST
|
I need to automatically calculate a field based on values from previous rows such that once the total of all the previous rows is greater than 450 and less than 500, the next row starts counting from 0 or the balance of what made the previous row greater than 500, i've been able to include my formula but it works within a single row i.e (${No of Persons in Sampled Building} + ${Estimated No of Persons in Residential Building}) the output would make the value for the field called Estimated Population
... View more
04-12-2016
04:35 PM
|
0
|
1
|
5345
|
|
POST
|
Thanks Christopher its now showing as the attached figure 1 and not like the 1 we saw on the recorded training seminar. Thanks
... View more
02-08-2016
03:31 PM
|
0
|
0
|
636
|
|
POST
|
Please find attached, the difference between the Operations Dashboard map configuration settings page I saw on your recorded seminar and the one I have on my machine. I noticed that there's no dynamic & static radio buttons on mine under the settings pane, what does this mean because I can't add a layer that has real time feeds from my webmap? Thank you
... View more
02-08-2016
01:47 PM
|
0
|
2
|
2426
|
|
POST
|
Thanks Jake, I was trying to run the script behind a button, see script below; import pythonaddins
import os
import datetime
import time
import os, sys
import urllib, urllib2, arcpy, json
import uuid
arcpy.env.overwriteOutput = True
class AGOLClass1(object):
"""Implementation for AGOL_addin.button (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
username = "TAXXXX"
password = "#######"
baseURL = 'http://services5.arcgis.com/b23aIR8OqGRlfJlE/arcgis/rest/services/PropertyEnumerationForm/FeatureServer/0'
arcpy.AddMessage('\nGenerating Token\n')
tokenURL = 'https://www.arcgis.com/sharing/rest/generateToken'
params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'http://www.arcgis.com'}
req = urllib2.Request(tokenURL, urllib.urlencode(params))
response = urllib2.urlopen(req)
data = json.load(response)
token = data['token']
# Return largest objectIds
params = {'where': '1=1', 'returnIdsOnly': 'true', 'token': token, 'f': 'json'}
req = urllib2.Request(baseURL, urllib.urlencode(params))
response = urllib2.urlopen(req)
data = json.load(response)
try:
data['objectIds'].sort()
except:
arcpy.AddWarning("\nURL is incorrect. Or, Service is secure, please enter username and password.\n")
iteration = str(data['objectIds'][-1])
minOID = str(data['objectIds'][0]) - 1
OID = data['objectIdsFieldName'] and I get the error below; >>> Traceback (most recent call last): File "C:\Users\KUNLE\AppData\Local\ESRI\Desktop10.2\AssemblyCache\{322E160C-A3DE-48C9-BEBC-86802FD9C785}\AGOL_addin.py", line 40, in onClick iteration = str(data['objectIds'][-1]) KeyError: 'objectIds' >>> But the script runs well as a script tool under a toolbox. Kindly assist, thanks.
... View more
10-19-2015
08:49 AM
|
1
|
0
|
1567
|
|
POST
|
Hi Jake Skinner, I found your tool very useful and helpful but I still get the error below; iteration = int(data['OBJECTIDS'][-1]) KeyError: 'OBJECTIDS' See my code block below as well; username = "ASDERT" password = "@######" baseURL = 'http://services5.arcgis.com/b23aIR8OqGRlfJlE/arcgis/rest/services/PropertyEnumerationForm/FeatureServer/0' arcpy.AddMessage('\nGenerating Token\n') tokenURL = 'https://www.arcgis.com/sharing/rest/generateToken' params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'http://www.arcgis.com'} req = urllib2.Request(tokenURL, urllib.urlencode(params)) response = urllib2.urlopen(req) data = json.load(response) token = data['token'] # Return largest objectIds params = {'where': '1=1', 'returnIdsOnly': 'true', 'token': token, 'f': 'json'} req = urllib2.Request(baseURL, urllib.urlencode(params)) response = urllib2.urlopen(req) data = json.load(response) try: data['objectIds'].sort() except: arcpy.AddWarning("\nURL is incorrect. Or, Service is secure, please enter username and password.\n") iteration = int(data['OBJECTIDS'][-1]) minOID = int(data['OBJECTIDS'][0]) - 1 OID = data['objectIdsFieldName'] Kindly assist me with this, Thanks
... View more
10-16-2015
04:42 PM
|
0
|
2
|
1567
|
|
POST
|
I have a script that is supposed to extract feature(s) from AGOL, the script runs without any error(s) but I don't get any output in the geodatabase I created specifically for this purpose as well as the attachment to the specified feature. I noticed that the script drops a .json file in my folder, when I tried to convert this .json file to a shapefile it throws an error - see error below; >>> arcpy.JSONToFeatures_conversion("C:\Users\KUNLE\Desktop\New folder (2)\PropertyEnumerationForm.json","Sample") Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\conversion.py", line 434, in JSONToFeatures raise e ExecuteError: ERROR 001558: Error parsing json file 'C:\Users\KUNLE\Desktop\New folder (2)\PropertyEnumerationForm.json'. Failed to execute (JSONToFeatures).>>> Below is my script gtUrl = 'https://www.arcgis.com/sharing/rest/generateToken' gtValues = {'username' : 'XPARCELS', 'password' : '@3$%678', 'referer' : 'http://www.arcgis.com', 'f' : 'json' } gtData = urllib.urlencode(gtValues) gtRequest = urllib2.Request(gtUrl, gtData) gtResponse = urllib2.urlopen(gtRequest) gtJson = json.load(gtResponse) token = gtJson['token'] ### Create Replica ### ### Update service url HERE ### crUrl = 'http://services5.arcgis.com/b23aIR8OqGRlfJlE/arcgis/rest/services/PropertyEnumerationForm/FeatureServer/CreateReplica' crValues = {'f' : 'json', 'layers' : '0', 'returnAttachments' : 'true', 'token' : token } crData = urllib.urlencode(crValues) crRequest = urllib2.Request(crUrl, crData) crResponse = urllib2.urlopen(crRequest) crJson = json.load(crResponse) replicaUrl = crJson['URL'] urllib.urlretrieve(replicaUrl, 'PropertyEnumerationForm.json') ### Get Attachment ### cwd = os.getcwd() with open('PropertyEnumerationForm.json') as data_file: data = json.load(data_file) for x in data['layers'][0]['attachments']: gaUrl = x['url'] gaFolder = cwd + '\\photos\\' + x['parentGlobalId'] if not os.path.exists(gaFolder): os.makedirs(gaFolder) gaName = x['name'] gaValues = {'token' : token } gaData = urllib.urlencode(gaValues) urllib.urlretrieve(url=gaUrl + '/' + gaName, filename=os.path.join(gaFolder, gaName),data=gaData) ### Create Features ### rows = arcpy.InsertCursor(cwd + '/data.gdb/PropertyEnumerationForm') fields = arcpy.ListFields(cwd + '/data.gdb/PropertyEnumerationForm') for cfX in data['layers'][0]['features']: pnt = arcpy.Point() pnt.X = cfX['geometry']['x'] pnt.Y = cfX['geometry']['y'] row = rows.newRow() row.shape = pnt ### Set Attribute columns HERE ### ## makes use of the "updatevalue function to deal with dates ## rows = arcpy.UpdateCursor("C:\Users\KUNLE\Desktop\TaxParcels\data.gdb\PropertyEnumerationForm") for row in rows: #row.setValue("BUFFER_DISTANCE", row.getValue("ROAD_TYPE") * 100) updateValue(row,'UNITNO', cfX['attributes']['UNITNO']) updateValue(row,'PROPERTYCLASSCODE', cfX['attributes']['PROPERTYCLASSCODE']) updateValue(row,'OWNERNAME1', cfX['attributes']['OWNERNAME1']) updateValue(row,'BUILDINGSTRUCTURETYPE', cfX['attributes']['BUILDINGSTRUCTURETYPE']) updateValue(row,'BUILDINGARRANGEMENT', cfX['attributes']['BUILDINGARRANGEMENT']) updateValue(row,'BUILDINGGROUPING', cfX['attributes']['BUILDINGGROUPING']) updateValue(row,'PHONENUMBER1', cfX['attributes']['PHONENUMBER1']) updateValue(row,'EMAILADDRESS', cfX['attributes']['EMAILADDRESS']) updateValue(row,'SUBORCONDO', cfX['attributes']['SUBORCONDO']) updateValue(row,'NOOFBUILDINGS', cfX['attributes']['NOOFBUILDINGS']) updateValue(row,'BUILDINGNUMBER', cfX['attributes']['BUILDINGNUMBER']) updateValue(row,'NUMBEROFUNITS', cfX['attributes']['NUMBEROFUNITS']) updateValue(row,'BUILDINGUNITNUMBER', cfX['attributes']['BUILDINGUNITNUMBER']) updateValue(row,'NUMBEROFFLOORS', cfX['attributes']['NUMBEROFFLOORS']) updateValue(row,'FLOORNUMBER', cfX['attributes']['FLOORNUMBER']) updateValue(row,'OWNERTYPE', cfX['attributes']['OWNERTYPE']) updateValue(row,'BUILDINGSTATUS', cfX['attributes']['BUILDINGSTATUS']) updateValue(row,'HasChildren', cfX['attributes']['HasChildren']) updateValue(row,'HASWATERPROVIDER', cfX['attributes']['HASWATERPROVIDER']) updateValue(row,'HASSEWERPROVIDER', cfX['attributes']['HASSEWERPROVIDER']) updateValue(row,'DATECREATED', cfX['attributes']['DATECREATED']) updateValue(row,'CreationDate', cfX['attributes']['CreationDate']) updateValue(row,'Creator', cfX['attributes']['Creator']) updateValue(row,'EditDate', cfX['attributes']['EditDate']) updateValue(row,'Editor', cfX['attributes']['Editor']) updateValue(row,'GlobalID_str', cfX['attributes']['GlobalID']) rows.insertRow(row) del row del rows ### Add Attachments ### ### Create Match Table ### rows = arcpy.InsertCursor(cwd + '/data.gdb/MatchTable') for cmtX in data['layers'][0]['attachments']: row = rows.newRow() row.setValue('GlobalID_Str', cmtX['parentGlobalId']) row.setValue('PhotoPath', cwd + '\\photos\\' + cmtX['parentGlobalId'] + '\\' + cmtX['name']) rows.insertRow(row) del row del rows ### Add Attachments ### arcpy.AddAttachments_management(cwd + '/data.gdb/PropertyEnumerationForm', 'GlobalID_Str', cwd + '/data.gdb/MatchTable', 'GlobalID_Str', 'PhotoPath') Kindly assist me with the above a I've tried all possible combinations to ensure that the script above runs successfully. Waiting for your response. Thanks Message was edited by: OLANIYAN OLAKUNLE
... View more
10-13-2015
07:28 AM
|
0
|
2
|
3540
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-19-2015 08:49 AM | |
| 1 | 10-15-2013 04:42 AM | |
| 1 | 09-20-2016 03:45 AM | |
| 2 | 09-25-2016 03:50 PM | |
| 1 | 08-25-2012 09:15 PM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:23 AM
|