Check if point is inside a polygon with a buffer - georuby

I have a geojson and a point (lat,lon). I need to figure out if the point is in the area defined by geojson. But the constraint is relaxed i.e. if the point is inside or within say 0.5 miles from the outer edge of geojson, the point can be considered to be in the area.
Is there a way to do this using georuby?

Related

How to calculate minimum distance between point and line in 3D space

I need to calculate the minimum distance between a 3D point (latitude, longitude, elevation) and a line (defined as two points).
The elevation is not necessary on the ground, I need to consider flying objects.
I only found an article that explains how to do that on a generic space but my points are defined with lat/lon/altitude(meters).
Thank you for pointing in the right direction, in my case I need to do that in Javascript but couldn't find any library that takes into consideration the altitude.
Point-Line Distance--3-Dimensional
If you want to compare a 3d point to a 2d line, I suppose you mean a "line" on our earth, at elevation 0. Take a look at st_distance in postgis.
If I understand you correctly, that'll give you what you want.
https://postgis.net/docs/ST_Distance.html

Find Inner most Polygon using actual Area from array of nested Polygon

I have Array of GMSPath and have Coordinate. I want to find out Path in which this Coordinate falls. I am able to find out total polygons in which this location falls. (Using this https://stackoverflow.com/a/38826411/2225439) Everything is working fine up to this step.
The Actual issue comes when One closed GMSPath overlap with another Closed GMSPath and Coordinate is in overlapped area. As per my requirement, I have to get only one GMSPath out of these two and which have the smaller area than another.
Please refer Image for better understanding.
You can find out the area of GMSPolygon by using following method from Google Maps iOS SDK, GMSGeometryArea(), it provides area of given polygon. Now you have area, so you can compare different polygons and find innermost area.
double GMSGeometryArea(GMSPath *path);
As per description provided by google
Returns the area of a geodesic polygon defined by |path| on Earth.
The "inside" of the polygon is defined as not containing the South pole.
If |path| is not closed, it is implicitly treated as a closed path nevertheless and the result is the same.
All coordinates of the path must be valid.
If any segment of the path is a pair of antipodal points, the result is undefined -- because two antipodal points do not form a unique great circle segment on the sphere.
The polygon must be simple (not self-overlapping) and may be concave.

Recreate the 3D outlines of a City street in iOS SceneKit with OSM XML data

What is best strategy to recreate part of a street in iOS SceneKit using .osm XML data?
Please assume part of a street is offered in the OSM XML data and contains the necessary geopoints with latitude and longitude denoting the Nodes to describe the paths/footprints of 6 buildings (i.e. ground floor plans that line the side of a street).
Specifically, what's the best strategy to convert latitude and longitude Nodes in order to locate these building footprints/polygons on the ground floor in a scene within SceneKit iOS? (i.e. running through position 0,0,0)? Thank you.
Very roughly and briefly, based on my own experience with 3D map rendering:
Transform the XML data from lat/long to appropriate coordinates for a 2D map (that is, project it to a plane using a map projection, then apply a 2D affine transform to get it into screen pixel coordinates). Create a 2D map that's wider and taller than the actual screen, because of what's going to happen in step 2:
Using a 3D coordinate system with your map vertical (i.e., set all the Z coordinates to zero), rotate the map so that it reclines at an appropriate shallow angle, as if you're in an aeroplane looking down on it; the angle might be 30 degrees from horizontal. To rotate the map you'll need to create a 3D rotation matrix. The axis of rotation will be the X axis: that is, the horizontal line that is the bottom border of your 2D map. The rotation is exactly the same as what happens when you rotate your laptop screen away from you.
Supply the new 3D coordinates to your rendering system. I haven't used SceneKit but I had a quick look at the documentation and you can use any coordinate system you like, so you will be able to use one that is convenient for the process I have just described: something that uses units the size of a screen pixel at the viewing plane, with Y going upwards, X going right, and Z going away from the viewer.
One final caveat: if you want to add extrusions giving a rough approximation of the 3D building shapes (such data is available in OSM for some areas) note that my scheme requires the tops of buildings, and indeed anything above ground level, to have negative Z coordinates.
Pretty simple. First, convert Your CLLocationCoordinate2D to a MKMapPoint, which is exactly the same as a CGRect. Second, scale down the MKMapPoint by some arbitrary number so it fits in with how you want it on your scene graph, let's say by 200. Since scenekit's coordinate system is centered at (0,0), you'll need to make sure your location is correct. Then just create your scnvector3's with the x/y of he MKMapPoint, and you will be locked to coordinates.

Calculate points for borders inside and outside of a polygon

In my code I get some set of points that define a simple polygon. I need to draw the polygon itself, as well as a border inside and outside of it
If it was a rectangle, I could simply use CGRectInset() on iOS. However, it isn't a rectangle.
So I need an algorithm that provides me the inner and outer borders from a simple polygon.
Check out CGPathCreateCopyByStrokingPath.

Given a set of points to define a shape, how can I contract this shape like Photoshop's Selection>Contract

I have a set of points to define a shape. These points are in order and essentially are my "selection".
I want to be able to contract this selection by an arbitrary amount to get a smaller version of my original shape.
In a basic example with a triangle, the points are simply moved along their normal which is defined by the points to the left and the right of the points in question.
Eventually all 3 points will meet and form one point but until that point they will make a smaller and smaller triangle.
For more complex shapes, when moving the individual points inward, they may pass through the outer edge of the shape resulting in weird artifacts. Obviously I'll need to cull these points and remove them from the array.
Any help in exactly how I can do that would be greatly appreciated.
Thanks!
This is just an idea but couldn't you find the center of mass of the object, create a vector from the center to each point, and move each point along this vector?
To find the center of mass would of course involve averaging each x and y coordinate. Getting a vector is as simple a subtracting the point in question with the center point. Normalizing and scaling are common vector operations that can be found with the Google.
EDIT
Another way to interpret what you're asking is you want to erode your collection of points. As in morphology erosion. This is typically applied to binary images but you can slightly modify the concept to work with a collection of points. Essentially, you need to write a function that, given a point, will return true (black) or false (white) depending on if that point is inside or outside the shape defined by your points. You'd have to look up how to do that for shapes that aren't always concave (it's harder but not impossible).
Now, obviously, every single one of your actual points will return false because they're all on the border (by definition). However, you now have a matrix of points around your point of interest that define where is "inside" and where is "outside". Average all of the "inside" points and move your actual point along the vector between itself and towards this average. You could play with different erosion kernels to see what works best.
You could even work with a kernel with floating point weights instead of either/or values which will affect your average calculation proportional to their weights. With this, you could approximate a circular kernel with a low number of points. Try the simpler method first.
Find the selection center (as suggested by colithium)
Map the selection points to the coordinate system with the selection center at (0,0). For example, if the selection center is at (150,150), and a given selection point is at (125,75), the mapped position of the point becomes (-25,-75).
Scale the mapped points (multiply X and Y by something in the range of 0.0..1.0)
Remap the points back to the original coordinate system
Only simple maths required, no need to muck about normalizing vectors.

Resources