1

Aplogoises if this has already been solved but I'm having problems using the Erase function in ArcGIS. I have had problems using the normal function, as it throws a Error9999 Topology error amongst others. So decided to Python! However having problems with invalid syntax, am I missing something obvious?

import arcpy
from arcpy import env

env.workspace = "K:\Head Offices\Conservation\Conservation Information Team\Systems Support\GIS\ArcGIS\Ancient Trees\Ancient trees\Comparisions\\"
arcpy.Erase_analysis('AncientTreesFullAugust2014 - Copy_font_point.shp','AncientTreesJuly2014TinyPolygon.shp','Aug2014AncientTreesDifferentToJuly2014.shp')

Many Thanks!

  • Hi Mole, I took the liberty of editing your code so it is more easily read. When you use the Erase function in ArcGIS (not the python) what errors were given in the geoprocessing results? – GISKid Aug 15 '14 at 17:19
  • 3
    The most obvious issue is the lack of escape characters in the workspace pathname -- Either use R"K:\Head"... or "K:\\Head"... docs.python.org/release/2.5.2/ref/strings.html – Vince Aug 15 '14 at 17:40
3

I believe what may be wrong with your python code is the double \\ at the end of your env. When writing paths in python you need double \\ or you can simply put an r before the path (see my code for examples)

I would also recommend putting your shapefiles as variables for a cleaner looking code.

import arcpy
from arcpy import env

env.workspace = r"K:\Head Offices\Conservation\Conservation Information Team\
Systems Support\GIS\ArcGIS\Ancient Trees\Ancient trees\Comparisions"

ancientTree = "C:\\yourdir\\ancienttree.shp"
treepoly = r"C:\yourdir\treepoly.shp"
eraseOutput = r"C:\yourdir\saveOutput"
xyTOL = "1 Meters"

arcpy.Erase_analysis(ancientTree,treepoly,eraseOutput,xyTol)
  • Thanks for all the help everyone has given, very helpful, suspected the directory business might be throwing the code. That code looks a lot cleaner and organised so thanks. sorry for being a bit of a novice, just not a lot of experience in Python or coding in general. I'll definitely give it a go when I get into work on Monday and let you know how I get on! Many thanks! – TheMole Aug 16 '14 at 1:33
  • Code executed well, didn't delete any of the points but I suspect that's due to geometry issues though than code so thanks very much for all the help! – TheMole Aug 18 '14 at 10:19

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.