Giter VIP home page Giter VIP logo

rgeo-proj4's Introduction

rgeo-proj4

Gem Version CI

This project contains proj.4 extensions to the rgeo gem.

Documentation about proj.4 is available at http://proj4.org/.

Installation

Install PROJ

Install proj using your package manager:

Homebrew

brew install proj

Ubuntu/Debian

apt-get install libproj-dev proj-bin

Or download binaries at https://proj.org/

Note that version 3.x requires PROJ 6.2+. This should be the default on most systems, but in some cases, specific repositories will need to be added to the package manager.

Add this line to your Gemfile:

gem "rgeo-proj4"

And then execute:

$ bundle

Or install it yourself as:

$ gem install rgeo-proj4

By default, the gem looks for the Proj4 library in the following paths:

/usr/local
/usr/local/proj
/usr/local/proj4
/opt/local
/opt/proj
/opt/proj4
/opt
/usr
/Library/Frameworks/PROJ.framework/unix

If Proj4 is installed in a different location, you must provide its installation prefix directory using the --with-proj-dir option.

Upgrading to V4

See the Upgrading to V4 docs for information about how to upgrade from RGeo-Proj4 V3 to V4.

For a comprehensive list of changes, see the 4.0.0* release information in the History file.

Usage

The rgeo-proj4 gem can be used by defining CoordSys::Proj4 objects, as a part of an RGeo::Geographic.projected_factory, or as an attribute of other factories.

RGeo::CoordSys::Proj4

This is the lowest level module to transform between coordinate systems and all of the other methods ultimately rely on this object. The object is created with a valid PROJ definition which is used to define a coordinate reference system (CRS). Note that 2 Proj4 objects need to be defined to transform between CRS's.

In addition to allowing transformations, this object can return information about the CRS.

require 'rgeo'
require 'rgeo/proj4'

# define CRS's
# can also be defined with the string "EPSG:XXXX" or a proj string
geography = RGeo::CoordSys::Proj4.create(4326)
projection = RGeo::CoordSys::Proj4.create(3857)

x,y = RGeo::CoordSys::Proj4.transform_coords(projection, geography, -8367354.015764384, 4859054.160863457, nil)

p x
# => -75.16522
p y
# => 39.95258299

Other information can be shown from the Proj4 object:

require 'rgeo'
require 'rgeo/proj4'

projection = RGeo::CoordSys::Proj4.create("EPSG:3857")
p projection.canconical_str
# => "+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs +type=crs"

p projection.auth_name
# => "EPSG:3857"

p projection.as_text
# => PROJCRS[\"WGS 84 / Pseudo-Mercator\",BASEGEOGCRS[\"WGS 84\",DATUM[\"World Geodetic System 1984\",ELLIPSOID[\"WGS 84\",6378137,298.257223563,LENGTHUNIT[\"metre\",1]]],PRIMEM[\"Greenwich\",0,ANGLEUNIT[\"degree\",0.0174532925199433]],ID[\"EPSG\",4326]],CONVERSION[\"Popular Visualisation Pseudo-Mercator\",METHOD[\"Popular Visualisation Pseudo Mercator\",ID[\"EPSG\",1024]],PARAMETER[\"Latitude of natural origin\",0,ANGLEUNIT[\"degree\",0.0174532925199433],ID[\"EPSG\",8801]],PARAMETER[\"Longitude of natural origin\",0,ANGLEUNIT[\"degree\",0.0174532925199433],ID[\"EPSG\",8802]],PARAMETER[\"False easting\",0,LENGTHUNIT[\"metre\",1],ID[\"EPSG\",8806]],PARAMETER[\"False northing\",0,LENGTHUNIT[\"metre\",1],ID[\"EPSG\",8807]]],CS[Cartesian,2],AXIS[\"easting (X)\",east,ORDER[1],LENGTHUNIT[\"metre\",1]],AXIS[\"northing (Y)\",north,ORDER[2],LENGTHUNIT[\"metre\",1]],USAGE[SCOPE[\"unknown\"],AREA[\"World - 85\xC2\xB0S to 85\xC2\xB0N\"],BBOX[-85.06,-180,85.06,180]],ID[\"EPSG\",3857]]

Projected Factory

The projected factory is a compound geographic factory that is useful for converting from lon/lat to the specified CRS.

require 'rgeo'
require 'rgeo/proj4'

factory = RGeo::Geographic.projected_factory(projection_srid: 3857)

p factory.projection_factory
# => #<RGeo::Geos::CAPIFactory srid=3857 bufres=1 flags=8>

p factory.projection_factory.coord_sys
# => #<RGeo::CoordSys::Proj4 "+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs +type=crs">

p factory.projection_factory.coord_sys.auth_name
# => "EPSG:3857"

pt = factory.point(-75.16522, 39.95258299)
p pt.projection
# => #<RGeo::Geos::CAPIPointImpl "POINT (-8367354.015764384 4859054.159411294)">

p factory.unproject(pt.projection)
# => #<RGeo::Geographic::ProjectedPointImpl "POINT (-75.16522 39.952582989999996)">

Feature::Cast

This method allows you to perform projections between more than just a lon/lat system. As long as 2 factories with valid Proj4 CRS's are defined, it can project between the CRS's.

require 'rgeo'
require 'rgeo/proj4'

# coord_sys is unnecessary here as just an srid can be used
# but coord_sys allows both Integer and String crs definitions.
geography = RGeo::Geos.factory(coord_sys: "EPSG:4326", srid: 4326)
projection = RGeo::Geos.factory(coord_sys: "EPSG:3857", srid: 3857)

p geography.coord_sys.auth_name
# => "EPSG:4326"
p projection.coord_sys.auth_name
# => "EPSG:3857"

proj_point = projection.parse_wkt("POINT (-8367354.015764384 4859054.159411294)")

geo_point = RGeo::Feature.cast(proj_point, project: true, factory: geography)
p geo_point
# => #<RGeo::Geos::CAPIPointImpl "POINT (-75.16522 39.952582989999996)">

proj_point2 = RGeo::Feature.cast(geo_point, project: true, factory: projection)

p proj_point == proj_point2
# => true

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/rgeo/rgeo-proj4. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the rgeo-proj4 project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

rgeo-proj4's People

Contributors

buonomo avatar keithdoggett avatar meinac avatar petergoldstein avatar teeparham avatar x4d3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rgeo-proj4's Issues

Not compatible with PROJ.4 v6.0.0

I had proj4 installed via homebrew and everything was working fine until just recently when 6.0.0 was released and then I started getting the following error: Proj4 not supported in this installation.

My first thought was that I needed just rebuild the native extensions for the gem so I did a bundle pristine but still no luck.

Switching back to 5.2.0 works and I've created a homebrew tap for this:

brew tap sethdeckard/proj
brew install sethdeckard/proj/proj

Failt to use proj4 with rails.

System: MacOSX Catalina 10.15.6

Instaled from Homebrew

brew install proj

When I run:

projsync --system-directory

At least one of --list-files, --file, --source-id, --area-of-use, --bbox or --all must be specified.

usage: projsync 
          [--endpoint URL]
          [--local-geojson-file FILENAME]
          ([--user-writable-directory] | [--system-directory] | [--target-dir DIRNAME])
          [--bbox west_long,south_lat,east_long,north_lat]
          [--spatial-test contains|intersects]
          [--source-id ID] [--area-of-use NAME]
          [--file NAME]
          [--all] [--exclude-world-coverage]
          [--quiet] [--dry-run] [--list-files]

Gemfile

gem "rgeo", "~> 2.1"
gem "rgeo-proj4", "~> 2.0"

Ruby Version

2.5.8

Rails Version

rails 5.2.4.2

rails c

pry(main)> RGeo::CoordSys::Proj4.supported?                                                                                                              
false

`RGeo::CoordSys::Proj4.transform_coords` slower in version 3.0.1 than version 2.0.1

Issue encountered

I've tried to update to the 3.0.1 version but I've observed that using RGeo::CoordSys::Proj4.transform_coords to project the coordinates of my geometry was slower than the 2.0.1 version.

Step to reproduce

Here is a minimal script to reproduce, you can uncomment to alternate between the 2 versions.

require "bundler/inline"

gemfile do
  source "https://rubygems.org"
  # gem "rgeo-proj4", "~> 3.0", ">= 3.0.1"
  gem "rgeo-proj4", "~> 2.0", ">= 2.0.1"
end

raise "RGeo::Geos is not supported" unless RGeo::Geos.supported?
puts "preferred_native_interface #{RGeo::Geos.preferred_native_interface}"
puts "rgeo-proj4 version #{RGeo::Proj4::VERSION}"
raise "proj4 is not supported" unless RGeo::CoordSys::Proj4.supported?
puts "proj4 version: #{RGeo::CoordSys::Proj4.version}"
puts "RUBY_VERSION: #{RUBY_VERSION}"
puts "RUBY_PLATFORM #{RUBY_PLATFORM}"
ws84_definition = "proj=longlat +datum=WGS84 +no_defs +type=crs"
# https://epsg.io/2154
paris_lambert_definition = "+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +type=crs"

ws84_proj4 = RGeo::CoordSys::Proj4.create(ws84_definition)
raise "invalid ws84_definition" unless ws84_proj4

paris_lambert_proj4 = RGeo::CoordSys::Proj4.create(paris_lambert_definition)
raise "invalid paris_lambert_definition" unless paris_lambert_proj4

starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
1000.times do
  RGeo::CoordSys::Proj4.transform_coords(ws84_proj4, paris_lambert_proj4, 784020.1897824854, 6722964.293806808, nil)
end
puts "Processed in #{Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting}"

With 2.0.1

preferred_native_interface capi
rgeo-proj4 version 2.0.1
proj4 version: 721
RUBY_VERSION: 2.6.6
RUBY_PLATFORM x86_64-darwin19
Processed in 0.0032739999987825286

With 3.0.1

preferred_native_interface capi
rgeo-proj4 version 3.0.1
proj4 version: 7.2.1
RUBY_VERSION: 2.6.6
RUBY_PLATFORM x86_64-darwin19
Processed in 1.5407219999979134

Versions

  • Proj: 7.2.1
  • Ruby: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]
  • OS: macOS Catalina, Version 10.15.7, x86_64-darwin19
    image

Note

I've tried to use WKT definition as well, it was faster but it was still slower than the 2.0.1 version

 paris_lambert_definition = <<~EOS
      PROJCS["RGF93 / Lambert-93",
          GEOGCS["RGF93",
              DATUM["Reseau_Geodesique_Francais_1993",
                  SPHEROID["GRS 1980",6378137,298.257222101,
                      AUTHORITY["EPSG","7019"]],
                  TOWGS84[0,0,0,0,0,0,0],
                  AUTHORITY["EPSG","6171"]],
              PRIMEM["Greenwich",0,
                  AUTHORITY["EPSG","8901"]],
              UNIT["degree",0.0174532925199433,
                  AUTHORITY["EPSG","9122"]],
              AUTHORITY["EPSG","4171"]],
          PROJECTION["Lambert_Conformal_Conic_2SP"],
          PARAMETER["standard_parallel_1",49],
          PARAMETER["standard_parallel_2",44],
          PARAMETER["latitude_of_origin",46.5],
          PARAMETER["central_meridian",3],
          PARAMETER["false_easting",700000],
          PARAMETER["false_northing",6600000],
          UNIT["metre",1,
              AUTHORITY["EPSG","9001"]],
          AXIS["X",EAST],
          AXIS["Y",NORTH],
          AUTHORITY["EPSG","2154"]]
    EOS

    ws84_definition = <<~EOS
      GEOGCS["WGS 84",
           DATUM["WGS_1984",
                 SPHEROID["WGS 84",6378137,298.257223563,
                          AUTHORITY["EPSG","7030"]],
                 AUTHORITY["EPSG","6326"]],
           PRIMEM["Greenwich",0,
                  AUTHORITY["EPSG","8901"]],
           UNIT["degree",0.0174532925199433,
                AUTHORITY["EPSG","9122"]],
           AUTHORITY["EPSG","4326"]]
    EOS

Result

preferred_native_interface capi
rgeo-proj4 version 3.0.1
proj4 version: 7.2.1
RUBY_VERSION: 2.6.6
RUBY_PLATFORM x86_64-darwin19
Processed in 0.4099999999998545

Docker image to reproduce

Here is a gist with a docker image where I've reproduced the issue with proj version:8.1.0

https://gist.github.com/x4d3/1dff5f2348a0a6ec1a6fd440d0d64ac7

invalid option: --with-proj-dir=/usr/local/bin for command gem install rgeo-proj4 --with-proj-dir=/usr/local/bin

Fundamentally, the issue is this error:

RGeo::Error::UnsupportedOperation: Coordinate system 'proj4' is not supported.

I've been using RGeo for years. Have never had to use the rgeo-proj4 gem, which I've replaced in my Gemfile from the previous 'rgeo' gem. I've followed all the online guides on making sure proj is already installed, making sure its located where it should be, but RGeo still can't find the Proj library.

Please help! Thanks

Can Segfault with Invalid Proj String

The following will segfault and create a core dump

require 'rgeo/proj4'

proj_str = "+proj=merc +lat_ts=56.5 +ellps=GRS80"

p1 = RGeo::CoordSys::Proj4.create(proj_str)
p2 = RGeo::CoordSys::Proj4.create("EPSG:3857")

x,y = RGeo::CoordSys::Proj4.transform_coords(p1, p2, 1, 2, nil)

p x
p y

The issue is that the proj_str is not a CRS because it is missing "+type=crs". We should check both proj objects to ensure they are valid before executing a transformation.

M1 proj 6.2+ proj4.rb::create::_create method - Error: dyld[xxxxxx]: missing symbol called

Hey,

I'm trying to start/fix an old project that's using the 6.2+ proj, and for some reason proj4.rb::create::_create method throws an error which is impossible to debug at the moment.

Just curios if you could help me with debugging main.c file? Is there an option to do so from the Ruby?

Ruby: ruby 2.6.10p210 (2022-04-12 revision 67958) [arm64-darwin22]
Proj: 6.3.2

