Giter Site home page Giter Site logo

blackshield6 / strapi-plugin-postgis Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thoranrion/strapi-plugin-postgis

0.0 0.0 0.0 24.87 MB

Add native postgis support to strapi.

Home Page: https://am2222.github.io/strapi-plugin-postgis/

JavaScript 77.34% CSS 22.66%

strapi-plugin-postgis's Introduction

DocSearch

Add native postgis support to strapi.

npm Package Docs

Documentation

Video

Screenshot


Under Development

How does it work?

Since Strapi does not support native database formats I convert requests before they being sent to the querybuilder and convert all the geometry objects to the geojson.

Requirements

Strapi Version 4.5.0 and up.

Installation

Setup your strapi app as usual

npx create-strapi-app@latest my-project --quickstart

Install pg and strapi-plugin-postgis

npm install pg --save
npm i strapi-plugin-postgis

Make sure to config your strapi to use postgrs database as backend, Use this link in case you need any help with this step (https://strapi.io/blog/postgre-sql-and-strapi-setup)

Make sure to install postgis on your database server.

  • This plugin is only compatible with postgis versions 3.1 and 3.2*

Modify your middlewares as following to let strapi load osm tiles. Add '*.tile.openstreetmap.org' to the img-src as follows

// ./config/middlewares.js
module.exports = [
  'strapi::errors',
  {
    name: 'strapi::security',
    config: {
      contentSecurityPolicy: {
        useDefaults: true,
        directives: {
          'img-src': ["'self'", 'data:', 'blob:', '*.tile.openstreetmap.org'],
          upgradeInsecureRequests: null,
        },
      },
    },
  },
  'strapi::cors',
  'strapi::poweredBy',
  'strapi::logger',
  'strapi::query',
  'strapi::body',
  'strapi::session',
  'strapi::favicon',
  'strapi::public',
];

Run strapi and you should see the following line


[2022-06-03 10:47:25.194] info: Welcome to Strapi Postgis πŸš€ + 🐘 + πŸ—ΊοΈ | 3.1 USE_GEOS=1 USE_PROJ=1 USE_STATS=1

Now in your content-types api folder modify schema.json and add a new column with the following format

{
  "kind": "collectionType",
  .
  .
  .
  "attributes": {
  .
  .
  .
    "geom": { //--> your column name. you can change to anything
      "columnType": {
        "type": "specificType",
        "args": [
          "geometry(POINT,4326)" //-> change this line according to the Supported Data Types section
        ]
      },
      "type": "customField", //->don't change this
      "customField": "plugin::postgis.map" //->don't change this
    }
  }
}

Supported Data Types

POINT

Screenshot

"geom": {
      "columnType": {
        "type": "specificType",
        "args": [
          "geometry(POINT,4326)"
        ]
      },
      "type": "customField",
      "customField": "plugin::postgis.map"
    }
  • POINT Z (0 0 0)

  • POINT ZM (0 0 0 0)

  • POINT EMPTY

LINESTRING

Screenshot

    "g_line": {
      "columnType": {
        "type": "specificType",
        "args": [
          "geometry(LINESTRING,4326)"
        ]
      },
      "type": "customField",
      "customField": "plugin::postgis.map"
    }

  • LINESTRING EMPTY

POLYGON

Screenshot

    "g_polygon": {
      "columnType": {
        "type": "specificType",
        "args": [
          "geometry(POLYGON,4326)"
        ]
      },
      "type": "customField",
      "customField": "plugin::postgis.map"
    }
  • MULTIPOINT((0 0),(1 2))

  • MULTIPOINT Z ((0 0 0),(1 2 3))

  • MULTIPOINT EMPTY

  • MULTILINESTRING((0 0,1 1,1 2),(2 3,3 2,5 4))

  • MULTIPOLYGON(((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1)), ((-1 -1,-1 -2,-2 -2,-2 -1,-1 -1)))

  • GEOMETRYCOLLECTION(POINT(2 3),LINESTRING(2 3,3 4))

  • GEOMETRYCOLLECTION EMPTY

TODO

  • Add tests
  • Support all the types
  • Add query options like sort by distance, overlap and etc.
  • Develop dashboard
  • Add cool pg queries and tilings ;)

Thanks to

  • strapi-plugin-point-list for the idea of how to add a custom components to the strapi content types
  • postgis knex plugin
  • leaflet editor plugin
  • strapi team
  • and so many other stuff

strapi-plugin-postgis's People

Contributors

am2222 avatar arrig0 avatar thoranrion avatar hotrungnhan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.