Python shapefiles, centroids, and CAD

976
8
06-10-2013 06:42 AM
ChristopherGraf
New Contributor III
I am trying to write a python script that can draw a polygon or some just some sort of selection square to select shapefiles on ArcMap, then calculate their centroids, add fields for CAD export, and export to AutoCAD. I was thinking of starting out with the ArcMap selection for "Edit Start" and seeing if I can use that to select the shapefiles and go from there.

Does anybody have any other good ideas? Please let me know


Thanks,
cgraf1
Tags (2)
0 Kudos
8 Replies
RobParsons
New Contributor
I have similar interest.

What will define the polygon? Input feature class? User draws on screen? The map view?

What ArcGIS version are you using?

From: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001w00000009000000

This Python code sets the environment extent (bounding box) that limits where geoprocessing tools operate:

import arcpy
from arcpy import env

# Set the extent environment using a keyword.
arcpy.env.extent = "MAXOF"

# Set the extent environment using the Extent class.
arcpy.env.extent = arcpy.Extent(-107.0, 38.0, -104.0, 40.0)

# Set the extent environment using a space-delimited string.
arcpy.env.extent = "-107.0 38.0 -104.0 40.0"
0 Kudos
ChristopherGraf
New Contributor III
Misinterpreted instructions given to me. What I am actually doing now is intersecting two feature classes, adding 5 fields, exporting those fields to a separate table, calculating cendroid, bringing those fields back into the intersecting feature class, making a point feautre class, and exporting all the info to CAD. I am also using ArcGIS model builder for now, but will use script or anything else if I have to. Just need to get the job done. If you have any advice for this, I would be greatful. If not, good luck with your project.
0 Kudos
NeilAyres
MVP Alum
You don't say here what version you are on.
I always think it wise when working out a workflow to do it "by hand" ie in ArcMap / Catalog using the tools first, before trying to automate it with modelbuilder or python scripting.

Intersect is there in the tool box. Add field by opening the attribute table and add the required fields.
Not sure why you need to then export these to a separate table.
The centroid can be added to the attributes by using "Calculate Geometry". Add 2 more fields CentX, CentY, for each click on the column header, right click and select "Calculate Geometry".
By now you should have everything in the feature class that you need. Poly to Point if you need it.

If you want to go out to CAD, I think you will need the data interop extension.

Cheers and good luck,
Neil
0 Kudos
ChristopherGraf
New Contributor III
Calculate Geometry is not a tool. I can right click and use it, but I am trying to make it automatic. The purpose of this is to save time for when field workers have new data they want to put into CAD. This is the process my boss has done many times manually, but now wants automated to save time and effort.
0 Kudos
ChristopherGraf
New Contributor III
Also, I am in ArcMap 10.1
0 Kudos
ShaunWalbridge
Esri Regular Contributor
Calculate Geometry is not a tool. I can right click and use it, but I am trying to make it automatic. The purpose of this is to save time for when field workers have new data they want to put into CAD. This is the process my boss has done many times manually, but now wants automated to save time and effort.


You can perform the centroid calculation using CalculateField, one of the code samples shows how to use it to add a centroid.
0 Kudos
ChristopherGraf
New Contributor III
I have used many different iterations of expressions trying to use the CalculateField tool, including the example shown on the link, but even when it seems to run correctly, I get all 0's as the calculated result for all the centroids, which I know is not correct.
0 Kudos
ChristopherGraf
New Contributor III
I figured out my problem. I was trying to calculate the centroids AFTER I brought it over to a table, so in the model I was trying to calculate the centroids of a table, which doesn't exist....
0 Kudos