0

I have a table with spatial data. This table contains a single record which is a unclosed linestring.

I calculated the Centroid of this geometry using query

SELECT ST_AsText(ST_Centroid("geom")) FROM "public"."ha_ground"

I got the output "POINT(73.8180699704927 18.6281375643436)"

My aim is to check if this point is inside the unclosed linestring

I used the following query

SELECT ST_Contains("geom",ST_GeomFromText('POINT(73.8180699704927 18.6281375643436)', 4326)) FROM "public"."ha_ground"

As We know Centroid of this geometry is inside the unclosed linestring. But, This query returns false instead of true.

What is the possible reason for this.

And what is the solution to check if point is inside unclosed linestring

  • 2
    Can you not close the linestring and create a polygon from it -- which should then return something from contains? – John Powell Jun 13 '15 at 12:53
  • I had also tried doing it using ST_Buffer(ST_GeomFromText(ST_AsText("geom")), 5,'join=mitre mitre_limit=8.0') which gives polygon form of the geometry. But, it still not works. – Rishabh Kalkundri Jun 13 '15 at 12:59
  • 2
  • Please edit the question to add details 2) The "inside" of a line is "on" the line but not at an endpoint.
  • – Vince Jun 13 '15 at 13:08
  • 3
  • The ST_Centroid function is documented as not being restricted to the interior of the shape -- This refutes your assertion.
  • – Vince Jun 13 '15 at 13:17
  • Ok but, I opened the geometry in QGIS and took a sample of latitude and longitude inside the geometry. But for that sample also its output is false. – Rishabh Kalkundri Jun 14 '15 at 05:28
  • Believe @John Barça and connect first end point to start point and build a polygon. – user30184 Jun 14 '15 at 10:54
  • Consider also http://gis.stackexchange.com/questions/76498/how-is-st-pointonsurface-calculated/76563#76563 in case your centroid is outside a convex polygon. – Martin F Jun 16 '15 at 15:45