A Way to Automate Adding Links to Attribute Table?

1237
9
Jump to solution
07-09-2013 12:46 PM
JonathanFarmer1
New Contributor
I work in local government and, thus, work with parcel data routinely. I am looking for an automated way to add a link for each parcel in my Geodatabase to the local appraisal district webpage for that parcel. This would be a service to use in our web maps when
completed.

I assume I can do part of this with Python but how can I get each specific link needed for each parcel without going through them one by one?

Thanks,

Jonathan
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
StacyRendall1
Occasional Contributor III
Great.

All you need to do then is add a Webpage (or whatever you want to call it...) field (TEXT), then use a field calculator to add the values! You need to make sure to increase the length of the text field when creating it, it defaults to 50, but I would suggest 100 (if you can shorten the links as I have below, otherwise 180).

I noticed that the links you shared seem to contain extra, unnecessary, information:
Leaving this unused information out will make it even easier...

Here is the code for the Field Calculator (assuming the ID field in your feature class is PropertyID and the webpage field is Webpage😞
Pre-logic script code:
def makeLink(pID):   return 'http://www.fbcad.org/Appraisal/PublicAccess/PropertyDetail.aspx?PropertyID=' + str(pID)

Webpage =
makeLink( !PropertyID!)


All it does is convert PropertyID to a string value and add it to the end of the webpage string.

Just in case you haven't used Python code in a field calculator I have attached an image of how to set it up.
[ATTACH=CONFIG]25859[/ATTACH]

View solution in original post

0 Kudos
9 Replies
StacyRendall1
Occasional Contributor III
Is there some commonality between the information you have and the structure of the website? For example, if the attribute parcel ID for a given parcel is 1197 is the webpage
http://www.../parcels/1197.html

or something similar?

If that is the case it should be simple to do what you are asking.

If there are no attributes common between the website and your database then you might have to investigate if there is a listing somewhere that maps between the two. As a last resort you might be able to scrape the website (make a Python script that looks through every page, finds some common ID listed within the page, and records the link)...
0 Kudos
JonathanFarmer1
New Contributor
Stacy,

This could be simple then!

Here are example links for two parcels:
http://www.fbcad.org/Appraisal/PublicAccess/PropertyDetail.aspx?PropertyID=191070&dbKeyAuth=Appraisa...

http://www.fbcad.org/Appraisal/PublicAccess/PropertyDetail.aspx?PropertyID=131364&dbKeyAuth=Appraisa...

There is a unique ID obviously and the structure is the same except for the "PropertyID" and the "PropertyOwnerID"
0 Kudos
StacyRendall1
Occasional Contributor III
Great.

All you need to do then is add a Webpage (or whatever you want to call it...) field (TEXT), then use a field calculator to add the values! You need to make sure to increase the length of the text field when creating it, it defaults to 50, but I would suggest 100 (if you can shorten the links as I have below, otherwise 180).

I noticed that the links you shared seem to contain extra, unnecessary, information:
Leaving this unused information out will make it even easier...

Here is the code for the Field Calculator (assuming the ID field in your feature class is PropertyID and the webpage field is Webpage😞
Pre-logic script code:
def makeLink(pID):   return 'http://www.fbcad.org/Appraisal/PublicAccess/PropertyDetail.aspx?PropertyID=' + str(pID)

Webpage =
makeLink( !PropertyID!)


All it does is convert PropertyID to a string value and add it to the end of the webpage string.

Just in case you haven't used Python code in a field calculator I have attached an image of how to set it up.
[ATTACH=CONFIG]25859[/ATTACH]
0 Kudos
JonathanFarmer1
New Contributor
That worked perfectly Stacy! Thanks!

I did find, however, that ArcMap would time out trying to get the entire County done (about 250,000 parcels). Luckily that is fine because I already had to trim the data down in order to upload to ArcGIS Online and just used that Feature Class instead of the entire County.

I just got a good beginner Python book and this makes me more excited to start reading it.

Jonathan
0 Kudos
StacyRendall1
Occasional Contributor III
That worked perfectly Stacy! Thanks!

I did find, however, that ArcMap would time out trying to get the entire County done (about 250,000 parcels). Luckily that is fine because I already had to trim the data down in order to upload to ArcGIS Online and just used that Feature Class instead of the entire County.

I just got a good beginner Python book and this makes me more excited to start reading it.

Jonathan


Yes, the calculate field tool can be painfully slow. If you do need to work on larger datasets you can use UpdateCursor from a Python script (or maybe from the Python window in ArcMap although I have never tried it...).

Interestingly, this solution wasn't really Python at all - VB Script could have done it too. The biggest step is figuring out how the website is laid out and how that relates to the information you have.

Great news on the Python book! I am working on some blog posts at the moment which are intended to help GIS users learn Python and Arcpy programming, so keep an eye on that (link below) - keen to hear if you have any particular questions!
0 Kudos
JonathanFarmer1
New Contributor
Yes, the calculate field tool can be painfully slow. If you do need to work on larger datasets you can use UpdateCursor from a Python script (or maybe from the Python window in ArcMap although I have never tried it...).

Interestingly, this solution wasn't really Python at all - VB Script could have done it too. The biggest step is figuring out how the website is laid out and how that relates to the information you have.

Great news on the Python book! I am working on some blog posts at the moment which are intended to help GIS users learn Python and Arcpy programming, so keep an eye on that (link below) - keen to hear if you have any particular questions!


Stacy,

If I wanted to set this up as standalone script, would I use this same code to do it? I am automating a task I do each quarter which involves multiple steps. Each step will be its own script and then I will use a separate script to run each individual task together.

If I already have a script done which adds in all the fields I need (the "Webpage" field along with some others), how would that change this script to add the hyperlinks?

Thanks!
Jonathan
0 Kudos
StacyRendall1
Occasional Contributor III
Hey,

you will want to look into the UpdateCursor (if you have 10.0) or da.UpdateCursor (if you have 10.1), this will allow you to set the field value.

Assuming you are using da.UpdateCursor this should do the trick:
## pre-calculation here, i.e. adding fields...

# note that fc is the feature class...
with arcpy.da.UpdateCursor(fc, ['PropertyID', 'Webpage']) as cursor:
    for row in cursor:
        ## row is a list where PropertyID is row[0], Webpage is row[1]
        row[1] = 'http://www.fbcad.org/Appraisal/PublicAccess/PropertyDetail.aspx?PropertyID=' + str(row[0])
        cursor.updateRow(row) 


Haven't tested, but let me know if it doesn't work!
0 Kudos
JonathanFarmer1
New Contributor
Thanks Stacy! I did some minor tweaking but got it to work. I originally had a script just for adding fields but I think it will be easier if I just add the needed fields and do the required processing in one script (well 3 scripts total since there are 3 fields I need to add and manipulate).

Here is what worked for me:

# Import Arcpy
import arcpy
from arcpy import env

# Set the Workspace
env.workspace = "J:\\GIS\\Parcel_Data\\Python_Data\\CAMASUMMARY.shp"

# Define Variables
inFeatures = "CAMASUMMARY"
fieldName1 = "Webpage"
fieldLength = 100

# Add the Webpage field to the parcel data
arcpy.AddField_management (inFeatures, fieldName1, "TEXT", "", "", fieldLength)

# Define the shapefile used below (CAMASUMMARY)
fc = "J:\\GIS\\Parcel_Data\\Python_Data\\CAMASUMMARY.shp"

# Update the Webpage field
with arcpy.da.UpdateCursor(fc, ['QUICKREFID', 'Webpage']) as cursor:
    for row in cursor:
        ## row is a list where QUICKREFID is row[0], Webpage is row[1]
        row[1] = 'http://www.fbcad.org/Appraisal/PublicAccess/PropertyDetail.aspx?PropertyID=' + str(row[0])
        cursor.updateRow(row)
0 Kudos
StacyRendall1
Occasional Contributor III
Thanks Stacy! I did some minor tweaking but got it to work. I originally had a script just for adding fields but I think it will be easier if I just add the needed fields and do the required processing in one script (well 3 scripts total since there are 3 fields I need to add and manipulate). 

Here is what worked for me: 

# Import Arcpy
import arcpy
from arcpy import env

# Set the Workspace
env.workspace = "J:\\GIS\\Parcel_Data\\Python_Data\\CAMASUMMARY.shp"

# Define Variables
inFeatures = "CAMASUMMARY"
fieldName1 = "Webpage"
fieldLength = 100

# Add the Webpage field to the parcel data
arcpy.AddField_management (inFeatures, fieldName1, "TEXT", "", "", fieldLength)

# Define the shapefile used below (CAMASUMMARY)
fc = "J:\\GIS\\Parcel_Data\\Python_Data\\CAMASUMMARY.shp"

# Update the Webpage field
with arcpy.da.UpdateCursor(fc, ['QUICKREFID', 'Webpage']) as cursor:
    for row in cursor:
        ## row is a list where QUICKREFID is row[0], Webpage is row[1]
        row[1] = 'http://www.fbcad.org/Appraisal/PublicAccess/PropertyDetail.aspx?PropertyID=' + str(row[0])
        cursor.updateRow(row)


Great work!

Just looking at your script I noticed a few things:

  • you add the field using env.workspace and feature class name BUT you call the cursor with the full path; one of these is redundant

  • you make the new Webpage field a variable for adding the field, but hard-code it again when you create the cursor


None of these problems is serious, but could cause problems in the future if you are copying and pasting code around. Here is your script with the above taken into account (red = delete, blue = change😞
# Import Arcpy
import arcpy
from arcpy import env

# Set the Workspace
env.workspace = "J:\\GIS\\Parcel_Data\\Python_Data\\CAMASUMMARY.shp"

# Define Variables
inFeatures = "CAMASUMMARY"
# Define the shapefile used below (CAMASUMMARY)
fc = "J:\\GIS\\Parcel_Data\\Python_Data\\CAMASUMMARY.shp"
fieldName1 = "Webpage"
fieldLength = 100

# Add the Webpage field to the parcel data
arcpy.AddField_management (fc, fieldName1, "TEXT", "", "", fieldLength)

# Define the shapefile used below (CAMASUMMARY)
fc = "J:\\GIS\\Parcel_Data\\Python_Data\\CAMASUMMARY.shp"

# Update the Webpage field
with arcpy.da.UpdateCursor(fc, ['QUICKREFID', fieldName1]) as cursor:
    for row in cursor:
        ## row is a list where QUICKREFID is row[0], Webpage is row[1]
        row[1] = 'http://www.fbcad.org/Appraisal/PublicAccess/PropertyDetail.aspx?PropertyID=' + str(row[0])
        cursor.updateRow(row)
0 Kudos