How to write shapefiles more efficiently in GeoScript?

المشرف العام

Administrator
طاقم الإدارة
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?



أكثر...
 
أعلى