使用shp-write将Geojson转换为Javascript中的Shapefile [英] Converting Geojson to Shapefile in Javascript using shp-write

查看:793
本文介绍了使用shp-write将Geojson转换为Javascript中的Shapefile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Mapbox,并且尝试使用 shp将Geojson转换为压缩的shapefile -写.但是,当我按照GitHub页面上给出的示例时,我得到了一个在此行上出现ReferenceError:未定义require"错误:

I'm using Mapbox, and I'm trying to convert a Geojson to a zipped shapefile using shp-write. But when I follow the example given on the GitHub page, I'm getting a "ReferenceError: require is not defined" error on this line:

var shpwrite = require('shp-write');

这是 jsfiddle ,您可以在其中进行测试.我对JavaScript相对较新,并且以前不必使用'require()'函数.

This is a jsfiddle in which you can test this. I'm relatively new to JavaScript, and haven't had to use the 'require()' function before.

推荐答案

您提供的jsfiddle包括多个外部资源,其中包括 unpkg 发送丢失.

The jsfiddle you provided includes several external resources, among which a shpwrite delivered by unpkg that you may be missing.

通常require 在您的浏览器中不存在.您可能需要使用Node.js来执行它,或使用 Webpack 之类的模块打包器,但是Unpkg会负责它给你.

Usually require doesn't exist in your browser. You would need to execute it with Node.js or use a module bundler like Webpack, but Unpkg takes care of it for you.

因此添加:

<script src="https://unpkg.com/shp-write@latest/shpwrite.js"></script>

您页面上的

应该可以正常工作.

on your page should make it work.

这篇关于使用shp-write将Geojson转换为Javascript中的Shapefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