0

I'm trying to convert a .shp to .stl in order to 3D-print the later as a model.

I am following guides described in "Shapefiles" and "Using shp2stl to Convert Maps to 3D Models".

Unfortunately shp2stl, the tool described in both articles, doesn't work for me – I am trying to run an example from shp2stl repository, but get an error during the process:

$ node index.js
bounds: 5979385.645656869 2085840.5000395626 6024741.001443654 2131293.9999859035 (cartesian)
pre-quantization: 0.00045355356240339045 0.0004545350040087592
topology: 1698 arcs, 37009 points
topojson done
simplification: effective minimum area 0.00000299
simplification: retained 29608 / 37009 points (80%)
making top planes
making side planes
making bottom planes
/Users/eugene/oss/shp2stl/node_modules/three/three.js:32605
                for ( i = 0, il = triangles.length; i < il; i ++ ) {
                                           ^

TypeError: Cannot read property 'length' of null
    at Object.triangulateShape (/Users/eugene/oss/shp2stl/node_modules/three/three.js:32605:30)
    at THREE.ShapeGeometry.addShape (/Users/eugene/oss/shp2stl/node_modules/three/three.js:35513:32)
    at THREE.ShapeGeometry.addShapeList (/Users/eugene/oss/shp2stl/node_modules/three/three.js:35458:8)
    at THREE.ShapeGeometry (/Users/eugene/oss/shp2stl/node_modules/three/three.js:35442:7)
    at THREE.Shape.makeGeometry (/Users/eugene/oss/shp2stl/node_modules/three/three.js:32162:17)
    at /Users/eugene/oss/shp2stl/src/topojson2threejs.js:396:24
    at Array.forEach (native)
    at topojson2threeJSBottomPlanes (/Users/eugene/oss/shp2stl/src/topojson2threejs.js:392:20)
    at topojson2threejs (/Users/eugene/oss/shp2stl/src/topojson2threejs.js:76:16)
    at topojson2stl (/Users/eugene/oss/shp2stl/src/shp2stl.js:77:21)

What I might be missing? Is there a better way to get 3D-printable file out of .shp?


I've prepared a docker image which help to replicate the issue. Steps to reproduce my issue:

  • pull the image:

    docker pull gmile/shp2stl-fiasco
    
  • start bash inside the image:

    docker exec -it gmile/shp2stl-fiasco bash
    
  • go into examples directory and try to run the script:

    $ cd /shp2stl/examples/sfPopulationDensity/
    
  • run the script & see the issue:

    $ node index.js
    

Alternatively, I've prepared a Dockerfile that can be used to build an image to reproduce the issue with minimal effort:

FROM ubuntu:18.04

RUN apt update; \
  apt install git curl ca-certificates -y --no-install-recommends; \
  git clone https://github.com/dougmccune/shp2stl.git

RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | bash

WORKDIR /shp2stl/examples/sfPopulationDensity

# After building and entering a container, manually run the following:
#
#   nvm install v6.17.1
#   npm i
#   node index.js
oldhomemovie
  • 14,621
  • 13
  • 64
  • 99
  • I'm not going to clone a docker project and dig through your code (it's on you to reduce all of this to a [mcve]. Not just for us, but also for yourself), but I will look at your error, which shows something that should be a thing, is a `null` instead, and I'm seeing three lines in the error log that are "your code". What code path is that, and is the value that is `null` passed to three.js in that codepath at some point? – Mike 'Pomax' Kamermans Nov 26 '19 at 18:47
  • @Mike'Pomax'Kamermans the lines you are referring to as my code must be the library code or the code from the example (part in the library code on GitHub) that I am trying to run. Indeed, I do see that `triangles` variable is `null`. But because this is library code, this will require me to dig into it. Before I do that, I am seeking advise from people skilled in JS more than I am (I'm a JS rookie) – oldhomemovie Nov 27 '19 at 08:43
  • 1
    If you want help, you're still going to have to create a [mcve]: people are very willing to help you, but their time is an investment, and the time it requires to read into an entire project is time that can be spent answering _several_ questions that already took the effort to reduce the code to the core of the problem. Click on that link, read through how to make one, and then do that: not just "for Stackoverflow", but forcing yourself to create one lets you find the actual problem _yourself_ 99% of the time. It's a _fantastic_ debugging exercise, no matter how new or experienced you are. – Mike 'Pomax' Kamermans Nov 27 '19 at 16:10
  • Did you solve your problem? I run into the same issue today. – yaqwsx Dec 05 '20 at 20:39

0 Answers0