Select to view content in your preferred language

How to use multiple layer while generating grid index feature in acpy ?

512
3
02-27-2023 03:25 AM
NiharSahoo
New Contributor III

I want to generate grid index feature using multiple layers as a common layer for the input parameter to the grid map. But the map will not use the filtered data in the definition query as input and it will take all data as input so my problem will not getting resolved.

 

Below is my code for which the issue is exist please let me know where is the issue with my code ?

my_cable_str = str(my_cable)
my_tail_str = str(my_tail)
my_closure_str = str(my_closure)

arcpy.cartography.GridIndexFeatures(grid_new_name, my_closure_str + ";" +my_cable_str +";"+ my_tail_str, "INTERSECTFEATURE",
"NO_USEPAGEUNIT")

 

NiharSahoo_0-1677497140611.png

 

 

0 Kudos
3 Replies
Kepa
by Esri Contributor
Esri Contributor

Hello @NiharSahoo

Not sure what values you are passing on those three variables, but this snippet works as expected creating grid index on those places where features intersect.

1) Create a filtered layer from a feature class

2) Create another filtered layer from another feature class

3) Create the index passing the temp layers as input parameter in the GridIndexFeatures tool

 

arcpy.management.MakeFeatureLayer("D:\\ArcGIS_Pro\\MyProject\\MyProject.gdb\\featureclass", 'temp_layer', "OBJECTID = 1")
arcpy.management.MakeFeatureLayer("D:\\ArcGIS_Pro\\MyProject\\MyProject.gdb\\featureclass2", 'temp_2_layer', "OBJECTID = 3")
arcpy.cartography.GridIndexFeatures(r"D:\ArcGIS_Pro\MyProject\MyProject.gdb\grid2", "temp_layer;temp_2_layer", "INTERSECTFEATURE", "NO_USEPAGEUNIT", None, '', '', '', 3, 3, 1, "NO_LABELFROMORIGIN")

 

Regards,

0 Kudos
NiharSahoo
New Contributor III

currently i am doing like this

LayerObj1 = map_object.listLayers("cable")[0]
LayerObj2 = map_object.listLayers("closure")[0]
arcpy.cartography.GridIndexFeatures(
out_feature_class="grid",
in_features="LayerObj1;LayerObj2",
intersect_feature="INTERSECTFEATURE",
use_page_unit="NO_USEPAGEUNIT",
scale=None,
polygon_width="405 Meters",
polygon_height="325 Meters",
starting_page_number=1,
label_from_origin="NO_LABELFROMORIGIN")

 still it is not working

0 Kudos
Kepa
by Esri Contributor
Esri Contributor

Looking at your code we can assume that layers on the map are already filtered with a definition query, right? Instead of using layers from the map object try to create them with MakeFeatureLayer directly from the feature class. Depending on ArcGIS PRO version I found that definition queries don't work as expected as input parameters of other tools.

If your workflow implies the use of map object you can use definitionQuery property of each layer to create this temp layers.

LayerObj1 = map_object.listLayers("cable")[0]
tempLayer1 = arcpy.management.MakeFeatureLayer(LayerObj1, 'temp1', LayerObj1.definitionQuery) LayerObj2 = map_object.listLayers("closure")[0]
tempLayer2 = arcpy.management.MakeFeatureLayer(LayerObj2, 'temp2', LayerObj2.definitionQuery)
arcpy.cartography.GridIndexFeatures(out_feature_class="grid",in_features="temp1;temp2" ...)

 

0 Kudos