Ticket #135 (closed defect: fixed)

Opened 6 years ago

Last modified 4 years ago

*_getDimensions functions do not return correct dimensions

Reported by: hrz@… Owned by: strk
Priority: major Milestone: 3.2.0
Component: Core Version: 2.2.2
Severity: Unassigned Keywords: imported,phpbugtracker
Cc: mloskot

Description (last modified by mloskot) (diff)

Based on the comments in geos_c.h, I would expect the following code to print 'dimensions=0' instead of the 'dimensions=3' I currently get.

  geom = GEOSGeomFromWKT("POLYGON EMPTY");
  printf("dimensions=%dn", GEOSGeom_getDimensions(geom));

This is the same for POINT, LINESTRING and LINEARRING types, although GEOMETRYCOLLECTION and subtypes thereof work as expected.

On a possibly related note, I would expect the following code to output 'coords dimensions=2' instead of the 'coords dimension=3' I get.

  coords = GEOSCoordSeq_create(1, 2);
  GEOSCoordSeq_setX(coords, 0, 43.2);
  GEOSCoordSeq_setY(coords, 0, 44.2);
  GEOSCoordSeq_getDimensions(coords, &dims);

  printf("coords dimensions=%dn", dims);

Wouldn't it be more useful if GEOSGeom_getDimensions() used a similar prototype to GEOSCoordSeq_getDimensions()? This would allow to easily distinguish between empty geometries and testing if an exception was thrown. Alternatively GEOSGeom_getDimensions() could return -1 if an exception occurred.

Or am I missing something fundamental?

My system details are the same as in Bug #133

Change History

Changed 6 years ago by strk@…

I don't know wheter getDimension() should return 0 for EMPTY geometries of all kind. In postgis we don't have the concept of *typed* EMPTY geometries, while in GEOS/JTS we have them. We should ask Martin Davis, being
the algorithms master for JTS.

About GEOSCoordSeq_create() the fact is that GEOS (and JTS) currenlty only support 3d geoms (2.5d actually)
so maybe we should return an error if any different dimension is specified... Discussion welcome on geos-devel for both questions.

About the last question I'm afraid it's too late to change the interface as the whole point of the C-API
is to maintain the interface stable.

Changed 5 years ago by mloskot

  • cc mloskot added
  • description modified (diff)

Changed 5 years ago by mloskot

  • version changed from 3.0.0 to 2.2.2
  • milestone imported deleted

Changed 5 years ago by mloskot

  • owner strk@… deleted
  • priority changed from 3 to major
  • status changed from assigned to new
  • component changed from C-API to Core

Changed 4 years ago by pramsey

  • milestone set to 3.2.0

We either need a new API for this, or to change it. It's odd we provide an API for something that is wrong much of the time.

Changed 4 years ago by strk

  • owner set to strk
  • status changed from new to assigned

Fixed in revision 2484 (the GEOSGeom_getDimensions part).

Changed 4 years ago by strk

  • status changed from assigned to closed
  • resolution set to fixed

For the GEOSCoordSeq_getDimensions, I belive it's expected to get 3 even if you create it with a request of 2 dimensions. The rationale is that on creation you request to have space for *at least* the given number of dimensions, but an higher value is acceptable.

GEOS itself isn't ready for a 2d-only Coordinate type so you always get a 3d sequence.

As a conclusion, I don't think getting 3 is to be considered a bug and I won't close.

If you want to be able to store 2d-only Coordinates that's an enhancement.

Note: See TracTickets for help on using tickets.