Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

48 lines (44 sloc) 2.279 kb
ogr2ogr -t_srs EPSG:4326 school_parcels_2012/ facility_parcels/BPS_schools.shp
ruby
require 'rgeo'
require 'rgeo/shapefile'
require 'rgeo/geo_json'
parcels = RGeo::Shapefile::Reader.open('../../Projects/SchoolSelection/Data/school_parcels_2012/facility_parcels.shp')
schools = RGeo::Shapefile::Reader.open('../../Projects/SchoolSelection/Data/school_parcels_2012/BPS_schools.shp')
schools_array = []
schools.each do |s|
schools_array << s
end
parcels.each do |parcel|
rails_parcel = Parcel.find_or_create_by_build_name_and_address_and_city_id_and_zipcode_and_shape(parcel.attributes['BLDG_NAME'], parcel.attributes['ADDRESS'], City.find_or_create_by_name(parcel.attributes['CITY'].try(:id)), parcel.attributes['ZIPCODE'], parcel.geometry)
bps_school = schools_array.find {|x| x.attributes['BLDG_ID'] == parcel.attributes['BUILD_ID']}
if bps_school.present?
rails_school = School.find_by_bpsid(bps_school.attributes['SCH_ID'])
rails_school.update_attribute(:parcel_id, rails_parcel.id) if rails_school.present?
end
end
# zones = RGeo::Shapefile::Reader.open('../../Projects/SchoolSelection/Data/assignment_zones/zones_4326')
# dbf_schools = DBF::Table.new('../../Projects/SchoolSelection/Data/school_parcels_2011/schools.dbf')
# georuby_parcels = GeoRuby::Shp4r::ShpFile.open('../../Projects/SchoolSelection/Data/school_parcels/school_parcels')
IMPORT SCHOOLS FROM 2011-2012 CSV
CSV.foreach("../../Projects/SchoolSelection/Data/Spreadsheets/CSV/admissions.csv") do |row|
if row[0].present?
city = City.find_or_create_by_name(row[5])
neighborhood = Neighborhood.find_or_create_by_name(row[7])
assignment_zone = AssignmentZone.find_or_create_by_name(row[8])
grades = row[13].split(/\b*-\b*/)
puts grades.inspect
start_grade = GradeLevel.find_by_number(grades[0])
end_grade = GradeLevel.find_by_number(grades[1])
puts [start_grade,end_grade].inspect
if start_grade.present? && end_grade.present?
grade_levels = GradeLevel.where("(id >= #{start_grade.id}) AND (id <= #{end_grade.id})").all
puts grade_levels.inspect
school = School.find_or_create_by_bpsid(row[1])
school.grade_levels << grade_levels
school.save
else
school = School.find_or_create_by_bpsid(row[1])
end
end
end
Jump to Line
Something went wrong with that request. Please try again.