@pgpm/geotypes 0.19.0 → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -14
- package/deploy/schemas/public/domains/geo_point.sql +10 -0
- package/deploy/schemas/public/domains/geo_polygon.sql +10 -0
- package/deploy/schemas/public/domains/geography_point.sql +10 -0
- package/deploy/schemas/public/domains/geography_polygon.sql +10 -0
- package/package.json +4 -4
- package/pgpm-geo-types.control +1 -1
- package/pgpm.plan +4 -2
- package/revert/schemas/public/domains/geo_point.sql +7 -0
- package/revert/schemas/public/domains/geo_polygon.sql +7 -0
- package/revert/schemas/public/domains/geography_point.sql +7 -0
- package/revert/schemas/public/domains/geography_polygon.sql +7 -0
- package/sql/pgpm-geo-types--0.15.3.sql +12 -4
- package/verify/schemas/public/domains/geo_point.sql +7 -0
- package/verify/schemas/public/domains/geo_polygon.sql +7 -0
- package/verify/schemas/public/domains/geography_point.sql +7 -0
- package/verify/schemas/public/domains/geography_polygon.sql +7 -0
- package/deploy/schemas/public/domains/geolocation.sql +0 -10
- package/deploy/schemas/public/domains/geopolygon.sql +0 -10
- package/revert/schemas/public/domains/geolocation.sql +0 -7
- package/revert/schemas/public/domains/geopolygon.sql +0 -7
- package/verify/schemas/public/domains/geolocation.sql +0 -7
- package/verify/schemas/public/domains/geopolygon.sql +0 -7
package/README.md
CHANGED
|
@@ -16,12 +16,14 @@ Geographic data types and spatial functions for PostgreSQL.
|
|
|
16
16
|
|
|
17
17
|
## Overview
|
|
18
18
|
|
|
19
|
-
`@pgpm/geotypes` provides PostgreSQL domain types for geographic data, built on top of PostGIS geometry types. This package enables type-safe storage and validation of geographic coordinates and polygons with proper SRID (Spatial Reference System Identifier) enforcement.
|
|
19
|
+
`@pgpm/geotypes` provides PostgreSQL domain types for geographic data, built on top of PostGIS geometry and geography types. This package enables type-safe storage and validation of geographic coordinates and polygons with proper SRID (Spatial Reference System Identifier) enforcement.
|
|
20
20
|
|
|
21
21
|
## Features
|
|
22
22
|
|
|
23
|
-
- **
|
|
24
|
-
- **
|
|
23
|
+
- **geo_point**: A geometry domain for geographic points (latitude/longitude) using WGS84 (SRID 4326) — planar coordinates, fast computation
|
|
24
|
+
- **geo_polygon**: A geometry domain for geographic polygons using WGS84 (SRID 4326) — planar coordinates
|
|
25
|
+
- **geography_point**: A geography domain for geographic points using WGS84 (SRID 4326) — geodetic calculations on the sphere, distances in meters
|
|
26
|
+
- **geography_polygon**: A geography domain for geographic polygons using WGS84 (SRID 4326) — geodetic calculations on the sphere
|
|
25
27
|
- Automatic SRID validation to ensure coordinate system consistency
|
|
26
28
|
- Integration with PostGIS spatial functions
|
|
27
29
|
|
|
@@ -82,23 +84,31 @@ pgpm deploy --createdb --database mydb1
|
|
|
82
84
|
### Creating Tables with Geographic Types
|
|
83
85
|
|
|
84
86
|
```sql
|
|
87
|
+
-- Geometry (planar) types
|
|
85
88
|
CREATE TABLE places (
|
|
86
89
|
id serial PRIMARY KEY,
|
|
87
|
-
loc
|
|
88
|
-
area
|
|
90
|
+
loc geo_point,
|
|
91
|
+
area geo_polygon
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
-- Geography (spherical) types
|
|
95
|
+
CREATE TABLE places_geo (
|
|
96
|
+
id serial PRIMARY KEY,
|
|
97
|
+
loc geography_point,
|
|
98
|
+
area geography_polygon
|
|
89
99
|
);
|
|
90
100
|
```
|
|
91
101
|
|
|
92
102
|
### Inserting Geographic Data
|
|
93
103
|
|
|
94
104
|
```sql
|
|
95
|
-
-- Insert a point
|
|
105
|
+
-- Insert a geometry point (San Francisco)
|
|
96
106
|
INSERT INTO places (loc)
|
|
97
107
|
VALUES (
|
|
98
108
|
ST_SetSRID(ST_MakePoint(-122.4194, 37.7749), 4326)
|
|
99
109
|
);
|
|
100
110
|
|
|
101
|
-
-- Insert a polygon
|
|
111
|
+
-- Insert a geometry polygon
|
|
102
112
|
INSERT INTO places (area)
|
|
103
113
|
VALUES (
|
|
104
114
|
ST_SetSRID(
|
|
@@ -106,6 +116,12 @@ VALUES (
|
|
|
106
116
|
4326
|
|
107
117
|
)
|
|
108
118
|
);
|
|
119
|
+
|
|
120
|
+
-- Insert a geography point (distances in meters, accounts for curvature)
|
|
121
|
+
INSERT INTO places_geo (loc)
|
|
122
|
+
VALUES (
|
|
123
|
+
ST_SetSRID(ST_MakePoint(-122.4194, 37.7749), 4326)::geography
|
|
124
|
+
);
|
|
109
125
|
```
|
|
110
126
|
|
|
111
127
|
### SRID Validation
|
|
@@ -118,28 +134,48 @@ INSERT INTO places (loc)
|
|
|
118
134
|
VALUES (
|
|
119
135
|
ST_SetSRID(ST_MakePoint(-122.4194, 37.7749), 3857)
|
|
120
136
|
);
|
|
121
|
-
-- ERROR: value for domain
|
|
137
|
+
-- ERROR: value for domain geo_point violates check constraint
|
|
122
138
|
```
|
|
123
139
|
|
|
124
140
|
## Domain Types
|
|
125
141
|
|
|
126
|
-
###
|
|
142
|
+
### Geometry Domains (Planar)
|
|
127
143
|
|
|
128
|
-
|
|
144
|
+
#### geo_point
|
|
145
|
+
|
|
146
|
+
A PostgreSQL domain based on `geometry(Point, 4326)` that stores geographic point coordinates using planar (flat) coordinates.
|
|
129
147
|
|
|
130
148
|
- **Base Type**: `geometry(Point, 4326)`
|
|
131
|
-
- **Use Case**: Storing latitude/longitude coordinates for locations
|
|
149
|
+
- **Use Case**: Storing latitude/longitude coordinates for locations, fast computation
|
|
132
150
|
- **SRID**: 4326 (WGS84 - World Geodetic System 1984)
|
|
133
151
|
|
|
134
|
-
|
|
152
|
+
#### geo_polygon
|
|
135
153
|
|
|
136
|
-
A PostgreSQL domain based on `geometry(Polygon, 4326)` that stores geographic polygon areas.
|
|
154
|
+
A PostgreSQL domain based on `geometry(Polygon, 4326)` that stores geographic polygon areas using planar coordinates.
|
|
137
155
|
|
|
138
156
|
- **Base Type**: `geometry(Polygon, 4326)`
|
|
139
157
|
- **Use Case**: Storing geographic boundaries, regions, or areas
|
|
140
158
|
- **SRID**: 4326 (WGS84)
|
|
141
159
|
- **Validation**: Ensures valid polygon geometry (closed rings, proper vertex count)
|
|
142
160
|
|
|
161
|
+
### Geography Domains (Spherical)
|
|
162
|
+
|
|
163
|
+
#### geography_point
|
|
164
|
+
|
|
165
|
+
A PostgreSQL domain based on `geography(Point, 4326)` that stores geographic point coordinates using geodetic (spherical) calculations.
|
|
166
|
+
|
|
167
|
+
- **Base Type**: `geography(Point, 4326)`
|
|
168
|
+
- **Use Case**: Real-world GPS data where distances should be in meters and account for Earth's curvature
|
|
169
|
+
- **SRID**: 4326 (WGS84)
|
|
170
|
+
|
|
171
|
+
#### geography_polygon
|
|
172
|
+
|
|
173
|
+
A PostgreSQL domain based on `geography(Polygon, 4326)` that stores geographic polygon areas using geodetic calculations.
|
|
174
|
+
|
|
175
|
+
- **Base Type**: `geography(Polygon, 4326)`
|
|
176
|
+
- **Use Case**: Real-world geographic boundaries where area/distance calculations need to account for Earth's curvature
|
|
177
|
+
- **SRID**: 4326 (WGS84)
|
|
178
|
+
|
|
143
179
|
## Dependencies
|
|
144
180
|
|
|
145
181
|
- `@pgpm/types`: Core PostgreSQL type definitions
|
|
@@ -153,9 +189,10 @@ pnpm test
|
|
|
153
189
|
```
|
|
154
190
|
|
|
155
191
|
The test suite validates:
|
|
156
|
-
- Successful insertion of valid points and polygons
|
|
192
|
+
- Successful insertion of valid geometry and geography points and polygons
|
|
157
193
|
- SRID validation and rejection of incorrect coordinate systems
|
|
158
194
|
- Polygon geometry validation
|
|
195
|
+
- Geography distance calculations return values in meters
|
|
159
196
|
|
|
160
197
|
## Related Tooling
|
|
161
198
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- Deploy schemas/public/domains/geography_polygon to pg
|
|
2
|
+
|
|
3
|
+
-- requires: schemas/public/schema
|
|
4
|
+
|
|
5
|
+
BEGIN;
|
|
6
|
+
|
|
7
|
+
CREATE DOMAIN geography_polygon AS geography (Polygon, 4326);
|
|
8
|
+
COMMENT ON DOMAIN geography_polygon IS E'@name pgpmInternalTypeGeographyPolygon';
|
|
9
|
+
|
|
10
|
+
COMMIT;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpm/geotypes",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.1",
|
|
4
4
|
"description": "Geographic data types and spatial functions for PostgreSQL",
|
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
6
6
|
"contributors": [
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"test:watch": "jest --watch"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@pgpm/types": "0.19.
|
|
25
|
-
"@pgpm/verify": "0.19.
|
|
24
|
+
"@pgpm/types": "0.19.1",
|
|
25
|
+
"@pgpm/verify": "0.19.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"pgpm": "^4.2.3"
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"bugs": {
|
|
36
36
|
"url": "https://github.com/constructive-io/pgpm-modules/issues"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "874490c55094ce0232bf230c613ee58685f369dc"
|
|
39
39
|
}
|
package/pgpm-geo-types.control
CHANGED
package/pgpm.plan
CHANGED
|
@@ -3,5 +3,7 @@
|
|
|
3
3
|
%uri=pgpm-geo-types
|
|
4
4
|
|
|
5
5
|
schemas/public/schema 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/schema
|
|
6
|
-
schemas/public/domains/
|
|
7
|
-
schemas/public/domains/
|
|
6
|
+
schemas/public/domains/geo_point [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/geo_point
|
|
7
|
+
schemas/public/domains/geo_polygon [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/geo_polygon
|
|
8
|
+
schemas/public/domains/geography_point [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/geography_point
|
|
9
|
+
schemas/public/domains/geography_polygon [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/geography_polygon
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
\echo Use "CREATE EXTENSION pgpm-geo-types" to load this file. \quit
|
|
2
|
-
CREATE DOMAIN
|
|
2
|
+
CREATE DOMAIN geo_point AS geometry(point, 4326);
|
|
3
3
|
|
|
4
|
-
COMMENT ON DOMAIN
|
|
4
|
+
COMMENT ON DOMAIN geo_point IS '@name pgpmInternalTypeGeoPoint';
|
|
5
5
|
|
|
6
|
-
CREATE DOMAIN
|
|
6
|
+
CREATE DOMAIN geo_polygon AS geometry(polygon, 4326);
|
|
7
7
|
|
|
8
|
-
COMMENT ON DOMAIN
|
|
8
|
+
COMMENT ON DOMAIN geo_polygon IS '@name pgpmInternalTypeGeoPolygon';
|
|
9
|
+
|
|
10
|
+
CREATE DOMAIN geography_point AS geography(point, 4326);
|
|
11
|
+
|
|
12
|
+
COMMENT ON DOMAIN geography_point IS '@name pgpmInternalTypeGeographyPoint';
|
|
13
|
+
|
|
14
|
+
CREATE DOMAIN geography_polygon AS geography(polygon, 4326);
|
|
15
|
+
|
|
16
|
+
COMMENT ON DOMAIN geography_polygon IS '@name pgpmInternalTypeGeographyPolygon';
|