Developing Importer for .SHP (or SHX) to SketchUp

shp
import
shx
extension

#43

If you open the Ruby Console before running the plugin (Window >> Ruby Console), it will display some useful information along with any errors that might occur. Depending on the shapefile dataset, the range of co-ordinate information may need to be scaled substantially. SketchUp cannot create an edge that is smaller than 0.001" in length. The workaround for this is to scale the geometry up before using it and then scale it back down when done. The plugin makes no assumptions about units and uses the data as raw units created as inches. The second issue is that large datasets may have so many polygons made up of so many edges that your computer may not be able to realistically handle it (mileage varies widely). This is the purpose of providing a limit on the number of polygons as well as providing a limit on the constraining bounding box. This is the purpose of creating the grid file to help determine the bounding box limit for any given run. If you run the plugin for the LARIAC buildings and use the following values, you should get a successful result:

xmin = 6483101
ymin = 1839530
xmax = 6487005
ymax = 1843435
scale = 1

For other shapefiles, like those available from GEOFABRIK, I ran a sample input with the original bounding box for the first 10,000-odd polygons using a scale factor of 100,000. This gave me a decent idea of where in the x/y space the data lies. Measuring from the origin with the tape measure gave me the xmin/ymin-xmax/ymax values I needed to restrict the data. Let me know how it works out for you … this is still a work in progress.


#44

Yep, the x/y location of the imported geometry is what was throwing me off. I kept expecting it to appear at SketchUp’s origin. Now I can actually start playing around. Thanks for the quick reply. I’ll let you know how it goes!


#45

Jim,

I am having trouble getting the height dialogue box to pop up when I try to import a shapefile. I go to extensions>import shapefile, navigate to my shapefile, and nothing happens.
I’m not sure if I installed the plug-in wrong. I am using a mac and sketchup pro 2015. I dragged the .rb file into > Library > Application Support > SketchUp # > SketchUp > Plugins.

Any advice??

I am trying to create 3d buildings with 2014 LA building footprints.Buildings.zip (636.1 KB)

I get the following error

