Data Transformations

This section provides some recipes for converting from one data format to another. Examples include: vector polygons to bitmaps or thematic rasters, bitmaps to vectors, DEMs to contours, LIDAR (.las) to raster DEM and more…

Convert bitmap to vector line or vector polygon layers

Takes an input bitmap segment and converts it to either a vector line or vector polygon layer. The output is written to a new file.

from pci.bit2line import bit2line
from pci.bit2poly import bit2poly

#Set input bitmap file and layer
bitmap_file = r"c:\input\bitmap.pix"
bitmap_layer = [2]

#Convert bitmap to vector lines
output_line = r"c:\output\lines.pix"
smooth_lines = "Yes"
format = "pix"
bit2line(fili=bitmap_file, dbib=bitmap_layer, filo=output_line, remedge="YES", smoothv=smooth_lines, ftype=format)

#Convert bitmap to vector polygons
output_poly = r"c:\output\polygons.shp"
smooth_poly = "Yes"
format = "shp" #output will be an ArcGIS shapefile
bit2poly(fili=bitmap_file, dbib=bitmap_layer, filo=output_poly, smoothv=smooth_poly, ftype=format)

Convert raster to vector line, vector polygon, vector point and bitmap layers

This recipe demonstrates how to convert a raster channel to various vector data types and an output bitmap.

from pci.ras2line import ras2line
from pci.ras2poly import ras2poly
from pci.ras2pnt import ras2pnt
from pci.ras2bit import ras2bit

#Set input raster file and layer
raster_file = r"c:\raster.pix"
raster_chan = [1]


#Convert raster channel to vector lines
output_line = r"c:\ras2lines.pix"
smooth_line = "Yes"
format = "pix"
ras2line(fili=raster_file, dbic=raster_chan, filo=output_line, remedge="yes", smoothv=smooth_line, ftype=format)


#Convert raster channel to vector polygons
output_poly = r"c:\ras2poly.shp"
smooth_poly = "Yes"
format = "shp" #output will be an ArcGIS shapefile
ras2poly(fili=raster_file, dbic=raster_chan, filo=output_poly, smoothv=smooth_poly, ftype=format)


#Convert raster channel to vector points
output_points = r"c:\ras2pnts.pix"
format = "shp"
ras2pnt(fili=raster_file, dbic=raster_chan, filo=output_points, ftype=format)


#Convert raster channel to bitmap
output_bitmap = r"c:\ras2bitmap.pix"
smooth_poly = "Yes"
format = "pix"
ras2bit(fili=raster_file, dbic=raster_chan, filo=output_bitmap, ftype=format)

Convert vector line layer to vector polygon, vector point and raster layers

This recipe demonstrates how to convert a vector line layer to various vector and raster data types.

from pci.line2poly import line2poly
from pci.line2pnt import line2pnt
from pci.line2ras import line2ras

#Set input vector line file and layer
line_file = r"c:\line.shp"
line_layer = [1]

#Convert vector line to vector polygon
output_poly = r"c:\line2poly.shp"
format = "shp"
line2poly(fili=line_file, dbvs=line_layer, filo=output_poly, ftype=format)

#convert vector line to vector points
output_points = r"c:\line2points.pix"
format = "pix"
convert_mthd = "vertices" #a unique point is placed on each vertex of each line
line2pnt(fili=line_file, dbvs=line_layer, filo=output_points, convmthd=convert_mthd, ftype=format)

#convert vector line to raster (burns values where the line exists into raster cells)
output_raster = r"c:\line2ras.pix"
format = "pix"
attr_field = "Num_of_lanes" #intersecting raster cells will be assigned a value based on the number of lanes in the road
connect = [8] #connect lines using all directions including diagonals
res = [1] #output raster set to 1m pixel resolution
line2ras(fili=line_file, dbvs=line_layer, filo=output_raster, fldnme=attr_field, connect=connect, pixres=res, ftype=format)

Convert vector polygon layer to vector line, vector point, bitmap and thematic raster layers

This recipe demonstrates how to convert a vector poylgon layer to various vector and raster data types.

Of particular interest, the final block demonstrates how to convert a polygon layer to a thematic raster (raster with attributes).

from pci.poly2line import poly2line
from pci.poly2pnt import poly2pnt
from pci.poly2bit import poly2bit
from pci.poly2ras import poly2ras

#Set input vector polygon file and layer
poly_file = r"C:\polygons.pix"
poly_layer = [12]

#Convert vector polygons to vector lines
output_line = r"C:\poly2line.shp"
format = "shp"
poly2line(fili=poly_file, dbvs=poly_layer, filo=output_line, ftype=format)

#convert vector polygons to vector points (does not create centroid, search cookbook for "centroid")
output_points = r"C:\poly2points.pix"
format = "pix"
poly2pnt(fili=poly_file, dbvs=poly_layer, filo=output_points, ftype=format)

#convert vector polygons to a bitmap
output_bitmap = r"C:\poly2bitmap.pix"
format = "pix"
res = [1]
poly2bit(fili=poly_file, dbvs=poly_layer, filo=output_bitmap, pixres=res, ftype=format)

#convert vector line to raster (burns values where the polygon exists into raster cells)
output_raster = r"C:\poly2thmras.pix"
format = "pix"
raster_type = "Thematic Raster"
attr_field = "class_num" #land use class number
res = [1] #output raster set to 1m pixel resolution
poly2ras(fili=poly_file, dbvs=poly_layer, filo=output_raster, imgtyp=raster_type, fldnme=attr_field, pixres=res, ftype=format)

Create raster DEM from various vector elevation layers

Interpolate a DEM from multiple vector sources, such as, contours, points and break-lines.

Note: the VDEMINGEST function discovers all valid input data in a directory.

from pci.vdemingest import vdemingest
from pci.vdemsetup import vdemsetup
from pci.vdemint import vdemint

#ingests the points, contours and breaklines from the following directories into a .pix file
points = r"C:\points"
contours = r"C:\lines"
break_lines = r"C:\breaklines"
pix_vector = r"C:\output\ingest_vectors.pix"
map_units    = "UTM 17 D000"
vdemingest(points=points, contours=contours, breaklin=break_lines, filv=pix_vector, mapunits=map_units)

#setup the vector files for interpolation into a raster DEM
index_file = r"c:\output\dem_from_vectors.txt"   # output index file, used by VDEMINT
dem_res = [1,1]
vdemsetup(filv=pix_vector, indexfil=index_file, demtype="PIX", dempxsz=dem_res)

#interpolate the LIDAR point cloud
vdemint(file=index_file, dboc=[1], filv=pix_vector, memsize=[1024])

Create raster DEM from LIDAR points (.las)

This recipe creates a 1m (GSD) raster DEM from lidar return points stored in a .las file.

from pci.vdemingest import vdemingest
from pci.vdemsetup import vdemsetup
from pci.vdemint import vdemint

#ingests the LIDAR point cloud (.las) into a working format (.pix)
lidar_point_cloud = r"C:\lidar\lidar_cloud.las"
lidar_return = "RETURNALL" #uses all lidar returns in the .las file
pix_vector = r"C:\lidar\lidar_vector.pix"
map_units    = "UTM 17 D000"
vdemingest(points=lidar_point_cloud, elevopts=lidar_return, filv=pix_vector, mapunits=map_units)


#setup the vector files for interpolation into a raster DEM
index_file = r"C:\lidar\lidar_dem.txt"   # output index file, used by VDEMINT
dem_res = [1,1]
vdemsetup(filv=lidar_point_cloud, indexfil=index_file, demtype="PIX", dempxsz=dem_res, elevunit="METER")


#interpolate the LIDAR point cloud
vdemint(file=index_file, dboc=[1], filv=pix_vector, memsize=[1024])

Generate contours from raster DEM

This recipe uses a single function to generate contour vectors from a raster DEM.

from pci.contour import contour

dem_file = r"D:\Data\Test\irvine.pix"
contour(file=dem_file, dbec=[11], dbsn="Contours", dbsd="Contours", contint=[10], backval=[-32768], fldnme="Elevation")