Skip to content

Optimize intersection computation for envelopes #166

@mbasmanova

Description

@mbasmanova

I cannot find a method to compute intersection of two envelopes. The only way I know to do that is via OGCGeometry:

OGCGeometry.createFromEsriGeometry(a, null).intersection(OGCGeometry.createFromEsriGeometry(b, null))

However this method is very slow. It is about 300 times slower than envelope-specific computation: prestodb/presto#10327

    @Nullable
    public static Envelope intersection(Envelope envelope, Envelope otherEnvelope)
    {
        requireNonNull(envelope, "envelope is null");
        requireNonNull(otherEnvelope, "otherEnvelope is null");

        if (envelope.getXMax() < otherEnvelope.getXMin()
                || envelope.getXMin() > otherEnvelope.getXMax()
                || envelope.getYMax() < otherEnvelope.getYMin()
                || envelope.getYMin() > otherEnvelope.getYMax()) {
            return null;
        }

        return new Envelope(
                max(envelope.getXMin(), otherEnvelope.getXMin()),
                max(envelope.getYMin(), otherEnvelope.getYMin()),
                min(envelope.getXMax(), otherEnvelope.getXMax()),
                min(envelope.getYMax(), otherEnvelope.getYMax()));
    }

Would it be possible to add an efficient Envelope#intersection API?

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions