# erikfva/upload-shapefile-to-postgis architecture

> Architecture diagram of the GitHub repository erikfva/upload-shapefile-to-postgis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/erikfva/upload-shapefile-to-postgis
- Repository: https://github.com/erikfva/upload-shapefile-to-postgis

## Overview

#### Purpose and Entry Points

This is a small PHP utility for uploading ESRI Shapefile data into a PostgreSQL/PostGIS database. The HTTP-facing entry point is likely `uploadshp.php`; shapefile parsing and database loading logic are concentrated in `shpparser/shpparser.php`.

#### Upload Boundary

`uploadshp.php` is the likely request/upload boundary. It should receive uploaded shapefile-related inputs, establish the processing context, and invoke the parser/importer. This is the main separation between web-server request handling and geospatial ingestion.

Grounding:
- `uploadshp.php`
- `README.md`

#### Shapefile Parsing Layer

The `shpparser` directory contains the binary Shapefile reader. `ShapeFile.inc.php` likely defines Shapefile structures, constants, or record-reading primitives, while `shpparser.php` orchestrates parsing of geometry and attributes.

Grounding:
- `shpparser/ShapeFile.inc.php`
- `shpparser/shpparser.php`

#### Import Orchestration

`shpparser/shpparser.php` is the primary application component: it likely opens the uploaded `.shp` dataset, iterates records, converts geometry into a PostGIS-compatible representation, and persists each feature. It is the key control-flow bridge between file parsing and database writes.

Grounding:
- `shpparser/shpparser.php`
- `shpparser/ShapeFile.inc.php`

#### Data Flow

Primary flow:

1. A client submits a shapefile upload through `uploadshp.php`.
2. Upload handling passes the file or path to the shapefile parser.
3. The parser reads Shapefile binary records and associated feature data.
4. Parsed geometries are translated into a representation accepted by PostGIS.
5. Feature records are inserted into PostgreSQL/PostGIS.

The crucial boundary is from filesystem-uploaded binary geospatial data to SQL/PostGIS persistence; validation, coordinate interpretation, and escaping are material concerns at this transition.

#### Runtime and Infrastructure

The application runs on PHP and requires a web-server PHP runtime for the upload path. Its external persistence dependency is PostgreSQL with the PostGIS extension enabled. The importer also depends on the uploaded Shapefile dataset being available to PHP; complete datasets commonly include related sidecar files even though only parser sources are present in this repository.

Grounding:
- `uploadshp.php`
- `shpparser/shpparser.php`

#### Legacy/Reference Artifact

`shpparser/shpparser.php.bak` is a backup copy of the importer and should not be treated as an active execution path unless the upload script explicitly references it. The active parser implementation should be considered `shpparser/shpparser.php`.

Grounding:
- `shpparser/shpparser.php`
- `shpparser/shpparser.php.bak`

Main entry points: [`shpparser/shpparser.php`](https://github.com/erikfva/upload-shapefile-to-postgis/blob/master/shpparser/shpparser.php) (Shapefile importer), [`uploadshp.php`](https://github.com/erikfva/upload-shapefile-to-postgis/blob/master/uploadshp.php) (Upload entry point), [`shpparser/ShapeFile.inc.php`](https://github.com/erikfva/upload-shapefile-to-postgis/blob/master/shpparser/ShapeFile.inc.php) (Shapefile reader primitives)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["PHP Upload Runtime"]
  node_upload["Upload entry point<br/>PHP request handler<br/>[uploadshp.php]"]
  node_dataset["Uploaded shapefile dataset<br/>filesystem input"]
end

subgraph group_parser["Shapefile Import"]
  node_importer["Shapefile importer<br/>PHP import orchestrator<br/>[shpparser.php]"]
  node_reader["Shapefile reader primitives<br/>PHP binary reader<br/>[ShapeFile.inc.php]"]
  node_features["Parsed features<br/>geometry and attributes"]
end

subgraph group_storage["Geospatial Storage"]
  node_postgis[("PostgreSQL / PostGIS<br/>geospatial database")]
end

node_client(("Upload client<br/>external client"))

node_client -->|"submits upload"| node_upload
node_upload -->|"makes available"| node_dataset
node_upload -->|"invokes"| node_importer
node_dataset -->|"file path / data"| node_importer
node_importer -->|"uses"| node_reader
node_reader -->|"reads records"| node_features
node_importer -->|"interprets geometry"| node_features
node_features -->|"inserts PostGIS features"| node_postgis

click node_upload "https://github.com/erikfva/upload-shapefile-to-postgis/blob/master/uploadshp.php"
click node_importer "https://github.com/erikfva/upload-shapefile-to-postgis/blob/master/shpparser/shpparser.php"
click node_reader "https://github.com/erikfva/upload-shapefile-to-postgis/blob/master/shpparser/ShapeFile.inc.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_upload,node_dataset toneBlue
class node_importer,node_reader,node_features toneAmber
class node_postgis toneMint
class node_client toneNeutral
```

## Components

### PHP Upload Runtime

- [Upload entry point](https://github.com/erikfva/upload-shapefile-to-postgis/blob/master/uploadshp.php): PHP request handler · Receives uploads and starts the import. · `uploadshp.php`
- **Uploaded shapefile dataset**: filesystem input · Binary .shp data with required sidecar files.

### Shapefile Import

- [Shapefile importer](https://github.com/erikfva/upload-shapefile-to-postgis/blob/master/shpparser/shpparser.php): PHP import orchestrator · Iterates features, converts geometry, and persists records. · `shpparser/shpparser.php`
- [Shapefile reader primitives](https://github.com/erikfva/upload-shapefile-to-postgis/blob/master/shpparser/ShapeFile.inc.php): PHP binary reader · Defines shapefile structures and record-reading primitives. · `shpparser/ShapeFile.inc.php`
- **Parsed features**: geometry and attributes

### Geospatial Storage

- **PostgreSQL / PostGIS**: geospatial database · Stores imported feature records and geometries.

### Other components

- **Upload client**: external client

## Connections

- Upload client → Upload entry point: submits upload
- Upload entry point → Uploaded shapefile dataset: makes available
- Upload entry point → Shapefile importer: invokes
- Uploaded shapefile dataset → Shapefile importer: file path / data
- Shapefile importer → Shapefile reader primitives: uses
- Shapefile reader primitives → Parsed features: reads records
- Shapefile importer → Parsed features: interprets geometry
- Parsed features → PostgreSQL / PostGIS: inserts PostGIS features
