Skip to content

feat: add BufferGeometry to PostGIS POLYHEDRALSURFACE Z conversion utilities#10

Merged
zamderax merged 4 commits into
mainfrom
feat/buffergeometry-conversions
Dec 4, 2025
Merged

feat: add BufferGeometry to PostGIS POLYHEDRALSURFACE Z conversion utilities#10
zamderax merged 4 commits into
mainfrom
feat/buffergeometry-conversions

Conversation

@zamderax

@zamderax zamderax commented Dec 4, 2025

Copy link
Copy Markdown
Contributor

Summary

Add utilities for converting Three.js BufferGeometry to/from PostGIS POLYHEDRALSURFACE Z WKT format, enabling 3D geofence storage in spatial databases.

New Functions

Function Description
bufferGeometryToWKT(geometry, options) Convert BufferGeometry → PostGIS WKT
wktToBufferGeometry(wkt, options) Parse WKT → BufferGeometry
isCoordsInPolyhedron(coords, geometry, origin) Test if geo-coords are inside 3D volume
isPointInPolyhedron(point, geometry) Test if 3D point is inside geometry
bufferGeometryToGeoTriangles(geometry, origin) Convert to JSON-serializable GeoTriangle[]
geoTrianglesToBufferGeometry(triangles, origin) Convert GeoTriangle[] → BufferGeometry
isPointOnSurface(point, geometry, tolerance) Test if point is on surface

Use Case

Users can draw 3D volumes representing geofences in geographic coordinates (lat/lng/altitude), store them in PostGIS with geometry(POLYHEDRALSURFACEZ, 4326), and query point containment.

// Convert geometry to WKT for PostGIS storage
const wkt = bufferGeometryToWKT(geofence, { origin });
// INSERT INTO geofences (geom) VALUES (ST_GeomFromText(wkt, 4326))

// Test if a point is inside the geofence
const result = isCoordsInPolyhedron(testPoint, geofence, origin);
if (result.inside) {
  console.log('Point is inside geofence!');
}

Includes

  • ✅ Comprehensive unit tests (39 tests)
  • ✅ User-friendly error messages with context
  • ✅ TypeDoc documentation with @throws and @example tags
  • ✅ README documentation section
  • ✅ Interactive Storybook demo

Test plan

  • Run npm run vitest - all 39 tests pass
  • Run npx tsc --noEmit - no type errors
  • Run Storybook and verify Geofence demo works
  • Test WKT output in PostGIS (optional)

🤖 Generated with Claude Code

zamderax and others added 4 commits December 3, 2025 16:44
…ilities

Add utilities for converting Three.js BufferGeometry to/from PostGIS
POLYHEDRALSURFACE Z WKT format, enabling 3D geofence storage in spatial
databases.

New features:
- bufferGeometryToWKT: Convert BufferGeometry to PostGIS WKT format
- wktToBufferGeometry: Parse WKT back to BufferGeometry
- isCoordsInPolyhedron: Test if geo-coordinates are inside a 3D volume
- isPointInPolyhedron: Test if 3D point is inside geometry
- bufferGeometryToGeoTriangles: Convert to JSON-serializable format
- geoTrianglesToBufferGeometry: Convert GeoTriangles back to geometry
- isPointOnSurface: Test if point is on surface within tolerance

Includes:
- Comprehensive unit tests (39 tests passing)
- User-friendly error messages with context
- TypeDoc documentation with examples
- README documentation section
- Interactive Storybook demo with point-in-polyhedron visualization

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@zamderax zamderax merged commit 3b84774 into main Dec 4, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant