Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm looking for a way to determine if a polyline is "mostly within" a polygon. Since mostly within is arbitrary, I would need be able to enter a percentage at its execution.

I thought there might have been an option in ArcMap using Select By Location, but there doesn't seem to be. There are similar methods, such as "completely within" but I don't see how I can use any of them to achieve what I'm looking for.

I'm open to suggestions that use either built in ArcMap functionality or ArcPy.

Does this functionality or a method exist to achieve this?

share|improve this question
    
define 'mostly within'... 75% within? –  mapBaker May 16 at 15:45
    
The is a centroid within option, so that is usually mostly within –  Vesanto May 16 at 15:47
    
@mapBaker Good point about the percentage. Perhaps if using ArcPy this could be a variable that could be adjusted to produce the desired result. –  amasephy May 16 at 15:56
1  
@Vesanto The centroid wouldn't work, if the polyline happened to clip the corner of a polygon the centroid could be inside the polygon but a significant portion of it may not be. –  amasephy May 16 at 15:57
2  
I would do an intersect between the polygon and line FC and then a statistics to determine the % of each line in a certain polygon (or any polygon). From this, then I would do my selection. –  dklassen May 16 at 16:18

3 Answers 3

While I think you could do with refining your question with a bit more detail (how much of the line has to be within to qualify, how do you want to handle lines coincident with polygon edges, etc... I do have a thought on generally how you might be able to approach this problem. Yes, this would be a relatively elaboarate method to accomplish what should be pretty easy to do, but... it should work none-the less. One way would be to build a model or script that would use a GP tool to split all of your line segments at the polygon boundary (I would probably do this with clip tool using a layer with selection applied for the polygon to clip by so it only uses the polygon(s) in question. If you have the output of that tool go to a geodatabase and you have your initial dataset in a geodatabase, then you would just have to do a table to table join on the two line files (original and output of GP tool) and then calculate the percentage difference between the two Shape.Len fields (if a line segment in original file is 100 ft long, and that same line segment, clipped to the polygon, is 75ft long, then 75% of that line would be within the polygon). Then you could just do a select by attribute based on this percent.

Again, I know this is rather involved, it creates an intermediary dataset, and there probably is an easier way to do this that I don't know about; but, if you write a model or script to do such, and delete the output line FC when you're done with it, it shouldn't appear all that difficult to the end user... even if it's a bit of a pain to build initially.

Just some thoughts, and let me know if that doesn't make sense and I'll try and explain better.

share|improve this answer
    
+1 Those sound like pretty good thoughts to me because they make good use of ArcGIS capabilities and, no matter how it's done, there really isn't any way to avoid some form of polygon-vs.polyline overlay operation. (BTW, I think you were the victim of a drive-by downvoter and I apologize for that.) –  whuber May 16 at 16:31
    
@John that is what I was thinking too... BUT - in order to do the join the input lines would need a UNIQUEID field (not the ArcGIS OBJECTID field mind you) that you could do the join on... –  mapBaker May 16 at 17:27
1  
@mapBaker Thank you, that's a good point (I'd forgotten if clip preserved input OID in the output like some tools do). You could calculate the OID out to another field before you run the clip to give you a UniqueID if one's not already available though. –  John May 16 at 17:31
    
@John ohhhh K... –  mapBaker May 16 at 17:46
    
This solution would work for me, but I think dklassen's use of Intersect instead of Clip makes this simpler. I ended up using a combination of the responses I received. I'm not sure who should get credit for answering the question. –  amasephy May 20 at 15:52
up vote 2 down vote accepted

Based on the responses I received here, I used a combination of ideas provided.

First what I did was add a Length and Percent field to my original dataset. I copied the Shape.Length values into the Length field.

Secondly, instead of using Clip, which is significantly more work in this case, I used the Intersect tool. This "clips" the polylines that intersect the polygons and adds in some potentially valuable attributes. Despite having a truly unique ID field, I don't think its really required when using a static length field.

Finally, I just simply calculate the percent of the difference between the new Shape.Length and the static Length field to the Percent field. Any polylines that intersected the polygon boundary will have a percentage less than 100.

Thank you to everyone for the great responses.

share|improve this answer
  1. Split the polyline at each vertex,
  2. for each segment call completely within on the end points,
  3. any segment that is completely within has 100% of its length within the polygon, (assuming no re-entrant polygons), and its length can be added to a total,
  4. any partial lines can be split into say 10 segments and the same calculation applied.
  5. Compare the total with the length calculated to get a resolution of 10%, (if you need more accurate results then you can sub-divide finer on the partial lines).
  6. You could even keep a total of the lengths of the totally outside lines as well and only do the partial line calculation only if you have neither answer past your threshold.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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