PostGIS and coordinates, determinate if a point is inside a polygon/multipolygon (kml) - sql

My goal is to determinate if a point (coordinate) in Input is inside the polygon (both the point and polygon/multipolygon are geographic objects from postGIS). Now my query always return false.
Basically this always returns false even if the point is inside the polygon:
select st_contains(st_geomfromtext('POINT(42.17591110412206 13.716918686169493)',4326),st_geomfromkml('<Polygon><outerBoundaryIs><LinearRing><coordinates>13.722101,42.177614,0 13.72....... </Polygon>')
);
i truncated the kml of course, anyway the format is (lat,lng,0), also on the point i used 4326 and i'm not sure if the value is correct. Also i tried both
Point(LAT,LNG) and Point(LNG,LAT)
Could anyone help me? I'm really out of ideas, surely there is something wrong on my query.

Actually, regarding to official documentation (https://postgis.net/docs/ST_Contains.html):
boolean ST_Contains(geometry geomA, geometry geomB);
Returns TRUE if geometry B is completely inside geometry A.
A point cannot contain polygon ;)

Related

converting Json coordinate into CLLocationCoordinate2D

I have a service returning geographies (points and polygons) the object return as strings for example:
"POINT (51.38494009999999 -0.3514684)"
I can do string manipulations to extract the two values but was wondering if there is a better way to convert that into CLLocationCoordinate2D.
mainly because of the polygons, inserting point by point doesn't seem like the correct solution.
If you want a more appropriate structure to represent a polygon, you could use the MKPolygon class from MapKit. It accepts an array of CLLocationCoordinate2D points as it's initialiser. Using this class may be handy if you are planning to interact with MapKit in your application. Otherwise, it is probably unnecessary to do so - a custom class will likely be the desired container then.
You are seeing well-known text, which was produced by ST_AsText. If you actually were expecting JSON and you are able to modify the server-side query, use ST_AsGeoJSON to instead return:
{"type":"Point","coordinates":[51.3849401,-0.3514684]}
If you have only point data, also consider returning the double precision data, ST_X for longitude and ST_Y for latitude. The last suggestion of course does not require any parsing of text results, but does not work on linestrings or polygons.

Semantic mediawiki - Set propery to range of values

I'm trying to set a specific property to a non exact value, for example say that I want to define the height of a pine tree to usually between 3-80 m (according to wikipedia). Then I would like to set something like [[Has height::3-80]] (of course this doesn't work) and defining the unit to meters with "custom units". Then I would like to be able to query for example "trees that can reach the height of 70 meters" and the pine tree would be included. I've been searching and trying different angles for hours now and I can't figure it out. Tried with #set_recurring_event but that seems to be only for dates/time. Also understood how to set multiple values for a property with #arraymap but this doesn't seem to help me here. Really would appreciate help with this (it's probably very easy and right in front of me) Thx! COG
There's no such things. But you able to create template, with parameters you want. The you just use code kinda {{range|min|max|units}}. For example your range of heights looks like {{range|3|80|m}}.

How to check if two given b2Body objects are touching?

I know how to check for collisions in the update loop - but I'm in a position where I need to see if two bodies are touching or overlapping in box2D. I have pointers to these objects and I don't want to check while moving through update.
I am still learning Box2D so apologies if this is a dumb question. I have tried to solve this for an hour or so now but I'm not having any luck.
It looks like you can do this using b2TestOverlap or maybe b2CollideCircles (since the objects are b2CircleShapes). If either of these is the correct strategy can you get the shape from a given body, and what should I use as the transform values? If these aren't the way to go, how can I check if two given b2Body objects are overlapping or touching.
UPDATE: Here's the code that I got thanks to LearnCocos2D:
-(BOOL)isTouchingCentre:(b2Body*)bodyToTest{
//body is a b2Body object
bool overlap = b2TestOverlap(body->GetFixtureList()->GetShape(), bodyToTest->GetFixtureList()->GetShape(), body->GetTransform(), bodyToTest->GetTransform());
return overlap;
}
Not sure about the details of b2TestOverlap but I would give it a try. You can get the necessary info from the bodies, assuming they only have one shape:
body->GetTransform();
body->GetFixtureList()->GetShape();

Check if a Point is inside a line2D

I didn't find any method on java api to do this... there is one like : line.contains(point).. but it says that line2d doesn't have any area so it will return always false..
Any idea ?
Compare point by point and see if the cursor matches it.
You can do the search using the for each loop described here.
You should compute the distance from the point to the line, and if it is sufficiently small, then consider the point being on the line.
Google "distance point to line" or "distance point to segment".

How do I get the "reverse" tangent in objective-c?

I know that tan(angle) gets me the tangent. But how do I do the "reverse tangent" so that I can get the angle given the length of both sides of the right triangle?
I'm assuming there is a method for this in math.h?
As others have mentioned, atan() is what you're looking for. Generally, the operation is referred to as "inverse tangent" or "arc tangent", not "reverse tangent". The name "atan" comes from "arc tangent". There's also an atan2() function which takes both the X and the Y coordinates as separate paramters and will give you an angle relative to the 0 mark whereas atan() will leave figuring out the quadrant as an exercise for the developer. Beware, however, that the atan2() function on certain older MS environments (or maybe visual studio libraries?) doesn't work quite right...
There should be an atan() function.
For example: http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.7.html
use atan()