npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tilelive-postgis

v1.3.5

Published

tilelive.js adapter for reading from the PostGIS

Downloads

11

Readme

tilelive-postgis

npm version npm downloads Build Status

Implements the tilelive API for generating mapnik vector tiles from PostGIS.

Installation

npm install @mapbox/tilelive tilelive-postgis

Usage

const tilelive = require('@mapbox/tilelive');
require('tilelive-postgis').registerProtocols(tilelive);

const uri = 'postgis://user:password@localhost:5432/test?table=test_table&geometry_field=geometry&srid=4326';
tilelive.load(uri, (error, source) => {
  if (error) throw error;

  source.getTile(0, 0, 0, (error, tile, headers) => {
    // `error` is an error object when generation failed, otherwise null.
    // `tile` contains the compressed image file as a Buffer
    // `headers` is a hash with HTTP headers for the image.
  });
});

If PostgreSQL server running locally and accepting connections on Unix domain socket, you can connect like this:

const uri = 'postgis:///var/run/postgresql/test?table=test&geometry_field=geom';
tilelive.load(uri, (error, source) => { ... });

You can also use query parameter to specify sub-query like this:

const query = `(select * from schemaName.tableName where st_intersects(geometry, !bbox!)) as query`;
const uri = `postgis://user@localhost/test?table=test_table&geometry_field=geometry&query=${encodeURI(query)}`;
tilelive.load(uri, (error, source) => { ... });

Parameters

The only parameter that is not mapnik specific is:

| parameter | value | description | default | |:------------------|----------|---------------|----------:| | layerName | string | name of the layer in resulting tiles. | defaults to the table name for backwards compatibility.|

Actual list of parameters you can see here.

| parameter | value | description | default | |:------------------|----------|---------------|----------:| | table | string | name of the table to fetch. | | | geometry_field | string | name of the geometry field, in case you have more than one in a single table. This field and the SRID will be deduced from the query in most cases, but may need to be manually specified in some cases.| | | geometry_table | string | name of the table containing the returned geometry; for determining RIDs with subselects | | | srid | integer | srid of the table, if this is > 0 then fetching data will avoid an extra database query for knowing the srid of the table | 0 | | extent | string | maxextent of the geometries | determined by querying the metadata for the table | | extent_from_subquery | boolean | evaluate the extent of the subquery, this might be a performance issue | false | | connect_timeout | integer | timeout is seconds for the connection to take place | 4 | | persist_connection | boolean | choose whether to share the same connection for subsequent queries | true | | row_limit | integer | max number of rows to return when querying data, 0 means no limit | 0 | | cursor_size | integer | if this is > 0 then server cursor will be used, and will prefetch this number of features | 0 | | initial_size | integer | initial size of the stateless connection pool | 1 | | max_size | integer | max size of the stateless connection pool | 10 | | multiple_geometries | boolean | whether to use multiple different objects or a single one when dealing with multi-objects (this is mainly related to how the label are used in the map, one label for a multi-polygon or one label for each polygon of a multi-polygon)| false | | encoding | string | internal file encoding | utf-8 | | simplify_geometries | boolean | whether to automatically reduce input vertices. Only effective when output projection matches (or is similar to) input projection. Available from version 2.1.x up. | false | | max_async_connection | integer | max number of PostGIS queries for rendering one map in asynchronous mode. Default value (1) has no effect. | 1 |