I've been following the RGeo series after listening to Daniel's great presentation at RailsConf. It's really made a difference in the way I'm learning to include GIS elements within my projects.
However, I've come to find something that I'd like to share with you related to Part 8 in the series.
When reading the shapefile as shown in the 1st example (no optimization), I end up with a count of 662 zctas.
However when reading the shapefile with optimization, I only ended up with 248 zctas
Result is obviously strange as the optimization should have produced a larger number of zctas.
Researching and "prying" into the code I discovered that code as it is for some unexepected reason is not actually fragmenting the zctas but only filtering those that are already below the MAX_SIZE. I discovered that the polygon.intersection(box) isn't producing new polygons for handling the geometry, even though the code looks ok to me.
The following result will illustrate what is happening in my environment, note that it contains a few output instructions for debugging purposes:
1:[zcta=98822,sides=4030][regular4]
[quadrant - min_x:-13449277.23, min_y:6041355.52, max_x:-13414100.39, max_y:6088043.36]
From: /Users/ernestoe/rails/geo_rails_test/db/seeds.rb @ line 90 Object#handle_quadrant:
90: def handle_quadrant(depth, polygon, min_x, min_y, max_x, max_y, zcta)
91: # We do this by creating a rectangle for the box, and computing
92: # the intersection with the input polygon. The result could be a
93: # polygon, a MultiPolygon, or an empty geometry.
94: box = Zcta::FACTORY.polygon(Zcta::FACTORY.linear_ring([
95: Zcta::FACTORY.point(min_x, min_y),
96: Zcta::FACTORY.point(min_x, max_y),
97: Zcta::FACTORY.point(max_x, max_y),
98: Zcta::FACTORY.point(max_x, min_y)]))
100: print "\n[quadrant - min_x:#{sprintf("%.2f",min_x)}, min_y:#{sprintf("%.2f",min_y)}, max_x:#{sprintf("%.2f",max_x)}, max_y:#{sprintf("%.2f",max_y)}]"
102: handle_geometry(depth, polygon.intersection(box), zcta)
=> #<RGeo::Geographic::ProjectedPolygonImpl:0x3fcdec8ffd14 "POLYGON ((-13449277.234375233 85.0511287, -13449277.234375233 85.0511287, -13449380.386604048 85.0511287, -13449380.386604048 85.0511287, -13449277.234375233 85.0511287))">
polygon doesn't intersect box, as the newly created box for some unknown reason is producing the same y-coordinate (85.0511287) outside the original range. Notice the y-points of the polygon envelope fall within 6041355 and 6088043.
My guess is something's wrong about projections in my setup, but haven't been able to locate it. I produced the optimization code within the seeds.rb script, don't know whether that is affecting my results.
If someone that ran the examples can confirm they work, that there is no typo affecting and just in case point me in the right direction, it would be greatly appreciated.
Regards,
--
José Ernesto Echeverría