MapInfo Pro Developers User Group

 View Only
Expand all | Collapse all

please i need how to plot points and line in mapinfo from open table with mapbasic ?

Mohammad Khan

Mohammad Khan06-26-2018 07:43

  • 1.  please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-26-2018 09:42

    ?please if can someone  show me what's wrong with my program , as I'm not familiar with mapbasic , when I execute it plot only one point, should i'have do loop with a counter i and fetch or the  update statement is enouph.

    here below this sample (my projection is WGS84):

    sub creatOpoint

    dim Longitude,Latitude as float

     

    OnError Goto ErrorHandler

    Create Map For stable CoordSys Earth Projection 1, 104

    Update stable Set Obj = CreatePoint(Longitude,Latitude)

    Map From stable

     

    ErrorHandler:

    Note Error$()

    end sub

     



  • 2.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-26-2018 06:29

    Hi Mohamed,

    The code snippet that you have provided is creating a point. You are having a latitude and longitude value which you are providing as an argument to the CreatePoint() function which returns point objects for your table. This is perfectly fine for creating points for your table.

    There is a difference between a point and a line. Points consists of a single latitude and longitude value but a line is a formation of multiple points. So firstly you need to have at-least two points and then use the CreateLine() function which takes a pair of latitude longitude values. Modified code for creating line:

     

    sub createLine

    dim lat_a,long_a,lat_b,long_b as float

    OnError Goto ErrorHandler

    Create Map For stable CoordSys Earth Projection 1, 104

    Update stable Set Obj = CreateLine(long_a,lat_a,long_b,lat_b)

    Map From stable

    ErrorHandler:

    Note Error$()

     

    end sub

     

    Following is the reference link on mapbasic help guide.

    Purpose

    Returns an Object value representing a line. You can call this function from the MapBasic window in MapInfo Pro.

     

    Syntax

    CreateLine( x1, y1, x2, y2 ) 

    x1 is a float value, indicating the x-position (for example,) of the line's starting point.

    y1 is a float value, indicating the y-position (for example, Latitude) of the line's starting point.

    x2 is a float value, indicating the x-position of the line's ending point.

    y2 is a float value, indicating the y-position of the line's ending point.

     

    Return Value

    Object

     

    Description

    The CreateLine() function returns an Object value representing a line. The x and y parameters use the current coordinate system. By default, MapBasic uses a Longitude/Latitude coordinate system. Use the Set CoordSys statement to choose a new system.

     

    The line object will use whatever Pen style is currently selected. To create a line object with a specific Pen style, you could issue the Set Style statement before calling CreateLine() or you could issue a Create Line statement, with an optional Pen clause.

     

    The line object created through the CreateLine() function could be assigned to an Object variable, stored in an existing row of a table (through the Update statement), or inserted into a new row of a table (through an Insert statement). If you need to create objects on a Layout window, you must first issue a Set CoordSys Layout statement.

     

     

     

     



  • 3.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-26-2018 06:59
      |   view attached

    Effectively  we need  at least two point to create a line, however  as first step , I ‘m still facing a problem to project points from table X,Y to map.

    All the points are plotted in one point with coordinate X, Y (0.0).

    I know I’m bothering you as I’m still newer in mapbasic but I’ll join the input sample as I’m using it as example.

       ?

    Attachment(s)

    txt
    sample table.txt   1 KB 1 version


  • 4.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-26-2018 07:02

    Please remove this line from your code

    dim Longitude,Latitude as float



  • 5.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-26-2018 07:06

    ?it show message error that the variable or field  longitude are not defined.



  • 6.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-26-2018 07:17

    Your table is having incorrect langitude and latitude values. Please replace the comma with a dot.



  • 7.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-26-2018 07:23

    ? ok i'll try , so no need to declare the arguments of creatpoint(long,lat).



  • 8.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-26-2018 07:32

    no. it is the name of the column having latitude and longitude values of your table



  • 9.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-26-2018 07:35
      |   view attached

    ?still the same message error , please have look to my snapshot. attached bellow

     

    i appreciate your concern and thanks in advance.

     



  • 10.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-26-2018 07:40

    Please follow the following steps:

    1. Go to File -> import and select the sample file.
    2. On the second screen, please make sure that you have checked the Use First Line for Columns Titles. then click ok.

     

    The table should now look like the following snapshots.

     



  • 11.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-26-2018 07:43
      |   view attached



  • 12.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-26-2018 07:45
      |   view attached

    You should check the checkbox as shown below.

     



  • 13.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-26-2018 09:17

    Now it's working , actually my aim is to open  tabale with interactive application , now i guess the problem in fact existaing to mu previous application with has the task  to open the input file  

    sorry again , ?i'll attache the hole example code , , please to have a look  in your free time. 



  • 14.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-27-2018 01:42

    Hi Mohamed,

    I went through your code and found out the issue that you are having.

    The Register table is not correct you need to replace it with this code;

    Register Table sInputFile type ASCII Delimiter 9 Titles Charset "WindowsLatin1" Into stemtabfile

    and run the code. It should work now. Please check it at your end and let me know in case of any issues.

     

     



  • 15.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-27-2018 05:27
      |   view attached

    Dear expert;

    Yes after correcting the register statement and it’s working perfectly .

    Really thanks for your assistance and hard support.

    Now I’ve to go to next step to plot the start_site , end_site and lines between them , all this data are included in the same table in differents columns .

    I think using statement update for the same table it will cancel the preceding one , so should I make three copy for that table to separate each statement  and how to do it?

    In fact I’m using this example for my training  which I found it very appropriate to  my  upcoming  objective .

    Thanks in advance

     

    Attachment(s)

    txt
    test.txt   5 KB 1 version


  • 16.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-27-2018 09:26

    Hi Mohamed,

    I have worked in Telecom sector so what I understand now is that you are trying to plot the sites and then links between these sites. If this is the understanding then you need to create a file where you put all the start_x,start_y and then append end_x and end_y to the sheet. This file will be your site locations which will be used in createpoints function. The other function createLinks will consume the above file and update statement createline will take the start_x,start_y,end_x,end_y as parameters which will create your links.

     

    Update table set obj = createline start_x,start_y,end_x,end_y)



  • 17.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-27-2018 10:04

    Exactly this is my purpose as I’m telecom engineer.

    But unfortunately I’m new in mapbasic I’m still not familiar in working with tables.

    I’ve managed to project the start_site  , start_end and even the links  separately , but each update statement  erase me the previous action as it is an update in the same name of table.

    So should I make copy of table for each statement or not .

    Please have look to my code (in your free time   of course) and tell me where is the problem.

    I know I’m stealing your precious time but I’ve been a long time a far from developing which make things a little bit  difficult for me.

    Sorry brother.

     

     

     

     

     

     

     

     

     



  • 18.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-28-2018 06:43

    Hi Mohamed,

    There will be two files created out of the input file that you have provided. The input file is the file which will be used for creation of links between the sites. You need to create another file which will be the sites file out of this file as it is having both the site information in the input file start_x,start_y will be the first site and end_x,end_y will be the second site location which we will use in create points.

    To accomplish this you need to take out the site information from the input file. We will first query and select all columns except the end_x,end_y in our first query and then save it as sitepart1. We need to make another query this time all columns except the start_x and start_y and save it as sitepart2.

    Now we open both the tables and append them and save it as sites table.Below is the code snippet.

    Select BTS_CODE, Start_X, Start_Y, BSC_CODE, Type1, Type2, HOP, LOS from inputtable into s1

    Select BTS_CODE, End_X, End_Y, BSC_CODE, Type1, Type2, HOP, LOS from inputtable into s2

    savepath = pathtodirectory$(sinputfile)+"sitepart1.tab"

    Commit Table s1 As savepath TYPE NATIVE Charset "WindowsLatin1" Interactive

    Open Table savepath Interactive

    savepath = pathtodirectory$(sinputfile)+"sitepart2.tab"

    Commit Table s2 As savepath TYPE NATIVE Charset "WindowsLatin1" Interactive

    Open Table savepath Interactive

    Close Table s1 Interactive

    Close Table s2 Interactive

     

    Insert Into sitepart1 ( COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8) Select COL1, COL2, COL3, COL4, COL5, COL6, COL7, COL8 From sitepart2

    Commit Table sitepart1 Interactive

    savepath = pathtodirectory$(sinputfile)+"sites.tab"

    Commit Table sitepart1 As savepath TYPE NATIVE Charset "WindowsLatin1" Interactive



  • 19.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-28-2018 06:46

    Hi Mohamed,

    I am also attaching the updated code for your reference.

    Please have a go with this mb and let me know in case of any issues.

    Thanks,

    Md. Aslam Khan



  • 20.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-28-2018 09:37

    ?Dear  expert;

    First i want to thanks you about your effort and your concern.

    your code work fine and it plot in Mapinfo my input point and link , there is a little confuse in label of code site, which are duplicated in start_site and end_site for some link,  following my table   we should affect the colunm  code_BTS for the start_site and the BSC_code for the End_site.

    first of all  I 've to understand your code which i found it very interesting  tutorial  for my training  and how things are doing ,  after I'll try to fixe that little miss in label if it possible.

    Any way I'm so grateful and thanks.🙏



  • 21.  RE: please i need how to plot points and line in mapinfo from open table with mapbasic ?

    Posted 06-29-2018 03:18

    Hi Mohamed,

    I will be posting some interesting work which I have done with Mapbasic for Telecom companies very soon. Please follow me so that you get notification when I do so.