<?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 python script - generating a GeoJSON file for each shp file in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-script-generating-a-geojson-file-for-each/m-p/127189#M9905</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to write a python script in which the user enters the name of the directory with shapefile files. For each .shp file from a given directory (without checking subdirectories), the script generates a GeoJSON file in the current directory.&lt;/P&gt;&lt;P&gt;On the GitHub website I found a topic (https://gist.github.com/benbalter/5858851) in which someone may have written what I need:&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/496180_GitHub.PNG" /&gt;&lt;/P&gt;&lt;P&gt;But I need a script that first runs it, then in the console, the program asks the user for the path to the folder with the .shp files. In addition, if the GeoJSON file with the given name already exists, then before running the ogr2ogr command the program asks the user whether to overwrite it. Can you help me write such a program?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 11 Jun 2020 12:58:38 GMT</pubDate>
    <dc:creator>RafaelMichael</dc:creator>
    <dc:date>2020-06-11T12:58:38Z</dc:date>
    <item>
      <title>python script - generating a GeoJSON file for each shp file</title>
      <link>https://community.esri.com/t5/python-questions/python-script-generating-a-geojson-file-for-each/m-p/127189#M9905</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to write a python script in which the user enters the name of the directory with shapefile files. For each .shp file from a given directory (without checking subdirectories), the script generates a GeoJSON file in the current directory.&lt;/P&gt;&lt;P&gt;On the GitHub website I found a topic (https://gist.github.com/benbalter/5858851) in which someone may have written what I need:&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/496180_GitHub.PNG" /&gt;&lt;/P&gt;&lt;P&gt;But I need a script that first runs it, then in the console, the program asks the user for the path to the folder with the .shp files. In addition, if the GeoJSON file with the given name already exists, then before running the ogr2ogr command the program asks the user whether to overwrite it. Can you help me write such a program?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Jun 2020 12:58:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-generating-a-geojson-file-for-each/m-p/127189#M9905</guid>
      <dc:creator>RafaelMichael</dc:creator>
      <dc:date>2020-06-11T12:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: python script - generating a GeoJSON file for each shp file</title>
      <link>https://community.esri.com/t5/python-questions/python-script-generating-a-geojson-file-for-each/m-p/127190#M9906</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As an alternative to ogr2ogr, you might consider &lt;A href="https://desktop.arcgis.com/en/arcmap/latest/tools/conversion-toolbox/features-to-json.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Features to JSON&lt;/A&gt;.&amp;nbsp; If you are using Pro or Desktop 10.5+, there is an option to&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;Create output as GeoJSON, conforming to the &lt;A href="https://tools.ietf.org/html/rfc7946" target="_blank" rel="nofollow noopener noreferrer"&gt;GeoJSON specification&lt;/A&gt;.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I tested the following, to which you can add a walk through your shape file directory:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;import arcpy
shp = r'C:\Path\To\file.shp'
out = r'C:\Path\To\file.json' # cannot use '.geojson' as extension

arcpy.FeaturesToJSON_conversion(shp, out, format_json="FORMATTED", geoJSON='GEOJSON')
# format_json is optional, makes file a bit more human readable

print('Done')
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:13:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-generating-a-geojson-file-for-each/m-p/127190#M9906</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2021-12-11T07:13:08Z</dc:date>
    </item>
  </channel>
</rss>

