<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: add shapefiles in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/add-shapefiles/m-p/532908#M41756</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It depends if you want to make this layer permanent, as in create a .lyr file, or just add it to the map as a one off. You can accomplish the later using make feature layer.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 28 Mar 2012 14:55:11 GMT</pubDate>
    <dc:creator>MathewCoyle</dc:creator>
    <dc:date>2012-03-28T14:55:11Z</dc:date>
    <item>
      <title>add shapefiles</title>
      <link>https://community.esri.com/t5/python-questions/add-shapefiles/m-p/532907#M41755</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sometimes the most simple tasks are to most complicated (and thereby frustrating). I just want to add a shapefile in a mxd. I only am able to figure out how to add a layer file:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument(r"C:\gisbestanden\pythontest\test.mxd")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df = arcpy.mapping.ListDataFrames(mxd)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;addLayer = arcpy.mapping.Layer(r"C:\gisbestanden\pythontest\buurten.lyr") &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd.saveACopy(r"C:\gisbestanden\pythontest\test7.mxd")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;del mxd&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I see two options, but excuting is another story. First replace &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;&lt;STRONG&gt;addLayer = arcpy.mapping.Layer(r"C:\gisbestanden\pythontest\buurten.lyr") &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt; with &lt;/SPAN&gt;&lt;STRONG&gt;addLayer = arcpy.mapping.Layer(r"C:\gisbestanden\pythontest\testje.shp") &lt;/STRONG&gt;&lt;SPAN&gt;. But that doesn't work. Another one is the make a .lyr from C:\gisbestanden\pythontest\testje.shp, but I can't figure out how? Does anybody have a sollution&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Mar 2012 08:55:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-shapefiles/m-p/532907#M41755</guid>
      <dc:creator>ReneSchulenberg</dc:creator>
      <dc:date>2012-03-27T08:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: add shapefiles</title>
      <link>https://community.esri.com/t5/python-questions/add-shapefiles/m-p/532908#M41756</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It depends if you want to make this layer permanent, as in create a .lyr file, or just add it to the map as a one off. You can accomplish the later using make feature layer.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Mar 2012 14:55:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-shapefiles/m-p/532908#M41756</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-03-28T14:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: add shapefiles</title>
      <link>https://community.esri.com/t5/python-questions/add-shapefiles/m-p/532909#M41757</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I wanted the second. makefuturelayer worked in combination with addlayer:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.MakeFeatureLayer_management("C:\gisbestanden\pythontest\gedoe.shp", "test")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;addLayer = arcpy.mapping.Layer("test") &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Mar 2012 12:10:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-shapefiles/m-p/532909#M41757</guid>
      <dc:creator>ReneSchulenberg</dc:creator>
      <dc:date>2012-03-30T12:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: add shapefiles</title>
      <link>https://community.esri.com/t5/python-questions/add-shapefiles/m-p/532910#M41758</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Seems like that isn't possible when working in a stand alone script. The following worked for me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
arcpy.env.worksace = workspace = r"C:\GIS\scratch"
arcpy.env.overwriteOutput = True
mxd_string = r"C:\GIS\MXDs\empty_test.mxd"
fc = r"C:\GIS\someshapefile.shp"
mxd = arcpy.mapping.MapDocument(mxd_string)
df = arcpy.mapping.ListDataFrames(mxd)[0]

outlayer = "TEST_LYR"
layerfile = os.path.join(workspace,"ADDED_LAYER.lyr")

arcpy.MakeFeatureLayer_management(fc, outlayer)
arcpy.SaveToLayerFile_management(outlayer, layerfile, "ABSOLUTE")
addlayer = arcpy.mapping.Layer(layerfile)
arcpy.mapping.AddLayer(df, addlayer)

mxd.save()
del mxd
print "done"
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:10:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-shapefiles/m-p/532910#M41758</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T23:10:10Z</dc:date>
    </item>
  </channel>
</rss>

