Can I get some python gurus here to help me out with this tool?

468
10
11-15-2018 07:58 AM
IreneEgbulefu1
New Contributor III

I built a model that extracts selected attributes from my TCAD feature layer using a polygon feature. I am looking for a way to convert this model to a functional tool through python scripting. The requirement is that when the tool is run, it will prompt the user to enter the polygon feature (any polygon feature that is within the TCAD coverage); the tool will also  prompt the user to select the needed attributes from the TCAD layer feature.

So far my model is pretty much functioning manually but I would really want it to be more automated.

I have tried to export my model to a python script and tried modifying it but so far there has been no success, thus I am here to seek for help with this.

Please see my model and script below and I would really appreciate if I can get help with this here.

Attribute data  extraction Model

Here is the script

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# Extracting Property_IMprvtment_Values_By_ContourPoly.py
# Created on: 2018-11-01 14:54:20.00000
# Description: This script will extract selected atrributes from TCAD for any given polygon (in this case I am using a Contour Polygon)
# that is used to intersect the TCAD
# ------------------------
# Import arcpy module
import arcpy
import sys
import os
import datetime
import traceback
# Database Connection
editDB ="C:\Users\EgbuleI\AppData\Roaming\ESRI\Desktop10.5\ArcCatalog\TCAD.sde\TCAD.TC_USER.TCAD_PARCELS"
# Local variables:
TCAD_TC_USER_TCAD_PARCELS__3_ = "TCAD.TC_USER.TCAD_PARCELS"
TCAD_TC_USER_TCAD_PARCELS = TCAD_TC_USER_TCAD_PARCELS__3_
Parcels_on_710f = "C:\\Users\\egbulei\\Documents\\ArcGIS\\Default.gdb\\Parcels_on_710f"
Documents__2_ = "C:\\Users\\egbulei\\Documents"
Contour710ft_data2_dbf = "C:\\Users\\egbulei\\Documents\\Contour710ft data2.dbf"
# Process: Select Layer By Location
arcpy.SelectLayerByLocation_management(TCAD_TC_USER_TCAD_PARCELS__3_, "INTERSECT", Parcels_on_710f, "", "NEW_SELECTION", "NOT_INVERT")
# Process: Table to Table
arcpy.TableToTable_conversion(TCAD_TC_USER_TCAD_PARCELS, Documents__2_, "Contour710ft data2.dbf", "imprv_homesite_val IS NOT NULL AND imprv_homesite_val >0", "PROP_ID \"PROP_ID\" true true false 4 Long 0 10 ,First,#,Database Connections\\TCAD.sde\\TCAD.TC_USER.TCAD_PARCELS,PROP_ID,-1,-1;py_owner_n \"py_owner_name\" true true false 70 Text 0 0 ,First,#,Database Connections\\TCAD.sde\\TCAD.TC_USER.TCAD_PARCELS,py_owner_name,-1,-1;py_owner_i \"py_owner_id\" true true false 4 Long 0 10 ,First,#,Database Connections\\TCAD.sde\\TCAD.TC_USER.TCAD_PARCELS,py_owner_id,-1,-1;py_address \"py_address\" true true false 100 Text 0 0 ,First,#,Database Connections\\TCAD.sde\\TCAD.TC_USER.TCAD_PARCELS,py_address,-1,-1;geo_id \"geo_id\" true true false 15 Text 0 0 ,First,#,Database Connections\\TCAD.sde\\TCAD.TC_USER.TCAD_PARCELS,geo_id,-1,-1;tcad_acres \"tcad_acres\" true true false 8 Double 8 38 ,First,#,Database Connections\\TCAD.sde\\TCAD.TC_USER.TCAD_PARCELS,tcad_acres,-1,-1;GIS_acres \"GIS_acres\" true true false 8 Double 8 38 ,First,#,Database Connections\\TCAD.sde\\TCAD.TC_USER.TCAD_PARCELS,GIS_acres,-1,-1;imprv_home \"imprv_homesite_val\" true true false 4 Long 0 10 ,First,#,Database Connections\\TCAD.sde\\TCAD.TC_USER.TCAD_PARCELS,imprv_homesite_val,-1,-1;land_homes \"land_homesite_val\" true true false 4 Long 0 10 ,First,#,Database Connections\\TCAD.sde\\TCAD.TC_USER.TCAD_PARCELS,land_homesite_val,-1,-1;deed_num \"deed_num\" true true false 50 Text 0 0 ,First,#,Database Connections\\TCAD.sde\\TCAD.TC_USER.TCAD_PARCELS,deed_num,-1,-1;year_built \"year_built\" true true false 2 Short 0 5 ,First,#,Database Connections\\TCAD.sde\\TCAD.TC_USER.TCAD_PARCELS,year_built,-1,-1;Shape_STAr \"Shape_STAr\" false false true 0 Double 0 0 ,First,#,Database Connections\\TCAD.sde\\TCAD.TC_USER.TCAD_PARCELS,Shape.STArea(),-1,-1;Shape_STLe \"Shape_STLe\" false false true 0 Double 0 0 ,First,#,Database Connections\\TCAD.sde\\TCAD.TC_USER.TCAD_PARCELS,Shape.STLength(),-1,-1", "")

0 Kudos
10 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Irene,

Is the tools purpose to allow a user to select parcels from the TCAD_Parcels feature class and export specified fields to a DBF?

0 Kudos
IreneEgbulefu1
New Contributor III

Not exactly TCAD parcels. The Tools will select all features that falls within a specific area covered by the specified polygon. I am just using the TCAD to as a starting point because it covers a very wide area.

I actually started by creating some contour polygons and then have the polygon intersect TCAD and extract selected features of the TCAD that falls within the Contour polygon.

So my intention is to create a tool that will input any polygon of any size and extract selected features in TCAD that fall within the polygon.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

I think you will want your model to look something like below:

You will create the 'Selecting Features' parameter by right-clicking on the Select Layer By Location tool > Make Variable > From Parameter > Selecting Features.  Right-click on the Selecting Features variable > Properties > Data Type tab > set this to the following:

The feature class you specify for the schema and symbology will be the parcels feature class.

You will then create another variable from parameter by right-clicking on the Table to Table tool > Make Variable > From Parameter > Field Map.  You will then have two parameters the user can use when the tool is opened:

By clicking on Selecting_Features will allow the user to draw a polygon over the parcels.  They can then remove any field they do not want in the DBF by right-clicking on the field > Delete.

IreneEgbulefu1
New Contributor III

Hi Jake,

I have tried your suggestion  on building the model with the parameters, it did run when executed as a dynamic model but I am getting giving me this error 000368. please see my screenshot and see if you can help me further on this.

Thanks

Model

field selectionError

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Are you able to zip the toolbox and upload it here?  I can take a look to see what's going on with this error.

0 Kudos
IreneEgbulefu1
New Contributor III

Any idea on how I can get that zipped and upload it here as I cannot see anywhere to attach a file on the menu here. I see insert video, pictures and tables

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Go to the initial question (don't reply while you're in your Inbox) and click Reply.  You will then see an option at the top right Use advanced editor.  This will give you an option to upload attachments in the lower left corner.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Also, attached is an example of the model I built.

0 Kudos
IreneEgbulefu1
New Contributor III

Hi Jake, 

The attachment here contains the models. they contain virtually the same thing but yo9u may just check out the 'Extract_LakeTravis_Imprvment-Area_by Contour" and the 'Dynamic test Model (2)"

Thanks for the example you sent. I checked it out and tried to insert my own variable data into the paramenter but I am still getting the same error 00345

See screenshot please

0 Kudos