[postgis-users] intersections strange behavior

Marcin Mionskowski mionskowskimarcin at gmail.com
Wed May 30 08:28:02 PDT 2018


Try with ST_SnapToGrid:
ST_SnapToGrid('your geom',0.000001)
Vertex coordinates are doubles - even if it seems, that thay are the same in binary, thay can differ a bit, causing strange intersection results.

Regards,
Marcin


On Wed, 30 May 2018 13:59:28 +0200, franco base <frenk.calza at gmail.com> wrote:

> Hi all,
> maybe this example is easier to understand.
>
> I cannot explain why
> intersection between 2 line geometry return point (this is not true)
> and
> intersection between 2 same geometry transformed to WKT and then again to
> geometry return line (this is true)
>
>
>
> WITH geom AS
> (
> SELECT
>
> ---- linestring geometry
> '0102000020E610000002000000F1CB9E90EF5822400B08BFE04DB8464089928BE6E8582240A6DE39B92DB84640'::geometry(linestring,4326)
> as a0,
> '0102000020E610000003000000F4CB9E90EF5822400808BFE04DB8464089928BE6E8582240A6DE39B92DB846408C928BE6E8582240A9DE39B92DB84640'
> ::geometry(linestring,4326) as b0,
> ---------
>
> ---- makegeometry from output coordinate of ST_AsText
> ST_GeomFromText
> (ST_AsText('0102000020E610000002000000F1CB9E90EF5822400B08BFE04DB8464089928BE6E8582240A6DE39B92DB84640'::geometry(linestring,4326)))
> as a1,
> ST_GeomFromText
> (ST_AsText('0102000020E610000003000000F4CB9E90EF5822400808BFE04DB8464089928BE6E8582240A6DE39B92DB846408C928BE6E8582240A9DE39B92DB84640'::geometry(linestring,4326)))
> as b1,
> ---------
>
> ---- get point coordinate from linestring geometry
> ST_AsText('0102000020E610000002000000F1CB9E90EF5822400B08BFE04DB8464089928BE6E8582240A6DE39B92DB84640'::geometry(linestring,4326))
> as a,
> ST_AsText('0102000020E610000003000000F4CB9E90EF5822400808BFE04DB8464089928BE6E8582240A6DE39B92DB846408C928BE6E8582240A9DE39B92DB84640'
> ::geometry(linestring,4326) ) as b
> ----------
> )
>
>
> SELECT
> st_geometrytype(st_intersection(a0,b0)),st_geometrytype(st_intersection(a1,b1)),a,b
> FROM geom
>
> RETURN
> "ST_Point";"ST_LineString";"LINESTRING(9.17370273531376
> 45.4398766453524,9.17365189031377
> 45.4388953716819)";"LINESTRING(9.17370273531376
> 45.4398766453524,9.17365189031377 45.4388953716819,9.17365189031377
> 45.4388953716819)"
>
>
>
> "POSTGIS="2.2.1 r14555" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel. 4.9.2, 08
> September 2015" GDAL="GDAL 1.11.3, released 2015/09/16" LIBXML="2.9.3"
> LIBJSON="0.11.99" TOPOLOGY RASTER"
>
>
>
> Thanks a lot
> f
>
>
>
> 2018-05-29 12:49 GMT+02:00 franco base <frenk.calza at gmail.com>:
>
>> Thanks I undesrtand.
>> Infact
>>
>> SELECT st_contains(b,a)  return true.
>>
>>
>> I still don't understand why
>>
>> SELECT  st_intersection(a,b) return a line
>> and
>> SELECT st_intersection(a,c) return a point
>> and
>> SELECT st_intersection(b,c) return a point
>>
>>
>>
>> SELECT ST_AsText (c)
>>
>> return
>>
>> "LINESTRING(*9.18334214253396 45.4443310195606,9.18284350788197
>> 45.4441804010334,9.18274220788201 45.4441483010334,9.18274220788201
>> 45.4441483010334,9.18271080788202 45.4441388010335,9.18271080788202
>> 45.4441388010335*,9.18267210788205 45.4442348010335,9.18267210788205
>> 45.4442348010335,9.18256900788209 45.4442025010335,9.18256930788208
>> 45.4442020010335,9.1817161078824 45.4439402010335,9.1817161078824
>> 45.4439402010335,9.18096850788267 45.4437069010336,9.18096850788267
>> 45.4437069010336,9.18075270788275 45.4436465010336,9.18075270788275
>> 45.4436465010336,9.18046820788286 45.4435903010337,9.18046820788286
>> 45.4435903010337,9.18017890788296 45.4435440010337,9.18017890788296
>> 45.4435440010337,9.17996920788304 45.4435166010337,9.17996920788304
>> 45.4435166010337,9.17973530788314 45.4435053010337,9.17973530788314
>> 45.4435053010337,9.17950020788323 45.4435044010337,9.17950020788323
>> 45.4435044010337,9.17913950788338 45.4435149010338,9.17913950788338
>> 45.4435149010338,9.17903360788343 45.4435180010338,9.17903360788343
>> 45.4435180010338,9.17900690788344 45.4435188010338,9.17900690788344
>> 45.4435188010338,9.17898210788345 45.4435200010338,9.17898210788345
>> 45.4435200010338,9.17890050788348 45.4435241010338,9.17890050788348
>> 45.4435241010338,9.17876780788353 45.4435307010338,9.17847140788366
>> 45.4435455010338,9.17875697558416 45.4435312419178)"
>>
>> The first 6 point are the same that make b geometry
>>
>> >> st_makepoint(9.18334214253396,45.4443310195606),
>> >> st_makepoint(9.18284350788197,45.4441804010334),
>> >> st_makepoint(9.18274220788201,45.4441483010334),
>> >> st_makepoint(9.18274220788201,45.4441483010334),
>> >> st_makepoint(9.18271080788202,45.4441388010335),
>> >> st_makepoint(9.18271080788202,45.4441388010335)
>>
>> The first 2 point are the same that make a geometry
>> >> st_makepoint(9.18284350788197,45.4441804010334),
>> >> st_makepoint(9.18334214253396,45.4443310195606)
>>
>>
>>
>> thanks
>> f
>>
>>
>>
>>
>>
>>
>> 2018-05-28 21:22 GMT+02:00 Paul Ramsey <pramsey at cleverelephant.ca>:
>>
>>> Also knowing that the end points of a line string are considered the
>>> boundary of the linestring, not the interior...
>>>
>>> On Mon, May 28, 2018 at 12:21 PM, Paul Ramsey <pramsey at cleverelephant.ca>
>>> wrote:
>>> > Does knowing that an overlaps test is only true if the interiors of
>>> > both objects interact, but there is no full containment relationship
>>> > help you understand a little?
>>> >
>>> > On Mon, May 28, 2018 at 8:03 AM, franco base <frenk.calza at gmail.com>
>>> wrote:
>>> >> Hi all,
>>> >>
>>> >>
>>> >> question 1)
>>> >> why ST_Overlaps doesn't work with geometry a and b?
>>> >> The first 2 point of the 2 line (bold) are the same.
>>> >> ST_Intersection works
>>> >>
>>> >> question 2)
>>> >> if I extend line b it becomes c
>>> >> (sorry i write text geometry because I have a lot of point coord),
>>> >> ST_Overlaps return false and also
>>> >> ST_Intersection return a point (length =0)
>>> >>
>>> >> What's happen?
>>> >>
>>> >> "POSTGIS="2.2.1 r14555" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel.
>>> 4.9.2, 08
>>> >> September 2015" GDAL="GDAL 1.11.3, released 2015/09/16" LIBXML="2.9.3"
>>> >> LIBJSON="0.11.99" TOPOLOGY RASTER"
>>> >>
>>> >>
>>> >> WITH geom AS
>>> >> (
>>> >> SELECT
>>> >> st_setsrid(st_makeline(
>>> >> st_makepoint(9.18284350788197,45.4441804010334),
>>> >> st_makepoint(9.18334214253396,45.4443310195606)
>>> >> ),4326) a,
>>> >>
>>> >> st_setsrid(st_makeline(ARRAY[
>>> >> st_makepoint(9.18334214253396,45.4443310195606),
>>> >> st_makepoint(9.18284350788197,45.4441804010334),
>>> >> st_makepoint(9.18274220788201,45.4441483010334),
>>> >> st_makepoint(9.18274220788201,45.4441483010334),
>>> >> st_makepoint(9.18271080788202,45.4441388010335),
>>> >> st_makepoint(9.18271080788202,45.4441388010335) ]),4326) b,
>>> >>
>>> >> '0102000020E610000027000000E8527405DF5D224039CEBED6DFB846402
>>> A470DAA9D5D22403CFB43E7DAB8464073E7FC62905D22409DC1FDD9D9B84
>>> 64073E7FC62905D22409DC1FDD9D9B8464040F560458C5D224065A94C8AD
>>> 9B8464040F560458C5D224065A94C8AD9B84640577DD232875D224085179
>>> BAFDCB84640577DD232875D224085179BAFDCB84640C43B5CAF795D2240B
>>> B5EA7A0DBB84640BB366DB9795D2240D5A0759CDBB84640CB05C9E4095D2
>>> 240CC685208D3B84640CB05C9E4095D2240CC685208D3B8464088EC7DE7A
>>> 75C224074794263CBB8464088EC7DE7A75C224074794263CBB84640280A7
>>> 29E8B5C224050769668C9B84640280A729E8B5C224050769668C9B846403
>>> 1A63554665C224097E12591C7B8464031A63554665C224097E12591C7B84
>>> 6409A92E968405C22406A63C10CC6B846409A92E968405C22406A63C10CC
>>> 6B84640164A8CEC245C22402356E826C5B84640164A8CEC245C22402356E
>>> 826C5B84640D4962A44065C22406FC51DC8C4B84640D4962A44065C22406
>>> FC51DC8C4B84640A5F78473E75B2240380991C0C4B84640A5F78473E75B2
>>> 240380991C0C4B84640B08F6F2CB85B2240449DA518C5B84640B08F6F2CB
>>> 85B2240449DA518C5B84640087D054BAA5B224050D0A632C5B84640087D0
>>> 54BAA5B224050D0A632C5B84640213C1ECBA65B2240F2CC5C39C5B846402
>>> 13C1ECBA65B2240F2CC5C39C5B846406BDBF78AA35B2240F0C76D43C5B84
>>> 6406BDBF78AA35B2240F0C76D43C5B84640D731EDD8985B2240C676D265C
>>> 5B84640D731EDD8985B2240C676D265C5B84640EFDF4074875B224027DB2
>>> F9DC5B846404443B89A605B2240369D5619C6B84640B521C808865B22404
>>> 765B9A1C5B84640'::geometry
>>> >> as c
>>> >> )
>>> >>
>>> >>
>>> >> SELECT
>>> >> ---- question 1
>>> >> st_overlaps(a,b),
>>> >> st_length(st_intersection(a,b)::geography)::int,
>>> >> ---- question 2
>>> >> st_overlaps(a,c),
>>> >> st_length(st_intersection(a,c)::geography)::int
>>> >>
>>> >> FROM geom
>>> >>
>>> >>
>>> >> return
>>> >>
>>> >> f;42;f;0
>>> >>
>>> >>
>>> >>
>>> >> thanks
>>> >> ft
>>> >>
>>> >>
>>> >>
>>> >>
>>> >>
>>> >>
>>> >>
>>> >> _______________________________________________
>>> >> postgis-users mailing list
>>> >> postgis-users at lists.osgeo.org
>>> >> https://lists.osgeo.org/mailman/listinfo/postgis-users
>>> _______________________________________________
>>> postgis-users mailing list
>>> postgis-users at lists.osgeo.org
>>> https://lists.osgeo.org/mailman/listinfo/postgis-users
>>>
>>
>>
>


-- 
Using Opera's mail client: http://www.opera.com/mail/


More information about the postgis-users mailing list