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 am writing a program that finds overlapping objects. I can't perform the AreaOverlap() function on objects that don't enclose an area (e.g. text, points) as the result would be meaningless.

Is there a way to select only records that have objects that are regions?

I have a function that checks whether an object is a region (see below) so I could loop through the objects and check them one-by-one but it would be more efficient to do this as part of a select statement.

My example function:

Function IsObjectRegion(ObjAlias As Object) As Logical
  Do Case ObjectInfo(ObjAlias, OBJ_INFO_TYPE)
    Case OBJ_TYPE_REGION, 
         OBJ_TYPE_RECT, 
         OBJ_TYPE_ROUNDRECT, 
         OBJ_TYPE_ELLIPSE
      IsObjectRegion = True
    Case Else
      IsObjectRegion = False
  End Case
End Function

Update: my final, working code using Peter's method and my function:

Include "mapbasic.def"

Declare Sub main
Declare Function IsObjectRegion(ByVal ObjAlias As Object) As Logical

Function IsObjectRegion(ByVal ObjAlias As Object) As Logical
  Do Case ObjectInfo(ObjAlias, OBJ_INFO_TYPE)
    Case OBJ_TYPE_REGION, 
         OBJ_TYPE_RECT, 
         OBJ_TYPE_ROUNDRECT, 
         OBJ_TYPE_ELLIPSE
      IsObjectRegion = True
    Case Else
      IsObjectRegion = False
  End Case
End Function

Sub Main
  Select * from TargetTable Where obj into temp1 noselect
  Select * from temp where IsObjectRegion(OBJ) into results noselect
  Browse * from results
  Close table temp
End Sub
share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

You could create you function like you have described above and use this directly in your Select statement:

Select * From MYTABLE
   Where IsObjectRegion(OBJ)
   Into __THESE__HAVE__AN__AREA NoSelect

Pretty clever

share|improve this answer
    
Hmm that sounds perfect but it's telling me "Subroutine argument OBJ not defined." and "Unrecognized command: INTO". I'm using this code: gist.github.com/1510947 –  Mr_Chimp Dec 22 '11 at 16:45
    
Time for me to go home now. I'll have another look at it in the new year. Merry Christmas and thanks for all your help! –  Mr_Chimp Dec 22 '11 at 17:29
    
Just noticed that you are missing a ByVal in front of your parameter: Function IsObjectRegion(ByVal ObjAlias As Object) As Logical –  Peter Horsbøll Møller Jan 9 '12 at 8:13
    
I've updated the code in my link above. I'm getting an error on line 8 "Cannot use an uninitialized object variable in an expression". I assume this means it's not passing in the value properly? –  Mr_Chimp Jan 9 '12 at 9:49
    
Do you get the error when you run the app? If yes, I think you might have some records without an spatial object. You can find these with this statement: Select * from MYTABLE Where not OBJ –  Peter Horsbøll Møller Jan 10 '12 at 18:52
show 1 more comment

A simple approach would be as follows:

select *
from MYTABLE
where str$(obj) IN ("Region","Rectangle","Ellipse","Rounded Rectangle")
into q_RegionObjects
share|improve this answer
add comment

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.