以编程方式将 .shp 文件转换为 Excel 电子表格

发布于 2024-12-29 06:57:12 字数 78 浏览 5 评论 0原文

我有一个 .shp 格式的文件,我需要它以编程方式将其转换为 Excel 电子表格。我想使用 PHP 或 JavaScript 来完成此操作。

I have a file in .shp format and I need it to convert it to an Excel spreadsheet programmatically. I want to do this using PHP or JavaScript.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

并安 2025-01-05 06:57:13

一旦我使用了小型 PHP lib ShapeFile,您就可以在 phpclasses.org。虽然这个设计有点不太好,但它确实有效。

这是我自己的代码中的一个小例子:

require_once 'lib/ShapeFile.inc.php';
$shp = new ShapeFile($filename, array('noparts' => false));
if ($shp->getError() !== '')
  print_r($shp->getError());
else
{
  $records = array();
  while ($record = $shp->getNext())
  {
    $dbf_data = $record->getDbfData();
    $shp_data = $record->getShpData();

    //Dump the information
    $obj = array(
      'type' => $shp->getShpTypeName($record->getShpType())
    );

    $obj['shape'] = $shp_data;
    $obj['meta'] = $dbf_data;

    $records[] = $obj;
  }
}

print_r($records);

因此,之后 $records 包含 shapefile 中的所有数据。当然,您需要一些时间来弄清楚 shapefile 是什么以及它可以保存哪些数据(假设您不熟悉它)。从维基百科开始。实际上有一堆带有一些标签的数组。

然后使用一些 php excel lib(只需在 so 中查找)就完成了:)

Once I've used small PHP lib ShapeFile, you can get it in phpclasses.org. Although it is a bit of not so good design, it works.

Here is a little example from my own code:

require_once 'lib/ShapeFile.inc.php';
$shp = new ShapeFile($filename, array('noparts' => false));
if ($shp->getError() !== '')
  print_r($shp->getError());
else
{
  $records = array();
  while ($record = $shp->getNext())
  {
    $dbf_data = $record->getDbfData();
    $shp_data = $record->getShpData();

    //Dump the information
    $obj = array(
      'type' => $shp->getShpTypeName($record->getShpType())
    );

    $obj['shape'] = $shp_data;
    $obj['meta'] = $dbf_data;

    $records[] = $obj;
  }
}

print_r($records);

So, after that $records contain all the data from shapefile. Of course, you will need some time to figure out what shapefile is and what data it can hold (assuming you are not familiar with it). Start from wikipedia. Actually there are bunch of arrays with some labels.

Then use some php excel lib (just seek in so) and you're done :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文