create a layer using python in ArcMap 10.4

6247
16
06-15-2016 08:48 AM
PaulHacker2
Deactivated User

I'm a self taught (well still learning) Python/ArcGis programmer. The company I work for does well maps.

How does one use python to create a layer?

I know I can click down to the personal Geodatabase.mdb on ArcMaps and right click and do a 'create layer' but we have a huge number of maps to create and we have a large library of GDB to make into layers on maps. I would hope the script behind that 'create layer' would be visible but it isn't.

I want to make a batch process to do all the work instead of getting on ArcMap 10.4 and doing them one by one. I presume arcpy and one (or several of the functions/methods) are used.

Thanks for any help!

0 Kudos
16 Replies
MicahBabinski
Frequent Contributor

Hi Paul,

If I understand what you are trying to do, then I think Append (management) and Rename (management) will get you there. However...

Paul Hacker wrote:

But now I need to copy INTO the new created F, G, and H Geodatabase Feature Class from another GDB that already has a F, G, and H Geodatabase Feature Classes that has data they want to show up on ALL of them.

...why not just copy the feature classes over, rather than creating a new (empty) feature class and loading data into it? That way you would get it done in fewer steps.

Micah

0 Kudos
WesMiller
Deactivated User
0 Kudos
PaulHacker2
Deactivated User

Thanks guys.

I got the first part to work perfect (creating features for all 189 of 'em!) using arcpy.CreateFeatureclass_management.

Now on FeatureClassToFeatureClass_conversion (copying a template to the newly created feature classes.)

My ArcMap shows the template I wish to copy/convert as:

c:\output

      - maps

           - code_mapgrid.mdb

              - Mapgrid

                     [] Block_template_number      (feature class I wan to copy but rename with such as Block_002_003)

Does the arcpy.env.workspace point to the mdb where the class is? How does it know where to find the inFeatures?

arcpy.FeatureClassToFeatureClass_conversion(inFeatures, outLocation, outFeatureClass, expression)

All want it to do is copy over the blank features (Block_002_003) I made in the new GDB with features in the template mdb  (Block_template_number).

Thanks,

Paul

0 Kudos
WesMiller
Deactivated User

If you just want the schema and not any records. You could use create feature class and use the existing feature classes as a template. See creating feature class above

0 Kudos
PaulHacker2
Deactivated User

Thanks. We need the records that are in them.

Paul

0 Kudos
MicahBabinski
Frequent Contributor

So you have created empty feature classes in your personal geodatabase, and now want to load some features into them? For that, you would use Append (management). Feature Class To Feature Class will write an entire feature class to a given output location. It's just a little unclear what exactly you are going for.

Here's a tip: before writing any code, start by writing a step-by-step explanation of what you want your script to do, in the simplest possible terms. I do that regularly and it helps me complete the script, and ask for help if I need it. Then, if you complete your process using individual geoprocessing tools, you can go to your results tab (Geoprocessing Menu -> Results), right-click a tool, and select 'Copy as Python snippet.' Then you can paste that into a script to see how the parameters work. Also, if you have ModelBuilder experience you can set up your process in ModelBuilder and then choose Export -> Export to Python Script. This may also help you understand how parameters and results of tools are handled (although the script often comes out a little hard to understand).

0 Kudos
PaulHacker2
Deactivated User

Thanks. I would have made the sniplet if the license they got for my ArcMap allowed it. And it would have made my life MUCH simpler.

I'll now research the Append and get it to work.

Thanks.

0 Kudos