Ticket #1673 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

OGR_G_CloseRings side-effect on OGR_G_GetGeometryType

Reported by: jbronn Assigned to: mloskot
Priority: low Milestone: 1.4.2
Component: OGR_SF Version: 1.4.1
Severity: normal Keywords: geometry
Cc: jbronn@gmail.com, warmerdam

Description

After closing the rings on a Polygon, when attempting to get the geometry type of one of the closed rings, OGR returns a nonsense number. Exporting the closed-ring Polygon to WKT fixes this scenario, and the closed ring will subsequently return the correct geometry type.

Here is a Python script that demonstrates the problem:

import ogr

# Unclosed Polygon WKT
wkt = 'POLYGON((0 0, 5 0, 5 5, 0 5), (1 1, 2 1, 2 2, 2 1))'

if __name__=='__main__':

    # Creating the polygon from the WKT
    poly = ogr.CreateGeometryFromWkt(wkt)

    # Getting the exterior ring before we close all rings
    ring_b = poly.GetGeometryRef(0)
    print 'Ring Geometry Type Before Closure: %d' % ring_b.GetGeometryType()

    # Closing the rings
    poly.CloseRings()

    # Now getting the same ring again
    ring_a = poly.GetGeometryRef(0)
    print 'Ring Geometry Type After Closure: %d' % ring_a.GetGeometryType()

    # Exporting closed Polygon to  WKT "fixes" this.
    ring_wkt = str(poly)
    ring_a = poly.GetGeometryRef(0)
    print 'Ring Geometry Type Fixed: %d' % ring_a.GetGeometryType()

Here is the output from that script:

Ring Geometry Type Before Closure: 2
Ring Geometry Type After Closure: -2147483646
Ring Geometry Type Fixed: 2

Attachments

close_rings_test.cpp (2.0 kB) - added by mloskot on 06/22/07 11:35:12.
C++ program reproducing this bug

Change History

06/14/07 20:05:36 changed by jbronn

  • cc set to jbronn@gmail.com.

06/14/07 20:13:38 changed by warmerdam

  • keywords set to geometry.
  • owner changed from warmerdam to mloskot.
  • component changed from default to OGR_SF.
  • cc changed from jbronn@gmail.com to jbronn@gmail.com, warmerdam.
  • milestone set to 1.4.2.

Mateusz,

Could you look into this?

Thanks,

06/22/07 11:35:12 changed by mloskot

  • attachment close_rings_test.cpp added.

C++ program reproducing this bug

06/22/07 11:55:23 changed by mloskot

  • status changed from new to assigned.

Diagnosis:

  • In the closeRings() operation, if start point and end point differs, additional end point is added with the same coordinates of start point.
  • The addPoint() operation was passed with X,Y and Z coordinates without respect of current coordinate dimension.
  • Next, 2D ring was completed with end point of X,Y,Z coordinates what in turn caused re-qualification of coordinate dimension of the ring, from 2D to 2.5D.
  • In result, incorrect (different) geometry type of the ring was reported.

Solution:

The OGRLinearRing::closeRings() has to be patched to respect current coordinate dimension, to avoid implicit changes.

06/22/07 12:03:16 changed by mloskot

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

Fixed in SVN trunk (r11694).

06/22/07 12:14:41 changed by mloskot

Fix ported to branches/1.4 (r11695).