Skip to content

Instantly share code, notes, and snippets.

@ddd1600
Created October 18, 2013 20:26
Show Gist options
  • Save ddd1600/7047703 to your computer and use it in GitHub Desktop.
Save ddd1600/7047703 to your computer and use it in GitHub Desktop.
'export geojson' textmate snippet, triggered by 'geojson[tab]'
def nonspatials
cols = self.class.columns.select{|c| c.type != :spatial}.map(&:name).sort
attributes.slice(*cols)
end
def self.export_geojson(fn, records, criteria_only=false)
features = []
f = RGeo::GeoJSON::EntityFactory.new
ActiveRecord::Base.silence do
records.each_with_index do |r, i|
puts i
cols = criteria_only ? r.criteria_cols_only : r.nonspatials
features << f.feature($gnc.proj_to_geo(r.proj_shape_2264), r.id, cols)
end
end
@coll = f.feature_collection(features)
geojson = RGeo::GeoJSON.encode(@coll).to_json
File.open("#{fn}.geojson", "w") {|f| f.write(geojson)}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment