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(bitmap_file, bitmap_layer, output_line, "YES", smooth_lines, "", format, "")


#Convert bitmap to vector polygons
output_poly = r"c:\output\polygon_shp\polygons.shp"
smooth_poly = "Yes"
format = "shp" #output will be an ArcGIS shapefile

bit2poly(bitmap_file, bitmap_layer, output_poly, smooth_poly, "", 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(raster_file, raster_chan, output_line, "yes", smooth_line, "", 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(raster_file, raster_chan, output_poly, smooth_poly, "", format, "")


#Convert raster channel to vector points
output_points = r"c:\ras2pnts.pix"
format = "shp"

ras2pnt(raster_file, raster_chan, output_points, "", format, "")


#Convert raster channel to bitmap
output_bitmap = r"c:\ras2bitmap.pix"
smooth_poly = "Yes"
format = "pix"

ras2bit(raster_file, raster_chan, output_bitmap, "", 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(line_file, line_layer, output_poly, "", 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(line_file, line_layer, output_points, convert_mthd, "", 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(line_file, line_layer, output_raster, [], attr_field, [], connect,
         res, 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(poly_file, poly_layer, output_line, "", format, "")


#convert vector polygons to vector points (does not create centroid, search cookbook for "centroid")
output_points = r"C:\poly2points.pix"
format = "pix"

poly2pnt(poly_file, poly_layer, output_points, "", format, "")


#convert vector polygons to a bitmap
output_bitmap = r"C:\poly2bitmap.pix"
format = "pix"
res = [1]

poly2bit(poly_file, poly_layer, output_bitmap, "", res, 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(poly_file, poly_layer, output_raster, [], raster_type,
         attr_field, res, format, "")

Automatically collect GCP points and convert to Chip Database - Partial Workflow

This example demonstrates how to automatically collect GCPs on an image and create a chip database from the GCP points, using the geographically accurate reference image as the base

#UNDER CONSTRUCTION

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, contours, break_lines, "", "", [], "",
            "", "", pix_vector, 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( pix_vector, index_file, "PIX", "",
           dem_res, [], "", [], "" )


#interpolate the LIDAR point cloud
maxiter = [20] # max 20 smoothing iterations
memsize= [1024] # use 2048 MB (~2GB) of memory

vdemint( index_file, [1], [], pix_vector, [], [], "", maxiter, memsize )

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( lidar_point_cloud, "", "", "", lidar_return, [], "",
            "", "", pix_vector, 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( lidar_point_cloud, index_file, "PIX", "",
           dem_res, [], "", [], "" )


#interpolate the LIDAR point cloud
maxiter = [20] # max 20 smoothing iterations
memsize= [2048] # use 2048 MB (~2GB) of memory

vdemint( index_file, [1], [], pix_vector, [], [], "", maxiter, memsize )

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"C:\dem.pix"
elev_chan = [1]
contour_layer_name = "Contours"
contour_interval = [10] #10m intervals between contour lines
dem_no_data = [-32768] #no data value set for inptu DEM
contour_field = "Elevation"

contour(dem_file, elev_chan, [], contour_layer_name,
        "", contour_interval, [], contour_field)