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 🙏

© 2026 – Pkg Stats / Ryan Hefner

xgis-bdgrid

v0.1.0

Published

基于GB/T 39409-2020b标准实现北斗网格位置码的编码、解码和剖分计算的基础库。

Downloads

1,065

Readme

xgis-bdgrid

xgis-bdgrid基础库

北斗网格位置码编码与计算的基础库

基于beidou-grid-location-codec库的进行定制修改与扩展,实现北斗网格位置码(GB/T 39409-2020)标准,用于2D/3D北斗网格编码、解码和剖分计算。(目前基于网格的空间计算功能正在内部测试完善中……)

  • v0.1.0 修改高度边界计算层级问题(例如:1层的顶是2层的底,应属于2层);
  • v0.0.9 修改层级计算错误(应该向上取整),修改其他小问题;
  • ~~v0.0.8 修改发现的内部bug;增加相邻关系判断;~~
  • ~~v0.0.7 新增部分方法;增加内部基础常量导出;~~
  • ~~v0.0.6 重构代码分组和方法命名,空间编码(bdgrid_2d_和 bdgrid_3d_) 、空间运算(spatial_2d_和 spatial_3d_)、高度编码(bdgrid_elevation_);~~
  • ~~v0.0.5 解决内部bug;增加临近网格计算;~~
  • ~~v0.0.4 解决0.0.3版本存在的问题。~~
  • ~~v0.0.3 增加基于北斗编码的空间运算引擎。~~
  • ~~v0.0.2 修改功能BUG,补充新功能。~~
  • ~~v0.0.1 初始版本,包括网格编码、解码和剖分计算。~~

主要功能:

  • 二维网格(含极坐标)编码、解码、参考短码、短码还原、最大级别、临近网格等

  • 三维网格编码、解码,高程编码、解码,临近网格

  • 三维网格剖分

使用

pnpm add xgis-bdgrid

or

npm i xgis-bdgrid

import type { IGrid3DMeta } from "xgis-bdgrid";
import { Cesium, GroundPrimitiveLayer } from 'xgis-cesium';
import {
computeGrid3DMeshMeta,
createGridBoxOptions,
getAboveFitLevel,
getArcLengthByLevel,
getGrid2DExtent,
getBoxCenter,
getElevationByLevel,
getGrid3DMeshMeta,
getGridBox,
getGridBoxByMeta,
getGridBoxList,
getGridGeoExtent,
getHeightUnitByLevel,
getLevelAngleRad,
getN,
getNMax,
getRadiusByLevel,
intGrid3DMeshMeta,
searchGrid3DMeta,
getLevelByXRange,
}
from 'xgis-bdgrid';

//初始化代码
    intGrid3DMeshMeta();
    console.log('0000000000加载了widget:  TestBD3DGridWidget');
    const viewer = Global.CesiumViewer;
    if (viewer) {
        const gridPrimitiveLayer = new GroundPrimitiveLayer('testGrid');
        viewer.addLayer(gridPrimitiveLayer);
        console.log('添加了图层,开始构建网格要素')
        testInit2(gridPrimitiveLayer.delegate);
    }
async function testInit2(primitiveCollection: Cesium.PrimitiveCollection) {
    const colorGroup = ['#f00', '#ff0', '#0f0', '#00f'];
    for (let level = 1; level <=3; level++) {
        const  colorString = colorGroup[level - 1];

       const gridBoxOptions= createGridBoxOptions(geoExtent,level);
       
       console.log(level,gridBoxOptions);
       const len=gridBoxOptions.length;
       for(let i=0;i<len;i++)
       {
        const gridBoxOption=gridBoxOptions[i];
        if(gridBoxOption)
          drawGridBoxOutline(gridBoxOption, primitiveCollection, colorString);
       }     
        console.log('完成网格构建,层级:' + level);
    }
}
function drawGridBoxOutline(gridParam: any, primitiveCollection: Cesium.PrimitiveCollection, colorString: string = '#0f0') {
    const center = gridParam.center;
    const dimens = gridParam.dimensions;

    const position = Cesium.Cartesian3.fromDegrees(center[0], center[1], center[2]);
    const dimensions = new Cesium.Cartesian3(dimens[0], dimens[1],dimens[2]);

    // BoxOutlineGeometry:创建仅轮廓的长方体
    const boxOutlineGeometry = Cesium.BoxOutlineGeometry.fromDimensions({
        dimensions: dimensions,
    });
    const boxOutlineInstance = new Cesium.GeometryInstance({
        geometry: boxOutlineGeometry,
        modelMatrix: Cesium.Transforms.eastNorthUpToFixedFrame(position),
        attributes: {
        color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromCssColorString(colorString))
    }
    });
const appearance = new Cesium.PerInstanceColorAppearance({
    flat: true,
    translucent: false
});
    // 轮廓长方体用 LineAppearance(仅渲染线)
    const boxOutlinePrimitive = new Cesium.Primitive({
        geometryInstances: boxOutlineInstance,
        appearance,
    });
    primitiveCollection.add(boxOutlinePrimitive);

}

相邻网格自动扩展,测试代码

import {
    bdgrid_2d_between,
    bdgrid_2d_codelevel,
    bdgrid_2d_decode,
    bdgrid_2d_derefer,
    bdgrid_2d_encode,
    bdgrid_2d_join,
    bdgrid_2d_neighbors,
    bdgrid_2d_refer,
    bdgrid_2d_refer_range,
    bdgrid_2d_shorten,
    bdgrid_2d_size,
    bdgrid_2d_split,
    bdgrid_3d_code2d,
    bdgrid_3d_codelevel,
    bdgrid_3d_contains,
    bdgrid_3d_decode,
    bdgrid_elevation_decode,
    bdgrid_elevation_encode,
    bdgrid_3d_elevationcode,
    bdgrid_elevation_code,
    bdgrid_3d_encode,
    bdgrid_3d_join,
    bdgrid_3d_neighbor,
    bdgrid_3d_neighborcode,
    bdgrid_3d_neighborcode2,
    bdgrid_3d_parentcode,
    bdgrid_3d_split,
    Codec3D,
    getGrid2DRowCol,
    getGrid3DMeshMeta,
    getGridBox,
    getGridBoxByCode3D,
    getGridBoxByStruct,
    getN} from 'xgis-bdgrid';

async function testBDGridEngine2(primitiveCollection: Cesium.PrimitiveCollection)
{
    const code3D = bdgrid_3d_encode({
        lngDegree: 114,
        latDegree: 25,
        elevation: 2000,
    }, 5);

   const code3DStruct=bdgrid_3d_split(code3D);
//    drawGridByCode(code3D,primitiveCollection);
//   const code3DStructE= bdgrid_3d_neighborcode(code3D,'NW');
//    drawGridByCode(code3DStructE,primitiveCollection,'#00f');
//    console.log('444444444',code3DStruct,code3DStructE);
//,'SW','NW'   'NE','SE','SW','NW', 'U',
 const group=['E','W','N','S','NE','SE','SW','NW'];//['E','SE','SW'];//,'U','D'  ,'U','D'
 const colorStrs=['#00f','#0f0','#FFF','#000','#ff0','#ff0','#0ff','#0ff','#f00','#ff'];
 let current=code3DStruct;
 for(let i=0;i<100;i++)
 {
    const dir=getRandomItem(group);//'E';
    const code3DStructE= bdgrid_3d_neighborcode2(current,dir);
   drawGridByCode(code3DStructE,primitiveCollection,colorStrs[i%9]);
   current=code3DStructE;
   console.log('000000000完成第:'+i,dir);
 }
}

async function drawGridByCode(code3d:string|IBDCodeStruct,primitiveCollection: Cesium.PrimitiveCollection,colorStr='#f00')
{
    let gridBoxOption:any;
   if(isString(code3d)) 
    gridBoxOption=await getGridBoxByCode3D(code3d);
   else 
   gridBoxOption= await getGridBoxByStruct(code3d);
    if (gridBoxOption)
    {
        //console.log('7777777777888',colorStr,gridBoxOption);
        drawGridBoxOutline(gridBoxOption, primitiveCollection, colorStr);
    }
}
//根据高度和级别,计算层级
 const n1=  getN(5,551);

//根据三维码,计算高度值和层级
 const codeEle0 = bdgrid_elevation_code(code3DStruct);
 const height0 =bdgrid_elevation_decode(codeEle0);
 const n0 = getN(5, height0);

同步参考:https://www.npmjs.com/package/beidou-grid-location-codec

应用示例

北斗三维网格 北斗三维对角相邻网格 北斗网格自动随机扩展 北斗飞行预报网格 建筑剖分网格

关联资源

beidou-grid-location-codec

xframelib

xgis-ol

xgis-cesium