GridIndexFeatures does not respect a manual origin point?

578
4
03-19-2020 03:13 PM
KristianHerner
New Contributor III

In an effort to create a series of simplified polygons for large national complicated datasets, I am using the arcpy.GridIndexFeatures_cartography function for this: 

I take a feature class, use the XMin and YMin values to define the origin point of my analysis. I then subtract an adequate value (~500 meters or so), and use that point as my origo point. 

I first create a GridIndexFeature (the red squares) over my input feature class (green polygon). I then offset the origin point with half of the width of my grid and run GridIndexFeatures again on the previous result. I can then dissolve this for a rough, low vertex count, rough bounding geometry, where I know i have atleast half a grid-size worth of buffer. This works fine in Python 2.7.

However in python 3.5, It always uses the input feature extent. I am using the exact same script. If I run the tool in ArcGIS Pro, I can enter the origin point manually and it will provide the same result as python 2.7. But not when running through arcpy in python 3.5. I guess I can just use python 2.7, but I dont know if this is a bug in arcpy?

Is there a way to enforce the origin point in arcpy.GridIndexFeatures in python 3.5?

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

example 4 shows how to set an origin point/location.  I think their example must be in web mercator, so make sure you are specifying your parameters in your desired coordinate system

Grid Index Features—ArcGIS Pro | Documentation 

KristianHerner
New Contributor III

Example 4 has no input polygon to intersect with/create a grid around. None of the examples uses origin and an input feature together (unfortunately). I have my environment, input features and grid all set in the same map projection.

0 Kudos
DanPatterson_Retired
MVP Emeritus

I didn't say an exact match, but the origin example is there

origin_coord
(Optional)

Specifies the coordinate value for the lower left origin of the output grid feature class. If input features are specified, the default value is determined by the extent of the union of extents for these features. If there are no input features specified, the default coordinates are 0 and 0.

which if you have input features, these are 0,0, otherwise, I assume you can specify your actual offset coordinate values here.

0 Kudos
KristianHerner
New Contributor III

I am using all the correct variables and I am using the correct syntax. If I run my script in python 2.7, it works as expected. But in python 3.5 it ignores the origin input:

def grid(Origin,in_fc, fc_name, size):

polygonWidth = str(size) + " meters"
polygonHeight= str(size) + " meters"
originCoord = Origin
print(originCoord) # string type, ex: "262119 6125142"

fc_out = arcpy.GridIndexFeatures_cartography(fc_name,
                                                                           in_fc, "", "", "",

                                                                           polygonWidth, polygonHeight, originCoord,
                                                                           "", "", "", "")


return fc_out

I guess the documentation insinuates that an input feature overrides the origin coordinates, but if i use the tool in Pro, i can edit the values, and it performs as expected. it is just the arcpy version in the python 3.5 that ignores the origin point. 

0 Kudos