+ Reply to Thread
Results 1 to 7 of 7

Thread: Save as Shapefile

  1. #1
    James Smith
    Join Date
    Sep 2011
    Posts
    17
    Points
    0
    Answers Provided
    0


    0

    Default Save as Shapefile

    Hi,

    I'm sure that this is a very simple question, but I can't find the answer unfortunately. I have wrote a short Python script to do some geoprocessing, Network Analysis to be exact, and I want the routes that have been created from this process to be outputted as a Shapefile and saved to my PC - but using Python rather than right clicking and doing 'Data Export'. How do I go about this please? What is the Syntax?

    Thanks

    James

  2. #2
    Claire Parsons
    Join Date
    Jul 2011
    Posts
    27
    Points
    0
    Answers Provided
    0


    0

    Default Re: Save as Shapefile

    Hi James

    Well, I've managed to write the code that will loop through all your layers in the mxd remembering there names 'ListLayers' but I'm flumaxed as to how to export them. The saveas property of Layer exports everything to a layer file rather than a shapefile.

    sorry, I can't be more helpful.

    Claire

  3. #3
    James Smith
    Join Date
    Sep 2011
    Posts
    17
    Points
    0
    Answers Provided
    0


    0

    Default Re: Save as Shapefile

    Quote Originally Posted by parsonz View Post
    Hi James

    Well, I've managed to write the code that will loop through all your layers in the mxd remembering there names 'ListLayers' but I'm flumaxed as to how to export them. The saveas property of Layer exports everything to a layer file rather than a shapefile.

    sorry, I can't be more helpful.

    Claire
    Hey Claire,

    Thanks loads for trying to help. To be honest, maybe I'm asking the wrong question. At the end of using Network Analyst I'm given a 'Route'. If I right click on this, I can view the attribute table of the Route (there is just one row in my example but there could be more if I was using the Closest Facility tool instead). This table has has attributes such as FirstStopID, LastStopID, RouteName etc. What I want to do is to save this table somewhere, so that the next piece of my Python code can access the fields and do some additional processing.

    If anyone can suggest a way forward that would be great please.

    Thanks

    James

  4. #4
    Stacy Rendall
    Join Date
    Jun 2011
    Posts
    321
    Points
    167
    Answers Provided
    16


    0

    Default Re: Save as Shapefile

    Claire, this or the stuff below might help you: arcpy.featureClassToShapefile_conversion()

    James (just working off the top of my head - I think this is correct - will have to check it out tomorrow and get back to you), you can select the Routes simply by adding "\\Routes" to the end of the layer name, i.e.:
    Code:
    arcpy.Solve_na(outNALayer)
    routes = outNALayer + '\\Routes'
    then copy the selected routes to a new shapefile with:
    Code:
    arcpy.Copy_management(routes, "C:\\output\\routesOutput.shp")
    You may also want to look into arcpy.CopyRows_management as you are just interested in the table...
    Use the tools on the right hand side:
    if a reply answers your question
    ^ if a reply contains useful information (even if you didn't ask the original question)


    pythongisandstuff.wordpress.com

  5. #5
    James Smith
    Join Date
    Sep 2011
    Posts
    17
    Points
    0
    Answers Provided
    0


    0

    Default Re: Save as Shapefile

    I'll try this out later today - thank you very much!

  6. #6
    James Smith
    Join Date
    Sep 2011
    Posts
    17
    Points
    0
    Answers Provided
    0


    0

    Default Re: Save as Shapefile

    Hi guys,

    Some feedback...

    - arcpy.featureClassToShapefile_conversion("Sample_Routing\Routes", "E:\\")
    This appears to work, but then says it had a problem naming the output. Which is odd, as this isn't even a parameter in the code.

    - arcpy.CopyFeatures_management("Sample_Routing\Routes", "test")
    I didn't think that this would work, but it does. It makes a shapefile of the Routes and saves them to the default location. Note, there's no need for .shp in the code.

    -arcpy.FeatureClassToFeatureClass_conversion(in_features, out_path, out_name)
    - Although rather strangely named (how is feature to feature a conversion?), this also makes a shapefile as its output.

    So in summary, thanks!

    James

  7. #7
    Stacy Rendall
    Join Date
    Jun 2011
    Posts
    321
    Points
    167
    Answers Provided
    16


    0

    Default Re: Save as Shapefile

    Glad to hear it worked, James!

    Just one thing, I think you need either two back slashes or one forward slash in your paths, i.e.:
    "Sample_Routing\\Routes" or "Sample_Routing/Routes" not "Sample_Routing\Routes"

    Cheers
    Use the tools on the right hand side:
    if a reply answers your question
    ^ if a reply contains useful information (even if you didn't ask the original question)


    pythongisandstuff.wordpress.com

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts