Skip to content

Question: Is there a way to determine geometry dimension? #654

Open

Description

@hisener

The WKBWriter constructor expects output dimension (e.g. new WKBWriter(dimension, ByteOrderValues.LITTLE_ENDIAN, true)) and it has to be either 2 or 3. However, Geometry#getDimension is not appropriate to use here. Is there a generic way to determine the dimension for a given Geometry object? In other words, is there such method that satisfies the following:

  • #getDimension(GEOMETRY_FACTORY.createPoint(new Coordinate(1,2))) -> 2
  • #getDimension(GEOMETRY_FACTORY.createPoint(new Coordinate(1,2,3))) -> 3
  • #getDimension(GEOMETRY_FACTORY.createPolygon(new Coordinate[]{new Coordinate(1,2,3), new Coordinate(2,2,3), new Coordinate(2,3,3), new Coordinate(1,2,3)})) -> 3
  • #getDimension(GEOMETRY_FACTORY.createMultiPolygon(new Polygon[]{GEOMETRY_FACTORY.createPolygon(new Coordinate[]{new Coordinate(1,2,3), new Coordinate(2,2,3), new Coordinate(2,3,3), new Coordinate(1,2,3)})})) -> 3

where #getDimension accepts Geometry.

Activity

  1. dr-jts commented on Jan 22, 2021

    @dr-jts
    Contributor

    There isn't anything like this now, but this method would be useful for sure.

  2. dbaston commented on Jan 23, 2021

    @dbaston
    Contributor

    GEOS has Geometry::getCoordinateDimension that could be ported back.

  3. mdedetrich commented on Aug 3, 2026

    @mdedetrich

    I have created an upstream PR to resolve this #1220

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions