2

I would like to extrude shapefile polygons to a KML based on a value stored in the attribute table. I am hoping to do this using open source software (QGIS, FWTools, GDAL, etc.). I looked at ogr2ogr using the -zfield option, but the polygons were not extruded as a KML, they were just an outline.

Any help would be appreciated,

Thanks...

1

You can use a specific column for extruding a shapefile to a kml using GDAL's ogr2ogr utility, but only if it's been compiled with libkml support. If it's been compiled with libkml support, that will become the default KML driver.

So you can try the following, first specify the zfield to be used in an environment variable, then run the ogr2ogr utility:

# Use **export** if on linux, but use **set** command instead if on Windows!
export LIBKML_EXTRUDE_FIELD=zfield
ogr2ogr -f libkml output.kml input.shp

...where zfield is the name of the actual column that contains the z values

Then there is also the creation option available for the regular KML driver, but this doesn't specify a field for extrusion, only the altitudeMode:

ogr2ogr -f KML output.kml input.shp -dsco AltitudeMode=absolute

The other AltitudeMode options are in the link I gave there, but the default is relativeToGround.

0

You can load the shapefile into QGIS, rightclick on the layer and select Query to filter the elements of the shapefile you want.

Then you can save the filtered layer as KML with rightclick -> Save as...

  • The creation of a kml is not the issue, it's extruding it into a 3D kml based on an attribute height is where I am having the issue – Ryan Garnett Jul 16 '13 at 5:14
  • OK, 3D is a special case. I'm not sure wether the developers have implemented that in the kml or libkml driver. I'm afraid you have to do that on your own... – AndreJ Jul 16 '13 at 7:59
0

there is a opensource python-library for generating kml. I never used it, but the documentation (entering "extrude" into the quick-search-box) shows, that the lib can extrude. maybe together with a python library for reading shps (e.g. pyshape) you can do the job?

pykml http://pythonhosted.org/pykml/index.html pyshp: https://code.google.com/p/pyshp/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.