Files & Layers

This section provides details about creating and modifying .pix files (Geomatica’s working file format). Recipes in this section also demonstrate how to import foreign file formats into .pix and conversely, exporting .pix files to foreign file formats.

The PCIDSK (.pix) file format is a very powerful, flexible and clean file format. As a database file, it can store hundreds of raster channels of varying bit-depths, vector segments, bitmaps and many other segment types in a single file. Unlike flat files where projection, attribute information, metadata and imagery/vectors are all stored in separate files, the pix file holds everything in one, easy to use file.

Create .pix (PCIDSK) file with empty channels defined

This recipe demonstrates how to create a projected .pix file with empty image channels defined. Imagery can then be directly copied into these empty channels.

from pci.cimpro2 import cimpro2

new_file = r"C:\FilesLayer\empty_file.pix"
create_channels = [4, 0, 1, 2] #creates 4 8bit, 0 16bit signed, 1 16bit unsigned and 2 32bit real channels
extents = ["514418.000", "5262616.000", "527908.000", "5246564.000"] #List of ULX, ULY, LRX and LRY values
res= "2.0"

cimpro2(file=new_file, dbnc=create_channels, dblayout="PIXEL", project="UTM", zone=[55], row="G", ellips="D000",
        llbound="N", ulx=extents[0], uly=extents[1], lrx=extents[2], lry=extents[3], bxpxsz="2", bypxsz="2")

Create .pix (PCIDSK) file with no projection defined

This recipe creates a .pix file with empty channels defined by pixels and lines, but a coordinate system is not defined.

from pci.cim import cim

new_file = r"D:\Data\Test\empty_file.pix"
create_channels = [7, 1, 2, 5]  # Creates 7 8bit, 1 16bit signed, 2 16bit unsigned and 5 32bit real channels

cim(file=new_file, dbsz=[1024, 1024], pxsz=[15, 15], dbnc=create_channels, dblayout="PIXEL")

Add or delete new channel to an existing .pix file

This recipe demonstrates how to quickly add or delete a 8bit, 16bit unsigned, 16bit signed and/or 32bit floating point channels to an existing .pix file. This can be very useful for when building custom models.

from pci.pcimod import pcimod

#Add new image channels to existing file
new_file = r"c:\data\image.pix"
channels = [4, 0, 3, 1] #add 4 8bit, 0 16bit signed, 3 16bit unsigned and 1 32bit real channels

pcimod(file=new_file, pciop="ADD", pcival=channels)

#delete image channel(s) from existing file
new_file = r"c:\data\image.pix"
channels = [1, 4, 6] #delete channels 1, 4 and 6

pcimod(file=new_file, pciop="DEL", pcival=channels)

Copy image channels to an existing file with different projection

This recipe demonstrates how to copy a raster channel from one file to another with different projections. It requires that the user reproject the source image to the same projection and bounds as the destination image, create an empty channel in the destination file and finally, copy the pixels.

from pci.pcimod import pcimod
from pci.iii import iii
from pci.reproj import reproj

source_file = r"c:\data\ndvi_1.pix"
destination_file = r"c:\data\ndvi_2.pix"

#Add a single 32 bit channel to destination file
pcimod(file=destination_file, pciop="ADD", pcival=[0,0,0,1])

#reproject the source channel to the same projection and extents of destination file

#Note: It is required to know the projection information of the
#destination file. You can get the georeferencing information by running PROREP in terminal

ndvi_channel = [5] #NDVI was calculated for this image and is stored in channel 5
reproj_file = r"c:\data\ndvi_1_temp_reproj.pix"
reproj_method = "BR" #Bounds and resolutions are unchanged, calculates pixels and lines
extents = ["514418.000", "5262616.000", "527908.000", "5246564.000"]

reproj(fili=source_file, dbic=ndvi_channel, filo=reproj_file, repmeth=reproj_method, pxsz=[2.0, 2.0], maxbnds="NO",
        mapunits="UTM 55 G D000", llbounds="N", ulx=extents[0], uly=extents[1], lrx=extents[2], lry=extents[3])

#copy image channel
iii(fili=reproj_file, filo=destination_file, dbic=[1], dboc=[6])

Export rasters or vectors to different file formats

This recipe demonstrates how to export rasters and vectors from the .pix format to another file format, such as, .shp, .tif, etc.

from pci.fexport import fexport

#export image raster(s) to jpeg2000 format
pix_file = r"D:\kompsat-2.pix"
jp2_file = r"C:\kompsat-2.jp2"
compression = "10" #10% compression applied to output file

fexport(fili=pix_file, filo=jp2_file, dbic=[1,2,3,4], ftype="jp2", foptions=compression)

#export vector layer
pix_file = r"c:\data\vector.pix"
shp_file = r"c:\data\vector.shp"
vector_layer = [2]
format = "shp"

fexport(fili=pix_file, filo=shp_file, dbvs=[2], ftype="shp")