# shenyih0ng/ovr2shp architecture

> Architecture diagram of the GitHub repository shenyih0ng/ovr2shp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shenyih0ng/ovr2shp
- Repository: https://github.com/shenyih0ng/ovr2shp

## Overview

##### Project type and purpose
- This is an open-source command-line conversion tool (`ovr2shp`) written in C++ that reads ERDAS HFA annotation layers (`.ovr`) and outputs vector formats (Shapefile, GeoJSON). It also optionally visualizes geometries via gnuplot on Linux.

##### File structure
- Top-level:
- ovr2shp.cpp/.h   → CLI front-end and main conversion logic
- hfa/             → C++ modules for parsing ERDAS HFA file internals (hfaopen, hfaband, hfadictionary, etc.)
- data/            → sample input files (e.g., colorscale.ovr)
- docs/            → PDF documentation on HFA internals
- build scripts    → Makefile, Dockerfile, shell/batch scripts for Windows and Linux
- logging.h        → centralized logging interface
- No separate frontend/backend – it’s a single executable with clear modules.

##### README
- Confirms conversion focus, references GDAL’s approach to HFA, and notes use of gnuplot-iostream for visualization.

##### Components
a. Main components
1. CLI Layer (ovr2shp.cpp)
2. HFA Parser Library (hfa/* modules)
3. Geometry Extraction & SRS Handling (hfafield, hfasrs)
4. Output Writers
– Shapefile writer
– GeoJSON writer
5. Visualization Module (gnuplot-iostream) [optional]
6. Logging Module
7. Build & Deployment (Makefile, Docker, VS build scripts)
8. External Dependencies (GDAL headers if used, gnuplot binary)

b. Relationships and interactions
- User invokes CLI → passes input path + flags → CLI Layer
- CLI Layer calls HFA Parser → produces in-memory annotation objects
- Parser hands objects to Geometry Extraction → builds coordinate arrays & attributes
- Geometry data flows to Output Writers → writes .shp/.geojson to disk
- (Optional) Geometry data also piped to gnuplot for visualization
- All modules use central Logging interface to emit status/errors
- Build & Deployment orchestrates compilation of parser library + CLI into one executable

c. Architectural patterns / design principles
- Modular C++ library for HFA internals (separation of parsing, data models, I/O)
- Single-responsibility: each hfa/*.cpp handles one aspect (compression, dictionary, entry, etc.)
- Cross-platform build support (Makefile, Docker, Windows bat scripts)

d. Key technologies/frameworks
- C++17 (or similar)
- gnuplot + gnuplot-iostream for on-the-fly visualization
- Make, Docker, Windows build scripts
- (Potential) GDAL APIs or custom Shapefile/GeoJSON writer

##### Details to capture
- Sample data directory feeding into tests or CLI invocation
- Optional visualization path
- Versions or key config files (e.g., Dockerfile, .clang-format) near build component

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Input"
        SampleData["Sample Data"]:::external
    end

    subgraph "Core Pipeline"
        CLI["CLI Layer"]:::io
        Parser["HFA Parser Library"]:::internal
        Extractor["Geometry Extraction & SRS Handling"]:::internal
        Writers["Output Writers"]:::io
        Visualization["Visualization Module (gnuplot)"]:::external
        Logging["Logging Module"]:::aux
    end

    subgraph "Build & Deployment"
        MakefileNode["Makefile"]:::aux
        DockerfileNode["Dockerfile"]:::aux
        DockerignoreNode[".dockerignore"]:::aux
        BuildDebSh["build_dep.sh"]:::aux
        BuildDebBat["build_dep.bat"]:::aux
        MakefileVC["makefile.vc"]:::aux
        WinSetupBat["win_setup.bat"]:::aux
        Exe["ovr2shp Executable"]:::io
    end

    subgraph "Documentation"
        Docs["Documentation"]:::aux
    end

    ExternalDeps["External Dependencies\n(GDAL headers, gnuplot binary)"]:::external

    SampleData -->|"input .ovr"| CLI
    CLI -->|"HFA binary stream"| Parser
    Parser -->|"annotation objects"| Extractor
    Extractor -->|"geometry data"| Writers
    Extractor -->|"geometry data"| Visualization
    CLI --> Logging
    Parser --> Logging
    Extractor --> Logging
    Writers --> Logging
    Visualization --> Logging

    ExternalDeps --> CLI
    ExternalDeps --> Visualization

    MakefileNode --> Exe
    DockerfileNode --> Exe
    DockerignoreNode --> Exe
    BuildDebSh --> Exe
    BuildDebBat --> Exe
    MakefileVC --> Exe
    WinSetupBat --> Exe

    Exe --> CLI

    SampleData --> Docs

    classDef internal fill:#ADD8E6,stroke:#000
    classDef io fill:#90EE90,stroke:#000
    classDef external fill:#FFD700,stroke:#000
    classDef aux fill:#D3D3D3,stroke:#000

    click CLI "https://github.com/shenyih0ng/ovr2shp/blob/dev/ovr2shp.cpp"
    click Parser "https://github.com/shenyih0ng/ovr2shp/tree/dev/hfa/"
    click Extractor "https://github.com/shenyih0ng/ovr2shp/blob/dev/hfa/hfafield.cpp"
    click Extractor "https://github.com/shenyih0ng/ovr2shp/blob/dev/hfa/hfasrs.cpp"
    click Logging "https://github.com/shenyih0ng/ovr2shp/blob/dev/logging.h"
    click MakefileNode "https://github.com/shenyih0ng/ovr2shp/tree/dev/Makefile"
    click DockerfileNode "https://github.com/shenyih0ng/ovr2shp/tree/dev/Dockerfile"
    click DockerignoreNode "https://github.com/shenyih0ng/ovr2shp/blob/dev/.dockerignore"
    click BuildDebSh "https://github.com/shenyih0ng/ovr2shp/blob/dev/build_dep.sh"
    click BuildDebBat "https://github.com/shenyih0ng/ovr2shp/blob/dev/build_dep.bat"
    click MakefileVC "https://github.com/shenyih0ng/ovr2shp/blob/dev/makefile.vc"
    click WinSetupBat "https://github.com/shenyih0ng/ovr2shp/blob/dev/win_setup.bat"
    click SampleData "https://github.com/shenyih0ng/ovr2shp/tree/dev/data/"
    click Docs "https://github.com/shenyih0ng/ovr2shp/tree/dev/docs/"
```
