User Tools

Site Tools


guides:tutorials:python

Hello Python

Documentation | Tutorials | Hello Python

This tutorial demonstrates how to create a simple application using VS.NET, PyCharm, or another Python IDE.

Preparations

TatukGIS Developer Kernel for Python (DK.Python) can be installed with a commonly used package installer for Python – pip. The only prerequisite for installing DK.Python is Python, which is bundled with pip.

If you are not familiar with Python and pip, start here:

You can start writing Python programs using IDLE – an integrated development environment bundled with Python, but there are a lot of free and commercial dedicated solutions on the market, e.g.:

Installation

When your Python environment is ready, install the DK for Python from PyPI package with:

pip install tatukgis-pdk

If you have already installed package, use the --force-reinstall option to install the latest version.

pip install tatukgis-pdk --force-reinstall

Activation

From January 2025 DK for Python is free, and the activation is no longer needed!

First application

Now, it’s time to open an IDE and create a new python file (with extension *.py) and paste the below code.

import tatukgis_pdk as pdk
 
 
# A class to create Python GIS application with a GUI
class HelloPythonForm(pdk.TGIS_PvlForm):
    def __init__(self, _owner):
        # Create a form
        self.Caption = "Hello DK for Python"
        self.Width = 600
        self.Height = 400
        self.OnShow = self.on_show
 
        # Add a GIS viewer to the form
        self.GIS = pdk.TGIS_ViewerWnd(self.Context)
        self.GIS.Align = "Client"
        self.GIS.Mode = pdk.TGIS_ViewerMode().Zoom
 
    def on_show(self, _sender):
        # Download if necessary and returns path to the sample data directory.
        sample_data_dir = pdk.TGIS_Utils.GisSamplesDataDirDownload()
 
        # Open a Shapefile and add to the map
        self.GIS.Open(sample_data_dir + "World/WorldDCW/world.shp")
 
 
def main():
    # Minimal code to run a GUI application in Python, powered by the TatukGIS DK for Python package
    form = HelloPythonForm(None)
    form.Show()
    pdk.RunPvl(form)
 
 
if __name__ == '__main__':
    main()

Run the Python script to display the TatukGIS map viewer with the world shapefile loaded.

To go further, find our DK.Python-Samples GitHub page.

2025/02/12 12:25

Page Tools