Error: #<Errno::ENOENT: No such file or directory - Buildings.shx>
/Users/lolabelittle/Library/Application Support/SketchUp 2015/SketchUp/Plugins/jimhami42_shapefile_importer.rb:244:in initialize' /Users/lolabelittle/Library/Application Support/SketchUp 2015/SketchUp/Plugins/jimhami42_shapefile_importer.rb:244:inopen’
/Users/lolabelittle/Library/Application Support/SketchUp 2015/SketchUp/Plugins/jimhami42_shapefile_importer.rb:244:in jimhami42_shapefile_import_get_data' /Users/lolabelittle/Library/Application Support/SketchUp 2015/SketchUp/Plugins/jimhami42_shapefile_importer.rb:128:injimhami42_shapefile_import_get_input’
/Users/lolabelittle/Library/Application Support/SketchUp 2015/SketchUp/Plugins/jimhami42_shapefile_importer.rb:104:in jimhami42_shapefile_import' /Users/lolabelittle/Library/Application Support/SketchUp 2015/SketchUp/Plugins/jimhami42_shapefile_importer.rb:279:inblock in module:ShapefilePolygonImporter
SketchUp:1:in `call’


#46

did you read above where both I and then TIG, offer changes for mac usage?

[click here…][1]

john
[1]: Developing Importer for .SHP (or SHX) to SketchUp


#47

Why not offer it in a rbz file?


#48

I’m sorry you’re having trouble … I had thought we had resolved the issues with the Macs, but I have no way of testing it. One question, did you unzip the data files first? There are three files that have to be in the same folder:

Buildings.shp
Buildings.shx
Buildings.dbf

I’ve attached the results you should get: lolabelittle.skp (950.5 KB)

John and Colin are Mac users that may be able to help fix things.


#49

Good idea … https://sites.google.com/site/spirixcode/code/jimhami42_shapefile_importer.rbz


#50

Ah, I’m new to SketchUp and don’t understand what it means or where to input that. Can you explain?


#51

Installing SketchUp extensions -http://help.sketchup.com/en/article/38583


#52

I’ve installed the extension fine, I’m just having trouble with the MAC workaround. Not sure what ui.openpanel is or does.


#53

The ui.openpanel is what SketchUp uses to browse to the folders and files you pick. A workaround for Macs is to edit the plugin and specify the location of the files in the program. There are three files so there are three places this needs to be done:

[line 150] file = @@basename + '.dbf'
[line 243] file = @@basename + '.shx'
[line 254] file = @@basename + '.shp'

For example, if your building files (not the plugin) are in an easy to type folder like “/tmp”, you would need to change the above referenced lines in the plugin to read:

[line 150] file = '/tmp/Buildings.dbf'
[line 243] file = '/tmp/Buildings.shx'
[line 254] file = '/tmp/Buildings.shp'

The plugin is a text file and can be edited with most any text editor (avoid using a word-processor, however … use something like TextEdit on a Mac and Notepad on a PC).


#54

Jim, the path code works now…
@lolabelittle, are you seeing ‘other’ errors…
john


#55

@lolabelittle

Fyi… If there are errors, you will see them in the Ruby Console located in SketchUp’s Windows area.

Open the console first, then activate the extension.


#56

I am on a mac as well and I initially received an error stating “… No such file or directory - Buildings.shx>”

The shapefile collection of files is in my Downloads area but after the selection of the Buildings.shp, the extension looks for the Buildings.shx in my Documents area and not in the location of the selected Buildings.shp.
I believe this is because, for Mac, the working directory defaults to Documents unless deliberately changed via ruby

To get it to work, I moved the shapefile collection of files to my Documents area.

Cheers
CD


#57

Thanks for all the help! It worked when I moved the shapefiles into my Documents folder, but not when I put it into a subfolder “/shp” within Documents.

How would I edit the plugin lines (150, 243, 254) if I wanted to direct it to a general folder like “/shp”? I’m looking to import multiple shapefiles.


#58

sorry I only had a quick look earlier and line 126 ‘looked’ ok…
it needs to be…

        @@basename = File.join(File.dirname(base), File.basename(base,".*"))

then it all works from any folder…

john


#59

Be aware that when the extension finishes importing the data and creating the geometry, each groups’ origin is positioned in accordance with the shapefile’s coordinate systems origin. In the Buildings sample, the groups are imported over 106 miles from the SketchUp origin.

Geometry at such a large distance from the origin wreaks havoc with how SketchUp displays geometry and one might see strange flickering and odd geometry artifacts.

.
.

To fix the issue, you will want to …

1) Move the groups closer to the origin. To do this you can select all the groups, start a move using the Move tool and before finishing the move, type “[0,0,0]”

.
.

2) Move each individual groups’ origin closer to the building geometry. Dont freak out because Thomthom’s Axis Tools makes it a snap.

  • FYI… in the example below, you don’t first see the axis when I open the group. This is because it is over 106 miles from the geometry.


#60

Thank you everyone! I was able to get it to show up with John’s workaround.

Chris, thanks for the tip. I would never have known otherwise.


#61

Good to hear that’s it’s working for you now, @lolabelittle :smile:

Some notes about datasets and importing them into SkecthUp … as Chris pointed out, the data for Los Angeles is referenced to a western origin somewhere near Santa Rosa Island and a southern one near the tip of Long Beach. If you are planning on importing a number of different buildings from the same dataset, you should probably import them all first and then scale/relocate them as needed. This will insure that they align relative to each other.

If you are trying to match a set of buildings to a satellite photo, keep in mind that some of the datasets are “uncorrected” and will line up with a Google Earth satellite view. Some of them are “corrected” and will line up with a Google Maps satellite view (they are not the same). Most of the datasets do not have a building height associated with them in the database. Also, for those that do, no attempt is made to determine what units they are using … they could be specified in cubits or fathoms or whatever. Los Angeles provides a second data height (“ELEV”) that is the elevation of the building roof above sea level. A more correct approach would be to create the building footprint at elevation and then extend it downwards to the ground using the “HEIGHT” value (a possible future feature).

The only input to override the native numbers is the scale value. For some datasets, the distance between two points in a building polygon is below the 0.001" (0.0254mm) threshold for creating geometry in SketchUp (what I refer to as “the tiny edge problem”). This will cause the program to fail when it tries to use two points that are too close together. For some datasets, I had to scale the nominal numbers by only 100 or so. For others I needed 200,000 or more.

For Los Angeles and New York City, I created some models and placed them in the 3D Warehouse. There are also some random building footprints in Liechtenstein. Not in the Warehouse are Delaware, Arizona, Hawaii, Dresden, and several others that I used to test the importer. Due to the wide variety of purposes that utilize the collected data, there is sometimes useful information in the database and sometimes not (some of them only have a building ID number).

I appreciate @john_drivenupthewall and @ChrisDizon helping you to figure out why it wasn’t working (I don’t have a Mac to test things with). I have some changes that were suggested by a couple of the coding gurus that should prevent these problems down the road, but I haven’t gotten around to implementing them yet. If you have any further problems or ideas on how this could be changed to make it better for your purposes, please let me know.

https://3dwarehouse.sketchup.com/by/jimhami


#62

Hi Jim,
Great tool this one!
However, it won’t work for me…
It only imports only a tiny portion of the buildings and those few imported are down scaled 100 times (I assume). What it should be 15m comes in 0.15m.

I attach here the dataset.
Any tip/suggestion would be highly appreciated!

Thankstest for SU EXTRUSION.zip (1.5 MB)