PointSetIO Basics

This example demonstrates the basic usage of the PointSetIO class.

import tempfile
from pathlib import Path

import pandas as pd
import geopandas as gpd
import pyvista as pv

from omf_io.pointset import PointSetIO
from omf_io.reader import OMFReader

Load a PointSet

Load a point set from a OMF file

pointset_io: PointSetIO = PointSetIO.from_omf(omf_input=Path('../assets/copper_deposit.omf'),
                                              pointset_name='collar')

pointset_io.data.head(10)
holeid holeid_color
x y z
445198.219 494110.594 3057.757537 WP001 (61, 255, 61)
445196.625 494109.656 3054.265408 WP002 (255, 255, 96)
445260.563 493860.719 3009.038328 WP003 (255, 25, 25)
445203.344 493720.656 3033.777664 WP004 (255, 132, 193)
445291.563 493566.219 2957.434730 WP005 (158, 255, 61)
445294.031 493886.813 2970.848677 WP006 (255, 175, 96)
445296.594 493890.250 2974.079767 WP007 (255, 168, 168)
445460.813 493321.156 2979.143623 WP008 (96, 96, 255)
445452.313 493402.188 2980.300987 WP009 (61, 61, 255)
445427.219 493523.688 2978.657715 WP010 (255, 193, 132)


Demonstrate conversions

Exercise the PointSetIO class with various conversions

CSV file

point_data: pd.DataFrame = pointset_io.data.head(10)
out_filepath: Path = Path(tempfile.gettempdir()) / 'pointset_data.csv'
csv_filepath: Path = PointSetIO(data=point_data).to_csv(out_filepath)

# read and print the csv
csv_point_data = pd.read_csv(csv_filepath)
csv_point_data
x y z holeid holeid_color
0 445198.219 494110.594 3057.757537 WP001 (61, 255, 61)
1 445196.625 494109.656 3054.265408 WP002 (255, 255, 96)
2 445260.563 493860.719 3009.038328 WP003 (255, 25, 25)
3 445203.344 493720.656 3033.777664 WP004 (255, 132, 193)
4 445291.563 493566.219 2957.434730 WP005 (158, 255, 61)
5 445294.031 493886.813 2970.848677 WP006 (255, 175, 96)
6 445296.594 493890.250 2974.079767 WP007 (255, 168, 168)
7 445460.813 493321.156 2979.143623 WP008 (96, 96, 255)
8 445452.313 493402.188 2980.300987 WP009 (61, 61, 255)
9 445427.219 493523.688 2978.657715 WP010 (255, 193, 132)


Pandas DataFrame object

df: pd.DataFrame = PointSetIO(data=point_data).to_pandas()
df
holeid holeid_color
x y z
445198.219 494110.594 3057.757537 WP001 (61, 255, 61)
445196.625 494109.656 3054.265408 WP002 (255, 255, 96)
445260.563 493860.719 3009.038328 WP003 (255, 25, 25)
445203.344 493720.656 3033.777664 WP004 (255, 132, 193)
445291.563 493566.219 2957.434730 WP005 (158, 255, 61)
445294.031 493886.813 2970.848677 WP006 (255, 175, 96)
445296.594 493890.250 2974.079767 WP007 (255, 168, 168)
445460.813 493321.156 2979.143623 WP008 (96, 96, 255)
445452.313 493402.188 2980.300987 WP009 (61, 61, 255)
445427.219 493523.688 2978.657715 WP010 (255, 193, 132)


GeoPandas geodataframe object

gdf: gpd.geodataframe = PointSetIO(data=point_data).to_geopandas()
gdf
holeid holeid_color geometry
0 WP001 (61, 255, 61) POINT Z (445198.219 494110.594 3057.758)
1 WP002 (255, 255, 96) POINT Z (445196.625 494109.656 3054.265)
2 WP003 (255, 25, 25) POINT Z (445260.563 493860.719 3009.038)
3 WP004 (255, 132, 193) POINT Z (445203.344 493720.656 3033.778)
4 WP005 (158, 255, 61) POINT Z (445291.563 493566.219 2957.435)
5 WP006 (255, 175, 96) POINT Z (445294.031 493886.813 2970.849)
6 WP007 (255, 168, 168) POINT Z (445296.594 493890.25 2974.08)
7 WP008 (96, 96, 255) POINT Z (445460.813 493321.156 2979.144)
8 WP009 (61, 61, 255) POINT Z (445452.313 493402.188 2980.301)
9 WP010 (255, 193, 132) POINT Z (445427.219 493523.688 2978.658)


PLY file

ply_filepath: Path = PointSetIO(data=point_data).to_ply(out_filepath.with_suffix('.ply'), binary=False)

# read and print the PLY using file.open
with ply_filepath.open('r') as f:
    ply_data = f.readlines()
print(''.join(ply_data))
ply
format ascii 1.0
element vertex 10
property float x
property float y
property float z
property object holeid
property object holeid_color
end_header
445198.219 494110.594 3057.757537 WP001 (61, 255, 61)
445196.625 494109.656 3054.265408 WP002 (255, 255, 96)
445260.563 493860.719 3009.038328 WP003 (255, 25, 25)
445203.344 493720.656 3033.777664 WP004 (255, 132, 193)
445291.563 493566.219 2957.43473 WP005 (158, 255, 61)
445294.031 493886.813 2970.848677 WP006 (255, 175, 96)
445296.594 493890.25 2974.079767 WP007 (255, 168, 168)
445460.813 493321.156 2979.143623 WP008 (96, 96, 255)
445452.313 493402.188 2980.300987 WP009 (61, 61, 255)
445427.219 493523.688 2978.657715 WP010 (255, 193, 132)

PyVista Polydata object

poly: pv.PolyData = PointSetIO(data=point_data).to_pyvista()
poly.point_data
pyvista DataSetAttributes
Association     : POINT
Active Scalars  : None
Active Vectors  : None
Active Texture  : None
Active Normals  : None
Contains arrays :
    holeid                  <U5        (10,)
    holeid_color            <U15       (10,)

OMF file

omf_filepath: Path = PointSetIO(data=point_data).to_omf(element_name='collar_top_10',
                                                        output_file=out_filepath.with_suffix('.omf'))

View the OMF elements

omfr: OMFReader = OMFReader(filepath=out_filepath.with_suffix('.omf'))
omfr.element_types
{'collar_top_10': 'PointSet'}

Total running time of the script: (0 minutes 0.236 seconds)

Gallery generated by Sphinx-Gallery