[GIS] Converting Shapefile to X3D format

3d3d-analystconvert

Does anyone know of an effective workflow to convert 3d-enabled shapefiles to X3D format? I have several projects containing anywhere from 10 to 5000 features (building sections) that I would like to convert into X3D format. The shapefiles in question have topheight and baseheight attribute fields.

I have read these:

How can a 3D model of a building be displayed in a web-browser?

Georeferenced 3D Model Import

I have browsed this list of applications and resources to see what is available for import/export/conversion. I have experimented with ArcGlobe, exporting my shapes to COLLADA using Layer 3D to Feature Class and Multipatch to Collada. This tool limited me to exporting building sections or contiguous building sections (whole buildings). I then used Meshlab to convert COLLADA to 3DX. The only downfall with this is that I would have to convert thousands of building files to 3DX.

I would be interested in hearing of other workflows for similar situations.

Best Answer

Clearly you need some batch processing method. Unfortunately, I don't recall Meshlab having any means of natively reading shapefiles so some coding there would be necessary. Meshlab is a great package but I've never tried extending it as I tend to use Blender.

FME has been recommended and if you have it (perhaps as the Data Interoperability Suite) then that is an excellent route.

Though not quite batch processing, using ArcScene, you could merge your building files or have them in multiple layers and export to VRML and thereby reduce your manual input. VRML is X3D's older cousin and is viewable in most X3D viewers and modelling packages. What I never tried was to see if you could have a script in ArcObjects or ArcPy load the shapefiles and export to VRML automatically. My gut feeling is you can't... but like I said, I never tried to do it, so who knows?

If you don't have FME and the ArcScene route is too 'clunky', then there is not such a direct route from a shapefile to X3D unless you don't mind a bit of programming. The X3D format is pretty straightforward, so, using ArcPy or the Python GDAL libraries (other programming languages are available). It is a simple enough task to either write a script to pull the shapefile geometry into a modelling package and have it spit out the X3D or write not much more code and have your script just write the X3D file directly. You can then configure this as a batch process and with a bit of multiprocessing, rattle through your files quickly. It also shouldn't be too hard to set face normals, texture vertices and lights too.

If I had a LOT of files to work through and especially if there is the possibility of having to repeat the process in the future, I think I would opt for the stand-alone, home-grown version. That said, if you are intending to go further and edit your scene in a 3D package, then finding one which supports Python or one of the other GDAL APIs would be beneficial. You then adapt your code to pull the geometry in to the modelling package in its internal format (I do this a lot with Blender).

A related aside:
For other sorts of data you can actually use Excel to create much of your X3D/VRML code! This is a nasty but effective little trick I used to use for rapidly creating scenes with thousands of trees or other instantiated objects represented by point data from shapefiles. Use SpatialAnalyst to get the Z value from your DEM and export your data as a CSV with X,Y and Z columns. Open the CSV in Excel (or OpenOffice Calc) and insert some columns so you can add code for a transform node for one row ending with open brackets in the column before your XYZ columns. Then close all your brackets at the other end. Auto fill down for all your rows. In your first point, reference your model that is to be placed at the point (e.g. a tree). In your second point, instantiate the first point and then copy/fill down for all remaining points. Add a few rows at the top of the spreadsheet and insert the VRML/X3D header line and then save as a text file but give it the appropriate extension. This method is quick and dirty and gets results. You can even get fancy and randomize your output to (say) jitter your points, rotate them about the Z axis or apply a random scaling factor (thus making your trees or whatever look a bit more natural) and you can do this by using applying a formula to appropriate cells in Excel.