Code Monkey home page Code Monkey logo

Comments (13)

workmaster2n avatar workmaster2n commented on May 28, 2024 1

@handlers I got confused, sorry. I meant to point out that if you make a linear_ring first (linear_ring = factory.linear_ring(<array of points>)) and then pass that linear_ring to the polygon factory, it will return a polygon (factory.polygon(linear_ring)). Definitely a work around, but it works. I think you can even create the linear_ring from the line_string (factory.linear_ring(line_string)), but I'll have to double check that in the morning.

from rgeo.

tilo avatar tilo commented on May 28, 2024 1

+1 depending on the precision of the provided points, factory.polygon() returns nil
for spherical_factory SRID 4326

This has been open for a long time - Is there any update on when it's going to be fixed?
rgeo (0.3.20)

from rgeo.

spatchcock avatar spatchcock commented on May 28, 2024

Doesn't a polygon require at least 3 distinct points, otherwise it is just a 1-dimensional straight line? Try adding another point before the last, 'closing' point perhaps to make it into a polygon...

a=[factory.point(-92.272935049926986,15.831411705496032)]
 => [#<RGeo::Geographic::SphericalPointImpl:0x15b43d8 "POINT (-92.27293504992699 15.831411705496032)">] 

a << factory.point(-92.273079163754431,15.830847348631419)
 => [#<RGeo::Geographic::SphericalPointImpl:0x15b43d8 "POINT (-92.27293504992699 15.831411705496032)">, #<RGeo::Geographic::SphericalPointImpl:0x15cff98 "POINT (-92.27307916375443 15.83084734863142)">] 

# Add a NEW point
a << factory.point(-92.27315,15.83001)
 => [#<RGeo::Geographic::SphericalPointImpl:0x15b43d8 "POINT (-92.27293504992699 15.831411705496032)">, #<RGeo::Geographic::SphericalPointImpl:0x15cff98 "POINT (-92.27307916375443 15.83084734863142)">, #<RGeo::Geographic::SphericalPointImpl:0x15e49c0 "POINT (-92.27315 15.83001)">] 

# closing point
a << factory.point(-92.272935049926986,15.831411705496032)
 => [#<RGeo::Geographic::SphericalPointImpl:0x15b43d8 "POINT (-92.27293504992699 15.831411705496032)">, #<RGeo::Geographic::SphericalPointImpl:0x15cff98 "POINT (-92.27307916375443 15.83084734863142)">, #<RGeo::Geographic::SphericalPointImpl:0x15e49c0 "POINT (-92.27315 15.83001)">, #<RGeo::Geographic::SphericalPointImpl:0x15eaec4 "POINT (-92.27293504992699 15.831411705496032)">] 

linear_ring = factory.linear_ring(a)
 => #<RGeo::Geographic::SphericalLinearRingImpl:0x15ec878 "LINESTRING (-92.27293504992699 15.831411705496032, -92.27307916375443 15.83084734863142, -92.27315 15.83001, -92.27293504992699 15.831411705496032)"> 

from rgeo.

workmaster2n avatar workmaster2n commented on May 28, 2024

Cartesian polygon still returns nil. Trying the code on http://blog.daniel-azuma.com/archives/88 results in any polygon being returned as nil.

from rgeo.

workmaster2n avatar workmaster2n commented on May 28, 2024

If I use a different factory (like the spherical factory), I can create a polygon with the line_string

from rgeo.

plantfansam avatar plantfansam commented on May 28, 2024

I am having the same issue while following the tutorial. My factory object is:

RGeo::Geos::CAPIFactory:0x3fc076578cb4 srid=0 bufres=1 flags=8

Creating a polygon from a linestring returned nil. There is a rescue nil statement in the capi_factory.rb polygon method, but I have no idea why it's being tripped.

from rgeo.

workmaster2n avatar workmaster2n commented on May 28, 2024

@handlers I was able to get things to work if I made a linear_ring first. Can you gist your code that isn't working?

from rgeo.

plantfansam avatar plantfansam commented on May 28, 2024

@workmaster2n sure thing: https://gist.github.com/handlers/5693967

from rgeo.

plantfansam avatar plantfansam commented on May 28, 2024

@workmaster2n cool -- passing in a linear ring solves the problem for me! I wasn't able to pass a linestring into linear_ring().

from rgeo.

piyushchauhan2011 avatar piyushchauhan2011 commented on May 28, 2024

@workmaster2n ya linear_ring solves the problem with charm. author should update the tutorial.

from rgeo.

tilo avatar tilo commented on May 28, 2024

I found a bug on my side which caused this - hopefully this helps other people:

I had four points which would not be in the right order -- if you connected them by a line, the lines would cross.

#polygon and #linestring just return nil in that case, without any error or explanation.

RGeo should throw an error with a sufficient explanation, or even have code to fix the order

from rgeo.

babasbot avatar babasbot commented on May 28, 2024

@tilo is there a way to sort those points?

from rgeo.

keithdoggett avatar keithdoggett commented on May 28, 2024

Closing this since the spherical factory now raises an error when an invalid linear ring is being initialized.

from rgeo.

Related Issues (20)

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.