Select to view content in your preferred language

Combining multiple grids in the same layer using python

1275
5
Jump to solution
02-22-2023 01:11 PM
neomapper
Frequent Contributor

How do I combine multiple grids using python without having to create a new layer ?

neomapper_0-1677100130576.png

 

1 Solution

Accepted Solutions
Kepa
by Esri Contributor
Esri Contributor

So looking at your table I assume you want to merge them by system number field. The "easy" way would be (you'll have to deal with python logic a bit):

  1. Dissolve by system number field, this will create a temporary feature class with the features merged by its value.
  2. Create a SearchCursor for dissolved feature class storing system number value and SHAPE@ object in differente variables
  3. Create an InsertCursor for your existing grid feature class
  4. For every system number value from SearchCursor apply a Selection by attribute on your grid feature class and execute DeleteFeatures.
  5. Finally add/insert the shape and system number value into your existing grid feature class with the InsertCursor (the rest of the fields would be Null of course, although I see only Name field has values)
  6. Delete temporary feature class

Hope that helps!

View solution in original post

5 Replies
Kepa
by Esri Contributor
Esri Contributor

Hello @neomapper 

Do you mean having all different grids in one feature class? If that's the case you can create them (Grid Index Features -Cartography) and merge them with python into a singel FC. Or just merge them if you already have them.

If not try to clarify what's your goal here. Regards,

neomapper
Frequent Contributor

Hi Kepa,

The grid index creates an entirely new layer which is something that I can't utilize because we have over +200 systems and approx. +3000 grids. There is the edit merge tool but I would have to manually select each and every system and grids to merge which is difficult doing this by hand each week. Is there a way or tool to select features in the same feature class and merge grids without having to create an entire new feature class?

 

neomapper_0-1677246061516.png

 

0 Kudos
Kepa
by Esri Contributor
Esri Contributor

Ok, I was misunderstanding your goal here. You are talking about merging grid features of the same feature class and not grid feature classes, is that right?

0 Kudos
neomapper
Frequent Contributor

Yep, grid features of the same feature class!

0 Kudos
Kepa
by Esri Contributor
Esri Contributor

So looking at your table I assume you want to merge them by system number field. The "easy" way would be (you'll have to deal with python logic a bit):

  1. Dissolve by system number field, this will create a temporary feature class with the features merged by its value.
  2. Create a SearchCursor for dissolved feature class storing system number value and SHAPE@ object in differente variables
  3. Create an InsertCursor for your existing grid feature class
  4. For every system number value from SearchCursor apply a Selection by attribute on your grid feature class and execute DeleteFeatures.
  5. Finally add/insert the shape and system number value into your existing grid feature class with the InsertCursor (the rest of the fields would be Null of course, although I see only Name field has values)
  6. Delete temporary feature class

Hope that helps!