{"id":15024850,"url":"https://github.com/jsuyog2/postgis","last_synced_at":"2026-03-07T21:03:16.914Z","repository":{"id":255104498,"uuid":"848526944","full_name":"jsuyog2/postgis","owner":"jsuyog2","description":"This Node.js class provides methods for interacting with a PostgreSQL/PostGIS database. It abstracts common spatial operations and queries, allowing you to easily perform spatial operations on your PostGIS-enabled PostgreSQL database.","archived":false,"fork":false,"pushed_at":"2025-07-28T06:51:36.000Z","size":215,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-02T22:38:49.617Z","etag":null,"topics":["database","geobuf","geojson","geojson-data","geospatial","geospatial-data","mvt","nodejs","postgis","postgres","postgresql","spatial-data"],"latest_commit_sha":null,"homepage":"https://github.com/jsuyog2/postgis","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jsuyog2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-27T23:36:07.000Z","updated_at":"2025-07-28T06:50:24.000Z","dependencies_parsed_at":"2024-08-28T02:43:09.517Z","dependency_job_id":"a59ba7d5-6d74-4983-9e3c-6ae4a51cef5f","html_url":"https://github.com/jsuyog2/postgis","commit_stats":null,"previous_names":["jsuyog2/postgis"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/jsuyog2/postgis","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsuyog2%2Fpostgis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsuyog2%2Fpostgis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsuyog2%2Fpostgis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsuyog2%2Fpostgis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsuyog2","download_url":"https://codeload.github.com/jsuyog2/postgis/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsuyog2%2Fpostgis/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30231490,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T19:01:10.287Z","status":"ssl_error","status_checked_at":"2026-03-07T18:59:58.103Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","geobuf","geojson","geojson-data","geospatial","geospatial-data","mvt","nodejs","postgis","postgres","postgresql","spatial-data"],"created_at":"2024-09-24T20:01:04.010Z","updated_at":"2026-03-07T21:03:16.898Z","avatar_url":"https://github.com/jsuyog2.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PostGIS for Node.js\n\nThis Node.js class provides methods for interacting with a PostgreSQL/PostGIS database. It abstracts common spatial operations and queries, allowing you to easily perform spatial operations on your PostGIS-enabled PostgreSQL database.\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [API Reference](#api-reference)\n  - [list_tables](#list_tables)\n  - [list_columns](#list_columns)\n  - [query_table](#query_table)\n  - [bbox](#bbox)\n  - [centroid](#centroid)\n  - [intersect_feature](#intersect_feature)\n  - [intersect_point](#intersect_point)\n  - [geojson](#geojson)\n  - [geobuf](#geobuf)\n  - [mvt](#mvt)\n  - [nearest](#nearest)\n  - [transform_point](#transform_point)\n- [Error Handling](#error-handling)\n- [License](#license)\n\n## Installation\n\n1. Install the required packages using npm:\n\n   ```bash\n   npm install pg\n   ```\n\n2. Install the `postgis` package:\n\n   ```bash\n   npm install postgis\n   ```\n\n## Usage\n\nTo use the `Postgis` class, first initialize it with a PostgreSQL client instance from the `pg` package:\n\n```javascript\nconst { Client } = require('pg');\nconst Postgis = require('postgis');\n\nconst client = new Client({\n    connectionString: 'your_connection_string'\n});\n\nclient.connect();\n\nconst postgis = new Postgis(client);\n\n// Example usage\nasync function run() {\n    try {\n        const tables = await postgis.list_tables({ filter: 'table_type = \\'BASE TABLE\\'' });\n        console.log('Tables:', tables);\n\n        const columns = await postgis.list_columns('your_table');\n        console.log('Columns:', columns);\n\n        const features = await postgis.query_table('your_table', {\n            columns: 'name, geom',\n            filter: `\"column_name\" = 'value'`,\n            sort: 'name ASC',\n            limit: 50\n        });\n        console.log('Features:', features);\n    } catch (err) {\n        console.error('Error:', err);\n    } finally {\n        await client.end();\n    }\n}\n\nrun();\n```\n\n## API Reference\n\n### `list_tables(options)`\n\nLists all tables in the database. Optionally, you can filter by schema or other parameters.\n\n**Parameters:**\n- `options` (optional): JSON object with the following properties:\n  - `filter` (optional): A SQL WHERE clause filter.\n\n**Returns:**\nA list of tables with their metadata.\n\n**Example:**\n\n```javascript\nconst tables = await postgis.list_tables({ filter: 'table_type = \\'BASE TABLE\\'' });\n```\n\n### `list_columns(table)`\n\nLists all columns in a given table.\n\n**Parameters:**\n- `table`: The name of the table.\n\n**Returns:**\nA list of columns in the table.\n\n**Example:**\n\n```javascript\nconst columns = await postgis.list_columns('your_table');\n```\n\n### `query_table(table, options)`\n\nQueries a table with optional parameters for columns, filtering, grouping, sorting, and limiting the results.\n\n**Parameters:**\n- `table`: The name of the table.\n- `options` (optional): JSON object with the following properties:\n  - `columns` (optional): Columns to retrieve, defaults to `'*'`.\n  - `filter` (optional): A SQL WHERE clause filter.\n  - `group` (optional): Columns to group by.\n  - `sort` (optional): Sorting order.\n  - `limit` (optional): Limit the number of results, defaults to `100`.\n\n**Returns:**\nA list of rows from the query.\n\n**Example:**\n\n```javascript\nconst features = await postgis.query_table('your_table', {\n    columns: 'name, geom',\n    filter: `\"column_name\" = 'value'`,\n    sort: 'name ASC',\n    limit: 50\n});\n```\n\n### `bbox(table, options)`\n\nCalculates the bounding box (extent) for a given table based on a specified geometry column.\n\n**Parameters:**\n- `table`: The name of the table.\n- `options` (optional): JSON object with the following properties:\n  - `geom_column` (optional): The geometry column, defaults to `'geom'`.\n  - `srid` (optional): The SRID for the bounding box, defaults to `4326`.\n  - `filter` (optional): A SQL WHERE clause filter.\n\n**Returns:**\nAn object representing the bounding box with coordinates.\n\n**Example:**\n\n```javascript\nconst bbox = await postgis.bbox('your_table', {\n    geom_column: 'geom',\n    srid: 4326,\n    filter: `\"some_column\" = 'some_value'`\n});\n```\n\n### `centroid(table, options)`\n\nCalculates the centroid of geometries in a given table.\n\n**Parameters:**\n- `table`: The name of the table.\n- `options` (optional): JSON object with the following properties:\n  - `force_on_surface` (optional): Whether to force the centroid to be on the surface, defaults to `false`.\n  - `geom_column` (optional): The geometry column, defaults to `'geom'`.\n  - `srid` (optional): The SRID, defaults to `'4326'`.\n  - `filter` (optional): A SQL WHERE clause filter.\n\n**Returns:**\nA list of centroids.\n\n**Example:**\n\n```javascript\nconst centroids = await postgis.centroid('your_table', {\n    force_on_surface: true,\n    geom_column: 'geom',\n    srid: 4326,\n    filter: `\"column_name\" = 'value'`\n});\n```\n\n### `intersect_feature(table_from, table_to, options)`\n\nFinds intersections between features in two tables.\n\n**Parameters:**\n- `table_from`: The first table.\n- `table_to`: The second table.\n- `options` (optional): JSON object with the following properties:\n  - `columns` (optional): Columns to retrieve, defaults to `'*'`.\n  - `distance` (optional): Distance for the intersection, defaults to `'0'`.\n  - `geom_column_from` (optional): The geometry column for the first table, defaults to `'geom'`.\n  - `geom_column_to` (optional): The geometry column for the second table, defaults to `'geom'`.\n  - `filter` (optional): A SQL WHERE clause filter.\n  - `sort` (optional): Sorting order.\n  - `limit` (optional): Limit the number of results.\n\n**Returns:**\nA list of intersecting features.\n\n**Example:**\n\n```javascript\nconst intersections = await postgis.intersect_feature('table1', 'table2', {\n    columns: 'name, geom',\n    distance: '10',\n    filter: `\"some_column\" = 'some_value'`,\n    sort: 'name ASC',\n    limit: 50\n});\n```\n\n### `intersect_point(table, point, options)`\n\nFinds features in a table that intersect with a given point.\n\n**Parameters:**\n- `table`: The name of the table.\n- `point`: The point to intersect with.\n- `options` (optional): JSON object with the following properties:\n  - `columns` (optional): Columns to retrieve, defaults to `'*'`.\n  - `distance` (optional): Distance for the intersection, defaults to `'0'`.\n  - `geom_column` (optional): The geometry column, defaults to `'geom'`.\n  - `filter` (optional): A SQL WHERE clause filter.\n  - `sort` (optional): Sorting order.\n  - `limit` (optional): Limit the number of results.\n\n**Returns:**\nA list of features intersecting with the point.\n\n**Example:**\n\n```javascript\nconst features = await postgis.intersect_point('your_table', '1,1,4326', {\n    columns: 'name, geom',\n    distance: '5',\n    filter: `\"some_column\" = 'some_value'`,\n    sort: 'name ASC',\n    limit: 10\n});\n```\n\n### `geojson(table, options)`\n\nConverts features from a table to GeoJSON format.\n\n**Parameters:**\n- `table`: The name of the table.\n- `options` (optional): JSON object with the following properties:\n  - `bounds` (optional): Bounding box for the results.\n  - `id_column` (optional): Column to use as the feature ID.\n  - `precision` (optional): Precision for coordinates, defaults to `9`.\n  - `geom_column` (optional): The geometry column, defaults to `'geom'`.\n  - `columns` (optional): Columns to retrieve.\n  - `filter` (optional): A SQL WHERE clause filter.\n\n**Returns:**\nA GeoJSON `FeatureCollection`.\n\n**Example:**\n\n```javascript\nconst geojson = await postgis.geojson('your_table', {\n    bounds: 'xmin ymin, xmax ymax',\n    id_column: 'id',\n    precision: 6,\n    geom_column: 'geom',\n    columns: 'name, geom',\n    filter: `\"some_column\" = 'some_value'`\n});\n```\n\n### `geobuf(table, options)`\n\nConverts features from a table to Geobuf format.\n\n**Parameters:**\n- `table`: The name of the table.\n- `options` (optional): JSON object with the following properties:\n  - `bounds` (optional): Bounding box for the results.\n  - `geom_column` (optional): The geometry column, defaults to `'geom'`.\n  - `columns` (optional): Columns to retrieve.\n  - `filter` (optional): A SQL WHERE clause filter.\n\n**Returns:**\nA Geobuf binary encoded string.\n\n**Example:**\n\n```javascript\nconst geobuf = await postgis.geobuf('your_table', {\n    bounds: 'xmin ymin, xmax ymax',\n    geom_column: 'geom',\n    columns: 'name, geom',\n    filter: `\"some_column\" = 'some_value'`\n});\n```\n\n### `mvt(table, x, y, z, options)`\n\nGenerates a Mapbox Vector Tile (MVT) for a given tile coordinate.\n\n**Parameters:**\n- `table`: The name of the table.\n- `x`: The x-coordinate of the tile.\n- `y`: The y-coordinate of the tile.\n- `z`: The zoom level.\n- `options` (optional): JSON object with the following properties:\n  - `columns` (optional): Columns to retrieve.\n  - `id_column` (optional): Column to use as the feature ID.\n  - `geom_column` (optional): The geometry column, defaults to `'geom'`.\n  - `filter` (optional): A SQL WHERE clause filter.\n\n**Returns:**\nA Mapbox Vector Tile.\n\n**Example:**\n\n```javascript\nconst mvt = await postgis.mvt('your_table', 1, 2, 3, {\n    columns: 'name, geom',\n    id_column: 'id',\n    filter: `\"some_column\" = 'some_value'`\n});\n```\n\n### `nearest(table, point, options)`\n\nFinds the nearest features to a given point.\n\n**Parameters:**\n- `table`: The name of the table.\n- `point`: The point to find the nearest features to.\n- `options` (optional): JSON object with the following properties:\n  - `columns` (optional): Columns to retrieve, defaults to `'*'`.\n  - `geom_column` (optional): The geometry column, defaults to `'geom'`.\n  - `filter` (optional): A SQL WHERE clause filter.\n  - `limit` (optional): Limit the number of results, defaults to `10`.\n\n**Returns:**\nA list of the nearest features.\n\n**Example:**\n\n```javascript\nconst nearest = await postgis.nearest('your_table', '1,1,4326', {\n    columns: 'name, geom',\n    filter: `\"some_column\" = 'some_value'`,\n    limit: 5\n});\n```\n\n### `transform_point(point, options)`\n\nTransforms a point from one SRID to another.\n\n**Parameters:**\n- `point`: The point to transform.\n- `options` (optional): JSON object with the following properties:\n  - `srid` (optional): The target SRID, defaults to `4326`.\n\n**Returns:**\nThe transformed point.\n\n**Example:**\n\n```javascript\nconst transformed = await postgis.transform_point('1,1,4326', { srid: 3857 });\n```\n\n## Error Handling\n\nAll methods throw an error if the query execution fails. Ensure proper error handling in your application to manage these errors.\n\n```javascript\ntry {\n    const result = await postgis.someMethod();\n    console.log(result);\n} catch (err) {\n    console.error('Error:', err);\n}\n```\n\n## Version Compatibility\n\n- **PostgreSQL:** Compatible with PostgreSQL 12 and higher.\n- **PostGIS:** Compatible with PostGIS 3.0 and higher.\n- **Node.js:** Compatible with Node.js 14.x and higher.\n- **pg (node-postgres):** Version 8.x and higher.\n\n## Testing\n\nIf you create a pull request, tests better pass :)\n\n  ```bash\n  npm install\n  npm test\n  ```\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsuyog2%2Fpostgis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsuyog2%2Fpostgis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsuyog2%2Fpostgis/lists"}