Author Topic: Poly in poly?  (Read 2413 times)

0 Members and 1 Guest are viewing this topic.

mohobrien

  • Guest
Poly in poly?
« on: June 15, 2005, 12:45:44 PM »
I've been using a simple routine to check if I have a polygon inside another polygon. Just lately, I've noticed that it has been falling down on the job. This is a stripped down version with some extraneous stuff left in that I use. Is there a problem with ssget with "wp" or am I doing something wrong.
Code: [Select]
(defun c:polyinside (/)
  (setq entity (car (entsel "\nPick a polygon to check: ")))
  (setq wp (LWPolylineInfo entity))
  (if (equal (car wp) (last wp))
;make sure first vertex = last vertex
    (setq closedwp wp)
    (setq closedwp (append wp (list (car wp))))
  )

  (setq ;check to see if there are any inner rings
    innerss (ssget
     "wp"
     closedwp
     (list (cons 0 "LWPOLYLINE"))
   )
  )
  (if innerss
    (princ "Yes")
    (princ "No")
  )
)
;; most of this routine courtesy of Rakesh Rao at 4dTechnologies
(defun LWPolylineInfo (ename /   wp     entitylist
      len n   e1    
      windowpolygon   coords    xcoord
      ycoord
     )
  (setq
    entitylist (entget ename) ;get the entity list
    len       (length entitylist) ;get the length of the list
    n       0 ;set counter to zero
  )
  (repeat len ;repeat for the length of the entity list
    (setq e1 (car (nth n entitylist))) ;get each item in the entity list
;and strip the entity code number
    (if (= e1 10) ;check for code 10 (vertex)
      (progn ;if it's group 10 do the following
(setq coords (cdr (nth n entitylist)))
;get the vertex (a list)
(setq windowpolygon (append windowpolygon coords))
(setq xcoord (car coords)) ;get the xcoord
(setq ycoord (cadr coords)) ;get the y coord
      ) ;progn
    ) ;if
    (setq n (1+ n)) ;increment the counter to get next polyline
  ) ;repeat
  (setq wp (xyList->ListOfPoints windowpolygon))

))

It works with some polygons but not others.
http://www.theswamp.org/lilly_pond/mohobrien/north.wmf?nossi=1
The polygons on the left find the interior polygons, the one on the right does not.

mohobrien

  • Guest
Poly in poly?
« Reply #1 on: June 15, 2005, 06:00:57 PM »
Found the cause in case any body else has the same problem. The polygon that the routine didn't work on had a double vertex. Once that was removed it found the inner polygon. Anyone know why that would be the case?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Poly in poly?
« Reply #2 on: June 15, 2005, 07:12:04 PM »
What is a double vertex?
Are you talking about two vertex at the same point?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

mohobrien

  • Guest
Poly in poly?
« Reply #3 on: June 15, 2005, 09:16:43 PM »
yes

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Poly in poly?
« Reply #4 on: June 15, 2005, 09:55:46 PM »
I am cofused by your  LWPolylineInfo routine.
You did not post the xyList->ListOfPoints routine.
Why are you getting the xcoord & ycoord ?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

mohobrien

  • Guest
Poly in poly?
« Reply #5 on: June 15, 2005, 10:08:01 PM »
The routine I posted was part of a larger routine I use to convert some of my polygon layers to esri shape files. I just stripped out parts to make the small routine I posted. I didn't clean it up much and so that's where the unused functions come from. I posted the whole routine once. I can't remember if it was here or cadvault but never had any interest or feedback so didn't want to clutter up the postings. If anybody wants it I'll post it.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Poly in poly?
« Reply #6 on: June 15, 2005, 10:21:13 PM »
If you are simply getting a point list this will do it.
Code: [Select]
(setq pline (car (entsel)))
(setq ent (entget pline))
(setq coords (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 10 (car x))) ent)))


This would not take bulges into account.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

mohobrien

  • Guest
Poly in poly?
« Reply #7 on: June 15, 2005, 10:33:26 PM »
I like it. I don't do any programming very often but once in a while I have a need and basically crib what I can from all sources available. I'll post the whole routine tomorrow via a link to the lilly pad. Actually while the routine I used is a little cumbersome for just the coordinate list, there are a few other items I need from the the assoc lists (don't know the proper name to call them) that I grab at the same time. Perhaps grabbing the info the way you suggest may be cleaner.
 The more I look at your suggestion the cleaner it looks. I think a rewrite is due.

mohobrien

  • Guest
Poly in poly?
« Reply #8 on: June 16, 2005, 10:12:58 AM »
http://www.theswamp.org/lilly_pond/mohobrien/esriout.LSP?nossi=1
http://www.theswamp.org/lilly_pond/mohobrien/esriout.dcl?nossi=1
http://www.theswamp.org/lilly_pond/mohobrien/WriteShp.dvb?nossi=1

The routine is for converting polygons, some with holes, some with islands into esri shape files. The dbf gets its data from attached object data. I tried to write the whole routine in lisp but couldn't get past the need to write to a binary file. Thats why I use the WriteShp routine.
Please tear it to shreds and give more suggestions for improvement.

I guess I should have given a test data set.
http://www.theswamp.org/lilly_pond/mohobrien/Testdata.dwg?nossi=1
Is object data as I'm using it available in vanilla cad or is it only in map? Maybe this should be in the geographicaly afflicted forum. :)