I have Census datasets that store attributes in three separate files, corresponding to three separate summary levels, or spatial resolutions -- in this case, Municipalities, Census Tracts, and Census Blockgroups.
It's not the Rails way: I know. But it's not anybody else's way -- not even GeoNode has solved the problem of having attribute data separate from spatial data and joining them on the fly to one of several possible geographies.
I'd love to be able to write
class Dataset
has_many :summary_levels
end
commute_mode = Dataset.new(name: "Commute Mode",
summary_levels: [SummaryLevel.find(1), SummaryLevel.find(2), SummaryLevel.find(3)]
table_name: "commute_mode")
and have the model figure out itself how to connect the dataset to its own three tables, because there's one table for each of the spatial resolutions.
There's a commute_mode_m
for Municipality, commute_mode_ct
for Census Tract, okay, you get me.
But for now, we can't.
So I have a superclass MultiGeo
that a model could inherit from eventually (you can run this code in pure Ruby, there's presently no Rails involved). MultiGeo
itself will inherit from ActiveRecord::Base.
If someone can see a path to making a multi-geo
gem, please let me know.
At the moment, the has_summary_levels
method checks to see if those spatial models exist, and creates by_#{summary_method}
instance methods for each spatial model. Once I hook it to Rails, it should return the model's attributes joined to the spatial. Right now it outputs the SQL to be passed to #joins
later on.
Also, unlike my example above, CommuteMode is its own model, not an instance of a Dataset class. I don't even know how you'd subvert Rails enough to get to a point where instances become models.
Maybe Rails really isn't right for geospatial at this level.