Model builder/python - creating a table with data from 2 shapefiles

3888
3
02-25-2015 08:52 AM
ChristineButterfield
New Contributor II

I am trying to automate a process to select polygons by location based on a different shapefile. This is the model I have built:

 

Export Graphic.png

This model seems to be running in an infinite loop. What I am trying to do instead is to have it run through each of my 48,000+ data points from "DiatomsPoints" and select the polygon from "huc250kSUBSv2" for each point. Then, I would like the information to be collated into a table which shows the data from "DiatomsPoints" and the corresponding polygon from "huc250kSUBSv2". Is there a simple way to do this with model builder? I also have the Python code below, but I don't know how to code in Python (yet), so I'm not sure where I need to make changes, or even what changes to make. Thanks for your help!

 

Python:

 

# -*- coding: utf-8 -*-

# ---------------------------------------------------------------------------

# DiatomScript.py

# Created on: 2015-02-25 10:39:32.00000

#   (generated by ArcGIS/ModelBuilder)

# Usage: DiatomScript <DiatomPoints>

# Description:

# ---------------------------------------------------------------------------

 

 

# Import arcpy module

import arcpy

 

 

# Load required toolboxes

arcpy.ImportToolbox("Model Functions")

 

 

# Script arguments

DiatomPoints = arcpy.GetParameterAsText(0)

if DiatomPoints == '#' or not DiatomPoints:

    DiatomPoints = "DiatomPoints" # provide a default value if unspecified

 

 

# Local variables:

DiatomPoints__2_ = DiatomPoints

Value = DiatomPoints__2_

huc250kSUBSv2__2_ = DiatomPoints__2_

DiatomData = huc250kSUBSv2__2_

huc250kSUBSv2 = "huc250kSUBSv2"

DiatomDiversity = "C:\\Users\\an997533\\Documents\\DiatomDiversity"

 

 

# Process: Select Layer By Attribute

arcpy.SelectLayerByAttribute_management(DiatomPoints, "NEW_SELECTION", "")

 

 

# Process: For

arcpy.IterateCount_mb("1", "48606", "1")

 

 

# Process: Select Layer By Location

arcpy.SelectLayerByLocation_management(huc250kSUBSv2, "INTERSECT", DiatomPoints__2_, "", "NEW_SELECTION")

 

 

# Process: Create Table

arcpy.CreateTable_management(DiatomDiversity, "DiatomData", "", "")

Tags (3)
3 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Christine,

You can accomplish this using the Spatial Join tool w/o the need for a model or script.

0 Kudos
StevenGraf1
Occasional Contributor III

I see you are trying to do this in Model Builder but a tool is already developed for this call Spatial Join.  You can join 2 feature classes based on a spatial relationship.

ArcGIS Help 10.1

Hope this helps.

0 Kudos
ChristineButterfield
New Contributor II

Thank you both for your help! That worked perfectly

0 Kudos