Skip to content

Instantly share code, notes, and snippets.

@unRob
Last active December 28, 2015 06:09
Show Gist options
  • Save unRob/7455249 to your computer and use it in GitHub Desktop.
Save unRob/7455249 to your computer and use it in GitHub Desktop.
mercaditoses
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env ruby
# encoding: utf-8
require 'CSV'
require 'json'
features = []
CSV.foreach('./mercados.csv', headers: true).each do |line|
# Obviamente no todos traen lat/lng, y no siempre es nil, a veces es NULL
# porque BUROCRACIA, THAT'S WHY
next if line['longitud'] == 'NULL' || line['longitud'] == "0"
features << {
geometry: {
coordinates: [line['longitud'], line['latitud']].map(&:to_f),
type: 'Point'
},
properties: {
nombre: line['nombre'],
fid: line['fid'].to_i,
locales: line['locales'],
tipo: line['tipo_desc'],
actualizado: line['actualizado'],
delegacion: line['delegacion']
},
type: 'Feature'
}
end
puts ({type: 'FeatureCollection', features: features}).to_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment