Giter Club home page Giter Club logo

csw-client's Introduction

CSW-CLIENT

This package provides client-side API for OGC CSW service(s) written in TypeScript.

Suits for Node.JS and React/Angular applications

Package boilerplate based on ts-npm-package-boilerplate

This Client library is based on Jsonix and ogc-schemas libraries.

Code samples are provided by TypeScript.

Installation

Install package by NPM

npm install @map-colonies/csw-client --save

Install package by YARN

yarn add @map-colonies/csw-client --save

!!! IMPORTANT: Apply integrated PATCHES

Add following script to your package.json

"scripts": {
  .
  .
  .
  "patch:deps": "cd ./node_modules/@map-colonies/csw-client && patch-package --patch-dir ./dist/patches"
}

You can add patch:deps script to one of the npm hooks or run it manually.

For example add it to postinstall hook:

"scripts": {
  "postinstall": "yarn run patch:deps && <your_own_postinstall>",
  .
  .
  .
  "patch:deps": "cd ./node_modules/@map-colonies/csw-client && patch-package --patch-dir ./dist/patches"
}

Usage

// import CswClient class 
import { CswClient, ICapabilities } from from '@map-colonies/csw-client';

// later in code
const csw = new CswClient('<YOUR_OGC_CSW_SRV_URL>', <YOUR_REQUEST_EXECUTOR_FUNC>, <CONFIG>);
// trigger one of the exposed methods
csw.GetDomain('<propertyName>').then((data: ICapabilities) => {
  // your code
}); 

Implemented operations/methods

Client library instantiation

  • Instantiation - new
      // import CswClient class 
      import { CswClient } from from '@map-colonies/csw-client';
      import Axios, { Method } from 'axios';
    
      // import desired ADDITIONAL schemas
      const ISO19139_GCO_20060504 = require('ogc-schemas').ISO19139_GCO_20060504;
      const ISO19139_GMD_20060504 = require('ogc-schemas').ISO19139_GMD_20060504;
      const GML_3_2_0 = require('ogc-schemas').GML_3_2_0;
    
      // define your own requestExecutor
      const myRequest = async (url: string, method: string, params: Record<string, unknown>): Promise<any> => {
        const errorMsg = 'CLIENT HTTP ERROR BY AXIOS';
        return Axios.request({
          url,
          method: method as Method,
          ...params,
        })
          .then((res) => res)
          .catch((error) => {
            console.error(errorMsg);
            throw error;
          });
      };
    
      // later in code
      const cswConfig = {
        schemas: [
          GML_3_2_0,
          ISO19139_GCO_20060504,
          ISO19139_GMD_20060504,
        ],
        nameSpaces: {
          namespacePrefixes: { // define ADDITIONAL namespace prefixes
            'http://schema.mapcolonies.com': 'mc',
            'http://www.isotc211.org/2005/gmd': 'gmd',
            'http://www.isotc211.org/2005/gco': 'gco',
          },
        },
        credentials: {},
      };
      const csw = new CswClient('http://127.0.0.1:56477/?version=2.0.2&service=CSW', myRequest, cswConfig);

Basic OWS operations

  • GetCapabilities(): Promise

    Allow clients to retrieve information describing the service instance

      csw.GetCapabilities().then((data: ICapabilities) => {
        ... // your code
      });
  • DescribeRecord(): Promise

    Allows a client to discover elements of the information model supported by the target catalog service

      csw.DescribeRecord().then((data) => {
        ... // your code
      });

CSW queries

  • GetDomain(propertyName: string): Promise

    Obtain runtime information about the range of values of a metadata record element or request parameter.

      csw.GetDomain('title').then((data) => {
        ... // your code
      });
  • GetRecords(start: number, max: number, opts: { filter?: IFilterField[]; sort?: ISortField[] }, outputSchema: string): Promise

    Get metadata records according to defined filter and sort order

     const options = {
       filter: [
         {
           field: 'mcgc:geojson',
           bbox: {
             llat: 31.90,
             llon: 36.80,
             ulat: 31.91,
             ulon: 36.81,
           },
         },
         {
           field: 'mcgc:name',
           like: 'magic_place',
         },
       ],
       sort: [
         {
           field: 'mcgc:name',
           desc: false,
         },
         {
           field: 'mcgc:creation_date',
           desc: true,
         },
    
       ]
     };
     csw.GetRecords(1, 10, options, 'http://schema.myschema.com').then((data) => {
       ... // your code
     });
  • GetRecordsById(id_list: string[]): Promise

    Get metadata records by ID list

     csw.GetRecordsById(['1', '2', '5']).then((data) => {
       ... // your code
     });

CSW CRUD operations

  • InsertRecords(records: any[]): Promise

    Create catalog records

     csw.InsertRecords(records).then((data) => {
       ... // your code
     });
  • UpdateRecord(record: any): Promise

    Modify catalog record

     csw.UpdateRecord(records).then((data) => {
       ... // your code
     });
  • DeleteRecords(filters: IFilterField[]): Promise

    Delete catalog records according to defined filter

     csw.DeleteRecords(filters).then((data) => {
       ... // your code
     });

Utils

  • xmlStringToJson(xmlString: string): any

    Converts XML-like string to JSON object according to defined schemas

     const obj = csw.xmlStringToJson(xmlString);
  • jsonToXml(json: any): XMLDocument
    Converts JSON object to XMLDocument according to defined schemas

     const xmlDoc: XMLDocument = csw.jsonToXml(json);
  • xmlToJson(xml: XMLDocument): any

    Converts XMLDocument to JSON object according to defined schemas

     const obj = csw.xmlToJson(xml);
  • xmlToString(xml: XMLDocument): string

    Converts XMLDocument to XML-like string according to defined schemas

     const str = csw.xmlToString(xml);

OGC Filters

  • Operators:

    • Logical Operators:
      • AND
          let filter: any = new FilterBuilder().PropertyName('dc:title').isLike('%water%');
          filter = filter.and(new FilterBuilder().PropertyName('dc:subject').isLike('%polution%'));
      • OR
          let filter: any = new FilterBuilder().PropertyName('dc:title').isLike('%water%');
          filter = filter.or(new FilterBuilder().PropertyName('dc:title').isLike('%oil%'));
  • Spatial Operatos:

    • BBOX
    let filter: any = new FilterBuilder().PropertyName('dc:title').isLike('%water%');
    filter = filter.and(new FilterBuilder().BBOX(-80, 150, 80, -150));
  • Comparison

    • isLike
    • isBetween
    • isEqualTo
    • isLessThanOrEqualTo
    • isGreaterThan
    • isLessThan
    • isGreaterThanOrEqualTo
    • isNotEqualTo

OGC Sort

  const sort: SortBuilder = new SortBuilder().Sort('dc:title');
  sort.Sort('dc:dummy', true);

Applyed patches ( ./patches/*.patch )

csw-client's People

Contributors

alebinson avatar anguiar avatar cl-shaharshavit-rnd avatar yossizz avatar

Stargazers

Hanokh Aloni avatar

Watchers

James Cloos avatar Jkamz avatar  avatar  avatar  avatar Asaf avatar  avatar

Forkers

tommatheussen

csw-client's Issues

Option to specify ElementSetName on GetRecords method

Is your feature request related to a problem? Please describe.
Currently I am unable to get records (GetRecords) using the default 'full' element set name.

Describe the solution you'd like
An option to specify 'summary' or 'brief'

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.