Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENVELOPE method on linestring does not return POLYGON #369

Open
yogeshsyn23 opened this issue Feb 2, 2024 · 5 comments
Open

ENVELOPE method on linestring does not return POLYGON #369

yogeshsyn23 opened this issue Feb 2, 2024 · 5 comments

Comments

@yogeshsyn23
Copy link

yogeshsyn23 commented Feb 2, 2024

Steps to reproduce

 factory = RGeo::Cartesian.factory
 linestring = factory.line_string([factory.point(0, 48), factory.point(0, 82)])
 envelope = linestring.envelope

 p envelope
 #<RGeo::Cartesian::LineImpl:0x2b78c "LINESTRING (0.0 48.0, 0.0 82.0)"> 

Expected behavior

Should return POLYGON.

Actual behavior

Returning LineImpl when the 2 points are on a vertical or a horizontal line

System configuration

Ruby version:
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]

OS:
MacOS Ventura Version 13.3.1

@keithdoggett
Copy link
Member

What version of geos are you using? On 3.10 I'm seeing a polygon when I run this.

@yogeshsyn23
Copy link
Author

yogeshsyn23 commented Feb 5, 2024

I have not installed geos for this.
Correct me if i am wrong, but this method no where specifies explicit dependency on geos.
Also in the factory-compatibiltiy doc, LineString#envelope shows compatibilty with cartesian factory.

@keithdoggett
Copy link
Member

Got it you're using the Ruby implementation. I think since Geos is now returning either NULL a point or a polygon rather than a linestring as well like in older versions we can make this change to match. I can work on a fix in the next few days.

@yogeshsyn23
Copy link
Author

@keithdoggett is there any update to this.
also can i help in fixing this.

@keithdoggett
Copy link
Member

I've looked into it but haven't had time to write a PR. We need to change the envelope method in RGeo::Cartesian::GeometryMethods (

def envelope
BoundingBox.new(factory).add(self).to_geometry
end
) to match the definition given by Geos now.

Per Geos it can either return a polygon or a point (https://github.com/libgeos/geos/blob/a8d2ed0aba46f88f9b8987526e68eea6565d16ae/capi/geos_c.h.in#L3881-L3887), so we should just add a check for the returned geometry from the BoundingBox call and if it's a linestring, coalesce it into a polygon (probably by taking the points into an array).

i.e. something like this (haven't run this)

def envelope
        env = BoundingBox.new(factory).add(self).to_geometry
        if RGeo::Feature::LineString.check_type(env)
           boundary = factory.line_string([env.start_point, env.end_point, env.start_point, env.end_point])
           env = factory.polygon(boundary)
       end
       env
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants