@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 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
- - **geolocation**: A domain type for geographic points (latitude/longitude) using WGS84 (SRID 4326)
24
- - **geopolygon**: A domain type for geographic polygons using WGS84 (SRID 4326)
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 geolocation,
88
- area geopolygon
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 location (San Francisco)
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 area
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 geolocation violates check constraint
137
+ -- ERROR: value for domain geo_point violates check constraint
122
138
  ```
123
139
 
124
140
  ## Domain Types
125
141
 
126
- ### geolocation
142
+ ### Geometry Domains (Planar)
127
143
 
128
- A PostgreSQL domain based on `geometry(Point, 4326)` that stores geographic point coordinates.
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
- ### geopolygon
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/geo_point to pg
2
+
3
+ -- requires: schemas/public/schema
4
+
5
+ BEGIN;
6
+
7
+ CREATE DOMAIN geo_point AS geometry (Point, 4326);
8
+ COMMENT ON DOMAIN geo_point IS E'@name pgpmInternalTypeGeoPoint';
9
+
10
+ COMMIT;
@@ -0,0 +1,10 @@
1
+ -- Deploy schemas/public/domains/geo_polygon to pg
2
+
3
+ -- requires: schemas/public/schema
4
+
5
+ BEGIN;
6
+
7
+ CREATE DOMAIN geo_polygon AS geometry (Polygon, 4326);
8
+ COMMENT ON DOMAIN geo_polygon IS E'@name pgpmInternalTypeGeoPolygon';
9
+
10
+ COMMIT;
@@ -0,0 +1,10 @@
1
+ -- Deploy schemas/public/domains/geography_point to pg
2
+
3
+ -- requires: schemas/public/schema
4
+
5
+ BEGIN;
6
+
7
+ CREATE DOMAIN geography_point AS geography (Point, 4326);
8
+ COMMENT ON DOMAIN geography_point IS E'@name pgpmInternalTypeGeographyPoint';
9
+
10
+ COMMIT;
@@ -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.0",
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.0",
25
- "@pgpm/verify": "0.19.0"
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": "83be2dd4b07831c8c4f903437d20d350a673d19b"
38
+ "gitHead": "874490c55094ce0232bf230c613ee58685f369dc"
39
39
  }
@@ -1,6 +1,6 @@
1
1
  # pgpm-geo-types extension
2
2
  comment = 'pgpm-geo-types extension'
3
- default_version = '0.15.3'
3
+ default_version = '0.15.5'
4
4
  module_pathname = '$libdir/pgpm-geo-types'
5
5
  requires = 'plpgsql,citext,postgis,pgpm-types,pgpm-verify'
6
6
  relocatable = false
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/geolocation [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/geolocation
7
- schemas/public/domains/geopolygon [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/geopolygon
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
@@ -0,0 +1,7 @@
1
+ -- Revert schemas/public/domains/geo_point from pg
2
+
3
+ BEGIN;
4
+
5
+ DROP TYPE public.geo_point;
6
+
7
+ COMMIT;
@@ -0,0 +1,7 @@
1
+ -- Revert schemas/public/domains/geo_polygon from pg
2
+
3
+ BEGIN;
4
+
5
+ DROP TYPE public.geo_polygon;
6
+
7
+ COMMIT;
@@ -0,0 +1,7 @@
1
+ -- Revert schemas/public/domains/geography_point from pg
2
+
3
+ BEGIN;
4
+
5
+ DROP TYPE public.geography_point;
6
+
7
+ COMMIT;
@@ -0,0 +1,7 @@
1
+ -- Revert schemas/public/domains/geography_polygon from pg
2
+
3
+ BEGIN;
4
+
5
+ DROP TYPE public.geography_polygon;
6
+
7
+ COMMIT;
@@ -1,8 +1,16 @@
1
1
  \echo Use "CREATE EXTENSION pgpm-geo-types" to load this file. \quit
2
- CREATE DOMAIN geolocation AS geometry(point, 4326);
2
+ CREATE DOMAIN geo_point AS geometry(point, 4326);
3
3
 
4
- COMMENT ON DOMAIN geolocation IS '@name pgpmInternalTypeGeoLocation';
4
+ COMMENT ON DOMAIN geo_point IS '@name pgpmInternalTypeGeoPoint';
5
5
 
6
- CREATE DOMAIN geopolygon AS geometry(polygon, 4326);
6
+ CREATE DOMAIN geo_polygon AS geometry(polygon, 4326);
7
7
 
8
- COMMENT ON DOMAIN geopolygon IS '@name pgpmInternalTypeGeoPolygon';
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';
@@ -0,0 +1,7 @@
1
+ -- Verify schemas/public/domains/geo_point on pg
2
+
3
+ BEGIN;
4
+
5
+ SELECT verify_domain ('public.geo_point');
6
+
7
+ ROLLBACK;
@@ -0,0 +1,7 @@
1
+ -- Verify schemas/public/domains/geo_polygon on pg
2
+
3
+ BEGIN;
4
+
5
+ SELECT verify_domain ('public.geo_polygon');
6
+
7
+ ROLLBACK;
@@ -0,0 +1,7 @@
1
+ -- Verify schemas/public/domains/geography_point on pg
2
+
3
+ BEGIN;
4
+
5
+ SELECT verify_domain ('public.geography_point');
6
+
7
+ ROLLBACK;
@@ -0,0 +1,7 @@
1
+ -- Verify schemas/public/domains/geography_polygon on pg
2
+
3
+ BEGIN;
4
+
5
+ SELECT verify_domain ('public.geography_polygon');
6
+
7
+ ROLLBACK;
@@ -1,10 +0,0 @@
1
- -- Deploy schemas/public/domains/geolocation to pg
2
-
3
- -- requires: schemas/public/schema
4
-
5
- BEGIN;
6
-
7
- CREATE DOMAIN geolocation AS geometry (Point, 4326);
8
- COMMENT ON DOMAIN geolocation IS E'@name pgpmInternalTypeGeoLocation';
9
-
10
- COMMIT;
@@ -1,10 +0,0 @@
1
- -- Deploy schemas/public/domains/geopolygon to pg
2
-
3
- -- requires: schemas/public/schema
4
-
5
- BEGIN;
6
-
7
- CREATE DOMAIN geopolygon AS geometry (Polygon, 4326);
8
- COMMENT ON DOMAIN geopolygon IS E'@name pgpmInternalTypeGeoPolygon';
9
-
10
- COMMIT;
@@ -1,7 +0,0 @@
1
- -- Revert schemas/public/domains/geolocation from pg
2
-
3
- BEGIN;
4
-
5
- DROP TYPE public.geolocation;
6
-
7
- COMMIT;
@@ -1,7 +0,0 @@
1
- -- Revert schemas/public/domains/geopolygon from pg
2
-
3
- BEGIN;
4
-
5
- DROP TYPE public.geopolygon;
6
-
7
- COMMIT;
@@ -1,7 +0,0 @@
1
- -- Verify schemas/public/domains/geolocation on pg
2
-
3
- BEGIN;
4
-
5
- SELECT verify_domain ('public.geolocation');
6
-
7
- ROLLBACK;
@@ -1,7 +0,0 @@
1
- -- Verify schemas/public/domains/geopolygon on pg
2
-
3
- BEGIN;
4
-
5
- SELECT verify_domain ('public.geopolygon');
6
-
7
- ROLLBACK;