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

New computed bounding box code #84

Closed
stansmith907 opened this issue Apr 8, 2017 · 0 comments
Closed

New computed bounding box code #84

stansmith907 opened this issue Apr 8, 2017 · 0 comments
Labels
bug Unexpected problem or unintended behavior

Comments

@stansmith907
Copy link
Contributor

I found an issue with improperly computed bounding boxes when one geometry was fully contained in the eastern hemisphere and another fully contained in the western hemisphere. I think this new code should work in all cases, please review and let me know if you see a problem.

    # compute bounding box
    def self.computeBbox(aGeo)

        # find all the eastings (x) and northings (y) in the GeoJSON object
        aNorthings = []
        aEastings = []
        aGeo.each do |hGeo|
            unpackGeometry(hGeo, aNorthings, aEastings)
        end

        # find most north/south points
        north = aNorthings.max
        south = aNorthings.min

        # find most east/west spanning the meridian
        eastM = aEastings.max
        westM = aEastings.min

        # find most east/west spanning the anti-meridian
        positiveEast = []
        negativeEast = []
        aEastings.each do |east|
            negativeEast << east if east < 0.0
            positiveEast << east if east >= 0.0
        end
        eastAM = negativeEast.max
        westAM = positiveEast.min

        # if eastings are all positive or all negative no meridian was spanned
        if positiveEast.empty? || negativeEast.empty?
            east = eastM
            west = westM
        else
            # choose which meridian was spanned based on smaller edge-to-edge distance
            distanceM = eastM - westM
            distanceAM = (180 + eastAM) + (180 - westAM)
            if distanceM <= distanceAM
                # this spanned to  meridian
                east = eastM
                west = westM
            else
                # this spanned tne anti-meridian
                east = eastAM
                west = westAM
            end
        end

        bBox = {}
        bBox[:westLongitude] = west
        bBox[:eastLongitude] = east
        bBox[:southLatitude] = south
        bBox[:northLatitude] = north

        return bBox

    end
@stansmith907 stansmith907 added the bug Unexpected problem or unintended behavior label Apr 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

1 participant