5 Replies Latest reply on May 7, 2011 2:13 AM by dwightlanier

    Rotate Feature or Find Rotating Envelope Polygon

      Couldn't find anything posted on this, if I overlooked, please redirect, otherwise:

      Ultimate Goal:  Create a series of polygons (each polygon in it's own separate shapefile) whose width is the same as the width of an input feature, but at different angles from 0 - 360 degrees.  See attached image where the red lines would represent the extent of the feature at different angles of rotation.

      Method:  I'm looking to find the min and max x value of a single polygon feature, which can easily be done when the feature is sitting in it's normal angle of 0 degrees rotation by using the properties or the create envelope polygon tool.  To build the other polygons that show the width of the feature at different angles, I would think that it's easier to rotate the input feature one degree, recalculate the extent rectangle as if it's sitting at zero degrees rotation, and then rotate the extent rectangle back the same degree of rotation that the input feature was rotated. 

      Question:  How can I use Python to rotate a feature in ArcGIS 9.3?


        • Re: Rotate Feature or Find Rotating Envelope Polygon
          The Minimum Area Bounding Rectangle has been implemented already in the Bounding Containers toolset.  It does exactly what you want and the code can be extracted from the Python scripts.  This version http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=3D230972-1422-2418-34A5-2F3FFF97C238  is for ArcGis 10.
          • Re: Rotate Feature or Find Rotating Envelope Polygon
            Dan, thanks for the reply, but I don't think that this is what I'm looking for.

            What I need is a regular bounding extend rectangle, but for different angles of rotation.  See attached image 2 for a bit of clarrification.  I need a regular bounding rectangle so i can extend it out and find features that cross the width of the input feature (like the green line) which I will then clip.  A minimum area bounding rectangle doesn't give me these extended lateral lines for the feature at all intermidiate angles.  Unless the toolset you linked to provides min max coordinates at each angle of rotation, then that could be used?

            As in the example picture, I would do this for 90, 91, 92, etc. degrees looking for features with a certain criteria that fall within that area for each angle.  As you look at the input feature from different angles you will get different areas of influence before and after the feature.

            This is why I think it might be easiest to rotate the input feature and then do a standard extent rectangle and then rotate the extent rectangle back.

            Thanks again for the try,

            • Re: Rotate Feature or Find Rotating Envelope Polygon
              There is a Rotate GP tool, but this is only for raster datasets.  You could create a script to convert the features to a raster dataset (Polygon to Raster), rotate the raster datasets (Rotate), then convert the rasters back to a feature class (Raster to Polygon).  You will then be able to retrieve the new extent of the rotated feature.
              • Re: Rotate Feature or Find Rotating Envelope Polygon
                Here is some sample code if interested:

                list = []
                # Specify feature class whose features you want to rotate
                # Append to list to find the Max OBJECTID/FID
                lstFCs = arcpy.ListFeatureClasses("Parcels")
                for fc in lstFCs:
                    rows = arcpy.SearchCursor(fc)
                    for row in rows:
                del row, rows        
                maxOID = list[-1]
                x = 1
                y = 1
                # Loop through each feature, convert to a feature layer, then to raster, rotate raster, convert back to polygon feature class
                while y <= maxOID:
                    for fc in lstFCs:
                        feat_lay = arcpy.MakeFeatureLayer_management(fc, fc + str(x), "OBJECTID = " + str(x))
                        ras_lay = arcpy.PolygonToRaster_conversion(feat_lay, "OBJECTID", fc + str(x) + "_ras") # Can improve processing time by specifying a larger cell size
                        feat_lay2 = arcpy.Rotate_management(ras_lay, "ras_rotate" + str(x), 45)
                        arcpy.RasterToPolygon_conversion(feat_lay2, fc + "_rotate_" + str(x))
                        y = y + 1
                        x = x + 1
                # Print extent of rotated feature classes
                lstFCs2 = arcpy.ListFeatureClasses("*rotate*")
                for fc2 in lstFCs2:
                    rows2 = arcpy.SearchCursor(fc2)
                    for row2 in rows2:
                        geom = row2.Shape
                        Extent = geom.extent
                        print Extent
                del row2, rows2
                # Deleted rasters
                lstRasters = arcpy.ListRasters("*ras*")
                for raster in lstRasters:
                • Re: Rotate Feature or Find Rotating Envelope Polygon

                  Thanks for the reply; I think this will work for what I need.  I'll have to look at the effects of rasterizing the boundary of the input feature, but as long as I do each angle of rotation from the original input feature it should be controllable.

                  Also this is a lot less of a headache than trying to implement some sort of rotating calipers function with a convex hull.  My friend Rick suggested an ArcObjects approach, but I would really like to think that there is an accessible solution to rotating objects with python?  That and I don't have the time it would take to dust off my VBA or .NET skills.

                  Anyway, thanks again,