Fundamentals 2 min read

Drawing China's Map with PySimpleGUI: Polygon Data and Code Example

This article explains how China's map is represented by three closed polygons, describes the text file format containing longitude‑latitude point groups, and provides a complete PySimpleGUI Python script to read the data and render the map as red polygons.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Drawing China's Map with PySimpleGUI: Polygon Data and Code Example

The map of China consists of three closed polygons: the mainland, Hainan Island, and Taiwan. The data is stored in a plain‑text file that, when evaluated, yields a list containing three sub‑lists, each representing one of these regions as a collection of point groups.

Each point group is composed of two floating‑point arrays: longitude and latitude. Longitude values range from -180 to 180 (positive for east, negative for west) and latitude values range from -90 to 90 (positive for north, negative for south). Since all of China lies in the eastern and northern hemispheres, its coordinates are positive.

The following Python code uses PySimpleGUI to create a window with a graph canvas, reads the polygon data from china.txt , and draws each polygon in red:

import PySimpleGUI as sg
layout = [[sg.Graph(canvas_size=(800,800),
                    graph_bottom_left=(70,10),
                    graph_top_right=(140,60),
                    background_color="white",
                    float_values=True,
                    key='graph')]]
window = sg.Window('祖国山河一片红', layout, finalize=True)
with open('china.txt','r',encoding='utf-8') as f1:
    china = eval(f1.read())
    for shp in china:
        window['graph'].DrawPolygon(shp, fill_color='red')
event, values = window.read()

The script visualizes the entire Chinese territory as a single red shape, demonstrating a simple method for geographic data rendering using Python GUI libraries.

GISMap visualizationPolygonPySimpleGUI
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.