Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Comparing the payload sizes of various GIS data transport types
# Test the size of serialized geometries, GZipped or not.
require 'msgpack'
require 'rio'
require 'fastercsv'
require 'orderedhash'
res = []
Country.all(:include => :land_geom).each do |c|
begin
puts c.name.upcase
v = c.land_geom.postgis_calculate(:npoints, c.land_geom)
geojson = c.land_geom.postgis_calculate(:asgeojson, c.land_geom)
wkt = c.land_geom.postgis_calculate(:asewkt, c.land_geom)
wkb = c.land_geom.postgis_calculate(:asewkb, c.land_geom)
kml = c.land_geom.postgis_calculate(:askml, c.land_geom)
gml = c.land_geom.postgis_calculate(:asgml, c.land_geom)
svg = c.land_geom.postgis_calculate(:assvg, c.land_geom)
h = OrderedHash.new
h[:name] = c.name
h[:vertices] = v
h[:geojson] = (rio('temp') < geojson).size
h[:ewkt] = (rio('temp') < wkt).size
h[:ewkb] = (rio('temp') < wkb).size
h[:kml] = (rio('temp') < kml).size
h[:gml] = (rio('temp') < gml).size
h[:svg] = (rio('temp') < svg).size
h[:geojson_gzip] = (rio('temp').gzip < geojson).size
h[:ewkt_gzip] = (rio('temp').gzip < wkt).size
h[:ewkb_gzip] = (rio('temp').gzip < wkb).size
h[:kml_gzip] = (rio('temp').gzip < kml).size
h[:gml_gzip] = (rio('temp').gzip < gml).size
h[:svg_gzip] = (rio('temp').gzip < svg).size
h[:geojson_msgpack] = (rio('temp') < JSON.parse(geojson).to_msgpack).size
h[:ewkt_msgpack] = (rio('temp') < wkt.to_msgpack).size
h[:ewkb_msgpack] = (rio('temp') < wkb.to_msgpack).size
h[:kml_msgpack] = (rio('temp') < kml.to_msgpack).size
h[:gml_msgpack] = (rio('temp') < gml.to_msgpack).size
h[:svg_msgpack] = (rio('temp') < svg.to_msgpack).size
h[:geojson_msgpack_gzip] = (rio('temp').gzip < JSON.parse(geojson).to_msgpack).size
h[:ewkt_msgpack_gzip] = (rio('temp').gzip < wkt.to_msgpack).size
h[:ewkb_msgpack_gzip] = (rio('temp').gzip < wkb.to_msgpack).size
h[:kml_msgpack_gzip] = (rio('temp').gzip < kml.to_msgpack).size
h[:gml_msgpack_gzip] = (rio('temp').gzip < gml.to_msgpack).size
h[:svg_msgpack_gzip] = (rio('temp').gzip < svg.to_msgpack).size
res << h
rescue
puts "No geom for #{c.name}"
end
end
#output to CSV
FasterCSV.open("size_test.csv", "w") do |csv|
keys = res.first.keys
csv << keys
res.each do |r|
csv << keys.map{|k| r[k] }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment