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

1017
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
IreneEgbulefu1
New Contributor III

I think I eventually found the solution to the above error 00368.

The input data file must be a layer file (.lyr) and not a feature class. So I had to open my TCAD layer inside ArcMap This TCAD originally exists as a feature class within a geodatabase . I then saved it as a Layer file into a folder (not inside a geodatabase).

It is this layer file (.lyr) that now got rid of the error.

See details below

Select Layer By Location

Summary

Selects features in a layer based on a spatial relationship to features in another layer.

Each feature in the Input Feature Layer  is evaluated against the features in the  Selecting Features  layer or feature class; if the specified  Relationship  is met, the input feature is selected.

A feature class is a set of common geographic features, for example roads, or parcels, or land use, as they are stored in a geodatabase or shapefile, or other storage format. Here is the help file on Feature Class Basics. A feature layer is the representation of a feature class after it is loaded into ArcMap.

http://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/select-layer-by-location.htm

Usage

  • The input must be a feature layer; it cannot be a feature class.

  • This tool works on layers in ArcMap, ArcGlobe, or ArcScene and also on layers created in models and scripts using the Make Feature Layer tool.

  • The coordinate system in which the spatial relationship is evaluated may affect the result. Features that intersect in one coordinate system may or may not intersect in another.

    • This tool evaluates a spatial relationship in the coordinate system of the Input Feature Layer data source (the feature class on disk). Set the output coordinate system environment to evaluate the spatial relationship in a different coordinate system.