How to identify lines that are outside a polygon

240
5
a month ago
JoseSanchez
Occasional Contributor III

Hello everyone,

I need to create  a python script that finds all the liens that were digitized outside a grid polygon layer.

 

What geoprocessing tools do you recommend in Model Builder or Python to perform this analysis?

 

Thanks

 

 

0 Kudos
5 Replies
JohannesLindner
Regular Contributor
0 Kudos
RPGIS
by
Regular Contributor

You could use either the tabulate intersection tool, which will tabulate every instance of the coinciding lines that are within a grid polygon layer.

If using python:

  1. Set the script to utilize the tabulate intersection tool
  2. Run the search cursor on the tabulate intersection table to append values to a list
  3. Run another search cursor to identify the ones that are not within that list (list comprehension may work best for this situation if looking to simplify your code)

That would help you identify the ones that are outside of the grid.

If using ModelBuilder:

  1. Similar process but requires using the iterators and if statements.
0 Kudos
DuncanHornby
MVP Frequent Contributor

No code or model is required for this, simply use the select by location tool, have the selection type set to intersect and ensure invert selection is ticked on

0 Kudos
JoseSanchez
Occasional Contributor III

Does the Select By Location identify the lines that start inside a grid (polygon) and finish in a area without any grid (polygon).

 

What about this solution: Use the erase tool to delete all lines inside the grid area (polygon). The remaining lines are the ones that are outside the grid.

0 Kudos
DuncanHornby
MVP Frequent Contributor

This is a different question you are asking and strongly demonstrates why you should always include images in your question so it very clear what you are asking (may be you should go back and edit your question and include an image?).  Your original questions asks:

finds all the lines that were digitized outside a grid polygon layer

Well my simple solution finds all the lines outside the polygons.

You now seem to be asking  to:

find all portions of lines outside the polygons.

This includes whole polylines and parts of a polyline that originated from within the polygons but are outside the polygon.

The erase tool would certainly achieve this, deleting the portions of lines within the polygons but be aware that this is an advance level licensed tool and if you plan to distribute your tool you need to state this in any documentation to stop people with the incorrect license using it.

0 Kudos