Note
Go to the end to download the full example code.
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)
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
Pandas DataFrame object
df: pd.DataFrame = PointSetIO(data=point_data).to_pandas()
df
GeoPandas geodataframe object
gdf: gpd.geodataframe = PointSetIO(data=point_data).to_geopandas()
gdf
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)