[PostGIS] #5895: Distance Calculation Issue with `ST_DistanceSphere`
PostGIS
trac at osgeo.org
Tue Feb 3 04:08:03 PST 2026
#5895: Distance Calculation Issue with `ST_DistanceSphere`
------------------------------+---------------------
Reporter: giovannicimolin | Owner: pramsey
Type: defect | Status: new
Priority: medium | Milestone:
Component: postgis | Version: 3.4.x
Resolution: | Keywords:
------------------------------+---------------------
Comment (by lnicola):
Just found a similar case:
{{{
create table us_counties(geog geography not null);
insert into us_counties values('MULTIPOLYGON(((-106.195372
40.989938,-106.194231 40.99197,-106.192357 40.993688,-106.190553863626
40.9976070173843,-106.061181 40.996999,-105.77056285729
40.9968997139614,-105.730421 40.996886,-105.724804
40.99691,-105.412718025682 40.9977904880995,-105.277138
40.998173,-105.276859991921 40.99817324279,-105.256527
40.998191,-105.254779 40.99821,-104.943371 40.9980837238089,-104.943127
40.903405,-104.943091 40.884895,-104.943469 40.844088,-104.943337
40.783294,-104.943369 40.740221,-104.943476 40.711295,-104.943543
40.696509,-104.94311 40.696495,-104.943244 40.682254,-104.943484
40.653219,-104.943862 40.638777,-104.944001 40.616785,-104.944091
40.595356,-104.944095 40.58809,-104.94412 40.582431,-104.944019
40.581177,-104.944021 40.580939,-104.944023 40.580824,-104.944113
40.573053,-104.944108 40.566251,-104.944132 40.564294,-104.944135
40.564112,-104.944099 40.563613,-104.944151 40.551715,-104.944186
40.542832,-104.944258 40.522768,-104.944247 40.522663,-104.944213
40.519137,-104.944164 40.508104,-104.944154 40.504925,-104.944147
40.486445,-104.944096 40.4793,-104.944108 40.47636,-104.944116
40.473495,-104.944116 40.473375,-104.944186 40.457026,-104.944257
40.450374,-104.944222 40.435894,-104.944427 40.414196,-104.944562
40.407348,-104.944568 40.406964,-104.944583 40.40651,-104.944605
40.405309,-104.945229 40.370759,-104.945346 40.363476,-104.945551
40.349099,-104.954798 40.349121,-104.955039 40.349121,-104.957356
40.349123,-104.959956 40.349132,-104.961729 40.349138,-104.966444
40.349142,-104.970387 40.349149,-104.980379 40.349171,-104.981291
40.349164,-104.981677 40.349165,-105.002429 40.349217,-105.05672
40.349281,-105.055135 40.335183,-105.055221 40.321045,-105.055326
40.319905,-105.05512 40.308232,-105.055148 40.305264,-105.055162
40.298167,-105.055166 40.296766,-105.055174 40.294532,-105.055175
40.290912,-105.055089 40.269286,-105.055089 40.261793,-105.099937
40.261484,-105.102451 40.261367,-105.110138 40.261284,-105.130179
40.261584,-105.131155 40.261283,-105.142948 40.261283,-105.15906
40.261219,-105.208144 40.261185,-105.212623 40.261185,-105.21483
40.261299,-105.237319 40.261895,-105.289224 40.262781,-105.335177
40.261781,-105.336248 40.261685,-105.336352 40.261685,-105.354747
40.261784,-105.375226 40.261291,-105.390996 40.257884,-105.462752
40.259384,-105.465394 40.259357,-105.495321 40.259726,-105.500481
40.260277,-105.518083 40.260753,-105.535354 40.261284,-105.539455
40.261284,-105.542801 40.26134,-105.56174 40.261507,-105.653321
40.260457,-105.657235 40.262886,-105.66072 40.264228,-105.662378
40.264124,-105.665236 40.266894,-105.667909 40.267718,-105.672055
40.268101,-105.67559 40.267267,-105.678187 40.26812,-105.678903
40.269869,-105.681508 40.271684,-105.682233 40.273164,-105.680347
40.274668,-105.681469 40.279046,-105.679262 40.278912,-105.680732
40.282927,-105.680579 40.28446,-105.685046 40.286409,-105.686346
40.287486,-105.686403 40.288918,-105.68365 40.29119,-105.681165
40.291945,-105.684758 40.292383,-105.687368 40.293733,-105.688272
40.297334,-105.686177 40.303075,-105.689295 40.303479,-105.691278
40.306164,-105.69014 40.308648,-105.691863 40.309373,-105.694834
40.309323,-105.697764 40.310939,-105.700909 40.310715,-105.702109
40.312083,-105.701507 40.314445,-105.700167 40.316364,-105.697648
40.318273,-105.698719 40.32078,-105.70202 40.321711,-105.70168
40.324309,-105.706773 40.325051,-105.713127 40.325568,-105.721438
40.332018,-105.724533 40.3327,-105.729088 40.335278,-105.728786
40.337935,-105.729944 40.339624,-105.733108 40.340774,-105.735441
40.342984,-105.736444 40.344906,-105.736345 40.346615,-105.739613
40.347108,-105.742441 40.349263,-105.747757 40.347508,-105.752383
40.349093,-105.753782 40.35152,-105.757117 40.35165,-105.759271
40.353307,-105.759765 40.355779,-105.763028 40.357118,-105.764441
40.359263,-105.767699 40.359764,-105.769133 40.364474,-105.772596
40.364411,-105.774105 40.365233,-105.774219 40.366759,-105.776437
40.369545,-105.78195 40.373759,-105.78182 40.37699,-105.784997
40.379715,-105.78725 40.380872,-105.788561 40.384282,-105.790729
40.386263,-105.791232 40.387863,-105.790545 40.38964,-105.791664
40.394335,-105.790951 40.39864,-105.793815 40.4008,-105.794182
40.401882,-105.798265 40.405835,-105.800423 40.407218,-105.801294
40.410175,-105.808265 40.414954,-105.811126 40.419399,-105.81534
40.421486,-105.816423 40.423991,-105.817266 40.424323,-105.817231
40.426488,-105.814456 40.428522,-105.814337 40.431334,-105.816366
40.435519,-105.815784 40.437434,-105.813019 40.439161,-105.811728
40.442853,-105.810399 40.443231,-105.806557 40.446202,-105.80569
40.447882,-105.807614 40.452262,-105.805136 40.459233,-105.804479
40.464224,-105.805691 40.4665,-105.80818 40.468868,-105.810669
40.471087,-105.808865 40.471078,-105.807133 40.47241,-105.806793
40.473913,-105.808543 40.475061,-105.812793 40.475855,-105.81542
40.475339,-105.820114 40.475972,-105.822463 40.476829,-105.827956
40.478289,-105.830608 40.479568,-105.834605 40.479869,-105.837823
40.483033,-105.841082 40.483618,-105.843064 40.482994,-105.846967
40.482791,-105.847308 40.483931,-105.854926 40.486252,-105.855822
40.487738,-105.856105 40.490412,-105.855787 40.492682,-105.854773
40.495106,-105.852026 40.497569,-105.851755 40.500475,-105.852297
40.503534,-105.852303 40.506553,-105.854732 40.507789,-105.857058
40.507856,-105.858203 40.509629,-105.860621 40.511549,-105.8619
40.514449,-105.863109 40.515521,-105.866369 40.517257,-105.867513
40.519714,-105.869091 40.520738,-105.871805 40.521748,-105.878048
40.522465,-105.879041 40.523174,-105.881954 40.522853,-105.883852
40.521751,-105.891104 40.521003,-105.894576 40.520196,-105.899111
40.518225,-105.904507 40.514119,-105.907857 40.515493,-105.91078
40.520179,-105.911175 40.522181,-105.909764 40.523452,-105.907868
40.52621,-105.905914 40.530519,-105.905098 40.535361,-105.90715
40.540578,-105.907049 40.542888,-105.909577 40.544982,-105.90951
40.54793,-105.911833 40.552688,-105.909914 40.558806,-105.909784
40.562134,-105.910892 40.56642,-105.91321 40.568313,-105.915032
40.570724,-105.918444 40.5707,-105.921248 40.572559,-105.924977
40.580934,-105.924388 40.582146,-105.926543 40.590589,-105.927697
40.591709,-105.92813 40.600058,-105.929 40.601202,-105.928953
40.603794,-105.930207 40.60619,-105.934711 40.60643,-105.938681
40.608811,-105.942064 40.609077,-105.944535 40.612092,-105.944742
40.614231,-105.947021 40.616689,-105.94511 40.621191,-105.945495
40.622741,-105.947199 40.623746,-105.949261 40.62732,-105.948667
40.630185,-105.948573 40.633678,-105.948062 40.635986,-105.948485
40.642318,-105.950816 40.643289,-105.951079 40.645878,-105.953844
40.646977,-105.954765 40.65021,-105.956686 40.654964,-105.955821
40.658854,-105.957838 40.660874,-105.958639 40.66301,-105.962292
40.666584,-105.965039 40.668207,-105.965114 40.671418,-105.966455
40.673455,-105.966664 40.675681,-105.969392 40.67774,-105.971873
40.681856,-105.970026 40.686265,-105.973584 40.689274,-105.97376
40.691129,-105.972196 40.694811,-105.977085 40.702648,-105.980521
40.703842,-105.982448 40.706692,-105.986021 40.707627,-105.988739
40.709605,-105.989763 40.713982,-105.990077 40.718313,-105.988079
40.721368,-105.989284 40.72352,-105.990939 40.724801,-105.99058
40.72718,-105.991965 40.728919,-105.99627 40.733126,-105.998677
40.734223,-106.000569 40.734337,-106.004026 40.736794,-106.006008
40.737619,-106.00839 40.740064,-106.0107 40.741041,-106.01036
40.742401,-106.012215 40.743946,-106.013978 40.746644,-106.015447
40.750603,-106.015266 40.752816,-106.022255 40.754689,-106.020651
40.757201,-106.020673 40.758429,-106.02388 40.761328,-106.02335
40.763534,-106.024338 40.766296,-106.026643 40.768315,-106.024488
40.771264,-106.029247 40.773436,-106.029566 40.775068,-106.028908
40.777515,-106.031033 40.77787,-106.029685 40.781562,-106.031236
40.782281,-106.03197 40.783767,-106.035211 40.785551,-106.039652
40.78576,-106.04281 40.79013,-106.045371 40.791857,-106.045979
40.796373,-106.044896 40.797682,-106.046694 40.800791,-106.046471
40.802447,-106.047971 40.804643,-106.049587 40.805507,-106.05235
40.805862,-106.051502 40.809141,-106.053288 40.810417,-106.053779
40.812662,-106.055097 40.813631,-106.057798 40.814438,-106.057715
40.81712,-106.062533 40.819509,-106.064831 40.821567,-106.071316
40.822331,-106.073125 40.824633,-106.075306 40.825609,-106.076392
40.827925,-106.077828 40.828498,-106.080861 40.830903,-106.083221
40.831177,-106.087914 40.833403,-106.088596 40.836133,-106.090502
40.837181,-106.092494 40.839781,-106.092686 40.840839,-106.095537
40.841645,-106.09878 40.841699,-106.101261 40.843563,-106.100138
40.84698,-106.098515 40.849736,-106.102442 40.852334,-106.108069
40.852507,-106.106284 40.854075,-106.104281 40.859263,-106.105092
40.860514,-106.107763 40.861368,-106.108404 40.863258,-106.113192
40.864279,-106.116536 40.866441,-106.118971 40.865776,-106.120803
40.867632,-106.123176 40.867501,-106.124647 40.868808,-106.126893
40.869556,-106.127691 40.871785,-106.130671 40.873868,-106.132425
40.876553,-106.12998 40.878213,-106.128251 40.882002,-106.127618
40.88489,-106.128987 40.889281,-106.13143 40.892865,-106.130734
40.895494,-106.131251 40.896608,-106.134102 40.898709,-106.136225
40.899228,-106.136908 40.902028,-106.139286 40.902402,-106.144069
40.9049,-106.147881 40.904638,-106.15069 40.906715,-106.152198
40.906789,-106.154593 40.909421,-106.158551 40.910619,-106.159577
40.912766,-106.158905 40.914266,-106.161166 40.915107,-106.163044
40.916727,-106.16817 40.918398,-106.169485 40.920315,-106.169084
40.922868,-106.170028 40.923804,-106.173435 40.924783,-106.175893
40.928254,-106.179945 40.931521,-106.185307 40.933973,-106.18617
40.936727,-106.187599 40.937745,-106.187166 40.940825,-106.189293
40.945893,-106.187651 40.950166,-106.185629 40.952248,-106.184226
40.955207,-106.186829 40.957425,-106.187391 40.95872,-106.185253
40.961032,-106.184844 40.963831,-106.187701 40.964906,-106.186751
40.968052,-106.187097 40.971167,-106.18973 40.973089,-106.190405
40.976098,-106.19004 40.97864,-106.192139 40.982836,-106.190553
40.984255,-106.191124 40.98603,-106.19494 40.986936,-106.195372
40.989938)))');
select
ST_IsValid(geog :: geometry),
ST_Distance(
geog,
ST_Point(-3.35196, 10.18321, 4326) :: geography
),
ST_Distance(
ST_GeometryN(geog :: geometry, 1) :: geography,
ST_Point(-3.35196, 10.18321, 4326) :: geography
),
ST_DistanceSphere(
geog :: geometry,
ST_Point(-3.35196, 10.18321, 4326)
),
ST_DistanceSpheroid(
geog :: geometry,
ST_Point(-3.35196, 10.18321, 4326)
)
from us_counties;
st_isvalid | st_distance | st_distance | st_distancesphere |
st_distancespheroid
------------+-------------+-------------------+-------------------+---------------------
t | 0 | 10230919.83706264 | 0 |
10230919.837062642
(1 row)
}}}
{{{
POSTGIS="3.6.1 f533623" [EXTENSION] PGSQL="180" GEOS="3.14.1-CAPI-1.20.5"
PROJ="9.6.2 NETWORK_ENABLED=OFF URL_ENDPOINT=https://cdn.proj.org
USER_WRITABLE_DIRECTORY=/var/lib/pgsql/.local/share/proj
DATABASE_PATH=/usr/share/proj/proj.db" (compiled against PROJ 9.6.2)
LIBXML="2.12.10" LIBJSON="0.18" LIBPROTOBUF="1.5.2" WAGYU="0.5.0
(Internal)" (core procs from "3.6.0 4c1967d" need upgrade)
}}}
--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/5895#comment:2>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.
More information about the postgis-tickets
mailing list