0

I have created some code to perform a a one to many spatial keeping all rows, I would like to export the resulting shapefile to CSV as that is the required format for the program the the data will be used in?

Spatial Join code:

import arcpy
from arcpy import env

env.workspace = r"U:\GIO\Geospatial_Services\ANALYTICS\Tools\Parliamentary"
env.overwrite = True

Parcel = r"U:\GIO\Geospatial_Services\ANALYTICS\Tools\Parliamentary\MP_Cut_Many.shp"
int_shp = r"U:\GIO\Geospatial_Services\ANALYTICS\Tools\Parliamentary\MP.shp"

output_speed_fc = r"U:\GIO\Geospatial_Services\ANALYTICS\Tools\Parliamentary\MP_Join_2.shp"

arcpy.SpatialJoin_analysis(Parcel, int_shp, output_speed_fc, join_operation="JOIN_ONE_TO_MANY", join_type="KEEP_COMMON", match_option="INTERSECT")

print 'worked'

The CSV conversions I have tried before haven't worked, got to convert to DBF, I am using Arcgis10.1

1

I have worked it out I have added this to it

arcpy.ImportToolbox("U:\GIO\Geospatial_Services\ANALYTICS\Tools\Table To Excel Tool\Table To Excel Tool.tbx")

arcpy.TableToExcel_xls("U:\GIO\Geospatial_Services\ANALYTICS\Tools\Parliamentary\MP_Join_4.shp","CSV_MPJOIN", "CSV")

The toolbox imported is a downloaded Table to excel toolbox which I found on our system which I just imported into arcpy and used that tool

http://www.arcgis.com/home/item.html?id=cbb7b0ea4c014dd8bc2832f9be1e2d03

0

You could use the Export Feature Attributes to ASCII which is in the Spatial Statistics > Utilities toolbox.

You can choose your delimiter (space, comma, tab), choose the fields you want to export and specify if you want to export your field names to the CSV file.

To use in your script:

arcpy.ExportXYv_stats(output_speed_fc, "select the fields", "COMMA", "output_speed.txt" ,"ADD_FIELD_NAMES")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.