Rotate/Scale Polylines Based on Field in Attribute Table

6047
19
12-02-2014 05:14 PM
MorganHarris
New Contributor III

Does anyone know a way or have a script that allows you to rotate and/or scale a polyline based on a field in the attribute table. I know you can do this with the editor, but I have about 1200 different lines that need to be rotated and scaled and all to different angles and sizes (based on the angle) that will be defined by a field in the attribute table. I am working with 3D polylines and have an advanced license for ArcGIS 10.2.2.

19 Replies
DanPatterson_Retired
MVP Emeritus

You want to use the Spatial Adjustment tools using an 'Affine' transformation.  search the help using that keyword and it will link you to the concepts and the tools but there is no field based option so you will have to roll out your own using the Polyline class in arcpy

MorganHarris
New Contributor III

I will look in to that and see if I can figure it out. Thanks for the tip!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Dan Patterson‌, doesn't the Spatial Adjustment tools transform the entire featureclass (all features) the same way? The help  (ArcGIS Help (10.2, 10.2.1, and 10.2.2) ) may assist in programming the formula to apply for each polygon based on the attributes for that specific polygon. I just wonder when using rotation, will you rotate the feature around the center? And with 3D data things get a little more interesting...

Maybe this resource helps you:

geometry/transformations.py at hydro-devel · ros/geometry · GitHub

DanPatterson_Retired
MVP Emeritus

Xander Bakker‌ I got the impression that the various parameters were set within a table so that translation, rotation and/or scale could be applied to individual features and not the whole featureclass itself.  If the affine were to be applied to the whole feature class, then yes, spatial adjustment would be easy.

On a side note, affine (translation to...rotation about...and scaling along the axis... of the origin) is what I used to determine the base parameters for a minimum area bounding ellipse (MABR) for feature data (ie point clusters, polylines and/or points).   An affine transformation of an ellipse to the origin will yield a circle, hence, if the transformed feature isn't a pure circle, then you can solve for the ellipse parameters there using 3,4 or 5 point solutions to the ellipse...then reverse the transform and the resultant ellipse.  A long story, but something William Huber‌ was coaching me on during my last sabbatical when I was working on my 'containers' toolbox and studying algorithms, programming and computational geometry.

XanderBakker
Esri Esteemed Contributor

Cool! A sabbatical and being coached by William Huber‌. I'm getting a little jealous here.

MorganHarris
New Contributor III

This got over my head pretty quick! It does seem to me, Dan Patterson, looking through the spatial adjustments help it seems that method will change each section of my polyline the same. What I need to be able to do is iterate through basically each line (every section of line in my polyline has its own "span ID" in the attribute table) in my attribute table and rotate each "span ID" by a field labelled "angle" in my attribute table. I feel like this should be a pretty simple script just to rotate and then call in a field in the attribute table to be the value for rotation, but I haven't used code in about 2 years now and have only ever used it minimally.

Xander Bakker‌, I looked at that code you sent and am trying to decipher it. There are a lot of terms in there that I have never used so I'm not sure yet if that will work for me. In the mean time, maybe the way I re-worded the problem here will help spark up a simple solution! Thanks for helping!

0 Kudos
DanPatterson_Retired
MVP Emeritus

Can you post a section of your attribute table.  You say "every section of your polyline" suggests to me that your polyline consists of parts which are separated out and that each "section" is part of a bigger one.  A polyline is usually represented by one record in the table and you would not see its sections unless the part was exploded into its individual parts...essentially making many polylines from the original and they may be "sections" in the sense that they originated from the parent polyline...but now they are all grown up and have move out on their own...

0 Kudos
XanderBakker
Esri Esteemed Contributor

If the feature has attributes about the rotation and translation, I suppose it doesn't really matter if it is a multipart or not, since the affine transformation will be applied to the entire feature. Right?

But yeah, it would be nice to post a small part of you data or create some comparable dummy data so we can have a look at it.

0 Kudos
MorganHarris
New Contributor III

Xander Bakker and Dan Patterson‌ I attached my "Power_Line_Spans" so that you can take a look. Right now, this is what I have, but it only represents 2d lines because my 3D data is not here yet. The attribute table for the 3D data will be the same though with each "section" of polyline containing a separate "span_ID". Thanks for taking a look! I also don't have the angle field in this data yet because I'm waiting on another part of my team to complete that task.

0 Kudos