The Question: Can ArcGIS SDK for iOS in Objective C find this solution with precision utilizing Lat/Long coordinates for ABCD to find E? if so! HOW?
How do you input for the coordinates for lineAB? This would be two sets of coordinates. I have not dealt with ArcGIS SDK for iOS yet. Can you explain for me?
Actually - you should get back a line when intersecting 2 lines. My first answer above is incorrect, I will remove it for clarity.
Code should look something like this:
<SPAN class="operator token">-</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">void</SPAN><SPAN class="punctuation token">)</SPAN>lineIntersection<SPAN class="punctuation token">{</SPAN> AGSPolyline <SPAN class="operator token">*</SPAN>lineAB <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>AGSPolyline polylineWithPoints<SPAN class="punctuation token">:</SPAN>@<SPAN class="punctuation token">[</SPAN><SPAN class="token function">AGSPointMakeWGS84</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token function">AGSPointMakeWGS84</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">10</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> AGSPolyline <SPAN class="operator token">*</SPAN>lineCD <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>AGSPolyline polylineWithPoints<SPAN class="punctuation token">:</SPAN>@<SPAN class="punctuation token">[</SPAN><SPAN class="token function">AGSPointMakeWGS84</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token function">AGSPointMakeWGS84</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">10</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token function">AGSPointMakeWGS84</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">5</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token function">AGSPointMakeWGS84</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token function">AGSPointMakeWGS84</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">10</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> AGSPolyline <SPAN class="operator token">*</SPAN>lineE <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>AGSPolyline<SPAN class="operator token">*</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN>AGSGeometryEngine intersectionOfGeometry1<SPAN class="punctuation token">:</SPAN>lineAB geometry2<SPAN class="punctuation token">:</SPAN>lineCD<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="token function">NSLog</SPAN><SPAN class="punctuation token">(</SPAN>@<SPAN class="string token">"lineE: %@"</SPAN><SPAN class="punctuation token">,</SPAN> lineE<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Hello,I got NSLog reply of: lineE: AGSPolyline: [], sr: 4326How do I get the lat/long from lineE?
Wouldn't the AGSGeometry returned by the Geometry Engine be a point, not a polyline?
Brett,
Nick Furness pointed out to me that you need to actually union the lines together first to get what you are looking for.
Here is objective-c code to do what you need:
@interface AGSPolyline <SPAN class="punctuation token">(</SPAN>intersects<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">-</SPAN><SPAN class="punctuation token">(</SPAN>NSArray<SPAN class="operator token"><</SPAN>AGSPoint<SPAN class="operator token">*</SPAN><SPAN class="operator token">></SPAN><SPAN class="operator token">*</SPAN><SPAN class="punctuation token">)</SPAN>intersectionWithLine<SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">(</SPAN>AGSPolyline<SPAN class="operator token">*</SPAN><SPAN class="punctuation token">)</SPAN>line2<SPAN class="punctuation token">;</SPAN> @end @implementation AGSPolyline <SPAN class="punctuation token">(</SPAN>intersects<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">-</SPAN><SPAN class="punctuation token">(</SPAN>NSArray<SPAN class="operator token"><</SPAN>AGSPoint<SPAN class="operator token">*</SPAN><SPAN class="operator token">></SPAN><SPAN class="operator token">*</SPAN><SPAN class="punctuation token">)</SPAN>intersectionWithLine<SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">(</SPAN>AGSPolyline<SPAN class="operator token">*</SPAN><SPAN class="punctuation token">)</SPAN>line2<SPAN class="punctuation token">{</SPAN> NSMutableArray <SPAN class="operator token">*</SPAN>points <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>NSMutableArray array<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// first union the lines together</SPAN> AGSPolyline <SPAN class="operator token">*</SPAN>lineUnion <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>AGSPolyline<SPAN class="operator token">*</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN>AGSGeometryEngine unionOfGeometry1<SPAN class="punctuation token">:</SPAN>self geometry2<SPAN class="punctuation token">:</SPAN>line2<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// now get the intersecting line of union'ed line and self</SPAN> AGSPolyline <SPAN class="operator token">*</SPAN>line3 <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>AGSPolyline<SPAN class="operator token">*</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN>AGSGeometryEngine intersectionOfGeometry1<SPAN class="punctuation token">:</SPAN>self geometry2<SPAN class="punctuation token">:</SPAN>lineUnion<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">double</SPAN> tolerance <SPAN class="operator token">=</SPAN> <SPAN class="number token">1e-10</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">for</SPAN> <SPAN class="punctuation token">(</SPAN>AGSPart <SPAN class="operator token">*</SPAN>part in line3<SPAN class="punctuation token">.</SPAN>parts<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">for</SPAN> <SPAN class="punctuation token">(</SPAN>AGSPoint <SPAN class="operator token">*</SPAN>point in part<SPAN class="punctuation token">.</SPAN>points<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">double</SPAN> distance <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>AGSGeometryEngine distanceBetweenGeometry1<SPAN class="punctuation token">:</SPAN>point geometry2<SPAN class="punctuation token">:</SPAN>line2<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// if the point is on the passed-in line then add it to the return value</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>distance <SPAN class="operator token"><</SPAN> tolerance<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN> <SPAN class="punctuation token">[</SPAN>points addObject<SPAN class="punctuation token">:</SPAN>point<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="punctuation token">[</SPAN>points copy<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> @end <SPAN class="operator token">-</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">void</SPAN><SPAN class="punctuation token">)</SPAN>testLineIntersection<SPAN class="punctuation token">{</SPAN> AGSPolyline <SPAN class="operator token">*</SPAN>lineAB <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>AGSPolyline polylineWithPoints<SPAN class="punctuation token">:</SPAN>@<SPAN class="punctuation token">[</SPAN><SPAN class="token function">AGSPointMakeWGS84</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token function">AGSPointMakeWGS84</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">10</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> AGSPolyline <SPAN class="operator token">*</SPAN>lineCD <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>AGSPolyline polylineWithPoints<SPAN class="punctuation token">:</SPAN>@<SPAN class="punctuation token">[</SPAN><SPAN class="token function">AGSPointMakeWGS84</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token function">AGSPointMakeWGS84</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">10</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> NSArray <SPAN class="operator token">*</SPAN>pointsE <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>lineAB intersectionWithLine<SPAN class="punctuation token">:</SPAN>lineCD<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="token function">NSLog</SPAN><SPAN class="punctuation token">(</SPAN>@<SPAN class="string token">"intersection points: %@"</SPAN><SPAN class="punctuation token">,</SPAN> pointsE<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Thanks to Nick Furness for pointing this out. He also provided the swift code, which I converted to objective-c.
Thanks for posting that, Ryan Olson.
For reference, here's a Gist with the Swift code: Runtime Line Intersection Points · GitHub
The Gist also discusses a potential edge-case worth being aware of, depending on how your input data is generated.
Thank you sir I will try as soon as I get time. I currently have 42 warnings from the install of the SDK, trying to work them out..
Input data is generated, by manual input on:
<SPAN class="" style="color: #2b91af; border: 0px;">CGPoint</SPAN><SPAN class="" style="color: #303336; border: 0px;"> p1 </SPAN><SPAN class="" style="color: #303336; border: 0px;">=</SPAN><SPAN class="" style="color: #303336; border: 0px;"> </SPAN><SPAN class="" style="color: #2b91af; border: 0px;">CGPointMake</SPAN><SPAN class="" style="color: #303336; border: 0px;">(</SPAN><SPAN class="" style="color: #7d2727; border: 0px;">32.734444</SPAN><SPAN class="" style="color: #303336; border: 0px;">,</SPAN><SPAN class="" style="color: #303336; border: 0px;"> </SPAN><SPAN class="" style="color: #303336; border: 0px;">-</SPAN><SPAN class="" style="color: #7d2727; border: 0px;">116.577499</SPAN><SPAN class="" style="color: #303336; border: 0px;">);</SPAN><SPAN class="" style="color: #303336; border: 0px;"></SPAN><SPAN class="" style="color: #2b91af; border: 0px;">CGPoint</SPAN><SPAN class="" style="color: #303336; border: 0px;"> p2 </SPAN><SPAN class="" style="color: #303336; border: 0px;">=</SPAN><SPAN class="" style="color: #303336; border: 0px;"> </SPAN><SPAN class="" style="color: #2b91af; border: 0px;">CGPointMake</SPAN><SPAN class="" style="color: #303336; border: 0px;">(</SPAN><SPAN class="" style="color: #7d2727; border: 0px;">32.7337</SPAN><SPAN class="" style="color: #303336; border: 0px;">,</SPAN><SPAN class="" style="color: #303336; border: 0px;"> </SPAN><SPAN class="" style="color: #303336; border: 0px;">-</SPAN><SPAN class="" style="color: #7d2727; border: 0px;">117.008</SPAN><SPAN class="" style="color: #303336; border: 0px;">);</SPAN><SPAN class="" style="color: #303336; border: 0px;"></SPAN><SPAN class="" style="color: #2b91af; border: 0px;">CGPoint</SPAN><SPAN class="" style="color: #303336; border: 0px;"> p3 </SPAN><SPAN class="" style="color: #303336; border: 0px;">=</SPAN><SPAN class="" style="color: #303336; border: 0px;"> </SPAN><SPAN class="" style="color: #2b91af; border: 0px;">CGPointMake</SPAN><SPAN class="" style="color: #303336; border: 0px;">(</SPAN><SPAN class="" style="color: #7d2727; border: 0px;">33.363609</SPAN><SPAN class="" style="color: #303336; border: 0px;">,</SPAN><SPAN class="" style="color: #303336; border: 0px;"> </SPAN><SPAN class="" style="color: #303336; border: 0px;">-</SPAN><SPAN class="" style="color: #7d2727; border: 0px;">116.836388</SPAN><SPAN class="" style="color: #303336; border: 0px;">);</SPAN><SPAN class="" style="color: #303336; border: 0px;"></SPAN><SPAN class="" style="color: #2b91af; border: 0px;">CGPoint</SPAN><SPAN class="" style="color: #303336; border: 0px;"> p4 </SPAN><SPAN class="" style="color: #303336; border: 0px;">=</SPAN><SPAN class="" style="color: #303336; border: 0px;"> </SPAN><SPAN class="" style="color: #2b91af; border: 0px;">CGPointMake</SPAN><SPAN class="" style="color: #303336; border: 0px;">(</SPAN><SPAN class="" style="color: #7d2727; border: 0px;">32.64</SPAN><SPAN class="" style="color: #303336; border: 0px;">,</SPAN><SPAN class="" style="color: #303336; border: 0px;"> </SPAN><SPAN class="" style="color: #303336; border: 0px;">-</SPAN><SPAN class="" style="color: #7d2727; border: 0px;">116.836</SPAN><SPAN class="" style="color: #303336; border: 0px;">);</SPAN>
-(void)lineIntersection{ AGSPolyline *lineAB = [AGSPolyline polylineWithPoints:@[AGSPointMakeWGS84(p1), AGSPointMakeWGS84(p2)]]; AGSPolyline *lineCD = [AGSPolyline polylineWithPoints:@[AGSPointMakeWGS84(p3), AGSPointMakeWGS84(p4)]]; NSArray *pointsE = [lineAB intersectionWithLine:lineCD]; NSLog(@intersection points: %@", pointsE);}
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.