rgeo/rgeo-geojson

No block given error in zm_feature_methods.rb

ijdickinson opened this issue · 2 comments

I'm generating GeoJSON from some UK Ordnance Survey data. I read in a .shp file, then create RGeo::GeoJSON::Feature objects from the geometries I get from the .shp file. This is mostly working, but some of my features fail when I try to do the GeoJSON encoding. The stacktrace is:

/home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-0.5.2/lib/rgeo/geos/zm_feature_methods.rb:305:in `block in each': no block given (yield) (LocalJumpError)
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-0.5.2/lib/rgeo/geos/zm_feature_methods.rb:304:in `times'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-0.5.2/lib/rgeo/geos/zm_feature_methods.rb:304:in `each'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-0.5.2/lib/rgeo/geos/zm_feature_methods.rb:340:in `coordinates'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-geojson-0.4.1/lib/rgeo/geo_json/coder.rb:183:in `_encode_geometry'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-geojson-0.4.1/lib/rgeo/geo_json/coder.rb:130:in `_encode_feature'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-geojson-0.4.1/lib/rgeo/geo_json/coder.rb:75:in `block in encode'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-geojson-0.4.1/lib/rgeo/geo_json/entities.rb:141:in `each'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-geojson-0.4.1/lib/rgeo/geo_json/entities.rb:141:in `each'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-geojson-0.4.1/lib/rgeo/geo_json/entities.rb:195:in `map'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-geojson-0.4.1/lib/rgeo/geo_json/entities.rb:195:in `map_feature_collection'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-geojson-0.4.1/lib/rgeo/geo_json/coder.rb:75:in `encode'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-geojson-0.4.1/lib/rgeo/geo_json/interface.rb:16:in `encode'
    from generate.rb:95:in `block in <main>'
    from generate.rb:94:in `open'
    from generate.rb:94:in `<main>'

Looking at the data I'm reading in, most of the geometries are CAPMultiPolygonImpl instances, but some of them are ZMultiPolygonImpl:

(byebug) features.take(10).map {|f| f.geometry.class}
[RGeo::Geos::CAPIMultiPolygonImpl, RGeo::Geos::CAPIMultiPolygonImpl, 
 RGeo::Geos::CAPIMultiPolygonImpl, RGeo::Geos::CAPIMultiPolygonImpl, 
 RGeo::Geos::CAPIMultiPolygonImpl, RGeo::Geos::CAPIMultiPolygonImpl, 
 RGeo::Geos::CAPIMultiPolygonImpl, RGeo::Geos::CAPIMultiPolygonImpl, 
 RGeo::Geos::CAPIMultiPolygonImpl, RGeo::Geos::ZMMultiPolygonImpl]

The call to RGeo::GeoJSON.encode fails when it gets to the 10th element in that list. I'll keep digging, but I'm wondering first what is the reason that RGeo will encode some of the geometries as one class, and some another? What are the key differences between the CAPI- and ZM- polygons?

I have submitted a PR that addresses this issue: rgeo/rgeo#132

It looks like this has been fixed by rgeo/rgeo#132, please open a new issue if that is not the case.