It depends on SRSDatabase (which was removed), so cannot migrate it to the latest version of rgeo and rgeo-proj4 at the moment.

  spec.add_dependency 'rgeo', '~> 2.0'
  spec.add_dependency 'rgeo-geojson', '~> 2.0'
  spec.add_dependency 'rgeo-proj4', '~> 3.0'`
irb(main):001:0> RGeo::CoordSys::Proj4.supported?
=> true

Configs (might be an issue here, mb):

checking for proj.h... yes
checking for proj_create() in proj.h... yes
checking for proj_create_crs_to_crs_from_pj() in proj.h... yes
checking for proj_normalize_for_visualization() in proj.h... yes
checking for rb_gc_mark_movable()... no
creating Makefile

Part which fails:
Screenshot 2023-10-10 at 11 18 08

Thanks a lot for any help you could provide!

PS: I'd like to fix it without re-installing homebrew or anything with Rosetta terminal support. I know it might help, but I'd have to spend days to reinstall (remember also) everything that I have 😄
PS2: Found out that proj context is throwing an error PJ_CONTEXT *c = proj_context_create();;

Regression in projection definition

There is a regression between rgeo-proj4 2.0.1 and 3.0.1

The following example works in 2.0.1:

#  rgeo-proj4 2.0.1

source_projection = RGeo::CoordSys::Proj4.new('+proj=longlat +datum=WGS84 +no_defs')
target_projection = RGeo::CoordSys::Proj4.new('+proj=lcc +lat_0=46.5 +lon_0=3 +lat_1=49 +lat_2=44 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs ')

RGeo::CoordSys::Proj4.transform_coords(source_projection, target_projection, 2.3347587142445168, 48.738770796515, nil)
# => [651078.9599999869, 6848945.02999845]

But not in 3.0.1:

#  rgeo-proj4 3.0.1

source_projection = RGeo::CoordSys::Proj4.new('+proj=longlat +datum=WGS84 +no_defs')
target_projection = RGeo::CoordSys::Proj4.new('+proj=lcc +lat_0=46.5 +lon_0=3 +lat_1=49 +lat_2=44 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs')

RGeo::CoordSys::Proj4.transform_coords(source_projection, target_projection, 2.3347587142445168, 48.738770796515, nil)
# proj_create_operations: source_crs is not a CRS
# => nil

To make it work, I had to add +type=crs to both projection or use projection name (which is better)

#  rgeo-proj4 3.0.1

source_projection = RGeo::CoordSys::Proj4.new('+proj=longlat +datum=WGS84 +no_defs +type=crs')
target_projection = RGeo::CoordSys::Proj4.new('+proj=lcc +lat_0=46.5 +lon_0=3 +lat_1=49 +lat_2=44 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +type=crs')

RGeo::CoordSys::Proj4.transform_coords(source_projection, target_projection, 2.3347587142445168, 48.738770796515, nil)
# => [651078.9599999869, 6848945.02999845]

source_projection = RGeo::CoordSys::Proj4.new('EPSG:4326')
target_projection = RGeo::CoordSys::Proj4.new('EPSG:2154')

RGeo::CoordSys::Proj4.transform_coords(source_projection, target_projection, 2.3347587142445168, 48.738770796515, nil)
# => [651078.9599999869, 6848945.02999845]

FYI, epsg.io doesn't provide definition with +type=crs: https://epsg.io/2154.proj4
(spatialreference.org is down, so I cannot double check)

It may be a issue with proj4 and doing so should be noted as a breaking change ?

Heroku: `proj_create: Cannot find proj.db` and `proj_create: no database context specified`

I have a rails app that is deployed to heroku. I'm running into the following error when trying to create a projected factory:

> RGeo::Geographic.projected_factory(projection_proj4: "EPSG:4326", projection_srid: 4326)
proj_create: Cannot find proj.db
proj_create: no database context specified
/app/vendor/bundle/ruby/3.0.0/gems/rgeo-2.3.0/lib/rgeo/geographic/interface.rb:410:in `projected_factory': Bad proj4 syntax: "EPSG:4326" (ArgumentError)

Somewhat confusing things, RGeo::CoordSys::Proj4.supported? returns true.

About the setup:

I more-or-less used these instructions. Summarized, I have an Aptfile that has the following content:

libproj-dev
proj-bin
libgeos-dev

I would expect this to satisfy the requirements of the gem? But I wouldn't be surprised if I were missing something obvious. Any guidance on getting this to work would be very much appreciated.

CoordinateTransform Refactor

