[postgis-tickets] [PostGIS] #4585: st_astwkb not returning valid geometry

PostGIS trac at osgeo.org
Tue Nov 19 06:21:10 PST 2019


#4585: st_astwkb not returning valid geometry
--------------------------+---------------------------
  Reporter:  furstenheim  |      Owner:  pramsey
      Type:  defect       |     Status:  new
  Priority:  medium       |  Milestone:  PostGIS 2.4.9
 Component:  postgis      |    Version:  2.4.x
Resolution:               |   Keywords:
--------------------------+---------------------------

Comment (by nicklas):

 Hi

 What you posted is not a valid geojson. Both because of the question mark
 in it and because of the lack of nestling.

 It is just a lot of point couple arrays not a point array in a ring array
 as polygon demands.

 So, what I guess that you want to write is:

 {{{
 select
   st_isvalidreason(
     st_geomfromtwkb(
       st_astwkb(
         st_geomfromgeojson(
          '{
     "type": "Polygon", "coordinates": [2.1776390993201,41.3722988965004],
 [2.17763909886103,41.37229889631543],[2.17763909900003,41.3722988970001],
 [2.1820804568871637,41.37027921005133],[2.18208045654673,41.3702792096251],
 [2.1776390993201,41.3722988965004?]
     }'
           )
         )
       )
     )
 }}}


 Then I get the error Too few points for geometry type.

 That is because the points are so close so many of them gets removed as
 duplicates when creating twkb.
 twkb by default only saves the integer part for geometry.

 But even if you tell it to store 7 decimals it is only 2 different points,
 not 3 as needed for a polygon to be valid.

 If you manually remove the precesion beyond 7 decimals in your data you
 see that you get the same result from geojson:

 {{{

 select st_isvalidreason(
 st_geomfromgeojson('{
     "type": "Polygon", "coordinates": [[
 [2.1776390,41.3722988],
 [2.1776390,41.3722988],
 [2.1776390,41.3722988],
 [2.1820804,41.3702792],
 [2.1820804,41.3702792],
 [2.1776390,41.3722988]]]
     }')
     )
 }}}

-- 
Ticket URL: <https://trac.osgeo.org/postgis/ticket/4585#comment:1>
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