Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am using QGIS to map a number of radio antennas (for mobile network). Once I have the layer of the sites (done), I would like to assign to each site a coverage area (envelope). I could achieve that using the "fixed distance buffer" function of fTools

However, I couldn't make the envelope have a Hexagon shape.

When I specify the number of segments: 1: I obtain a square 2: I obtain an octagon ...

How can I do to have a Hexagon?

Thank you

share|improve this question
    
I don't know of a plugin that does hexagons and I also can't enter a value of less than 5 in the buffer tool so I can't reproduce what you see. There is a tool which will do squares, diamonds and oval buffers, but again that's not really what you're after. I suspect you will need to do a little scripting. –  MappaGnosis Jan 4 '13 at 14:41
add comment

1 Answer 1

As MappaGnosis indicated, you could write a little script for this. Here's one called polygonbuffer which takes three arguments: The output file name, the radius of your buffer, and the number of corners of the polygons.

Open a Python console in QGIS, paste the script and press enter to define the function, then call using something like polygonbuffer("polygons.shp",50,6) to get hexagons with a radius of 50 map units:

import numpy as np
def polygonbuffer(outputFilename, bufferLength, polygonSides=6):
 layer = qgis.utils.iface.activeLayer()
 provider = layer.dataProvider()
 fields = provider.fields()
 writer = QgsVectorFileWriter(outputFilename, "CP1250", fields, QGis.WKBPolygon, provider.crs(), "ESRI Shapefile")
 inFeat = QgsFeature()
 outFeat = QgsFeature()
 inGeom = QgsGeometry()
 provider.select( provider.attributeIndexes() )
 while provider.nextFeature(inFeat):
  point = inFeat.geometry().asPoint()
  inGeom = inFeat.geometry()
  outFeat.setGeometry(QgsGeometry.fromPolygon(
   [[QgsPoint(point[0]+np.sin(angle)*bufferLength, point[1]+np.cos(angle)*bufferLength)
     for angle in np.linspace(0,2*np.pi,polygonSides, endpoint=False)]]))
  outFeat.setAttributeMap( inFeat.attributeMap() )
  writer.addFeature( outFeat )
 del writer
 newlayer = QgsVectorLayer(outputFilename, "Polygons", "ogr")
 QgsMapLayerRegistry.instance().addMapLayer(newlayer)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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