MapInfo Pro

MapInfo Monday: Improved way to opening CSV Files in MapInfo Pro v2021

  • 1.  MapInfo Monday: Improved way to opening CSV Files in MapInfo Pro v2021

    Employee
    Posted 01-31-2022 08:28
    Happy #MapInfoMonday!

    Today we want to dive a bit more into the new OGR Driver support we added to MapInfo Pro v2021. In this example, I'll give you some examples of the benefit you can get from using the Vector Files (OGR) driver to open your CSV files compared to using the older way of letter​ MapInfo Pro process the data by selecting the Comma Delimited CSV (*.csv) file type.

    Below you can see more than 350,000 crash locations loaded from a CSV file into a map in MapInfo Pro. During the opening process, the points for the locations were automatically created from coordinates stored in two columns.

    Besides automatically creating points, the added benefits also include creating geometries from columns and being able to edit CSV files directly from MapInfo Pro.

    Selecting CSV File to Open

    From the Open dialog, select the Vector Files (OGR) in the list of Files of Type. This will give you access to the OGR formats that we have tested with MapInfo Pro v2021. One of these formats is CSV.

    Then select the CSV file or files that you want to open into MapInfo Pro. Hit the Open button to continue.

    When you select the Vector Files (OGR) file type, you can select multiple files to open. And these files can also be of different file types too. Often it may however be simpler to open each file type on it's own.

    Open Options

    Once you have selected the file to open, MapInfo Pro presents you with the dialog Vector File (OGR) Open Options. Here you can control how the file gets opened and settings around this process. If you have selected multiple file types in the Open dialog, you will see this dialog for each file type.

    For in our example CSV files, there are a couple of options that do come in handy as they can convert elements in the CSV file into spatial objects. It's the XPOSSIBLE_NAME and YPOSSIBLE_NAMES parameters that let you specify which columns to look for coordinates.

    Sometimes you will need to tweak the strings slightly for the process to pick up the columns. In my example, the columns holding latitude and longitude values are named CRASH_LONGITUDE_GDA94 and CRASH_LATITUDE_GDA94. By default, the search string expects the column names to start with "lon" and "lat". So I have to enter a * in front of these to indicate there might be some text in front of "lon" and "lat", too.

    The other option that can be useful is the ability to convert a WKT (Well Known Text) string into a spatial object. This happens in the same way as with the coordinates where you specify a column name to look for. This would typically be "WKT". If it's something else, you can change the search pattern to match your requirement.

    There are other options available. The options depend on the file type, or more specifically the OGR Driver being used. IN the dialog above, you can see that the driver is the CSV driver. If you want to understand more about the individual options, you can click the Help button. This will take you to the support page for the specific driver.

    Once you have modified the Open Options, click OK to continue.

    Selecting and Configuring Tables

    The next step is to select the tables, or datasets, to open. This sounds like an unneeded step, especially for CSV files. But this process is used for opening many different formats. SOm of these formats, such as GeoPackage and GPX files, may contain multiple tables. This final step allows you to control which datasets to open and also to set specific settings for the individual dataset such as styling and coordinate system.

    If multiple datasets should use the same settings, you can select these and configure these settings once for the selected datasets.

    You can set the styling details for the selected dataset(s) using the Style button and the coordinate system to use using the Coordinate System button.

    Through the Options button, you can access a dialog that is similar to the Vector File (OGR) Open Options we encountered earlier. But now it also has some additional settings.

    You can specify the resulting MapInfo TAB file created by this process.

    If you check the Cache option, you will see better performance when using these files in MapInfo Pro.

    You can also prevent users from editing the data through MapInfo Pro by checking the Read Only option.

    And finally, you can save the data into a native MapInfo table. This is especially recommended when you access text-based formats such as CSV files. The text-based files are often slower when using them in MapInfo Pro which means you will see a great performance improvement when saving the data into a native table.

    The Driver Options at the bottom of the dialog holds the same settings and parameters that you configured earlier. This time you can configure these differently for the individual dataset if needed.

    In this initial example, I have chosen to save the CSV file into a native table and create points from the two lat/long columns.

    You can see that saving the CSV file into a native table runs as a task in the Task window. This also means that I can continue using MapInfo Pro while this process is running.

    Once the process has finished the data gets loaded into my map window. In the Explorer window, you can see that the dataset Crash_Locations is a Native table.

    Opening data with Direct Access

    You can also open the same dataset without converting it into a native tab file. This means that MapInfo Pro will read the data directly from the selected input file.

    Below you can see that I have opened a subset of the previous dataset into MapInfo Pro where I haven't converted the dataset into a native tab file. In the Explorer window, you can see that the table Crash_Locations_Subset is listed under the Table Type OGR.

    Some of the OGR Vector File drivers also allow you to edit the data. The CSV driver does this. In the image below, I have made the layer Crash_locations_Subset editable in the Layer list. and in the browser window, you can see that I'm in the process of editing the value in the field Crash_Severity.

    When I have made changes to an editable OGR File type, I can use the Save command to save these changes to the original data file. This is very similar to the way you would save changes to a native table. But applying these changes can take a while especially if you are making changes to a very large text-based file such as a CSV file. That's because MapInfo Pro can't just save the small change you made but it will have to rewrite the entire file to disk.

    I hope this gave you some insight into some of the benefits of the OGR file types that we added to MapInfo Pro v2021. If you often open CSV files containing spatial data in the form of coordinates, I'm sure this will save you many clicks.

    Are you already taking advantage of some of the newly added formats?

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