Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've created a geoscript (in groovy) to create a shapefile from generated geometries with certain attributes.

It's a heatmap consisting roughly 65.000 polygons with an attribute storing the temperature. The final code to write the shapefile looks like that:

dir = new Directory("/my/path")
shp = dir.create('heatmap',
                     ["geom", "Polygon", "epsg:4326"],
                     ["temp", "float"]
// ...
temperatures.eachWithIndex{ temperature, index ->
    shp.add([geometries[index], temperature])

The last line is the issue here. Adding each of the 65k attributes to the shapefile is taking ages.

I've found out that (because shapefiles are a proprietary, binary format) adding each geometry causes the shapefile to completely be rewritten from scratch. The result is, that the efford to write records to a shapefile is not linear but exponential to the number of records.

That's a huge problem. Is there any way to write the stuff more efficiently to the shapefile? I got all geometries and all attributes stored in arrays, isn't there any way to write them all at once?

share|improve this question
Hi qdoe, I think you were not the only one with this problem. As it seems from this discussion , the library is currently being improved on that side. – moovida Oct 14 '13 at 12:07

You can use the dir.add() method for implicit data conversion. You must first store your geometries and temperatures in a temporary Layer, just like you did for the Shapefile. To write to the Shapefile in one command, execute dir.add(layer). Please see this example, data conversion.

share|improve this answer

Your Answer


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.