October 29, 2024

Monitor, Track, and Record Geospatial Housing Data with Python and JSON Files

Written by: Jason Kulinski

 

Global Mapper Pro® is a developer-friendly tool designed for ease of automation. Every day, more users learn how to take advantage of its powerful scripting and data storage capabilities.

From C++ to Python, Global Mapper Pro has an array of languages to help with your automation needs. Today, we will look in-depth at Python and JSON files to showcase how users can monitor, track, and record geospatial data to save time and money. The following workflow will discuss Python at an intermediate level and showcase custom Global Mapper functions.

Improve Workflow Efficiency With Python

Picture this: you have four people working tirelessly on extracting vector data points from Global Mapper, and you have heaps of it. Not only do you have all of these vector points to process, but you also have more files coming in every day. Over the month, these four people would have put in 640 hours and still have more work ahead of them. With the Python scripting functionality available in Global Mapper Pro, these difficult, time-consuming tasks can be completed instantly.

We encourage those unfamiliar with Python commands in Global Mapper Pro to check out our self-paced premium GIS course — Basics of Python in Global Mapper Pro — available on the Blue Marble Geographics Online Classroom. We also publish extensive workflows on our website and helpful information about the software on our Knowledge Base. Users can additionally reference sample Python scripts that are included as an extra download feature in all versions of Global Mapper.

Extracting Data by Area Features

The following workflow outlines a multitude of Global Mapper functions by demonstrating how to extract attribute data from existing area features. This can make subsequent computations near-instant.

Let’s say you have a bunch of area features in Global Mapper representing property information in Hawley, Minnesota. Each of these area features can be accessed in Python by using the right commands. Global Mapper has added wrapper classes that can access the C++ functions via Python scripting.

A double-nested for loop with the intended goal of referencing an area feature. Then, the attributes inside the area feature specifically “EMV_TOTAL”.
Figure 1.1. A double-nested for loop with the intended goal of referencing an area feature. Then, the attributes inside the area feature specifically “EMV_TOTAL”.

Store Extracted Values in a Custom JSON File Format

Now that we’ve built a list of data values that are important for our process, we can take advantage of some common Python libraries for storing and interpreting. Storing data is a key element of preservation and reuse. For example, the housing data you store in a JSON file could be sent to an SQL backend and redisplayed to a web page. Automated workflows remove the need for upkeep, allowing developers to focus on more important tasks.

Python data structures formatted for JSON file usage
Figure 1.2. Python data structures formatted for JSON file usage

One method would be to store these values in a custom JSON format by importing and taking advantage of the built-in Python JSON API. To do this, we can create the data structure, add some identifiers, and write the prices of the home from the EMV_TOTAL attribute to the JSON file inside of the for loop.

Implementing the Python dictionary and writing content to JSON file
Figure 1.3. Implementing the Python dictionary and writing content to JSON file

Since Python dictionaries have similar structures to that of JSON data, we will first create two dictionaries and nest one inside of the other. Every loop, a new instance of home_features is created and populated with a value from the EMV_TOTAL attribute. These data structures can be as complex or as simple as you need them to be to represent the data required for your project.

Incorporating that extra code allows us to create a massive store of housing data in seconds… and JSON data is just the start! Using this method, we can connect to backend servers and automatically update websites, as well as private and public data centers. You can also create custom reports to visualize data points in the form of pie charts, line graphs, and scatter plots.

Example JSON data automatically generated from the Python file
Figure 1.4. Example JSON data automatically generated from the Python file

Built-in Python Tools for Generating Engaging Preliminary Data Visualizations

To wrap up this blog, let’s get a better understanding of the data we’ve been working with. Python provides a number of ways to go about data visualization. The simplest of which is to output to the terminal with nice print statements, such as in Figure 1.5.

Terminal output based on values collected from the Global Mapper Project
Figure 1.5: Terminal output based on values collected from the Global Mapper Project

That’s pretty boring though. Let’s try something more exciting! Luckily, Python also has built-in tools such as MatPlotLib and Numpy to help make boring data look exciting. Using these tools, we can create intriguing graphs with minimal effort.

Figure 1.6: Utilizing the Python module MatPlotLib, we can reproject our values as a pie chart. The pie chart showcases the distribution of housing prices in ranges of 100,000 USD.

With our automatically generated graphs from the Global Mapper dataset, we can input any similar vector GIS files to automatically generate any of the output we created. This could take an hour or more in Excel if performed manually, however, it’s done in one fell swoop with Python in Global Mapper. In part 2 of this article, we’ll dig deeper into reverse engineering Global Mapper workflows and creating our own geospatial data from CSV files.

If you would like to explore using Global Mapper functionality in a Python script or writing the toolkit into your own apps, check out the Global Mapper SDK®. For more visual GIS data editing and Python integration download a free trial of Global Mapper Pro today!

To follow along with the blog download the files here.

Companies using Blue Marble’s geospatial technology