Get intermediate points over a MKPolyline - iphone

I have a MKPolyline with two points (a start and an ending point), on a MKMapView. Is there any way to get some intermediate points (or coordinates) along with the line, or to split the line in many segments?
I want something like this: http://i.imgur.com/qcbS9.png, where the black endpoints are the starting and ending points of the line and red points are the ones who I want to get. Sorry for the bad drawing, but I made it in an online drawing tool.
Thank you

Are the lines you're interpolating quite short, geographically? If so you can just scale linearly along the line. If you want 10 segments then work out the difference between the start and end point's latitude values and same for the longitude. After your existing start point the next point will be (lat + 0.1*latDif, lng + 0.1*lngDif), then (lat + 0.2*latDif, lng + 0.2*lngDif). All pretty simple so long as you're prepared to assume the coordinates exist in a uniform grid, which they don't really but it might be fine if you're using it on a city-scale map.

Related

Create circle around user inputted point and plot on map with custom latlon points

I have a question about if something is possible using Tableau.
I already have a coastline plotted on one map using custom LatLon coordinates and I would like to take a user inputted Lat and Lon and plot a circle around it with let's say radius 10 and display it on the same map.
I was using this tutorial before to plot a circle:
https://www.crowdanalytix.com/communityBlog/customers-within-n-miles-radius-analysis-using-tableau
But I don't think the same approach can work with user-inputted fields because then it would require restructuring the data..
Okay, a (much smarter LOL) coworker helped me figure this out....
So my goal was to graph distance band (like a distance of 5 miles around a coast) . In order to do this we can use the distance between two coastline points since they are connected by a line, not a curve...From there we can find the perpendicular point a certain distance away and connect those points. Much easier than my circle idea...

Find co-ordinates where LineString intersects a Polygon border in turfjs

Is there a way in Turfjs to determine the co-ordinates at which a LineString intersects with the border of a polygon?
There's a number of ways to find out if a point is within a polygon and a number of ways to find out if a point is on a line and so on, but I can't seem to figure out a way to ask "at what point does this line intersect this polygon's border".
I could enumerate the points in the polygon using a line intersection algorithm to find that point but I was wondering if there's a more "turf" way of doing this.
For context, I've loaded a GPX track and want to estimate the location/time at which the track enters/exits a defined area.
Because a GPX track only records locations at specific intervals it usually the case that pN recorded at time tN is outside the area and pN+1 recorded at time tN+1 is inside the area.
If I can get the point at which line (pN, pN+1) intersects the polygon's border I can estimate the exact time the track crosses into the polygon.
Ultimately, turfjs does not seem to have an API for doing this.
I was able to get the answer I wanted by enumerating the points in the polygon from the GeoJSON object to construct a sequence of line segments and then I used maxogden/geojson-js-utils linesIntersect function to test for intersection points.
I don't see a Turf function that does exactly that, but there is intersect, which finds the area of intersection between two polygons.
You could:
Construct a polygon by joining the line to itself reversed (so ABC becomes ABCBA)
Find the intersection of ABCBA and P, the original polygon using Intersect.
The intersection should be a zero-area polygon that is the part of ABCBA inside P. Somehow compute the length of it (strangely there's no perimeter function).
Subtract that length from the original length of ABC.
Not exactly elegant, true. :)
EDIT
Tried this. Turns out Turf-intersect doesn't return intersections if one of the polygons is zero-area.

SQL Server 2008 R2 large polygons along latitude

Working on the Pacific Ocean, i am dealing with huge polygons covering the whole area. Some of them are quite simple and are defined by 4 points in my shapefile.
However, when i import them into SQL server 2008 r2 as new geographies, due to the shape of the earth, i end up with curved lines while I would like the North and South boundaries to stick to some specific latitudes: for example, the north boundaries should follow the 30N latitude from 120E to 120W.
How can i force my polygons to follow the latitudes? Converting them as geometry could have been an option but since i will need to do some length and area calculations, i need to keep them as geography.
Do i need to add additional vertices along my boundaries to force the polygon to stay on a specific latitude? What should be the interval between each vertex?
Thanks for your help
Sylvain
You have already answered this yourself. Long distances between latitude coordinates will create curved lines to match the Earth's curvature. Therefore if you need to "anchor" them along a specific latitude you will need to manually insert points. As for the interval, there's no right or wrong, a little experimentation here (and considering how "anal" you want to be about it hugging the line) will give you the result you desire. 1 coordinate per degree should do it, might even be a little overkill.
That said, I do question why you would want to anchor them to create a projected "straight" line as this will skew the results of length and area calculations, the bigger the polygon, the bigger the skew.

Jump to arbitrary point on a UIBezierPath

I am developing an app that animates a motion on a UIBezierPath (made of several curves).
In some use cases I need to place an item so it will start moving from some point on the route, and not from its beginning. E.g put item in the middle or 2/3 point of the path. How can I calculate the location of such point?
Thanks!
A Bezier curve is parametric curve a http://en.wikipedia.org/wiki/B%C3%A9zier_curve meaning you have two functions of a parameter T over a range. One function generates the X coordinate, the other generates the Y coordinate. If you know the two functions, just pick a value of T halfway or 2/3rds of the way between the endpoints of the range and plug that into the two functions to get the X & Y coordinates of the desired point.

How to determine if a latitude & longitude is within an ellipse

I have data describing a rotated ellipse (the center of the ellipse in latitude longitude coordinates, the lengths of the major and minor axes in kilometers, and the angle that the ellipse is oriented). I do not know the location of the foci, but assume there is a way to figure them out somehow. I would like to determine if a specific latitude longitude point is within this ellipse. I have found a good way to determine if a point is within an ellipse on a Cartesian grid, but don't know how to deal with latitude longitude points.
Any help would be appreciated.
-Cody O.
The standard way of doing this on a Cartesian plane would be with a ray-casting algorithm. Since you're on a sphere, you will need to use great circle distances to accurately represent the ellipse.
EDIT: The standard ray-casting algorithm will work on your ellipse, but its accuracy depends on a) how small your ellipse is, and b) how close to the equator it is. Keep in mind, you'd have to be aware of special cases like the date line, where it goes from 179 -> 180/-180 -> -179.
Since you already have a way to solve the problem on a cartesian grid, I would just convert your points to UTM coordinates. The points and lengths will all be in meters then and the check should be easy. Lots of matlab code is available to do this conversion from LL to UTM. Like this.
You don't mention how long the axes of the ellipse are in the description. If they are very long (say hundreds of km), this approach may not work for you and you will have to resort to thinking about great circles and so on. You will have to make sure to specify the UTM zone to which you are converting. You want all your points to end up in the same UTM zone or you won't be able to relate the points.
After some more research into my problem and posting in another forum I was able to figure out a solution. My ellipse is relatively small so I assumed it was a true (flat) ellipse. I was able to locate the lat lon of the foci of the ellipse then if the sum of the distances from the point of interest to each focus is less than 2a (the major axis radius), then it is within the ellipse. Thanks for the suggestions though.
-Cody