Select to view content in your preferred language

Select features by bounding rectangle in Python

2834
4
07-30-2010 11:22 AM
CraigMalkmes
Deactivated User
Howdy,

I'm currently attempting to 'tile' a line shapefile (a river & stream layer) by selecting the line features which are contained within bounding rectangles. These bounding rectangles comprise a fishnet which has been converted to a polygon shapefile. The fishnet's attribute table is populated by values for the upper left and bottom right geographic coordinates of each individual bounding rectangle. The fishnet is 60x60, therefore the output should be 3600 individual line shapefiles. Unfortunately, I only have the single, giant 60x60 fishnet. Even if I decided to make small extent rectangles to do the query, I would need 3600 of them...

I need to write a Python script which will accomplish this task, and was considering gp.selectlayerbyattribute or gp.selectlayerbylocation. I could also use gp.searchcursor to grab the coordinates of each rectangle. However, I'm not quite sure how to select features from one layer based upon the attributes or location of another layer using Python (nor do I think that such a query would work for my project). I also do not know how I would use the coordinate output of gp.searchcursor for a spatial query in Python. Hope this all makes sense.

It would be easy to loop this 3600 times if I knew how to go about selecting the features. I'll eventually have to convert the 3600 .shp files to .lyr, and then do a Layer to KML in Python..... but that requires no more than 10 lines of code, which I already have.

Any suggestions?

Much appreciated,
Craig
0 Kudos
4 Replies
JeffLee
Deactivated User
Why don't you do a line on polygon intersect?  it would be a lot quicker.  then you could use Dan Patterson's split layer by attribute script @ http://arcscripts.esri.com/details.asp?dbid=14127 to export to individual shapefiles.  if you really want to code, take a look here http://forums.esri.com/Thread.asp?c=93&f=1729&t=297920&mc=5#msgid930410

this should get you started.

Cheers
0 Kudos
ChrisSnyder
Honored Contributor
Probably the most efficient method would be to figure out what tile contained each line features centroid. That way you didn't have to break any of the line feature into two or more pieces.

Use the FeaturetoPoint or FeatureVerticesToPoint tools and then the intersect or identity tools to identify what tile each point resides in.
0 Kudos
DanLee
by Esri Regular Contributor
Esri Regular Contributor
Have you looked at the Split tool in Analysis toolbox - Extract toolset? It splits input features into multiple output feature classes by specified polygon features, taking the values of a text field of the polygons as the output file names, providing the text values are unquie. You just need to have a text field in your fishnet feature class with a unique string for each polygon. Does this tool do what you wanted?

Thanks.
0 Kudos
DanPatterson_Retired
MVP Emeritus
0 Kudos