MapInfo Pro

 View Only

MapInfo Monday: Opening GeoJSON files via the OGR Vector Files

  • 1.  MapInfo Monday: Opening GeoJSON files via the OGR Vector Files

    Employee
    Posted 07-01-2024 03:01

    We have in a previous article looked at the OGR Vector Files support that we added to MapInfo Pro v2021. Today, we will look at opening GeoJSON files.

    If you need to export your data to GeoJSON, we have previously discussed doing this via a Python script and the Export via OGR Vector Files.

    Opening a GeoJSON File

    In this example, I want to download some earthquake data from the USGS (U.S. Geological Survey) and open this in MapInfo Pro.

    Under the Earthquake Hazards Program, I can access the GeoJSON Summary Format page. Here I can find links to earthquake summaries for the past hour, past day, past week, and past month.

    I'll right-click the summary for the M1.0+ Earthquakes under Past 30 days, and save this to my laptop. It will be saved as a GeoJSON file.

    In MapInfo Pro, I select the Open Table control from the Home tab. In the Open dialog I select Vector Files (OGR) from the Files of Type list and browse to the location where I saved the GeoJSON file that I downloaded.

    Now double-click on the GeoJSON file to open it.
    In the Vector Files (OGR) Open Options dialog, we don't have to change anything. Hit the OK button to continue.
    In the Select One or More Table to Open dialog, make sure that the GeoJSON dataset has been selected. You can also change the Style, the Coordinate System, and the location of the TAB File that can be used to open this file next. Under Options you can also choose to save the data into a native MapInfo tab. This is useful if the data is so big that working with it in its native format slows down MapInfo Pro.
    Click the OK button to load the data into MapInfo Pro. Below you can see the resulting dataset on a map.
    Now this works very well if this data is something you need once in a while and you are happy to download and save a copy of the GeoJSON file before opening it. But imagine, you need to refresh this data every day. If that's the case, read the next chapter.

    Opening a GeoJSON Url

    Let's go back to the GeoJSON Summary Format page where we download the GeoJSON file. Instead of right-clicking the reference link and saving the content to a local file, I can also right-click the reference link, and copy the link, the URL to the data.
    Copying the link, results in this link for the M1.0+ Earthquakes for the last month: https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_month.geojson.
    I can also ask MapInfo Pro to open the data using this link instead of the downloaded dataset.
    From the Open dialog, click the Open Connection button in the top right corner of the dialog.
    In the Open Connection dialog, select the OGR Connection Type and click on the New... button.
    In the OGR Web Connection dialog, I will paste the URL/link that I copied from the USGS site into the OGR Web URL field. I also make sure to select the GeoJSON - GeoJSON driver from the OGR Driver list.
    I will now be taken through the same two steps that I also saw when opening a GeoJSON file from my local laptop. In the Vector File (OGR) Open Options dialog, I don't have to specify anything. In the Select One or More Tables to Open dialog, I can make some adjustments. In this case, I open the Options dialog to specify a location for my TAB file.
    After setting the MapInfo TAB File, I click the OK Button. Make sure that you don't check the Save Copy as MapInfo Table option.
    By not saving a copy of the data into a MapInfo table, the tab file created will hold a link to the GeoJSON file generated on the USGS site. This means that every time you open the tab file, it will fetch the latest data from the USGS site.
    Below you can see the data in a map inside MapInfo Pro. This data is loaded directly from the USGS site.
    I hope this gave you some ideas on how you can use GeoJSON data directly in MapInfo Pro.


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