Indexof

IndexofPython Guide: Reading and Writing Geosoft PLY Polygon Files › Last update: Mar 17, 2026@jackcoolAbout › #PythonGuideReadingandWriting

Mapping the Boundary: Python Libraries for Geosoft PLY Files

In the specialized niche of exploration geophysics, the Geosoft PLY (Polygon) file format is a critical standard for defining spatial masks, survey boundaries, and inclusive/exclusive regions. Unlike the more common Stanford PLY format used in 3D modeling, Geosoft PLY files are fundamentally 2D vector boundaries often tied to specific coordinate systems. As of 2026, the primary method for interacting with these files programmatically is through the official Geosoft GX API for Python, though the simple ASCII nature of the format allows for lightweight custom parsing. This tutorial breaks down how to read and write these specialized GIS files effectively.

Table of Content

Purpose

Understanding the intent of a Geosoft PLY file is the first step toward successful data conversion. These files serve to:

  • Define Clipping Masks: Restrict grid calculations or data exports to a specific irregular shape.
  • Survey Planning: Store the perimeter of a geophysical flight or ground survey.
  • Inclusive vs. Exclusive Logic: Geosoft PLY files explicitly define whether the interior or exterior of a polygon is the "active" zone.

The Library Landscape

While standard GIS libraries like Fiona or GeoPandas do not natively support Geosoft PLY, you have two primary options:

1. geosoft.gxpy (Official): Part of the geosoft package available on PyPI. It is the most robust way to handle these files as it automatically manages coordinate systems and Geosoft-specific metadata.

2. Manual ASCII Parsing (Open Source/Lightweight): Since Geosoft PLY files are often simple ASCII text files starting with a poly header followed by XY coordinates, they can be read and written using standard Python file I/O operations without heavy dependencies.

Step-by-Step: Writing a PLY File with GXPY

1. Install the Geosoft Library

Ensure you are in a Windows-based Python environment (as the core Geosoft engine requires Windows binaries).

pip install geosoft

2. Create a Polygon Object

In gxpy, polygons are often handled within the geometry or map sub-modules. To create a PLY, you define a set of points and save them using the polygon handler.

import geosoft.gxpy.geometry as gxgeom

# Define vertices for a simple rectangle
vertices = [[500000, 7000000], [510000, 7000000], [510000, 7010000], [500000, 7010000]]

# Save as a Geosoft PLY file
# Note: Usually requires an active GX context or project
with gxgeom.Pyl.new("my_boundary.ply") as ply:
    ply.add_polygon(vertices)

3. Manual ASCII Reading (The Lightweight Way)

If you only need the coordinates and don't have Oasis montaj installed, you can parse the file manually:

def read_geosoft_ply(filepath):
    coords = []
    with open(filepath, 'r') as f:
        lines = f.readlines()
        for line in lines:
            if line.startswith('poly'): continue # Skip header
            parts = line.split()
            if len(parts) >= 2:
                coords.append((float(parts[0]), float(parts[1])))
    return coords

Use Case: Automated Survey Masking

A mining company has 500 different target areas defined as Shapefiles. They need to convert these into Geosoft PLY format to run automated "windowing" on their magnetic grids in Oasis montaj.

  • The Challenge: Manual conversion in the software would take days.
  • The Solution: A Python script using GeoPandas to read the SHP files and a custom writer to output the Geosoft-specific ASCII PLY structure.
  • The Result: All 500 masks are generated in seconds, with the correct "Inclusive" flag set in the file header.

Best Results

Requirement Recommended Method Key Benefit
Coordinate Accuracy geosoft.gxpy Handles Projection (.ipj) metadata automatically.
Speed / No License Manual ASCII Writing No Oasis montaj installation required.
3D Polygons Oasis montaj GDB PLY is primarily for 2D masking; use GDB for 3D.

FAQ

Why is my PLY file failing to load in Oasis montaj?

Check the first line of the file. A valid Geosoft ASCII PLY must start with the word poly. Additionally, ensure there are no empty lines between the coordinate pairs, as the Geosoft parser can be sensitive to whitespace.

Can Geosoft PLY files store multiple polygons?

Yes. A single .PLY file can contain multiple "inclusive" or "exclusive" blocks. Each block typically begins with a header line defining its type before the list of vertices.

Is Geosoft PLY the same as the .PLY used in Blender?

No. The Stanford PLY format (used in Blender/3D printing) describes vertices and faces for 3D meshes. The Geosoft PLY is a 2D GIS boundary format. Using a 3D library like plyfile will not work for Geosoft files.

Disclaimer

Geosoft file formats are proprietary to Seequent. While ASCII versions are easy to read, the internal binary structures and projection handling are best managed through the official GX API. Improper manual formatting may result in "invalid geometry" errors during gridding processes. Always test your exported PLY files in the Geosoft Viewer before full-scale deployment. March 2026.

Tags: Geosoft_Python, GIS_File_Formats, Exploration_Geophysics, Geosoft_PLY



What’s new

Close [x]
Loading special offers...