<?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 export feature to csv in arcmap in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/export-feature-to-csv-in-arcmap/m-p/1513610#M71178</link>
    <description>&lt;P&gt;i'm trying to export a feature layer with several fields of different datatypes but 5 of the fields are datetime data types but when i use the below i get this error&lt;/P&gt;&lt;LI-CODE lang="python"&gt;nparr = arcpy.da.FeatureClassToNumPyArray('mob', fields,null_value=-9)
numpy.savetxt('H:\mobcsv2.csv', nparr, delimiter=",", fmt="%s")&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="StuartMoore_0-1722521045610.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/111346iD2FF8E036D9CB478/image-size/medium?v=v2&amp;amp;px=400" role="button" title="StuartMoore_0-1722521045610.png" alt="StuartMoore_0-1722521045610.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;how do i get around this?&lt;/P&gt;&lt;P&gt;Stu&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Aug 2024 14:05:10 GMT</pubDate>
    <dc:creator>StuartMoore</dc:creator>
    <dc:date>2024-08-01T14:05:10Z</dc:date>
    <item>
      <title>export feature to csv in arcmap</title>
      <link>https://community.esri.com/t5/python-questions/export-feature-to-csv-in-arcmap/m-p/1513610#M71178</link>
      <description>&lt;P&gt;i'm trying to export a feature layer with several fields of different datatypes but 5 of the fields are datetime data types but when i use the below i get this error&lt;/P&gt;&lt;LI-CODE lang="python"&gt;nparr = arcpy.da.FeatureClassToNumPyArray('mob', fields,null_value=-9)
numpy.savetxt('H:\mobcsv2.csv', nparr, delimiter=",", fmt="%s")&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="StuartMoore_0-1722521045610.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/111346iD2FF8E036D9CB478/image-size/medium?v=v2&amp;amp;px=400" role="button" title="StuartMoore_0-1722521045610.png" alt="StuartMoore_0-1722521045610.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;how do i get around this?&lt;/P&gt;&lt;P&gt;Stu&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2024 14:05:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-feature-to-csv-in-arcmap/m-p/1513610#M71178</guid>
      <dc:creator>StuartMoore</dc:creator>
      <dc:date>2024-08-01T14:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: export feature to csv in arcmap</title>
      <link>https://community.esri.com/t5/python-questions/export-feature-to-csv-in-arcmap/m-p/1513628#M71180</link>
      <description>&lt;P&gt;It seems like the feature class contains fields with geometry or datetime data types which connot be converted to a numpy array.&lt;/P&gt;&lt;P&gt;So you can try to exclude them. Untested&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy
import numpy as np

# Set workspace
arcpy.env.workspace = 'Geodatabase_Path'  # Replace with your actual geodatabase path

# Define feature class and fields
feature_class = 'mob'
all_fields = [f.name for f in arcpy.ListFields(feature_class)]
fields = [f for f in all_fields if arcpy.ListFields(feature_class, f)[0].type not in ['Geometry', 'Date']]

# Check excluded fields
print(f"All fields: {all_fields}")
print(f"Selected fields: {fields}")

# Create NumPy array excluding geometry and datetime fields
try:
    nparr = arcpy.da.FeatureClassToNumPyArray(feature_class, fields, null_value=-9)
    np.savetxt('H:\\mobcsv2.csv', nparr, delimiter=",", fmt="%s")
    print("Array saved successfully.")
