Task 162: .E File Format

Task 162: .E File Format

  1. The specifications for the .E file format, identified as the ArcInfo Interchange File Format (commonly with extension .E00), are an ASCII-based format used for exchanging ArcInfo coverages, grids, TINs, and associated INFO tables. The format can be uncompressed, partially compressed, or fully compressed. The structure includes multiple sections for different data types, such as arcs, polygons, labels, and INFO tables. The key properties intrinsic to this file format are as follows:
  • The file begins with a line containing three fields and ends with a line beginning 'EOS'.
  • ARC files are included first, in a specific order, followed by INFO files in alphabetical order.
  • Precision is indicated by '2' for single-precision or '3' for double-precision.
  • Sections and headers include ARC, CNT, LAB, LOG, PAL, PRJ, SIN, TOL, TX6, TX7, RXP, RPL, and IFO.
  • ARC: Arc coordinates and topology, with repeating sets of arc information.
  • CNT: Polygon centroid coordinates, with polygon ID and coordinates.
  • LAB: Label points, with label number, polygon ID, and coordinates.
  • LOG: Coverage history, with free-form lines.
  • PAL: Polygon topology, with polygon number and bounding box, followed by arcs.
  • PRJ: Projection parameters, with keywords and values.
  • SIN: Spatial index, usually 'EOX'.
  • TOL: Tolerances, with ten lines of tolerance types and values.
  • TX6, TX7, RXP, RPL: Start with identifier and end with "JABBERWOCKY", containing sub-sections.
  • INFO: Begins with 'IFO 2' and ends with 'EOI', with filename.
  • No magic number, but identifiable by the initial line format (e.g., 'EXP 0' or 'ARC 2').
  • Structure is text-based, with fixed-field widths and repeating records.
  • Compression (if present) is a proprietary run-length encoding using '~' as a marker for repeated sequences.
  1. Two direct download links for .E00 files are:
  1. The following is an embedded HTML and JavaScript code for a simple webpage (suitable for a Ghost blog or similar platform) that allows a user to drag and drop a .E file (assumed .E00) and dumps the properties to the screen by parsing sections and printing key elements such as precision, section types, and basic content.
.E File Parser

Drag and Drop .E File

Drop .E file here
  1. The following is a Python class that can open, decode, read, write, and print the properties of a .E file (assumed .E00). It reads the file as text, identifies key sections, and prints them. For write, it creates a basic uncompressed E00 structure.
class EFileParser:
    def __init__(self, filepath):
        self.filepath = filepath
        self.lines = None
        self.precision = 'Unknown'
        self.sections = []

    def open_and_read(self):
        with open(self.filepath, 'r') as f:
            self.lines = f.readlines()
        self.decode()

    def decode(self):
        if not self.lines:
            return
        for line in self.lines:
            if line.startsWith('EXP'):
                parts = line.split()
                if len(parts) > 2:
                    self.precision = 'Single' if parts[2] == '2' else 'Double'
            elif line.strip().match(r'^[A-Z]{3}\s+[23]$'):
                self.sections.append(line.strip())

    def print_properties(self):
        print("Properties of .E file:")
        print(f"File path: {self.filepath}")
        print(f"Number of lines: {len(self.lines) if self.lines else 0}")
        print(f"Precision: {self.precision}")
        print("Sections found:", ', '.join(self.sections))

    def write(self, new_filepath):
        with open(new_filepath, 'w') as f:
            f.write('EXP  0\n')
            f.write('ARC  2\n')
            f.write('EOS\n')
        print(f"Basic .E file written to {new_filepath}")

# Example usage:
# parser = EFileParser('example.e00')
# parser.open_and_read()
# parser.print_properties()
# parser.write('new.e00')
  1. The following is a Java class that can open, decode, read, write, and print the properties of a .E file (assumed .E00). It uses BufferedReader for reading and PrintWriter for writing.
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class EFileParser {
    private String filepath;
    private List<String> lines;
    private String precision = "Unknown";
    private List<String> sections = new ArrayList<>();

    public EFileParser(String filepath) {
        this.filepath = filepath;
        this.lines = new ArrayList<>();
    }

    public void openAndRead() throws IOException {
        try (BufferedReader reader = new BufferedReader(new FileReader(filepath))) {
            String line;
            while (line = reader.readLine() != null) {
                lines.add(line);
            }
        }
        decode();
    }

    private void decode() {
        for (String line : lines) {
            if (line.startsWith("EXP")) {
                String[] parts = line.split("\\s+");
                if (parts.length > 2) {
                    precision = "2".equals(parts[2]) ? "Single" : "Double";
                }
            } else if (line.trim().matches("^[A-Z]{3}\\s+[23]$")) {
                sections.add(line.trim());
            }
        }
    }

    public void printProperties() {
        System.out.println("Properties of .E file:");
        System.out.println("File path: " + filepath);
        System.out.println("Number of lines: " + lines.size());
        System.out.println("Precision: " + precision);
        System.out.println("Sections found: " + String.join(", ", sections));
    }

    public void write(String newFilepath) throws IOException {
        try (PrintWriter writer = new PrintWriter(newFilepath)) {
            writer.println("EXP  0");
            writer.println("ARC  2");
            writer.println("EOS");
        }
        System.out.println("Basic .E file written to " + newFilepath);
    }

    // Example usage:
    // public static void main(String[] args) throws IOException {
    //     EFileParser parser = new EFileParser("example.e00");
    //     parser.openAndRead();
    //     parser.printProperties();
    //     parser.write("new.e00");
    // }
}
  1. The following is a JavaScript class that can open, decode, read, write, and print the properties of a .E file (assumed .E00). It uses FileReader for reading and Blob for writing (download).
