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 🙏

© 2025 – Pkg Stats / Ryan Hefner

geojson-shadow-generator

v1.0.6

Published

This module aims to generate shadow geometries as GeoJSON by using properties from GeoJSON files

Readme

Shadow Generator Demo

GeoJSON Shadow Generator

A powerful tool to simulate shadow geometries from 2D building footprints (as GeoJSON) using sun position (via direct angles or date-time). Supports elevation-based shadow generation and handles Polygon and MultiPolygon types.

Installation

npm install geojson-shadow-generator

or with yarn:

yarn add geojson-shadow-generator

or with vanillajs

https://cdn.jsdelivr.net/npm/geojson-shadow-generator/bundle.js

✨ Features

  • Calculates shadow geometries based on:

    • Direct sun azimuth/elevation angles.
    • Automatic sun position using date-time and GeoJSON center.
  • Validates input GeoJSON (Feature or FeatureCollection).

  • Supports Polygon and MultiPolygon geometry types.

  • Uses @turf and suncalc libraries under the hood.

  • Returns output as a valid GeoJSON FeatureCollection or Feature.


Usage

Import

const GeoJSONShadowGenerator = require('geojson-shadow-generator');

Example

const geojson = require('./yourGeoJSON.json');

const generator = new GeoJSONShadowGenerator(geojson, 'elevation');

// Using direct sun angles
const shadows1 = generator.getShadowGeometries({
  type: 'direct',
  sunAzimuth: 135,        // degrees from north, clockwise
  sunElevation: 30        // degrees above horizon
});

// Using date-time and automatic sun position
const shadows2 = generator.getShadowGeometries({
  type: 'datetime',
  date: '2025-06-01T10:00:00Z'
});

Constructor

new GeoJSONShadowGenerator(geojson: FeatureCollection | Feature, elevationPropertyName?: string)

| Parameter | Type | Required | Description | | ----------------------- | --------- | -------- | ----------------------------------------------------------------------------------------------- | | geojson | GeoJSON | ✅ | Input Feature or FeatureCollection with Polygon or MultiPolygon geometries. | | elevationPropertyName | string | ❌ | Property name in feature properties that holds the elevation value. Default is 'elevation'. |


⚙️ getShadowGeometries(options)

Generates shadow geometries.

Options

| Key | Type | Required | Description | | -------------- | -------------------------- | --------------------------------- | ------------------------------------------------------------------------ | | type | 'direct' | 'datetime' | ❌ | Type of shadow calculation. Default: 'direct'. | | sunAzimuth | number | Required if type === 'direct' | Azimuth angle (degrees from north, clockwise). | | sunElevation | number | Required if type === 'direct' | Sun elevation angle (degrees above horizon). | | date | string (ISO format) | Required if type === 'datetime' | ISO date-time string used to calculate sun position from GeoJSON center. |


GeoJSON Requirements

  • Input must be a valid GeoJSON Feature or FeatureCollection.
  • Geometry type must be Polygon or MultiPolygon.
  • Each feature must have a numeric elevation property (or custom property if set via constructor).

Example of a valid feature:

{
  "type": "Feature",
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [
        [27.09, 38.45],
        [27.10, 38.45],
        [27.10, 38.46],
        [27.09, 38.46],
        [27.09, 38.45]
      ]
    ]
  },
  "properties": {
    "elevation": 50
  }
}

Behind the Scenes

  • Uses suncalc to compute sun azimuth and elevation from date and latitude/longitude.
  • Projects coordinates to EPSG:3857 to perform shadow translation in meters.
  • Offsets geometry using the solar vector and elevation.
  • Combines the original and translated geometries to form shadows.
  • Uses Turf's convex, difference, and union functions.

Testing

Example test case:

const test = new GeoJSONShadowGenerator(geojson, 'elevation');

const result1 = test.getShadowGeometries({
  type: 'datetime',
  date: '2025-05-31T14:30:00'
});

const result2 = test.getShadowGeometries({
  type: 'direct',
  sunAzimuth: 50,
  sunElevation: 45
});

Output

The returned result is a GeoJSON FeatureCollection that represents the shadow geometries of the input features.


Dependencies

This package uses the following libraries:


License

MIT © 2025 - Ali Kilic | https://akilic.com


Tip

You can visualize the shadow outputs using: