How erikfva/upload-shapefile-to-postgis works
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.php Shapefile importer · uploadshp.php Upload entry point · ShapeFile.inc.php Shapefile reader primitives
Components 7
PHP Upload Runtime
- Upload entry point · Receives uploads and starts the import.
uploadshp.php - Uploaded shapefile dataset · Binary .shp data with required sidecar files.
Shapefile Import
- Shapefile importer · Iterates features, converts geometry, and persists records.
shpparser/shpparser.php - Shapefile reader primitives · Defines shapefile structures and record-reading primitives.
shpparser/ShapeFile.inc.php - Parsed features
Geospatial Storage
- PostgreSQL / PostGIS · Stores imported feature records and geometries.
Other components
- Upload client
Connections 8
- 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