MapInfo Pro Developers User Group

 View Only
  • 1.  MapBasic Delete Selection

    Posted 20 days ago

    This seems like a basic concept that I am totally stumped on. I simply want to programmatically delete objects highlighted after running a selection by location. 

    The query I am using:   

     mb_command = f'Select * From "{tabName}", "{plyName}" Where {tabName}.obj Entirely Within {plyName}.obj'    
     do(mb_command)

    .. and then delete the features selected. Select by location is best for my use since it allows for 'Intersects' and 'Within' conditions as well. A target erase is potentially an option but not ideal. Any simple Delete operation is encountering errors and this appears to require a multi-step process I cannot wrap my head around, whether it involves iterating RowID's, temporary tables, or views. Trying to execute a complex Delete operation using a Where clause also seems to have its limitations, not allowing for the spatial operation.



    ------------------------------
    Brandon Shepherd
    Knowledge Community Shared Account
    Shelton CT
    ------------------------------


  • 2.  RE: MapBasic Delete Selection

    Posted 19 days ago

    Hi Brandon,

    You might be finding that you can't delete from a view?  You might have to change your query to use the syntax:

    Select * From tabName Where obj Entirely Within Any (Select obj From plyName

    If that's too slow, stick with your original join but then carry out an Update that flags the records you want to delete from tabName.  Once these are flagged, you can perform a second Select that returns the flagged records in tabName.  You should then have no problem deleting them.

    Example:

    Select * From tabName Where obj Entirely Within Any (Select obj From plyName) Into updView

    Update updView Set flag = "D"

    Select * From tabName Where updView = "D" Into delTab

    Delete From delTab



    ------------------------------
    James Nolet
    GIS Manager
    CAF Consulting
    Melbourne office, VIC, Australia
    ------------------------------



  • 3.  RE: MapBasic Delete Selection

    Posted 19 days ago
    Edited by Brandon Shepherd 19 days ago

    Thank you, 

    The initial alteration to the query did the trick.

    I was encountering the Cannot Delete from View error previously. There are hundreds of thousands of records across hundreds of tables so refraining from any column updates is best. This is now working perfectly. 



    ------------------------------
    Brandon Shepherd
    Knowledge Community Shared Account
    Shelton CT
    ------------------------------