private School findAppropriateSchool(int age, Point location) { GeomVectorField zones; if (age < 11) { zones = elementarySchoolZones; } else if (age < 15) { zones = middleSchoolZones; } else { zones = highSchoolZones; } Bag catchment = zones.getContainingObjects(location); if (catchment.numObjs != 1) { System.out.format( "Error: school search (age: %d, location: %s) found %d catchments.\n", age, location, catchment.numObjs); for (int i = 0; i < catchment.numObjs; i++) { System.out.format( " Catchment %d: %s\n", i, ((MasonGeometry) catchment.get(i)).getAttribute("SCHID_3")); } return null; } MasonGeometry mg = (MasonGeometry) catchment.get(0); Integer num = mg.getIntegerAttribute("SCHOOL_NUM"); return schoolMap.get(num); }
private void countCatchments(GeomVectorField catchments) { Bag geoms = catchments.getGeometries(); for (int i = 0; i < geoms.numObjs; i++) { MasonGeometry mg = (MasonGeometry) geoms.get(i); Integer num = mg.getIntegerAttribute("SCHOOL_NUM"); if (num != null) { School s = schoolMap.get(num); if (s != null) { s.catchmentCount++; } else { System.out.format("School %s not found.\n", num); } } } }
private void createSchoolsFromData(GeomVectorField schoolField) { Bag geoms = schoolField.getGeometries(); for (int i = 0; i < geoms.numObjs; i++) { MasonGeometry mg = (MasonGeometry) geoms.get(i); Integer num = mg.getIntegerAttribute("SCHOOL_NUM"); String name = mg.getStringAttribute("SCHOOL_NAM"); String type = mg.getStringAttribute("SCHOOL_TYP"); if (num != null) { School s = new School(this, name, type); schoolMap.put(num, s); schools.add(s); } } }