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

closed as unclear what you're asking by Vince, John Powell, BradHards, Mapperz Jun 15 '15 at 13:38

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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
    1) 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
    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 5:28
2

I believe this is what you have: a line and a disjoint point

enter image description here

First step you must do is to close the linestring but it is still a linestring and point is disjoint. All points which are not on the line are disjoint.

enter image description here

You must go on and convert the linearring into a polygon. Polygon does have a two-dimensional interior (area).

enter image description here

And only then you can get an answer to the question "Does a point locate inside a polygon which outer ring is is created by closing a linestring so that its end point is connected to its start point.

Not the answer you're looking for? Browse other questions tagged or ask your own question.