MapInfo Pro

 View Only
Expand all | Collapse all

Distance Calculator taking Orientation in consideration

  • 1.  Distance Calculator taking Orientation in consideration

    Posted 01-07-2025 10:47

    Dears,

    Could you kindly support

    I would like to calculate the nearest distance between Sectors not between Sites

    For example:

    If I have used the Distance calculator tool, it will consider site A the nearest one to site B

    however site B, Sector 1 Orientation is in the direction to Site C

    so Site C should be the nearest to Site B if we take Orientation in consideration

    Any idea, how to do this?



    ------------------------------
    H. H
    Knowledge Community Shared Account
    ------------------------------


  • 2.  RE: Distance Calculator taking Orientation in consideration

    Employee
    Posted 01-08-2025 01:41

    Hey

    The Distance Calculator creates lines between the cells.

    You could create lines between each cell and its x nearest cells, as shown below.

    As a next step, you can delete all the lines that don't intersect a sector belonging to the same cell.
    As a final step, you find the remaining line with the short length.
    A MapBasic tool would be the obvious solution here.
    You could do a spatial query using an extended sector. As shown below, an extended sector (polygon) has been created for Site C Sector 3. You can select all the sectors intersecting this polygon and from these find the nearest.


    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 3.  RE: Distance Calculator taking Orientation in consideration

    Employee
    Posted 01-08-2025 09:25

    I had a closer look to see how this could be done.

    If the use case is to select one sector and then find the nearest x sectors in the direction of this sector - and maybe also taking the direction of the other sector into account, I came up with this possible solution.

    The initial case is a table of sectors. The table has a Cell ID and also a coordinate of the cell tower.

    I'll select the sector I want to find nearby sectors for that also lie in the direction of the sector.

    So I select my sector - the one in the lower right corner of the map.
    And then I run the query. I'll get back to that in a bit.
    As a result, I get, in this example, two sectors selected as you can see in the map below.
    The query I use looks like this:
    Set Coordsys Table Sectors
    Dim sCellID As String
    Dim oCell As Object
    Dim oSector As Object
    Fetch First From Selection
    sCellID = Selection.Cell
    oCell = CreatePoint(Selection.Longitude, Selection.Latitude)
    oSector = Selection.OBJ
    
    Print "Finding Sectors near " + sCellID
    
    Select nb.*, ObjectDistance(nb.obj, oSector, "m") As "Distance"
    From Sectors As "nb"
    Where ConnectObjects(CreatePoint(nb.longitude, nb.latitude), oCell, 1) Intersects nb.OBJ
    And ConnectObjects(CreatePoint(nb.longitude, nb.latitude), oCell, 1) Intersects oSector
    And CELL <> sCellID
    Order By Distance
    into __nearby_and_in_direction_off
    Limit 2
    
    Print TableInfo(__nearby_and_in_direction_off, TAB_INFO_NROWS) + " nearby and in direction sectors found!"
    I start by reading some attributes from the selected sector such as the Cell ID, the center of the cell tower, and the sector polygon.
    Next, I'll be using a Select statement to query out sectors:
    I set 3 conditions:
    1. The sector I'm querying must intersect the line between the two cell towers. In this way, I can ensure the sector points towards the selected sector.
    2. The selected sector must intersect the line between the two cell towers. In this way, I can ensure the selected sector points towards the sector
    3. The Cell ID must be different from the selected Cell ID

    Depending on your requirements, you can leave out the first or second condition.

    I also include a calculated distance between the two sectors and sort my result by this distance.

    And finally, I use the Limit keyword to make sure I only get the x nearest sectors returned.

    Let me know how this works for you.



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 4.  RE: Distance Calculator taking Orientation in consideration

    Posted 01-08-2025 20:45
    Edited by H. H 01-08-2025 20:46

    Thanks a lot Peter for your great effort

    it loos very good, just two points:

    1) when I have tried the same SQL in my mapinfo, it keep telling my (Table sectors is not open)

    while it is already opened as shown in below map,

    seems i miss something, if you could advise me please

    2) is it possible to make SQL script make this check for all cells and give one output table,

    as i need this for global study

    Example:

    Source Site1/ Cell A - Nearest Cell: Site2/ Cell A -  Distance between them: 120 Meters

    .........

    .....



    ------------------------------
    H. H
    Knowledge Community Shared Account
    ------------------------------



  • 5.  RE: Distance Calculator taking Orientation in consideration

    Employee
    Posted 01-09-2025 02:03

    Morning

    Let me think about how to do this for all cells. 

    As for the table, I refer to a table called Sectors in two places in my script. In the Set Coordsys statement in the first line and the Select statement.

    From the screenshot, I can't tell what your table is called. Can you try to delete the table name, and use the Table dropdown to insert your table name? Sometimes, a single character in the table name is off.



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 6.  RE: Distance Calculator taking Orientation in consideration

    Employee
    Posted 01-09-2025 04:03
      |   view attached

    Hey

    I  created a small tool that uses the SQL statement above and loops over the records in the Sector table.

    I have attached the tool as source code and a compiled MapBasic application.

    You will be prompted using 5 separate dialogs to select the sector table, columns with Cell ID, longitude and Latitude, and the resulting output table.

    That part could be improved with a single input dialog.



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------

    Attachment(s)

    zip
    FindNearstSectors.zip   3 KB 1 version


  • 7.  RE: Distance Calculator taking Orientation in consideration

    Employee
    Posted 01-09-2025 04:09

    PS: I have only tried this with a small table holding 100 sectors.

    If this turns out to run very slow on larger datasets, we could consider adding a distance limit. In this way, the tool would only analyze the sectors within say 10 km of each sector.



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 8.  RE: Distance Calculator taking Orientation in consideration

    Posted 01-09-2025 04:18

    yes please better add this option to control distance limit as my Database is huge

    don't know if we could also add an option to get (Only First nearest sector cell, or First & Second) so tool finish check operation faster



    ------------------------------
    H. H
    Knowledge Community Shared Account
    ------------------------------



  • 9.  RE: Distance Calculator taking Orientation in consideration

    Employee
    Posted 01-09-2025 11:08
      |   view attached

    Hey

    Give this a spin. Took less than a minute with 1,200 sectors

    Peter



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------

    Attachment(s)

    zip
    FindNearstSectors2.zip   4 KB 1 version


  • 10.  RE: Distance Calculator taking Orientation in consideration

    Posted 01-09-2025 19:59

    Thanks a lot Peter, the tool is much better now

    One small favor, please:

    in my database, Cell ID is repeated in all sites

    to make it unique, can we make the tool check Site ID Plus Cell ID

    and give final output in format of:
    Source Site ID & Cell ID

    Target Site ID & Cell ID

    Distance



    ------------------------------
    H. H
    Knowledge Community Shared Account
    ------------------------------



  • 11.  RE: Distance Calculator taking Orientation in consideration

    Employee
    Posted 01-10-2025 02:07
      |   view attached

    Hey

    The tool now allows you to also select a Site column in case your Cell column doesn't hold unique values.

    The tool will combine the value from the Site column with the value from the Cell column into a unique value and use this.

    If your Cell column holds unique values, you can just leave the Site column blank.



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------

    Attachment(s)

    zip
    FindNearstSectors2.zip   5 KB 1 version


  • 12.  RE: Distance Calculator taking Orientation in consideration

    Posted 01-10-2025 10:03

    Really appreciate your great effort and support

    Can we add a condition that nearest sector (can not be related to the same site of source sector)

    as you can see below that almost all results are from same site. 



    ------------------------------
    H. H
    Knowledge Community Shared Account
    ------------------------------



  • 13.  RE: Distance Calculator taking Orientation in consideration

    Posted 01-10-2025 14:38

    Important issue, to highlight please

    Source cell and Nearest Cell can have same Cell ID or it can be different, no issue

    but Site ID of Source & Nearest must be different



    ------------------------------
    H. H
    Knowledge Community Shared Account
    ------------------------------



  • 14.  RE: Distance Calculator taking Orientation in consideration

    Employee
    Posted 01-13-2025 01:44
      |   view attached

    Hey

    I have now included the Site column in the output and I'm using the Site to ensure the tool doesn't select cells from the same Site as the Source Site.



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------

    Attachment(s)

    zip
    FindNearstSectors2.zip   5 KB 1 version


  • 15.  RE: Distance Calculator taking Orientation in consideration

    Posted 01-13-2025 09:13

    Thanks Dear Peter,

    We have very good progress just I worry is the tool take in Azimuth/ Orientation in consideration

    I just run it, and i think it doesn't take Azimuth/ Orientation in calculation

    below is an example:

    Site ID: 9606 (Red Pin) both sectors have nearest cell from Site ID: 9607 (Blue Pin)

    however Site ID: 9606 Cell ID: 5 was supposed to have nearest cell from Site ID: 7256 (Green Pin)

     



    ------------------------------
    H. H
    Knowledge Community Shared Account
    ------------------------------



  • 16.  RE: Distance Calculator taking Orientation in consideration

    Employee
    Posted 01-13-2025 10:10

    Hey

    In your initial image, your cells didn't go all the way into the center of the site. So I took that as the way you had your sectors.

    I can see that if the sectors start from the center the line between the current site and potential nearest sites will always touch/intersect the sectors.

    Would you be able to share a small subset of your sectors so that I can test using these? If so, send them to peter.moller@precisely.com.



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 17.  RE: Distance Calculator taking Orientation in consideration

    Employee
    Posted 01-13-2025 11:03
      |   view attached

    With a slight adjustment, it takes the issue of the sectors going all the way into the center of the site into account.

    When comparing the line between the potential sectors, I remove the centerpiece of the sectors using a 10-meter buffer around the site.

    Here's the same position as you shared before:The blue center part is a zoomed example of the sectors in the top left corner where you can see that the centerpiece has been removed from the sector. This is only visible for the sectors where no nearest sector was found.



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------

    Attachment(s)

    zip
    FindNearstSectors2.zip   5 KB 1 version


  • 18.  RE: Distance Calculator taking Orientation in consideration

    Posted 01-13-2025 12:31

    I think we are very close,

    just don't know why some sector/ cells come without nearest cell

     



    ------------------------------
    H. H
    Knowledge Community Shared Account
    ------------------------------



  • 19.  RE: Distance Calculator taking Orientation in consideration

    Employee
    Posted 01-14-2025 02:17

    For this specific sector, it could seem that the nearest sector is the one to the southwest but that sector doesn't point towards it.

    As you can see in the image below. The red line doesn't go through the sector.



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------