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

spatial_query

v0.0.1

Published

A JQuery like Javascript library for working with Matrix / Vertex / Polygon / Latitude and Longitude

Downloads

3

Readme

Spatial Query - a JQuery like Javascript library for handling spatial maths Copyright (c) 2009 Chris Zelenak Spatial Query is freely distributable under the MIT X11 License - see LICENSE file.

A set of functions for initializing array data into spatial objects (matrix, vectors, polygons and latitude / longitude points) from which further operations may be made.

Most vector and matrix operations support calculations to any dimension size. In cases where they are not supported, one of the two following cases will arise:

  • The function will be named _2d or _3d to indicate what dimension the operated data should be in

  • The function will throw an error stating that the general case solution has not been implemented yet. (Matrix inversion, for example)

Examples:

Return a vector at point x:10, y:0, z: 40.

$v([10, 0, 40])

Return a 5 element vector:

$v([10, 0, 40, 21, 32])

Take the vector at x:10, y:20 and project it on the vector at x:30 y:50, then return the magnitude of that vector.

$v([10, 20]).project_on([30, 50]).magnitude();

Take the latitude / longitude pair for Indianapolis and convert it into cartesian (WSG84) coordinates

$ll([39.7670, -86.1563]).vector()

The same as above, but roundtrip convert it back to latitude / longitude.

$ll([39.7670, -86.1563]).vector().latlng()

Generate a polygon

$p([[0,0], [0, 10], [10, 10], [10, 0]])

Compute the area of the polygon

$p([[0,0], [0, 10], [10, 10], [10, 0]]).area_2d()

Compute the centroid point (vector) of the polygon

$p([[0,0], [0, 10], [10, 10], [10, 0]]).centroid_2d()

Compute the convex hull of the polygon

$p([[0,0], [0, 10], [10, 10], [10, 0]]).convex_hull_2d()

Compute the union of the given polygon with another polygon

$p([[0,0], [0, 10], [10, 10], [10, 0]]).union_2d([[5,5], [5, 7], [15, 7], [15, 5]])

Vector: $v([x, y, z, t, etc]) -vector() -> Vector -latlng() -> LatLng, Convert to Latitude and Longitude -matrix() -> Matrix -add(other_vector_or_scalar) -> Vector -subtract(other_vector_or_scalar) -> Vector -multiply(other_vector_or_scalar) -> Vector -dot_product(other_vector) -> Number -cross_product(other_vector) -> Vector if dimension greater than 2, Number if dimension == 2 -distance(other_vector) -> Number -midpoint_2d(other_vector) -> Vector -distance_2d_fast(other_vector) -> Number, A faster vector distance function. -magnitude() -> Number -norm(n) -> Number, The nth vectorm norm, defaults to 2. -angle_between(other_vector) -> Vector -project_onto(other_vector) -> Vector -x(), y(), z() -> Number, Convenience functions. -elm(i) -> Number

Matrix: $m( [[row1a, row1b, row1c], [row2a, row2b, row2c]] ) -matrix() -> Matrix -elm(i,j) -> Number -add(matrix_or_scalar) -> Matrix -subtract(matrix_or_scalar) -> Matrix -multiply(matrix_or_scalar) -> Matrix -divide(matrix) -> Matrix -transpose() -> Matrix -determinant() -> Number -inverse() -> Matrix -rotate() NOT IMPL -identity() -> Matrix -normalize() NOT IMPL

Polygon: $p( [ [x1, y1], [x2, y2], [x3, y3], [x4, y4] ] ) -matrix() -> Matrix -polygon() -> Polygon -add_point(vector) -> Polygon -to_point_array() -> Array -foreach(fn) -> Polygon, Calls fn with each node inside the polygon -point_inside_2d(vector) -> Boolean -point_inside_fast_2d(vector) -> Boolean -clip_2d(polygon) -> Polygon, or null if no operation took place -union_2d(polygon) -> Polygon, or null if no operation took place -subtract_2d(polygon) -> Polygon, or null if no operation took place -area_2d() -> Number -centroid_2d() -> Vector -centroid_3d() -> Vector -convex_hull_2d() -> Polygon -contains_2d(other_polygon) -> Boolean -intersects_2d(other_polygon) -> Array of vectors(intersections) or null

LatitudeLongitude: $ll( [latitude, longitude, altitude] ) -vector() -> Vector, convert to WSG84 x/y/z coords -latlng() -> LatLng -lat(), lng(), alt() -> Number, convenience functions -distance_to(latlng) -> Number (meters), Uses the Vincenty eq. for mm precision -distance_to_miles(latlng) -> Number (miles) -bearing_between(latlng) -> Number -destination_given_distance_and_bearing(distance_in_meters, bearing) -> LatLng

Known bugs:

  • Math is not my strong suit
  • Boolean operations on polygons are still not reliable. There are some kinks in the algorithm.
  • Some of the general case operations on a matrix are not yet implemented. It's because they are hard, and I don't personally need them right now.

Chris Z For work at www.indy.com Talked about at www.yeti-factory.org