Original Message:
Sent: 08-05-2024 00:47
From: Yong Zhang
Subject: MapBasic to create points from csv
I also tried the OGR way:
need help on Symbol settings, if I'd like to set different color for each file, how can I set it automatically as red below? tried to dim variable but didn't work.
Register Table sFileName TYPE "OGR" TABLE sTabName DRIVER "CSV" OpenOptions "AUTODETECT_TYPE=YES;AUTODETECT_WIDTH=STRING_ONLY;X_POSSIBLE_NAMES=lon*,x*;Y_POSSIBLE_NAMES=lat*,y*;Z_POSSIBLE_NAMES=z*" Charset "UTF-8" Cache On Symbol (34,16711680,12) Linestyle Pen (1,2,0) Regionstyle Pen (1,2,0) Brush (2,16777215,16777215) Font ("Arial",0,9,0) Into sTabFile
------------------------------
Yong Zhang
Knowledge Community Shared Account
Burlington MA
Original Message:
Sent: 08-05-2024 00:42
From: Yong Zhang
Subject: MapBasic to create points from csv
Thanks Peter,
my idea is to open the csv file which has lat/long, convert it into points map and then display it in MapInfo by MapBasic as mentioned before.
issues found:
- after commit table to a new table, need to wait for the new table to be saved, then it can be opened, do we have something like sleep(1 or 2 seconds) function?
- the coordinates displayed on map are not correct:should be
- the code you mentioned: Create Map For Table sTabName2 CoordSys CoordSys Earth Projection 1, 104 didn't pass on my machine. my mapinfo version is Mapinfo Pro 2023 Release build 97, after removed Table and CoordSys, it worked.the full scripts as below:
Dim sFileName As StringDim sTabFile As StringDim sTabFile2 As StringDim sTabName As String Dim sTabName2 As String Dim nDot As Integer Dim nLastBackslash As Integer sFileName = FileOpenDlg("Select CSV File", "*.csv", "CSV", "Select MDT CSV File") sTabFile = RegExReplace$(sFileName,"([a-z_0-9]+)(\.csv)", "$1.TAB") sTabFile2 = RegExReplace$(sFileName,"([a-z_0-9]+)(\.csv)", "$1_2.TAB")nDot = InStr(1,sFileName, ".")nLastBackslash = InStr(nDot-11,sFileName, "\")sTabName = Mid$(sFileName, nLastBackslash + 1, nDot - nLastBackslash - 1)sTabName2 = sTabName + "_2" Register Table sFileName TYPE ASCII Delimiter 44 Titles Charset "WindowsLatin1" Into sTabFileOpen Table sTabFile As sTabName InteractiveCommit Table sTabName As sTabFile2 TYPE NATIVE Charset "WindowsLatin1" Background supportmz off Close Table sTabName Interactive Open Table sTabFile2 As sTabName2 Interactive Create Map For sTabName2 CoordSys Earth Projection 1, 104Update sTabName2 set OBJ = CreatePoint(LATITUDE, LONGITUDE) Commit Table sTabName2 Interactive Close Table sTabName2 Interactive Open Table sTabFile2 As sTabName2 Interactive Add Map Auto Layer sTabName2
------------------------------
Yong Zhang
Knowledge Community Shared Account
Burlington MA
Original Message:
Sent: 07-30-2024 04:20
From: Peter Møller
Subject: MapBasic to create points from csv
Hi Yong
You need to change your two statements to this:
Create Map For Table sTabName2 CoordSys CoordSys Earth Projection 1, 104
Update sTabName2 Set OBJ = CreatePoint(LATITUDE, LONGITUDE)
I guessed that the coordinates are in Lat/Long WGS84. If that's not the case, you need to change the parameters after Coordsys
.
If you use MapInfo Pro v2021 or newer, you can open the CSV file using the OGR Vector File option. This will allow you to create points automatically when opening the file. Check out this article: MapInfo Monday: Improved Way to Opening CSV Files in MapInfo Pro v2021.
------------------------------
Peter Horsbøll Møller
Principal Presales Consultant | Distinguished Engineer
Precisely | Trust in Data
Original Message:
Sent: 07-30-2024 03:11
From: Yong Zhang
Subject: MapBasic to create points from csv
Hi everyone,
I have a csv file contains LATTIDUE/LONGITUDE, need to create points to display on map, I know the manual way, but need to do it in Mapbasic cause I have lots of files to do the same operation, part of codes as below, but got a error saying: unknown error encountered @ Alter Table sTabName2(Add geomerty obj)
anything wrong with my codes? any one can help? Thanks.
Open Table sTabFile2 As sTabName2 Interactive Alter Table sTabName2 (Add geometry obj)Update sTabName2 set geometry = CreatePoint(LATITUDE,LONGITUDE)
------------------------------
Yong Zhang
Knowledge Community Shared Account
Burlington MA
------------------------------