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'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
1  
Hi qdoe, I think you were not the only one with this problem. As it seems from this discussion groups.google.com/d/topic/geoscript/ztA1NLW2B2Q/discussion , the library is currently being improved on that side. –  moovida Oct 14 '13 at 12:07

1 Answer 1

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

 
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.