Monday, 12 October 2015

Validating whether shapefile exists using ArcPy?


I am very new to Python and am trying to complete my final project with not a lot of success.



My code works without functions, the problem is I need it to work with functions. In the main(): function I want the user to enter an .shp file path. Then I have an isValid(inPath): function that I want to call the file path the user entered and validate if the file exists. I have done this in many assignments before with .csv and .gpx files, but I am not having success with .shp files. When I keep everything under the main function, it works no problem.


Here is my code currently:


**# Import Modules:**
import arcpy
from arcpy import env
from arcpy import mapping
import os.path

**# Set workspace**
env.workspace = #this is where I set my workspace

env.overwriteOutput = True

**# Checks if shapefile is valid**

def isValid(inPath):
if arcpy.Exists(inPath):
print 'Exists'
else:
print ' Does NOT exist'


def main():
shpFile = raw_input("Enter a Map Document path: ") # User inputs a shapefile
shpFile = shpFile.replace("\\","/") #replaces backslashes with forward slashes


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...