except Exception as e:
    print(f"Error: {e}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;If you need them you can try something like this. Untested&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import numpy as np

# Set workspace
arcpy.env.workspace = 'Geodatabase_Path'  # Replace with your actual geodatabase path

# Define feature class
feature_class = 'mob'

# List all fields
all_fields = [f.name for f in arcpy.ListFields(feature_class)]
fields = [f for f in all_fields if arcpy.ListFields(feature_class, f)[0].type not in ['Geometry', 'Date']]

# Include geometry field to extract coordinates
fields_with_geometry = fields + ['SHAPE@XY']

# Include datetime fields separately for conversion
datetime_fields = [f.name for f in arcpy.ListFields(feature_class) if f.type == 'Date']

# Function to convert datetime fields to string
def convert_datetime_to_string(array, datetime_fields):
    for field in datetime_fields:
        array[field] = array[field].astype(str)
    return array

try:
    # Create NumPy array including geometry and datetime fields
    nparr = arcpy.da.FeatureClassToNumPyArray(feature_class, fields_with_geometry + datetime_fields, null_value=-9)
    
    # Convert datetime fields to strings
    nparr = convert_datetime_to_string(nparr, datetime_fields)
    
    # Add geometry as separate columns
    nparr_with_geometry = np.array(
        [(item.tolist() + list(coord)) for item, coord in zip(nparr, nparr['SHAPE@XY'])],
        dtype=[(name, nparr.dtype[name]) for name in nparr.dtype.names if name != 'SHAPE@XY'] + [('X', float), ('Y', float)]
    )
    
    # Save to CSV
    np.savetxt('H:\\mobcsv2_combined.csv', nparr_with_geometry, delimiter=",", fmt="%s")
    print("Array with geometry and dates saved successfully.")
except Exception as e:
    print(f"Error: {e}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2024 14:29:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-feature-to-csv-in-arcmap/m-p/1513628#M71180</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-08-01T14:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: export feature to csv in arcmap</title>
      <link>https://community.esri.com/t5/python-questions/export-feature-to-csv-in-arcmap/m-p/1513688#M71181</link>
      <description>&lt;P&gt;thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3265"&gt;@TonyAlmeida&lt;/a&gt;&amp;nbsp;really appreciate the time, i tried it but get the same error about the datetime, i did remove the geometry and got the same also&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="StuartMoore_0-1722526648367.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/111362i8981D1BA330A4A92/image-size/medium?v=v2&amp;amp;px=400" role="button" title="StuartMoore_0-1722526648367.png" alt="StuartMoore_0-1722526648367.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2024 15:38:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-feature-to-csv-in-arcmap/m-p/1513688#M71181</guid>
      <dc:creator>StuartMoore</dc:creator>
      <dc:date>2024-08-01T15:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: export feature to csv in arcmap</title>
      <link>https://community.esri.com/t5/python-questions/export-feature-to-csv-in-arcmap/m-p/1513741#M71184</link>
      <description>&lt;P&gt;It's hard to determine the issue, if we don' t see the entire code. Also what print out when the code got to lines 13 &amp;amp; 14 of the first code? I am guessing it's not finding the Date field, is the name of the actual field called "Date"?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2024 16:28:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-feature-to-csv-in-arcmap/m-p/1513741#M71184</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-08-01T16:28:09Z</dc:date>
    </item>
    <item>
      <title>Re: export feature to csv in arcmap</title>
      <link>https://community.esri.com/t5/python-questions/export-feature-to-csv-in-arcmap/m-p/1514148#M71196</link>
      <description>&lt;P&gt;thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3265"&gt;@TonyAlmeida&lt;/a&gt;&amp;nbsp;the first code does print all the field names and the next only the fields that are not geomentry or date but when it tried to export i get this error:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="StuartMoore_0-1722603302532.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/111450i7CD3C11191D702BD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="StuartMoore_0-1722603302532.png" alt="StuartMoore_0-1722603302532.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;when trying to run the second piece of code in steps i get this error with the code, but the&amp;nbsp;print(datetime_fields) does return the 5 date fields&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;nparr = arcpy.da.FeatureClassToNumPyArray(feature_class, fields_with_geometry + datetime_fields, null_value=-9)&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="StuartMoore_1-1722603433502.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/111451i0086EEF9E73F6F55/image-size/medium?v=v2&amp;amp;px=400" role="button" title="StuartMoore_1-1722603433502.png" alt="StuartMoore_1-1722603433502.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2024 12:58:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-feature-to-csv-in-arcmap/m-p/1514148#M71196</guid>
      <dc:creator>StuartMoore</dc:creator>
      <dc:date>2024-08-02T12:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: export feature to csv in arcmap</title>
      <link>https://community.esri.com/t5/python-questions/export-feature-to-csv-in-arcmap/m-p/1514465#M71200</link>
      <description>&lt;P&gt;The array memory error typically occurs when the script tries to create an array that's too large for the available memory, how big is the data?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy
import numpy as np

# Set workspace
arcpy.env.workspace = 'Geodatabase_Path'  # Replace with your actual geodatabase path

# Define feature class
feature_class = 'mob'

# List all fields
all_fields = [f.name for f in arcpy.ListFields(feature_class)]
fields = [f for f in all_fields if arcpy.ListFields(feature_class, f)[0].type not in ['Geometry', 'Date']]

# Include geometry field to extract coordinates
geometry_field = 'SHAPE@XY'

# Include datetime fields separately for conversion
datetime_fields = [f.name for f in arcpy.ListFields(feature_class) if f.type == 'Date']

# Function to convert datetime fields to string
def convert_datetime_to_string(datetime_values):
    return [val.strftime('%Y-%m-%d %H:%M:%S') if val else '' for val in datetime_values]

# Extract non-geometry and non-datetime fields
try:
    # Create NumPy array for non-geometry, non-datetime fields
    nparr = arcpy.da.FeatureClassToNumPyArray(feature_class, fields, null_value=-9)

    # Convert datetime fields to strings using a cursor
    datetime_data = []
    with arcpy.da.SearchCursor(feature_class, datetime_fields) as cursor:
        for row in cursor:
            datetime_data.append(row)
    
    datetime_data = np.array(convert_datetime_to_string([row[0] for row in datetime_data]), dtype=str)
    
    # Extract geometry
    geometry_data = []
    with arcpy.da.SearchCursor(feature_class, [geometry_field]) as cursor:
        for row in cursor:
            geometry_data.append(row[0])
    
    # Add geometry as separate columns
    nparr_with_geometry = np.array(
        [(item.tolist() + list(coord)) for item, coord in zip(nparr, geometry_data)],
        dtype=[(name, nparr.dtype[name]) for name in nparr.dtype.names] + [('X', float), ('Y', float)]
    )
    
    # Combine datetime data
    datetime_array = np.array(datetime_data.tolist(), dtype=str)
    
    # Create final array including datetime fields
    final_dtype = [(name, nparr_with_geometry.dtype[name]) for name in nparr_with_geometry.dtype.names] + \
                  [(f'DATE_{i}', str) for i in range(len(datetime_fields))]
    
    final_array = np.array(
        [(list(nparr_with_geometry[i]) + list(datetime_array[i])) for i in range(len(nparr_with_geometry))],
        dtype=final_dtype
    )
    
    # Save to CSV
    np.savetxt('H:\\mobcsv2_combined.csv', final_array, delimiter=",", fmt="%s", header=",".join(final_array.dtype.names), comments='')
    print("Array with geometry and dates saved successfully.")
except Exception as e:
    print(f"Error: {e}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2024 22:34:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-feature-to-csv-in-arcmap/m-p/1514465#M71200</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-08-02T22:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: export feature to csv in arcmap</title>
      <link>https://community.esri.com/t5/python-questions/export-feature-to-csv-in-arcmap/m-p/1516068#M71220</link>
      <description>&lt;P&gt;thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3265"&gt;@TonyAlmeida&lt;/a&gt;&amp;nbsp;i got the same error at the same point unfortunately, in terms of data there are around 350000 records and 95 fields.&lt;/P&gt;&lt;P&gt;i think i'm going to use a search cursor and just write it out as a csv file&lt;/P&gt;&lt;P&gt;thanks for the help&lt;/P&gt;&lt;P&gt;Stu&lt;/P&gt;</description>
      <pubDate>Wed, 07 Aug 2024 13:32:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-feature-to-csv-in-arcmap/m-p/1516068#M71220</guid>
      <dc:creator>StuartMoore</dc:creator>
      <dc:date>2024-08-07T13:32:45Z</dc:date>
    </item>
  </channel>
</rss>

