See the top rated post in this thread. Click here

Page 1 of 6 12345 ... LastLast
Results 1 to 10 of 54

Thread: Length of polylines within an area

  1. #1
    AUGI Addict .T.'s Avatar
    Join Date
    2000-12
    Location
    Lost
    Posts
    1,473
    Login to Give a bone
    1

    Question Length of polylines within an area

    I want to write a routine that will save a lot of time, but I’m not sure how to do one of the tasks.



    Some background:

    As part of the requirements for getting a plat approved here, we must submit slope calculations based on a formula listed in the Municipal Code that gives the average slope of the lot.



    The formula is S = (I x Lx 0.0023) / A

    Where:

    I is the contour interval of the contours being used (usually 2’, but varies)

    L is the length of the contours contained in the parcel

    0.0023 is a given factor

    A is the area of the parcel in acres



    In a drawing, we have the contours (usually as polylines at the correct elevation, I sacrifice {explode} the contour objects in a separate drawing specifically for doing this), and line work that represents the parcels, which are closed polylines themselves.



    The task I am having trouble wrapping my head around is finding the length of the portions of the contours enclosed in the lot.



    What I do now is use the parcel boundary to trim the contours to the boundary, and then I use a routine that returns the total length of the polylines selected, and then I plug that into the formula in a spread sheet or on my calculator, then undo back through the trim and go to the next parcel.



    What I want to do is:

    1. Select the index contour; extract the layer info
    2. Select the minor contour, extract the layer info
    3. Use the layer info and entity type to filter the contours to a selection set.
    4. Get the contour interval (I) (or, maybe get it from the contours themselves)
    5. Go into a while loop to:
    6. Select a closed polyline that reflects the parcel.
    7. Extract the area (A) of the parcel and convert to acres
    All of this I am capable of.


    8. Now the tricky part (at least for me):


    Once the parcel polyline is selected, I need to return the length of the potions of the polylines (contours) that are inside the parcel.



    Given that the parcel and contours are at different elevations, and that the contour polylines run through the parcel (sometimes more than once; some are totally within the parcel; some run in and out and back in and back out {you get the picture}). I am not sure how to even start writing something that will return the length of the potion of a polyline that falls within the given area, ignoring the length that is outside.



    Once that it accomplished, the rest is easy.



    Has anyone else accomplished this? Is there a way? Where should I start?

    Any help would be greatly appreciated,

  2. #2
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: Length of polylines within an area

    I'd use the Express Tools "Copy Objects to New Layer" and "Cookie Cuter Trim" to copy the contours to a work layer and then trim them outside the boundary. This routine by Peter Jamtgaard will give you the lengths:
    Code:
    (defun C:PLLEN (/ CNT ENAM LEN OBJCURVE)
     (setq SSET (ssget (list (cons 0 "*")))
    	   LEN   0
    	   FT2   0
    	   CNT   0
     )
     (repeat (sslength SSET)
       (progn
    	 (setq
    	   ENAM (ssname SSET CNT)
    		CNT   (1+ CNT)		  
    	 OBJCURVE (vlax-ename->vla-object ENAM)
    		FT2   (+ FT2 (vlax-curve-getArea OBJCURVE))
    		LEN   (+ LEN
    				  (vlax-curve-getDistAtParam OBJCURVE 
    					   (vlax-curve-getEndParam OBJCURVE)
    				  )
    			   )
    	 )
       )
     )
     (princ "Area = ")
     (princ FT2)
     (princ " ft², ")
     (princ (/ FT2 9))
     (princ " yds² or ")
     (princ (/ FT2 43560))
     (princ " Acres  ")
     (princ "Total Length = ")
     (princ LEN)
     (princ " ft.")
     (prin1)
    )

  3. #3
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    2

    Default Re: Length of polylines within an area

    There are several vlax-curve functions that can help you do this.

    vlax-curve-getdistatpoint used in conjunction the points returned using the intersectwith method of the boundary polyline object with the contour polyline object could determine the length of each contour between the boundaries.

    The area property of the boundary would be A

    The elevation property of each contour could be the means to determine I.

    Peter

  4. #4
    AUGI Addict .T.'s Avatar
    Join Date
    2000-12
    Location
    Lost
    Posts
    1,473
    Login to Give a bone
    0

    Default Re: Length of polylines within an area

    Thanks Tom and Peter,

    I think vla-intersectwith was the key that I was missing. It's really nice that it returns all of the intersection points.

    The biggest time saver I see will be not having to trim anything; just have the routine "measure" the portions that are inside the parcel.

    This will get me started, and I found a routine (thanks to another post that referenced another post...) that I can use to test if a point is inside or outside of the boundary. I'll probably have more questions though.

    Now where did I put that information on variants? ~searches through file cabinet~

    So much to learn and so little time

    Thank you both very much,

  5. #5
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    1

    Default Re: Length of polylines within an area

    It might be helpful to use the IntersectWith method like this.
    (vlax-invoke Obj1 'IntersectWith Obj2 acExtendNone)

    This will return a list of points instead of the variant.

  6. #6
    AUGI Addict .T.'s Avatar
    Join Date
    2000-12
    Location
    Lost
    Posts
    1,473
    Login to Give a bone
    0

    Default Re: Length of polylines within an area

    Thanks, Tim.

    That was a little easier/cleaner. I'm getting closer...I just have some logic woes to ponder.

  7. #7
    AUGI Addict .T.'s Avatar
    Join Date
    2000-12
    Location
    Lost
    Posts
    1,473
    Login to Give a bone
    0

    Default Re: Length of polylines within an area

    OK, time for one of those questions I promised; I'm almost bald:

    I'm using, as Tim suggested,
    Code:
     
    (vlax-invoke Obj1 'IntersectWith Obj2 acExtendNone)
    to get the intersections points of a contour with the boundary, which (with a little processing) returns the points just fine when the contour just passes in and out of the boundary once.

    But, I found, when the contour passes in and out of the boundary more than once (which contours have a habit of doing sometimes) that the points aren't following any specific path/order when they are returned. This makes it very difficult (if not impossible) to calculate the distance that is inside the boundary (at least using vlax-curve-getdistatpoint). Is there a way to sort the point elements so they follow the contour line instead of in a random order? Is there another function that will do this?


    TIA

  8. #8
    AUGI Addict .T.'s Avatar
    Join Date
    2000-12
    Location
    Lost
    Posts
    1,473
    Login to Give a bone
    0

    Default Re: Length of polylines within an area

    Shoot, I just had an epiphany : What if I sort the distances -shortest to longest- instead of the points...

    Let's see: the abs of the difference of the first two shortest + the abs of the difference of the third and fourth...

    Do you think it'll work? I'll try it tomorrow. My head hurts too much right now.
    ~reaches for asprin~

  9. #9
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    2

    Default Re: Length of polylines within an area

    Maybe something like this to test the objects that cross in & out.
    A separate test to determine if they were all in would be needed.
    < not tested, sub-functions not included >
    Code:
    (defun c:test ()
      (setq border (car (entsel "\nSelect the border."))
            pline  (car (entsel "\nSelect the conture line."))
      )
      (setq oborder (vlax-ename->vla-object border)
            opline  (vlax-ename->vla-object pline)
      )
      (setq ilst  (vlax-invoke oborder 'intersectwith opline acextendnone)
            ilst  (@cv_triple_up ilst) ; convert list to list of triples
            strpt (vlax-curve-getstartpoint opline)
            endpt (vlax-curve-getendpoint opline)
            len   0
      )
      ;;  make alist with distance
      (setq ilst (mapcar '(lambda (x) (cons x (vlax-curve-getdistatpoint opline x))) ilst))
      (setq ilst (vl-sort ilst '(lambda (e1 e2) (< (cdr e1) (cdr e2)))))
      (setq in_out (@cv_inside strpt oborder nil)) ; true if inside
      (setq lastpt strpt)
      (foreach pt ilst
        (if in_out ; t if inside
          (setq len (+ len
                       (- (vlax-curve-getdistatpoint opline (car pt))
                          (vlax-curve-getdistatpoint opline lastpt)
                       )
                    )
          )
        )
        (setq lastpt (car pt)
              in_out (not in_out)
        )
      )
      len
    )

  10. #10
    AUGI Addict .T.'s Avatar
    Join Date
    2000-12
    Location
    Lost
    Posts
    1,473
    Login to Give a bone
    0

    Default Re: Length of polylines within an area

    Thanks, Cab.

    It works wonderfuly. Now I have to disect it to figure out what you did and why.


    Thanks again,

Page 1 of 6 12345 ... LastLast

Similar Threads

  1. Polylines: total area and length
    By Wish List System in forum AutoCAD Wish List
    Replies: 6
    Last Post: 2015-05-24, 10:44 AM
  2. Total Length of Polylines
    By vijaybaskergundla in forum AutoLISP
    Replies: 7
    Last Post: 2015-04-30, 04:29 PM
  3. Polylines: total area and length
    By Wish List System in forum AutoCAD Wish List
    Replies: 1
    Last Post: 2014-01-29, 05:16 AM
  4. Polylines and Total Length
    By revit.wishlist1942 in forum Revit Architecture - Wish List
    Replies: 3
    Last Post: 2012-06-13, 08:10 PM
  5. LENGTH and area of many polylines
    By marijan.marsic in forum AutoLISP
    Replies: 16
    Last Post: 2008-12-02, 08:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •