Opened 8 years ago

Closed 8 years ago

#3539 closed defect (fixed)

geography ST_Segmentize returning straight line instead of curved

Reported by: robe Owned by: pramsey
Priority: blocker Milestone: PostGIS 2.3.0
Component: postgis Version: master
Keywords: Cc:

Description (last modified by robe)

This appears to be a new regression which I am not seeing in PostGIS 2.2.2 install.

When I tried this query in PostGIS 2.3.0 I'm getting a straight line instead of a curve.

SELECT ST_AsText(ST_Segmentize(
ST_MakeLine(ST_Point(-73.8893, 40.6975), ST_POINT(72.8667,19.1583))::geography, 10000000)::geometry);

In 2.2.2 I get this which gets curvier as I reduce the segmentize meters POSTGIS="2.2.2 r14797" GEOS="3.5.0-CAPI-1.9.0 r4090" PROJ="Rel. 4.9.1, 04 March 2015" GDAL="GDAL 2.0.2, released 2016/01/26" LIBXML="2.7.8" LIBJSON="0.12" RASTER

LINESTRING(-73.8893 40.6975,19.6313806536934 62.1086776667385,72.8667 19.1583)

In POSTGIS="2.3.0dev r14864" GEOS="3.5.0-CAPI-1.9.0 r4088" PROJ="Rel. 4.9.1, 04 March 2015" GDAL="GDAL 2.1.0dev, released 2015/99/99" LIBXML="2.7.8" LIBJSON="0.12" RASTER I get

LINESTRING(-73.8893 40.6975,-0.511300000000007 29.9279,72.8667 19.1583)

Look at snapshot for perspective.

Attachments (1)

bad_geog_segmentize.png (77.8 KB ) - added by robe 8 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 by robe, 8 years ago

Description: modified (diff)
Priority: mediumblocker

by robe, 8 years ago

Attachment: bad_geog_segmentize.png added

comment:2 by robe, 8 years ago

Version: 2.2.xtrunk

comment:3 by robe, 8 years ago

Description: modified (diff)

comment:4 by robe, 8 years ago

I took a closer look at this to see what changed in PostGIS 2.2 to 2.3 and most likely culprit to me seems like change in

ptarray_segmentize_sphere in lwgeodetic.c in PostGIS 2.2 there was a called to geog2cart which looks like it was taken out and replaced with something else in PostGIS 2.3.0

at r14706

comment:5 by robe, 8 years ago

reopened this pull request - ​https://github.com/postgis/postgis/pull/90. We'll have to rollback this change unless a revised pull request is submitted and preferably one that includes a test for the general case, so we catch this kind of thing in the future.

comment:6 by hmercier, 8 years ago

Hi, I may be missing something, but I fail to understand why the segmentize in 2.2 should curve the line …

comment:7 by robe, 8 years ago

Because this is the geography segmentize not the geometry segmentize. It should follow the great circle pattern. geography segmentize has now been reduced to nothing but geometry segmentize.

If I go from New York to Mumbai and I segmentize my line enough even on a flat map it should not show me going thru Africa.

Here is a query way of looking at it. Note how the 2.3 answer is way longer than the original segment and 2.2 answer

SELECT ST_Length(ST_MakeLine(ST_Point(-73.8893, 40.6975), ST_POINT(72.8667,19.1583))::geography) As orig_len,
ST_Length('LINESTRING(-73.8893 40.6975,19.6313806536934 62.1086776667385,72.8667 19.1583)'::geography) AS len_22_answer,
ST_Length('LINESTRING(-73.8893 40.6975,-0.511300000000007 29.9279,72.8667 19.1583)'::geography) AS len_23_answer;

     orig_len     |  len_22_answer   |  len_23_answer
------------------+------------------+------------------
 12544025.7530776 | 12544040.5248272 | 13998927.2849106
(1 row)


Last edited 8 years ago by robe (previous) (diff)

comment:8 by hmercier, 8 years ago

Oops, of course, my bad ! I am fixing again the segmentize function in order to fix this issue (and still have segments of constant length). I will send a new patch quickly. Thanks for the report.

comment:9 by robe, 8 years ago

While you are at it, add a test for this case. We don't have a test to catch this common use case.

comment:10 by robe, 8 years ago

Resolution: fixed
Status: newclosed

In 15044:

Segmentize geography using equal length segments, (Hugo Mercier of Oslandia)
Closes #3613
Closes #3539
Closes https://github.com/postgis/postgis/pull/90

Note: See TracTickets for help on using tickets.