<?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: Exporting WKT string from CSV to Shapefile in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/exporting-wkt-string-from-csv-to-shapefile/m-p/521433#M40880</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is a problem with FID and OBJECTID.&amp;nbsp; The easiest solution I have found is to add a column at the source so it is in the geodatabase table and calculate a new&lt;/P&gt;&lt;P&gt;'IDjoin' using the field calculator, ie OBJECTID - 1&lt;/P&gt;&lt;P&gt;then you will have a zero-based field.&lt;/P&gt;&lt;P&gt;Alternately, do the reverse in the csv to get an id field that is 1 based&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 08 Jun 2018 09:52:59 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2018-06-08T09:52:59Z</dc:date>
    <item>
      <title>Exporting WKT string from CSV to Shapefile</title>
      <link>https://community.esri.com/t5/python-questions/exporting-wkt-string-from-csv-to-shapefile/m-p/521430#M40877</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a CSV storing addresses, reference numbers, etc... and also a WKT string of boundary coordinates for each property:&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="410853" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/410853_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The script (ammended from another user's post in 2012) sccessfully converts the CSV to a shapefile, with the spatial refeence set to EPSG- 27700:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# convert well known text to geometry, and compile shapes into a single feature class...&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# 11/15/2012&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy

File &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"C:\\Users\\Team\\Documents\\Theo Laptop Folder\\Tasks\\Quick tasks\\WKTtest\\WKT_to_QGISmakealayerCSV2.csv"&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# dimension the WKT string field and poly ID field...&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# the field holding the WKT string...&lt;/SPAN&gt;
field1 &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"WKT"&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# the field holding the unique ID...&lt;/SPAN&gt;
field2 &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Our_ref"&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# set up the empty list...&lt;/SPAN&gt;
featureList &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# set the spatial reference to a known EPSG code...&lt;/SPAN&gt;
sr &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SpatialReference&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;27700&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# iterate on table row...&lt;/SPAN&gt;
cursor &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;File&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
row &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; cursor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;next&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;while&lt;/SPAN&gt; row&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;row&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;getValue&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;field2&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; WKT &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; row&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;getValue&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;field1&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;# this is the part that converts the WKT string to geometry using the defined spatial reference...&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; temp &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;FromWKT&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;WKT&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; sr&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;# append the current geometry to the list...&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; featureList&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;temp&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp; row &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; cursor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;next&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; 
&lt;SPAN class="comment token"&gt;# copy all geometries in the list to a feature class...&lt;/SPAN&gt;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;CopyFeatures_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;featureList&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"C:\\Users\\Team\\Documents\\Theo Laptop Folder\\Tasks\\Quick tasks\\WKTtest\\WKTShapes.shp"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; 

&lt;SPAN class="comment token"&gt;# clean up...&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;del&lt;/SPAN&gt; row&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; temp&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; WKT&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; File&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; field1&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; featureList&lt;SPAN class="punctu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SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is in python 2.7 language fyi. (I'd love this in 3.6 if possible...)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now when I drag the newly created shapefile into Arc it all looks great, but the fields from the CSV aren't carried across...&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="410854" class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/410854_pastedImage_2.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I ammend the code to include all the original string fields from the CSV?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:44:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-wkt-string-from-csv-to-shapefile/m-p/521430#M40877</guid>
      <dc:creator>TheodoreF</dc:creator>
      <dc:date>2021-12-11T22:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting WKT string from CSV to Shapefile</title>
      <link>https://community.esri.com/t5/python-questions/exporting-wkt-string-from-csv-to-shapefile/m-p/521431#M40878</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could add a 'Join' into the workflow since your key field would be the id's of the geometry.&amp;nbsp; That would just simplify things&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jun 2018 16:37:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-wkt-string-from-csv-to-shapefile/m-p/521431#M40878</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-06-07T16:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting WKT string from CSV to Shapefile</title>
      <link>https://community.esri.com/t5/python-questions/exporting-wkt-string-from-csv-to-shapefile/m-p/521432#M40879</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I tried using Join Field to join the shapefile with the CSV (converted to an ESRI table so it has OIDs), but they don't match up. The shapefile of the polygons has an FID field starting at 0 and running to 5 (6 polygons), but the ObjectIDs on the table start at 1, running to 6. So everything is out of sync by 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On the CSV I added a 'Join_id' column and filled it with 0 to 5, but the Join Field tool wouldn't recognise this as an OID field for use in the join.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;UPDATE: so using the Add Join tool I &lt;EM&gt;can&lt;/EM&gt; use my 'Join_id' column in the CSV to join to the shapefile. This tool only works off layers in the ToC of course... I'd be looking to run this script outside of ArcGIS, in the background.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm sure it must be possible to pull the columns from the original csv through...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jun 2018 09:36:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-wkt-string-from-csv-to-shapefile/m-p/521432#M40879</guid>
      <dc:creator>TheodoreF</dc:creator>
      <dc:date>2018-06-08T09:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting WKT string from CSV to Shapefile</title>
      <link>https://community.esri.com/t5/python-questions/exporting-wkt-string-from-csv-to-shapefile/m-p/521433#M40880</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is a problem with FID and OBJECTID.&amp;nbsp; The easiest solution I have found is to add a column at the source so it is in the geodatabase table and calculate a new&lt;/P&gt;&lt;P&gt;'IDjoin' using the field calculator, ie OBJECTID - 1&lt;/P&gt;&lt;P&gt;then you will have a zero-based field.&lt;/P&gt;&lt;P&gt;Alternately, do the reverse in the csv to get an id field that is 1 based&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jun 2018 09:52:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-wkt-string-from-csv-to-shapefile/m-p/521433#M40880</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-06-08T09:52:59Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting WKT string from CSV to Shapefile</title>
      <link>https://community.esri.com/t5/python-questions/exporting-wkt-string-from-csv-to-shapefile/m-p/521434#M40881</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So I've created a new field in the source csv, run Table to Table on that (which gives it an OID), then used this new table in the Join Field tool.&lt;/P&gt;&lt;P&gt;It works fine as a workaround for now. Thanks for suggesting the join.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jun 2018 11:11:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-wkt-string-from-csv-to-shapefile/m-p/521434#M40881</guid>
      <dc:creator>TheodoreF</dc:creator>
      <dc:date>2018-06-08T11:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting WKT string from CSV to Shapefile</title>
      <link>https://community.esri.com/t5/python-questions/exporting-wkt-string-from-csv-to-shapefile/m-p/521435#M40882</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;glad it worked out... when I switched to gdb's I discovered than since featureclass tables are 1-based and I am used to 0-based indexing with python and its ilk and shapefiles&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jun 2018 11:49:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-wkt-string-from-csv-to-shapefile/m-p/521435#M40882</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-06-08T11:49:12Z</dc:date>
    </item>
  </channel>
</rss>

