MapInfo Pro

 View Only
  • 1.  Automate multiple shape file processing steps

    Posted 20 days ago

    Hello,

    I am looking for automating below mentioned map file processing steps:
    1. download multiple shape files from a website like tomtom

    2. combine multiple shape files into one by editing table data and appending them into one

    3. save final file into .shp format

    Other tasks that I have to include
    - convert .gdl file to .mif 
    - custom map request where in I have to import an table with brickids or similar id onto an existing map and update the map, columns using that table and file the holes and save it as shape file.

    Since the idea is to automate most of the above steps. Can somone please suggest if below approach will work ?

    • Create an application using mapbasic with few buttons that will pick the input files, process them as explained above and output the file in specific place.
    • If there are some components which require external processing (not included in mapbasic) then use python to do that using external library using "run as a program" function.

    Does this look like a correct approach ?

    Any suggestions would be welcome and highly appreciated.

    thank you again.

    Best Regards...



    ------------------------------
    Deepak Gupta
    Knowledge Community Shared Account
    Burlington MA
    ------------------------------


  • 2.  RE: Automate multiple shape file processing steps

    Employee
    Posted 20 days ago

    Hi Deepak

    Most of what you describe can be done using MapBasic and/or Python in MapInfo Pro.

    A few follow-up questions:

    1. When you say shapefile, do you mean an ESRI shapefile or is that a general reference to a file holding spatial objects (shapes)?
    2. How are these files stored on the server? This is important when understanding how you can access the files programmatically.
    3. I haven't encountered the GDL format before. It could be this format, but I'm unsure: "The GDL file is an ArchiCAD Geometric Description Language File. ArchiCAD is an architectural CAD software developed by the Hungarian company Graphisoft." I am also not sure how you can convert this format.

    A couple of suggestions to get you started:

    If you are looking to open ESRI shapefiles in MapInfo Pro, you can use the Register Table command to create a TAB file referencing the ESRI shapefile and then use Open Table to open the ESRI shapefile in MapInfo Pro. Finally, you can save a copy of the shapefile into a native TAB file for read/write access using the Commit Table statement.

    '**Creating a few variables for the script

    Dim arrShapeFiles(0), sShapeTabFile, sNativeTabFile As String

    Dim sShapeTab, sNativeTab As String

    Dim nFile As Integer

    '**Defining the list of Shape Files to open using a String array

    Dim nFile As Integer

    nFile = nFile + 1

    ReDim arrShapeFiles(nFile)

    arrsShapeFiles(nFile) = "C.\Data\SomeShapeFile1.shp"

    nFile = nFile + 1

    ReDim arrShapeFiles(nFile)

    arrsShapeFiles(nFile) = "C.\Data\SomeShapeFile2.shp"

    nFile = nFile + 1

    ReDim arrShapeFiles(nFile)

    arrsShapeFiles(nFile) = "C.\Data\SomeShapeFile3.shp"

    '**Opening an ESRI Shapefile and saving it into a Native Tab File

    sNativeTabFile = "C.\Data\SomeNativeTabFile.tab"

    Register Table arrShapeFiles(1) Type SHAPEFILE Charset "WindowLatin1" CoordSys Auto PersistentCache ON Type NATIVEX Into sShapeTabFile

    Open Table sShapeTabFile

    sShapeTab = PathToTableName$(sShapeTabFile)

    Commit Table sShapeTab As sNativeTabFile

    Close Table sShapeTab

    Open Table sNativeTabFile

    sNativeTab = PathToTableName$(sNativeTabFile)

    If you want to add more tables into the same file, you can use the Insert statement to merge two tables. In the example below, I use the For loop to loop over the shapefiles in the array arrShapeFiles.

    '**Looping over the files 2 to number of files, opening each and inserting the rows into the native table

    For nFile = 2 To Ubound(arrShapeFiles

       Register Table arrShapeFiles(nFile) Type SHAPEFILE Charset "WindowLatin1" CoordSys Auto PersistentCache ON Type NATIVEX Into sShapeTabFile

       Open Table sShapeTabFile

       sShapeTab = PathToTableName$(sShapeTabFile)

       Insert Into sNativeTab

           Select * From sShapeTab

       Commit Table sNativeTab

    Next

    Hopefully, this can get you started. Feel free to come back with follow-up questions.



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



  • 3.  RE: Automate multiple shape file processing steps

    Posted 19 days ago

    Thanks a lot Peter for your quick and detailed reply. This will help me a lot. I'll answer some of your queries here.

    1. We are downloading maps from TomTom but there are other vendors too. They have API based map download access using python.
    2. These shape files usually have 4 files for each country with .shp, .shx, .dbf and .prj extension. We usually import .shp files into Mapinfo.
    3. I am trying to get details for .gdl file format and will share in this thread later.

    Some followup questions:

    • For custom map requests, usually our steps are as follows:

      • copy the postcodes from vendor (tomtom) files and requested files into one excel file
        change the column to text type
        use lookup to copy brick id from client data to vendor data and paste them as values
        fill the missing brickid with the brickid of the nearest postcode
        save it as csv format
        in mapinfo, open the tab file of the region received from vendor and then the above csv file using "open table"
        go to backend data and add brickid column and update the column with the data from csv file
        combine this and create a new tab file
        aggregate the data using brickid column
        if the brickids are not visible on map then edit the table structure of final file and remove postcode column
        Update the columns with the given values (CentroidX, Y and area). Save the file
        aggregate the data using brickid column
      • If we have a map where there is a hole (with no brick id) then we insert a shape in the map and combine it in the map. Can this be done using mapbasic ?

    if you could please review above steps and just tell me if all of it can be done using mapbasic then we can figure out the functions and use them.

    Thank you again.

    Best Regards



    ------------------------------
    Deepak Gupta
    Nagarro
    Burlington MA
    ------------------------------



  • 4.  RE: Automate multiple shape file processing steps

    Employee
    Posted 18 days ago

    Hi Deepak

    I don't quite follow your custom map request process, but if you do this manually in MapInfo Pro, you can automate it via MapBasic, too.

    I'd recommend opening the MapBasic window in MapInfo Pro from the Tools Window dropdown on the Home tab before manually doing the process.

    Now do the abovementioned process and notice how MapInfo Pro captures the MapBasic statements in the MapBasic window.

    Once done, copy the MapBasic statements from the MapBasic window into a MapBasic source file and inspect the code for any hardcoded WindowIDs. These need to be changed into dynamic variables. There can be other IDs that also need to be handled dynamically.

    Once done, try to compile the script and run it. You may find that your code needs some additional minor tweaks, such as setting the coordsys before using coordinates and similar.

    This article may be a good starting point if you are new to MapBasic: MapBasic Monday: An Introduction to MapBasic.

    You can find other MapBasic articles on the Home of #MapInfoMonday page under Writing MapBasic Applications.

    And feel free to continue to post your questions in the community too.



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