class EFileParser {
    constructor() {
        this.lines = [];
        this.precision = 'Unknown';
        this.sections = [];
    }

    openAndRead(file, callback) {
        const reader = new FileReader();
        reader.onload = (e) => {
            this.lines = e.target.result.split('\n');
            this.decode();
            callback();
        };
        reader.readAsText(file);
    }

    decode() {
        this.lines.forEach(line => {
            if (line.startsWith('EXP')) {
                const parts = line.split(/\s+/);
                if (parts.length > 2) {
                    this.precision = parts[2] === '2' ? 'Single' : 'Double';
                }
            } else if (line.trim().match(/^[A-Z]{3}\s+[23]$/)) {
                this.sections.push(line.trim());
            }
        });
    }

    printProperties() {
        console.log('Properties of .E file:');
        console.log('Number of lines:', this.lines.length);
        console.log('Precision:', this.precision);
        console.log('Sections found:', this.sections.join(', '));
    }

    write(filename) {
        const content = 'EXP  0\nARC  2\nEOS\n';
        const blob = new Blob([content], {type: 'text/plain'});
        const url = URL.createObjectURL(blob);
        const a = document.createElement('a');
        a.href = url;
        a.download = filename;
        a.click();
        URL.revokeObjectURL(url);
        console.log('Basic .E file written and downloaded as', filename);
    }
}

// Example usage:
 // const parser = new EFileParser();
 // parser.openAndRead(fileObject, () => parser.printProperties());
 // parser.write('new.e00');
  1. The following is a C++ class that can open, decode, read, write, and print the properties of a .E file (assumed .E00). It uses fstream for reading and writing.
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <regex>

class EFileParser {
private:
    std::string filepath;
    std::vector<std::string> lines;
    std::string precision = "Unknown";
    std::vector<std::string> sections;

public:
    EFileParser(std::string fp) : filepath(fp) {}

    void openAndRead() {
        std::ifstream file(filepath);
        if (file.is_open()) {
            std::string line;
            while (std::getline(file, line)) {
                lines.push_back(line);
            }
            file.close();
            decode();
        } else {
            std::cout << "Unable to open file" << std::endl;
        }
    }

    void decode() {
        for (const auto& line : lines) {
            if (line.find("EXP") == 0) {
                std::istringstream iss(line);
                std::string token;
                std::vector<std::string> parts;
                while (iss >> token) {
                    parts.push_back(token);
                }
                if (parts.size() > 2) {
                    precision = (parts[2] == "2") ? "Single" : "Double";
                }
            } else if (std::regex_match(line, std::regex("^\\s*[A-Z]{3}\\s+[23]\\s*$"))) {
                sections.push_back(line);
            }
        }
    }

    void printProperties() {
        std::cout << "Properties of .E file:" << std::endl;
        std::cout << "File path: " << filepath << std::endl;
        std::cout << "Number of lines: " << lines.size() << std::endl;
        std::cout << "Precision: " << precision << std::endl;
        std::cout << "Sections found: ";
        for (size_t i = 0; i < sections.size(); ++i) {
            std::cout << sections[i];
            if (i < sections.size() - 1) std::cout << ", ";
        }
        std::cout << std::endl;
    }

    void write(std::string newFilepath) {
        std::ofstream file(newFilepath);
        if (file.is_open()) {
            file << "EXP  0" << std::endl;
            file << "ARC  2" << std::endl;
            file << "EOS" << std::endl;
            file.close();
            std::cout << "Basic .E file written to " << newFilepath << std::endl;
        } else {
            std::cout << "Unable to write file" << std::endl;
        }
    }
};

// Example usage:
 // int main() {
 //     EFileParser parser("example.e00");
 //     parser.openAndRead();
 //     parser.printProperties();
 //     parser.write("new.e00");
 //     return 0;
 // }