|
POST
|
Okay, I did recognize that i can't use the same cursor, so starting a new cursor ('cursor1') within the exception is now only populating the errors table with actual error records, but there are multiple entries for each error. import arcpy
from arcpy import env
import os
import usaddress
from collections import OrderedDict
arcpy.env.overwriteOutput = True
# Get input table
table = arcpy.GetParameterAsText(0)
# Get the field containing the single-line addresses
infield = arcpy.GetParameterAsText(1)
# Get the output table for errors
outErrors = arcpy.GetParameterAsText(2)
# List of fields
fields = ["addr", "addrNum", "stNm", "zip", "OID@"]
with arcpy.da.UpdateCursor(table, fields) as cursor:
for addr, addrNum, stNm, zip, oid in cursor:
try:
parse = usaddress.tag(addr)[0]
addrNum = parse.get("AddressNumber", "")
stNm = parse.get("StreetName", "")
zip = parse.get("ZipCode", "")
cursor.updateRow([addr, addrNum, stNm, zip, oid])
except Exception:
cursor1 = arcpy.da.InsertCursor(outErrors, fields)
for row in (str(oid)):
cursor1.insertRow([addr, addrNum, stNm, zip, oid])
arcpy.AddMessage("Error with record: {}".format(oid))
arcpy.AddMessage("Bad Input Address = : {}".format(addr)) Need to figure out why it's giving multiple returns now... Justin
... View more
11-28-2018
02:10 PM
|
0
|
7
|
3003
|
|
POST
|
I spent most of the day on this and didn't get too far, but I have something. I wasn't able to write to a table in the same .gdb as the source address table, but I am writing to a table in a different .gdb. This isn't a huge deal. However, using the code below, as soon as the first exception is found, it stops parsing the addresses and populating fields in the source table ('addresses2'), and then populates all remaining records in the errors table ('errors'). So once it finds an exception it doesn't go back to the try. import arcpy
from arcpy import env
import os
import usaddress
from collections import OrderedDict
arcpy.env.overwriteOutput = True
# Get input table
table = arcpy.GetParameterAsText(0)
# Get the field containing the single-line addresses
infield = arcpy.GetParameterAsText(1)
# Get the output table for errors
outErrors = arcpy.GetParameterAsText(2)
# List of fields
fields = ["addr", "addrNum", "stNm", "zip", "OID@"]
with arcpy.da.UpdateCursor(table, fields) as cursor:
for addr, addrNum, stNm, zip, oid in cursor:
try:
parse = usaddress.tag(addr)[0]
addrNum = parse.get("AddressNumber", "")
stNm = parse.get("StreetName", "")
zip = parse.get("ZipCode", "")
cursor.updateRow([addr, addrNum, stNm, zip, oid])
except Exception:
cursor = arcpy.da.InsertCursor(outErrors, fields)
for row in (str(oid)):
cursor.insertRow([addr, addrNum, stNm, zip, oid])
arcpy.AddMessage("Error with record: {}".format(oid))
arcpy.AddMessage("Bad Input Address = : {}".format(addr)) Below you can see how record 310 in the addresses2 table is the first exception, which is written to the errors table, but all subsequent records are written as exceptions as well. I feel I'm close, I'm just not sure where to go from here. Thanks Justin
... View more
11-28-2018
01:44 PM
|
0
|
8
|
3003
|
|
POST
|
Joe - Yes, addresses are always funny. Fortunately the data in question for this client seems decent. The various needs around our organization keep things interesting; some need to see dots on the map, while others don't care about the location, they just need a clean mailing address. Thanks Justin
... View more
11-28-2018
07:01 AM
|
0
|
0
|
2155
|
|
POST
|
Thanks Josh - that makes sense and works to return the Object ID of the records in question, which is a great start. I'm now going to turn my attention to working on getting those records out into another table. Thanks again Justin
... View more
11-28-2018
06:57 AM
|
0
|
0
|
3003
|
|
POST
|
Yes, the data owner may eventually use some methods like you've suggested for scrubbing their data, but for now our initial task is to help them identify which records (and how many) have issues. Thanks
... View more
11-28-2018
06:28 AM
|
0
|
2
|
2155
|
|
POST
|
I thought I needed the 'continue' in there or it would 'stop' at the first error, but I now realize that's the point of try/except. There is currently no errors generated, it simply returns a text message of "Error" if an address record isn't parsed. I'd like to get an output of the actual record that cannot be parsed by usaddress.tag. So with that 'continue' removed I now have the following: import arcpy
from arcpy import env
import os
import usaddress
from collections import OrderedDict
# Get input table through parameter
table = arcpy.GetParameterAsText(0)
# Get the field containing the single-line addresses through parameter
infield = arcpy.GetParameterAsText(1)
# List of fields to be updated
fields = ["addr", "addrNum", "stNm", "zip"]
with arcpy.da.UpdateCursor(table, fields) as cursor:
for addr, addrNum, stNm, zip in cursor:
try:
parse = usaddress.tag(addr)[0]
addrNum = parse.get("AddressNumber", "")
stNm = parse.get("StreetName", "")
zip = parse.get("ZipCode", "")
cursor.updateRow([addr, addrNum, stNm, zip])
except Exception:
arcpy.AddMessage("Error") Which returns a message of "Error" for each of the two incorrect address records:
... View more
11-28-2018
06:25 AM
|
0
|
11
|
3003
|
|
POST
|
I'm using the usaddress library to split single-line addresses into their various components. Below is the functioning script that I'm using for testing: import arcpy
from arcpy import env
import os
import usaddress
from collections import OrderedDict
# Get input table through parameter
table = arcpy.GetParameterAsText(0)
# Get the field containing the single-line addresses through parameter
infield = arcpy.GetParameterAsText(1)
# List of fields to be updated
fields = ["addr", "addrNum", "stNm", "zip"]
with arcpy.da.UpdateCursor(table, fields) as cursor:
for addr, addrNum, stNm, zip in cursor:
try:
parse = usaddress.tag(addr)[0]
addrNum = parse.get("AddressNumber", "")
stNm = parse.get("StreetName", "")
zip = parse.get("ZipCode", "")
cursor.updateRow([addr, addrNum, stNm, zip])
continue
except Exception:
arcpy.AddMessage("Error") Here's what the testing input table looks like before: And after: My goal is to write the records that error out to a separate table. (Errors include situations where multiple areas of an address have the same label, like "5318 S 86 CT APT 3 APT 412, Omaha, NE 68137" - multiple APT entries, or "PO Box 291 PO BOX 291, Genoa, NE 68640" - multiple PO Box entries.) I've reviewed the examples in the error handling page, but they seem to be very focused on geoprocessing. Also, this is the first time I've used cursors in this manner, which prevents me from using something like the following: except Exception:
arcpy.AddMessage(str(row.getValue("OBJECTID")) + " Error") At least I can't figure it out so far. Any suggestions or bump in the right direction are greatly appreciated. Thanks Justin
... View more
11-27-2018
02:49 PM
|
1
|
18
|
5648
|
|
POST
|
This user is running ArcGIS Desktop v10.4.1, and the upgrade status of one of our .sde connections says "This 10.2.2 Geodatabase matches the ArcGIS release you are currently using, however, database internals such as stored procedures can be upgraded."
... View more
03-09-2018
10:16 AM
|
0
|
1
|
1499
|
|
POST
|
Yes, this user has multiple SDE connections and has been in/out of editing sessions testing multiple processes.
... View more
03-09-2018
08:47 AM
|
0
|
0
|
1499
|
|
POST
|
One of our user's machines reverts back from an Advanced concurrent use to a Basic concurrent use product level, almost daily. This requires me or another person with administrative privileges to run ArcGIS Administrator to switch it back to Advanced. Anyone else experience something like this? I'm certain it's user/machine-specific, but I don't know where to look/start. Thanks for any suggestions.
... View more
03-09-2018
06:46 AM
|
0
|
5
|
1614
|
|
POST
|
Thanks Jayanta. I was approaching this wrong. I was able to use dissolve and a join to get what I needed.
... View more
10-25-2017
11:04 AM
|
0
|
0
|
2767
|
|
POST
|
My organization requires North American Profile of ISO 19115 2003 metadata. Using this style in ArcCatalog I populated all the necessary information in a copy of my shapefile. I would like to simply import the 'static' metadata into a new copy of the .shp i have created. (The .shp schema are identical - they were created using the same process.) Using import tools do not work. I've even tried physically deleting the .shp.xml from the new.shp and replacing it with the 'good' .xml file in windows file explorer - but in the Description tab in ArcCatalog not everything shows up and I cannot edit it (not that I need to, but it's obviously behaving differently). What do I need to do in order to simply import preferred metadata content from a .xml into a newly created shapfile? Thanks - Justin
... View more
10-25-2017
09:31 AM
|
0
|
1
|
755
|
|
POST
|
Yesterday I posted this in the incorrect area instead of Python. I have a file gdb with a couple thousand features, a few hundred of which have duplicate attribute values. I want to merge these features with duplicate attribute values to become multipart lines. Because I'm working in a FGDB I cannot use a SQL query and the Find Identical helps me identify the records, but not much else. The source data is being created from linear referencing of SQL table data nightly, and I'll need to automate this select/merge as well. I need a nudge in the right direction. (I'll also need to do this to a point feature class, but I'm aware that's another set of problems with multipoint geometry.) Any help is appreciated. Thanks Justin
... View more
10-07-2017
09:44 AM
|
0
|
3
|
3603
|
|
POST
|
Thanks Joe. I've wanted to avoid adding a new field, and just use the selected, duplicates in a geoprocessing action. But, a new field may be what it takes.
... View more
10-06-2017
06:21 PM
|
0
|
0
|
3246
|
|
POST
|
Yes, thanks - i meant to put this in Python, not the API
... View more
10-06-2017
06:19 PM
|
0
|
0
|
3246
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 06-16-2021 01:50 PM | |
| 2 | 12-09-2020 12:51 PM | |
| 1 | 12-04-2018 01:23 PM | |
| 1 | 03-16-2016 02:52 PM | |
| 1 | 05-10-2019 10:54 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-06-2025
07:25 AM
|