Skip to content

DOC: pygeos.get_dimensions on empty LINESTRING #289

@telemmaite

Description

@telemmaite

Based on pygeos.get_dimensions

Returns the inherent dimensionality of a geometry.

The inherent dimension is 0 for points, 1 for linestrings and linearrings, and 2 for polygons. For geometrycollections it is the max of the containing elements. Empty and None geometries return -1.

Strange, I was expecting -1 here:

pygeos.get_dimensions(pygeos.Geometry("LINESTRING EMPTY"))
> 1

I am trying to filter out LINESTRING EMPTY, maybe I should use another method to check "emptiness"

mask = array([<pygeos.Geometry LINESTRING EMPTY>,
       <pygeos.Geometry LINESTRING EMPTY>,
       <pygeos.Geometry LINESTRING EMPTY>,
       <pygeos.Geometry LINESTRING EMPTY>,
       <pygeos.Geometry LINESTRING EMPTY>,
       <pygeos.Geometry MULTIPOINT (-7.23e+06 4.88e+06, -6.7e+06 4.96e+06)>,
       <pygeos.Geometry LINESTRING EMPTY>,
       <pygeos.Geometry LINESTRING EMPTY>,
       <pygeos.Geometry LINESTRING EMPTY>,
       <pygeos.Geometry LINESTRING EMPTY>,
       <pygeos.Geometry LINESTRING EMPTY>,
       <pygeos.Geometry LINESTRING EMPTY>,
       <pygeos.Geometry LINESTRING EMPTY>,
       <pygeos.Geometry LINESTRING EMPTY>,
       <pygeos.Geometry POINT (-6.7e+06 4.96e+06)>,
       <pygeos.Geometry LINESTRING EMPTY>,
       <pygeos.Geometry LINESTRING EMPTY>,
       <pygeos.Geometry LINESTRING EMPTY>], dtype=object)

pygeos.get_dimensions(mask)
> array([[1, 1, 1, 1, 1, 0, 1, 1, 1],
       [1, 1, 1, 1, 1, 0, 1, 1, 1]], dtype=int32)

Edit:
Looks like this would do it, but it is quite verbose, to filter out all empty LINESTRINGS

mask[(pygeos.get_num_coordinates(crosses_mask) == 2) & (pygeos.get_type_id(crosses_mask) == pygeos.GeometryType.LINESTRING)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions