0

I have imported North American wildfire incident data a comma delimited text file containing one line for each fire incident. Each fire incident has a latitude, longitude coordinate pair separated by commas along with a confidence value.

My first task was to create a shapefile, and make the data usable to import into the attribute table of the shapefile I created called Incidents.

My new task is to repeat this process in a new shapefile within my MDB. The shapefile is called NewFires by user input. My issue is that when I run the code a second time, I get the error:

Traceback (most recent call last): File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver_sandbox.py", line 29, in
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\arcpy\arcpy\management.py", line 1807, in CreateFeatureclass raise e arcgisscripting.ExecuteError: ERROR 000354: The name contains invalid characters Failed to execute (CreateFeatureclass).

My second shapefile starts with 'if 'Confidence' in fire:'

import arcpy

work = raw_input("Enter the full path of WildlandFires.mdb: ") # C:\Scripts\Lab 7 Data\WildlandFires.mdb
arcpy.env.workspace = work # Set the workspace to the geodatabase
arcpy.env.overwriteOutput = True

iFile = raw_input("Enter the full path of wildfire text file: ")# input text file C:\Scripts\Lab 7 Data\NorthAmericaWildfires_2007275.txt  
output = raw_input("Enter the name of the output feature class: ")

f = open(iFile, 'r')# input text file C:\Scripts\Lab 7 Data\NorthAmericaWildfires_2007275.txt in "read" mode

lstFires = f.readlines() # Read the lines of fire data from the input file
f.close() # close the file 

fields = ["SHAPE@", "CONFIDENCE"] # represents the field names for each row in the feature class

# Process: Create Feature Class
arcpy.CreateFeatureclass_management(work, "Incidents.shp", "POINT", "C:\\Scripts\\Lab 7 Data\\WildlandFires.mdb\\FireIncidents")

cursor = arcpy.da.InsertCursor("Incidents.shp", fields) # add the new points that you will create to the "FireIncidents" feature class

cntr = 0 # counter variable

for fire in lstFires:
        if 'Latitude' in fire: # Skip the header
            continue
        pnt = arcpy.Point() # Create a new Point object
        lstValues = fire.split(',') # create a list of values "lstValues" based on the type of delimiter
        str_int = lstValues [-3:]       
        str_int = list(map(float, str_int)) #turns string to integers
        latitude = str_int[0] # Latitude
        longitude = str_int[1] # Longitude
        confid = str_int[2] # Confidence Value 

        pnt.X = longitude # Assign the X and Y properties of the Point object
        pnt.Y = latitude 

       if 'Confidence' in fire:  # Skip the header
            continue
        output = arcpy.Point() # Create a new Point Object
        arcpy.CreateFeatureclass_management(work, "NewFires", "POINT", "'C:\\Scripts\\Lab 7 Data\\Incidents.shp'")
        arcpy.AddField_management(NewFires_shp, "CONFIVALUE", "FLOAT")
        field = ["SHAPE@", "CONFIDENCE"] # represents the field names for each row in the feature class       
        row = [pnt, confid] # Create a new row for the feature class        
        cursor.insertRow(row) # Insert the new row to the feature class

        cntr = cntr + 1 # update the counter
        print "Record # " + str(cntr) + " written to feature class"  

del cursor # release the cursor lock on the feature class  
4
  • 2
    An mdb is a geodatabase into which you can import a shapefile as a feature class. You can't create a shapefile within a geodatabase - they are completely different file formats. Lose the '.shp' to create a feature class rather than shapefile.
    – phloem
    Feb 3, 2017 at 19:43
  • @phloem that worked
    – A_Worthy
    Feb 3, 2017 at 20:38
  • @phloem You should put that as an answer
    – Midavalo
    Feb 3, 2017 at 22:20
  • Sure, I just wasn't sure if that was the only problem.
    – phloem
    Feb 3, 2017 at 22:33

1 Answer 1

3

An MDB is a (Personal) Geodatabase into which you can import a Shapefile, as a feature class within a Geodatabase. A Shapefile is a type of feature class that can exist outside of a Geodatabase, but you can't create a Shapefile within a Geodatabase - they are completely different file formats.

Lose the '.shp' to create a Geodatabase feature class, rather than a Shapefile.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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