Due to pending updates to the RGeo core gem, we will need to make this gem compatible with the new classes/specs defined in this issue (rgeo/rgeo#316).

  • Have CoordSys::Proj4 subclass CoordSys::CoordinateSystem. Possibly rename to Proj4CS or something similar.
  • Have CRSToCRS subclass CoordSys::CoordinateTransform. Possibly rename to Proj4CT or something similar.
  • Redefine the CoordSys.cs_adapter variable on load.
  • Maybe add convenience method to CRSToCRS to create it directly from 2 auth names or 2 srids.

proj_crs_get_geodetic_crs: Object is not a CRS

Hi,

I have an issue when upgrading to 3.1.1 on starting rails server

gems/rgeo-proj4-3.1.1/lib/rgeo/coord_sys/proj4.rb:93:in `canonical_hash': undefined method `strip' for nil:NilClass (NoMethodError)

Full stack trace

from /home/djoulin/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rgeo-proj4-3.1.1/lib/rgeo/coord_sys/proj4.rb:45:in `eql?'
11:57:34 web.1  | 	from /home/djoulin/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rgeo-2.3.1/lib/rgeo/geographic/factory.rb:87:in `eql?'
11:57:34 web.1  | 	from /home/djoulin/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rgeo-2.3.1/lib/rgeo/feature/types.rb:193:in `cast'
11:57:34 web.1  | 	from /home/djoulin/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rgeo-2.3.1/lib/rgeo/impl_helper/basic_line_string_methods.rb:15:in `block in initialize'
11:57:34 web.1  | 	from /home/djoulin/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rgeo-2.3.1/lib/rgeo/impl_helper/basic_line_string_methods.rb:14:in `map'
11:57:34 web.1  | 	from /home/djoulin/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rgeo-2.3.1/lib/rgeo/impl_helper/basic_line_string_methods.rb:14:in `initialize'
11:57:34 web.1  | 	from /home/djoulin/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rgeo-2.3.1/lib/rgeo/geographic/factory.rb:326:in `new'
11:57:34 web.1  | 	from /home/djoulin/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rgeo-2.3.1/lib/rgeo/geographic/factory.rb:326:in `line_string'
11:57:34 web.1  | 	from /home/djoulin/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rgeo-2.3.1/lib/rgeo/wkrep/wkt_parser.rb:287:in `parse_line_string'
11:57:34 web.1  | 	from /home/djoulin/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rgeo-2.3.1/lib/rgeo/wkrep/wkt_parser.rb:297:in `parse_polygon'
11:57:34 web.1  | 	from /home/djoulin/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rgeo-2.3.1/lib/rgeo/wkrep/wkt_parser.rb:369:in `block in parse_multi_polygon'
11:57:34 web.1  | 	from /home/djoulin/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rgeo-2.3.1/lib/rgeo/wkrep/wkt_parser.rb:368:in `loop'
11:57:34 web.1  | 	from /home/djoulin/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rgeo-2.3.1/lib/rgeo/wkrep/wkt_parser.rb:368:in `parse_multi_polygon'
11:57:34 web.1  | 	from /home/djoulin/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rgeo-2.3.1/lib/rgeo/wkrep/wkt_parser.rb:214:in `parse_type_tag'
11:57:34 web.1  | 	from /home/djoulin/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rgeo-2.3.1/lib/rgeo/wkrep/wkt_parser.rb:133:in `parse'
11:57:34 web.1  | 	from /home/djoulin/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rgeo-2.3.1/lib/rgeo/geographic/factory.rb:308:in `parse_wkt'

proj, postgres, spring, fork, Big Sur faulting

Spamming keywords to others might find this. I realize this this is spring centric, but there is high potential for some pg element to it, see below. This issue is, maybe, alluded to in various other tickets in various other places, none of which seem to come up with a concrete answer, crossreferencing:

When we run spring then we get faults on both M1 and Intel under Big Sur.

  • The issue has existed for months
  • Anecdotally this is related to some fork, somewhere
  • Most people who seem to hit this have a postgres related element in their env
  • This may be related to new mac binary protections, one of the errors leads with proj_create_operations: SQLite error on SELECT allowed_authorities FROM authority_to_authority_preference WHERE source_auth_name = ? AND target_auth_name = ?: disk I/O error
  • Replicated on numerous machines, with clean installs of many of the potential culprits.
  • When running the same command, 1 of 2 errors, apparently completley at random (fork?) are raised:

1

matt@Matts-MacBook-Pro taxonworks (dwc_fields *$%)$ spring rspec spec/models/otu_spec.rb 
Running via Spring preloader in process 3654
proj_create_operations: SQLite error on SELECT allowed_authorities FROM authority_to_authority_preference WHERE source_auth_name = ? AND target_auth_name = ?: disk I/O error

An error occurred while loading ./spec/models/otu_spec.rb.
Failure/Error:
  ILLINOIS = RSPEC_GEO_FACTORY.parse_wkt(
    'MULTIPOLYGON (((-88.02362060546875 38.08888244628906 0.0, ' \
      '-87.99749755859375 38.091102600097656 0.0, -87.98167419433594 38.091102600097656 0.0, ' \
      ' -87.975830078125 38.08971405029297 0.0, -87.97193908691406 38.08610534667969 0.0, ' \
      ' -87.96945190429688 38.078880310058594 0.0, -87.9727783203125 38.074440002441406 0.0, ' \
      ' -87.97721862792969 38.06999206542969 0.0, -87.9869384765625 38.06471252441406 0.0, ' \
      ' -88.03916931152344 38.03777313232422 0.0, -88.03388977050781 37.97221374511719 0.0, ' \
      ' -88.03443908691406 37.903045654296875 0.0, -88.03611755371094 37.89833068847656 0.0, ' \
      ' -88.040283203125 37.89471435546875 0.0, -88.05110168457031 37.888885498046875 0.0, ' \
      ' -88.05804443359375 37.888885498046875 0.0, -88.06388854980469 37.889991760253906 0.0, ' \

NoMethodError:
  undefined method `size' for nil:NilClass
# /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/feature/types.rb:206:in `cast'
# /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/geographic/proj4_projector.rb:23:in `project'
# /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/geographic/factory.rb:247:in `project'
# /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/geographic/projected_feature_methods.rb:17:in `projection'
# /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/geographic/projected_feature_methods.rb:39:in `equals?'
# /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/feature/geometry.rb:600:in `=='
# /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/impl_helper/basic_line_string_methods.rb:184:in `!='
# /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/impl_helper/basic_line_string_methods.rb:184:in `validate_geometry'
# /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/geographic/projected_feature_methods.rb:165:in `validate_geometry'
# /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/impl_helper/basic_line_string_methods.rb:19:in `initialize'
# /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/geographic/factory.rb:338:in `new'

2

matt@Matts-MacBook-Pro ~$ tw
matt@Matts-MacBook-Pro taxonworks (dwc_fields *$%)$ spring rspec spec/models/otu_spec.rb 
DEPRECATION WARNING: ActionView::Base instances should be constructed with a lookup context, assignments, and a controller. (called from <top (required)> at /Users/matt/data/src/github/species_file_group/taxonworks/config/environment.rb:5)
Running via Spring preloader in process 2842
/Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-proj4-3.0.1/lib/rgeo/coord_sys/proj4.rb:80: [BUG] Bus Error at 0x000000010b6b7ad4
ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-darwin20]

-- Crash Report log information --------------------------------------------
   See Crash Report log file under the one of following:                    
     * ~/Library/Logs/DiagnosticReports                                     
     * /Library/Logs/DiagnosticReports                                      
   for more details.                                                        
Don't forget to include the above Crash Report log file in bug reports.     

-- Control frame information -----------------------------------------------
c:0065 p:---- s:0358 e:000357 CFUNC  :_canonical_str
c:0064 p:0010 s:0354 e:000353 METHOD /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-proj4-3.0.1/lib/rgeo/coord_sys/proj4.rb:80
c:0063 p:0015 s:0350 e:000349 METHOD /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-proj4-3.0.1/lib/rgeo/coord_sys/proj4.rb:93
c:0062 p:0017 s:0346 e:000345 METHOD /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-proj4-3.0.1/lib/rgeo/coord_sys/proj4.rb:45
c:0061 p:0077 s:0341 e:000340 METHOD /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/geographic/factory.rb:87
c:0060 p:0136 s:0336 e:000335 METHOD /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/feature/types.rb:193
c:0059 p:0029 s:0316 e:000315 BLOCK  /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/impl_helper/basic_line_string_methods.rb:15 [FINISH]
c:0058 p:---- s:0312 e:000311 CFUNC  :map
c:0057 p:0011 s:0308 e:000307 METHOD /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/impl_helper/basic_line_string_methods.rb:14 [FINISH]
c:0056 p:---- s:0302 e:000301 CFUNC  :new
c:0055 p:0008 s:0296 e:000295 METHOD /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/geographic/factory.rb:326
c:0054 p:0041 s:0291 e:000290 METHOD /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/wkrep/wkt_parser.rb:287
c:0053 p:0037 s:0286 e:000285 METHOD /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/wkrep/wkt_parser.rb:297
c:0052 p:0006 s:0280 e:000278 BLOCK  /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/wkrep/wkt_parser.rb:369 [FINISH]
c:0051 p:---- s:0276 e:000275 CFUNC  :loop
c:0050 p:0028 s:0272 e:000271 METHOD /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/wkrep/wkt_parser.rb:368
c:0049 p:0416 s:0267 e:000266 METHOD /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/wkrep/wkt_parser.rb:214
c:0048 p:0111 s:0258 e:000257 METHOD /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/wkrep/wkt_parser.rb:133
c:0047 p:0007 s:0252 e:000251 METHOD /Users/matt/.rvm/gems/ruby-2.7.4/gems/rgeo-2.3.0/lib/rgeo/geographic/factory.rb:308
c:0046 p:0013 s:0247 e:000246 CLASS  /Users/matt/data/src/github/species_file_group/taxonworks/spec/support/shared_contexts/geo/illinois.rb:3
c:0045 p:0007 s:0244 e:000243 TOP    /Users/matt/data/src/github/species_file_group/taxonworks/spec/support/shared_contexts/geo/illinois.rb:1 [FINISH]
c:0044 p:---- s:0241 e:000240 CFUNC  :require
c:0043 p:0011 s:0236 e:000235 METHOD /Users/matt/.rvm/gems/ruby-2.7.4/gems/polyglot-0.3.5/lib/polyglot.rb:65
c:0042 p:0007 s:0228 e:000227 BLOCK  /Users/matt/.rvm/gems/ruby-2.7.4/gems/activesupport-6.0.4.1/lib/active_support/dependencies.rb:324
c:0041 p:0068 s:0225 e:000224 METHOD /Users/matt/.rvm/gems/ruby-2.7.4/gems/activesupport-6.0.4.1/lib/active_support/dependencies.rb:291
c:0040 p:0010 s:0218 e:000217 METHOD /Users/matt/.rvm/gems/ruby-2.7.4/gems/activesupport-6.0.4.1/lib/active_support/dependencies.rb:324
c:0039 p:0006 s:0212 e:000211 BLOCK  /Users/matt/data/src/github/species_file_group/taxonworks/spec/rails_helper.rb:24 [FINISH]
c:0038 p:---- s:0208 e:000207 CFUNC  :each

RGeo::CoordSys::Proj4.supported?` returns false with Homebrew + m1

Hi there,

A helpful answer from @keithdoggett on stackoverflow pointed me to this library (thank you!).

I'm struggling to get the install working.

brew install proj works as expected.

I verified it with:

$ proj  
Rel. 7.2.1, January 1st, 2021
usage: proj [-bdeEfiIlmorsStTvVwW [args]] [+opt[=arg] ...] [file ...]

I added the following to my Gemfile

gem "rgeo-proj4", "~> 3.0"

And install worked as expected.

However, when I try to create a factory I get the following error:

> require 'rgeo'
 => false 
3.0.1 :002 > require 'rgeo/proj4'
 => false 
3.0.1 :003 > 
3.0.1 :004 > factory = RGeo::Geographic.projected_factory(projection_proj4: "EPSG:3857", projection_srid: 3857)
.../gems/rgeo-2.3.0/lib/rgeo/coord_sys.rb:45:in `check!': Coordinate system 'proj4' is not supported. (RGeo::Error::UnsupportedOperation)

Digging under the hood a little, I found the following:

> RGeo::CoordSys::Proj4.supported?
 => false 

One possibility I thought of is that Homebrew isn't installing to the anticipated directory?

$ which proj 
/opt/homebrew/bin/proj

Do you have any idea what I might need to do to get this wired up?

V4

Due to a breaking change required to fix #25, we will have to do a major version upgrade with #26. But this is a good time to add some other changes to the package as well.

Suggestions

  • Add more validations/support around different proj objects (partially handled by #26)
    • Could be expanded on to add support for working with non-crs objects
  • Utilize bulk transformation methods
    • Newer versions of PROJ allow for transforming coordinates in bulk. This would likely improve the performance of transforming geometries other than points

Segfault when Rails enters parallell testing mode

Steps to reproduce

Include rgeo in a Rails 7 project. Add enough tests to trigger tests running in parallell (default is 50 tests). RGeo will segfault with the attached stack trace.

Expected behavior

Tests to run as usual

Actual behavior

Segfault in proj4-communication.

System configuration

Ruby version:
3.1.0

OS:
MacOS

Stack trace

/Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/rgeo-proj4-3.1.1/lib/rgeo/coord_sys/proj4.rb:191: [BUG] Segmentation fault at 0x0000000104c38a70 ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]

c:0049 p:---- s:0264 e:000263 CFUNC  :_create
c:0048 p:0052 s:0258 e:000257 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/rgeo-proj4-3.1.1/lib/rgeo/coord_sys/proj4.rb:191
c:0047 p:0392 s:0251 e:000250 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/rgeo-2.4.0/lib/rgeo/geos/capi_factory.rb:66
c:0046 p:0097 s:0234 e:000233 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/rgeo-2.4.0/lib/rgeo/geos/interface.rb:200
c:0045 p:0060 s:0228 e:000227 BLOCK  /Users/pekkaakerstrom/repos/pattern/app/models/local_plan.rb:113 [FINISH]
c:0044 p:---- s:0217 e:000216 IFUNC 
c:0043 p:---- s:0214 e:000213 CFUNC  :each
c:0042 p:---- s:0211 e:000210 CFUNC  :each_with_index
c:0041 p:0006 s:0207 e:000206 BLOCK  /Users/pekkaakerstrom/repos/pattern/app/models/local_plan.rb:107
c:0040 p:0012 s:0204 e:000203 BLOCK  /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/abstract/transaction [FINISH]
c:0039 p:---- s:0197 e:000196 CFUNC  :handle_interrupt
c:0038 p:0029 s:0192 e:000191 BLOCK  /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.3.1/lib/active_support/concurrency/load_interlock_aware_monit [FINISH]
c:0037 p:---- s:0189 e:000188 CFUNC  :handle_interrupt
c:0036 p:0021 s:0184 e:000183 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.3.1/lib/active_support/concurrency/load_interlock_aware_monit
c:0035 p:0008 s:0179 e:000178 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/abstract/transaction
c:0034 p:0053 s:0172 e:000171 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/abstract/database_st
c:0033 p:0011 s:0163 e:000162 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/activerecord-7.0.3.1/lib/active_record/transactions.rb:209
c:0032 p:0016 s:0157 e:000156 METHOD /Users/pekkaakerstrom/repos/pattern/app/models/local_plan.rb:106
c:0031 p:0032 s:0147 e:000146 BLOCK  /Users/pekkaakerstrom/repos/pattern/test/models/local_plan_test.rb:35 [FINISH]
c:0030 p:0018 s:0142 e:000141 BLOCK  /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/minitest-5.16.3/lib/minitest/test.rb:98
c:0029 p:0002 s:0139 e:000138 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/minitest-5.16.3/lib/minitest/test.rb:195
c:0028 p:0004 s:0134 e:000133 BLOCK  /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/minitest-5.16.3/lib/minitest/test.rb:95
c:0027 p:0015 s:0131 e:000130 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/minitest-5.16.3/lib/minitest.rb:296
c:0026 p:0004 s:0126 e:000125 BLOCK  /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/minitest-5.16.3/lib/minitest/test.rb:94
c:0025 p:0029 s:0123 E:001ac0 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/minitest-5.16.3/lib/minitest.rb:391
c:0024 p:0044 s:0115 E:001f78 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/minitest-5.16.3/lib/minitest/test.rb:243
c:0023 p:0004 s:0108 E:0014f0 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/minitest-5.16.3/lib/minitest/test.rb:93
c:0022 p:0008 s:0104 e:000103 BLOCK  /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.3.1/lib/active_support/executor/test_helper.rb:5
c:0021 p:0012 s:0101 e:000100 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.3.1/lib/active_support/execution_wrapper.rb:105
c:0020 p:0016 s:0096 e:000095 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.3.1/lib/active_support/executor/test_helper.rb:5
c:0019 p:0008 s:0090 e:000089 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/minitest-5.16.3/lib/minitest.rb:1059
c:0018 p:0015 s:0083 e:000082 BLOCK  /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.3.1/lib/active_support/testing/parallelization/worker.rb:50
c:0017 p:0029 s:0080 E:001440 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/minitest-5.16.3/lib/minitest.rb:391
c:0016 p:0029 s:0072 E:001238 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/minitest-5.16.3/lib/minitest.rb:378
c:0015 p:0049 s:0065 E:001338 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.3.1/lib/active_support/testing/parallelization/worker.rb:49
c:0014 p:0011 s:0056 e:000055 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.3.1/lib/active_support/testing/parallelization/worker.rb:38
c:0013 p:0053 s:0051 e:000050 BLOCK  /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.3.1/lib/active_support/testing/parallelization/worker.rb:27 [FINISH]
c:0012 p:---- s:0048 e:000047 CFUNC  :fork
c:0011 p:0004 s:0044 e:000043 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.3.1/lib/active_support/testing/parallelization/worker.rb:15
c:0010 p:0018 s:0040 e:000039 BLOCK  /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.3.1/lib/active_support/testing/parallelization.rb:37 [FINISH]
c:0009 p:---- s:0036 e:000035 IFUNC 
c:0008 p:---- s:0033 e:000032 CFUNC  :times
c:0007 p:---- s:0030 e:000029 CFUNC  :each
c:0006 p:---- s:0027 e:000026 CFUNC  :map
c:0005 p:0008 s:0023 e:000022 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.3.1/lib/active_support/testing/parallelization.rb:36
c:0004 p:0023 s:0019 e:000018 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.3.1/lib/active_support/testing/parallelize_executor.rb:18
c:0003 p:0162 s:0015 e:000014 METHOD /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/minitest-5.16.3/lib/minitest.rb:156
c:0002 p:0073 s:0008 E:001c50 BLOCK  /Users/pekkaakerstrom/.rvm/gems/ruby-3.1.2/gems/minitest-5.16.3/lib/minitest.rb:83 [FINISH]
c:0001 p:0000 s:0003 E:001960 (none) [FINISH]```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.