1

How can i script for intersecting the two shape files from two different folders based on their names?

i have two folders which contains the shape files with same name i want to intersect the shapefiles based on their name, scripting should pick the files based on their name from two different folders and output file should store in another folder.

I'm using ArcGIS Desktop 9.3 and arcgisscripting (that preceded ArcPy).

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Sep 3, 2014 at 5:24
0

1 Answer 1

4

From my collection of ArcGis 9.3 python scripts:

import arcgisscripting
gp = arcgisscripting.create(9.3)
Shape_A = "c:\\some\\path\\to\\shapefile.shp"
Shape_B = "c:\\some\\other\\path\\other_shapefile.shp"
Intersection = "c:\\output\\path\\output.shp"
gp.Intersect_analysis(Shape_A + ";" + Shape_B,Intersection,"ALL","#","INPUT")

You will need to change the paths to match your data - remember python uses the escape backslash \\ for a backslash or you can use the unix/linux forward slash in single eg. "c:/some/path/to/shapefile.shp".

Using a version 9.3 geoprocessor gp you append the feature class names (full path) with a semi-colon in between see Intersect_analysis - also for the explanation of the parameters "ALL","#","INPUT".

If you want to do a folder full of feature classes matching up to another folder you can do it like this:

import sys,arcgisscripting
gp = arcgisscripting.create(9.3)
InFolder = sys.argv[1]
MatchFolder = sys.argv[2]
OutFolder = sys.argv[3]
gp.workspace = InFolder # set the workspace
FeatureClasses = gp.ListFeatureClasses() # get a list of feature classes
# step through the feature classes
for FC in FeatureClasses:
 MatchFC = MatchFolder + "\\" + FC
 # if the same name is in the match folder
 if gp.Exists(MatchFC):
 InterFC = OutFolder + "\\" + FC
 # perform the intersection
 gp.Intersect_analysis( FC + ";" + MatchFC,InterFC,"ALL","#","INPUT")

The sys.argv match up with the tool parameters (read Adding a Script Tool)

answered Sep 3, 2014 at 5:39
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.