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

@wootapa/polygraph-ol

v1.0.8

Published

Extension of @wootapa/polygraph for OpenLayers 7+.

Downloads

81

Readme

Polygraph - OpenLayers

This is an extension of https://github.com/wootapa/polygraph with spatial operators for OpenLayers 7+. Use it to evaluate features/geometries (or geometrylike objects) or serialize into CQL/XML to be used by an OGC compliant server, such as Geoserver...all using the same instance of Polygraph.

See demo with WFS/WMS side by side.

Installation

Modern browsers and bundlers (es):

$ npm install --save @wootapa/polygraph-ol
import { Polygraph } from '@wootapa/polygraph-ol';
// Polygraph.and()... (types included)

Legacy (umd):

<script src="https://unpkg.com/@wootapa/polygraph-ol"></script>
// polygraph.and()...

Methods

Below is only the spatial methods. See Polygraph library for the standard operators available for comparing ordinary attributes.

Statics

  • defaultProjection(projection) - Sets default projection for all new Polygraphs. The projection is assumed to be known by OpenLayers and values are assumed to be transformed. Defaults to EPSG:3857.

Spatial operators

value = geometrylike object. See below for what that is.

  • intersects(value) - True when object intersects value.
  • disjoint(value) - True when object do not intersects value.
  • contains(value) - True when object completely contains value.
  • within(value) - True when object is completely within value.
  • distanceWithin(value, distance, greatCircle?) - True when object is no more than specified distance (in meters) from value. Requires a correct projection. Uses greatCircle by default.
  • distanceBeyond(value, distance, greatCircle?) - True when object is more than specified distance (in meters) from value. Requires a correct projection. Uses greatCircle by default.

Other

  • projection(projection) - Overrides the default projection for current Polygraph.
  • asOgcCql(opts?) - Outputs as OGC CQL.
  • asOgcXML(opts?) - Outputs as OGC XML.

CQL/XML serializers take an optional object:

geometryName?, // Serializes operators with a different geometryName. Ex 'the_geom'.
projection?, // Serializes operators with a different projection. Ex 'EPSG:4326'.
decimals? // Rounds geometry decimal precision on serialized operators. Ex, 5.

Geometrylike objects

These types are all valid values for the spatial operators. If you need to evaluate ordinary attributes, use a type that can carry attributes.

  • ol/Feature (can carry attributes and respects geometryName)
  • ol/Geometry
  • An object with a valid ol/Geometry (ex feature.getProperties()) (can carry attributes)
  • WKT
  • GeoJSON (can carry attributes)
  • Array(2=point, 4=extent=polygon, 6=linestring, 8+=linestring/polygon)

An example

So maybe you have a bunch of features and you need all wells.

const q = and().eq('type', 'well').done();

You figure the depth must be at least 32 meters

q.gte('depth', 32).done()

It also must be drilled before 1998

q.lte('drilled', new Date(1998,0)).done()

It should also intersect the area of interest

q.intersects([13.8517, 55.9646, 14.3049, 56.1017]).done() // <- You have options what you pass here.

In the end, this is the result.

const q = and()
    .eq('type', 'well')
    .gte('depth', 32)
    .lte('drilled', new Date(1998,0))
    .intersects([13.8517, 55.9646, 14.3049, 56.1017])
    .done();

Apply on client features...

const features = [...];
const wells = features.filter(q.evaluate);

...or output as CQL/XML and pass it to your OGC compliant server.

const opts = { geometryName: 'geom', projection: 'EPSG:3006', decimals: 0 }; // <- Optional
const cql = q.asOgcCql(opts);
const xml = q.asOgcXml(opts);

Pro ol-tip!

To hide/show features based on the result you can do:

const hiddenStyle = new Style();
source.forEachFeature(feature => {
    feature.setStyle(
        q.evaluate(feature)
            ? null        // visible (use layer style)
            : hiddenStyle // hidden (overrides layer style)
        );
});