Locating closest points

1265
10
05-22-2014 03:59 AM
HaiderAli
New Contributor
I have a point on line let say x,y and a list of points i want to find out the points closest to the point x,y at both ends for example




------------------------------ x1,y1
p1------------------------------|----------------------------------p2

and a list of point(p2,p3,p4,p5.......) now i want to find the closest two points


------------------------- p5-----x1,y1----p6
p1-----------------------|-------|---------|----------------------------------p2


is there any functioality available in arcobject that can perform this operation?
0 Kudos
10 Replies
RichardFairhurst
MVP Honored Contributor
I have a point on line let say x,y and a list of points i want to find out the points closest to the point x,y at both ends for example  




------------------------------ x1,y1 
p1------------------------------|----------------------------------p2 

and a list of point(p2,p3,p4,p5.......) now i want to find the closest two points 


------------------------- p5  -----x1,y1  ----p6 
p1-----------------------|-------|---------|----------------------------------p2 


is there any functioality available in arcobject that can perform this operation?


Use linear referencing. Locate Features Along Route to create an event table of the points on the line. Then you can find the measure of the point and select Min and Max of the points in the measure ranges above and below that measure or read the points in ascending and descending sorted order on the RouteID and measures.
0 Kudos
HaiderAli
New Contributor
for example i have this

Polyline poly = new Polyline();

Multipoint mp = new Multipoint();



can you tell me which classes to use?
0 Kudos
RichardFairhurst
MVP Honored Contributor
for example i have this

Polyline poly = new Polyline();

Multipoint mp = new Multipoint();



can you tell me which classes to use?


?  Multipoints should not be used with this problem, just regular points.  Don't you already have a line and point feature class to work with?  This code question is too vague and out of context and does not relate to your previous post as far as I can see.

Use a geoprocessing operation to use the Linear Referencing tools.  If you are building new polylines create them with M values.  Once you have a set of regular point events with M values you could convert them to a Multipoint with M values.

Anyway, look at Linear Referencing to help solve questions about the order of positions or segments along a preexisting line.
0 Kudos
HaiderAli
New Contributor
this was just wriiten as an expample that i have these two polyline and points list jsut was asking about an example.
i think this example is good enough http://help.arcgis.com/en/sdk/10.0/vba_desktop/conceptualhelp/index.html#//0001000000q5000000
0 Kudos
RichardFairhurst
MVP Honored Contributor
this was just wriiten as an expample that i have these two polyline and points list jsut was asking about an example.
i think this example is good enough http://help.arcgis.com/en/sdk/10.0/vba_desktop/conceptualhelp/index.html#//0001000000q5000000


I agree that the example you found can be applied to the problem.  I would probably use the Locate Features Along Route tool instead, because it is more flexible and optimized than that code example, unless you really need to tweak the process at a low level.  Whatever approach you use to create your point event table, once you have it then sorted cursors and standard SQL should be able to solve the problem and you will have data that can tell you the relative distance along the line between any set of points on the line you want to work with.

Since my suggestion has put you on the right track please consider up voting any helpful posts.  Look at my signature line for more info.
0 Kudos
HaiderAli
New Contributor
If u can post a link of an example it would be useful and I should have mentioned it earlier that I am creating soe
0 Kudos
RichardFairhurst
MVP Honored Contributor
If u can post a link of an example it would be useful and I should have mentioned it earlier that I am creating soe


I have no link I can think of that clearly relates to your problem.  It would probably have to be pieced together from many code snippets.  I have no real idea how comfortable you are with adapting sample code to your specific problem, so I don't know what level of examples to direct you to.  For example, can I assume you are familiar with using cursors or not?

If you mean you want an example of running a geoprocessing tool in .Net you can look at this link.  The example you came up with also could create the event table on the fly with very little modification.  If this tool does not require real time data from newly created or edited features, you could just run the Locate Features Along Routes tool outside of your code and consume the table with an ICursor process.

I have only developed Addins with .Net.  I have no idea what is involved in developing an soe.  You will have to look to others for any help specific to soe development.
0 Kudos
HaiderAli
New Contributor
I have no link I can think of that clearly relates to your problem.  It would probably have to be pieced together from many code snippets.  I have no real idea how comfortable you are with adapting sample code to your specific problem, so I don't know what level of examples to direct you to.  For example, can I assume you are familiar with using cursors or not?

If you mean you want an example of running a geoprocessing tool in .Net you can look at this link.  The example you came up with also could create the event table on the fly with very little modification.  If this tool does not require real time data from newly created or edited features, you could just run the Locate Features Along Routes tool outside of your code and consume the table with an ICursor process.

I have only developed Addins with .Net.  I have no idea what is involved in developing an soe.  You will have to look to others for any help specific to soe development.


IS is pooible that M values can be negative?
0 Kudos
RichardFairhurst
MVP Honored Contributor
IS is pooible that M values can be negative?


Yes.  However, if you used the Create Routes tool then negative M values is not likely to happen unless you are using very complex line inputs with many self intersections and branches.  Lines have to be simplified if that is the case for your problem to use LR.  Otherwise you would need to use Network Analyst to trace meaningful paths.  Your example made me have no reason to think that you were using complex, branching lines in your analysis and such lines will cause you severe problems, since such lines have no single way of organizing them that yields a consistent result for your problem.

A single continuous line that never self intersects or branches, like the one in your example, should always have positive measures if it was created by the Create Route tool, even if it curves and meanders in a variety of directions.  That is the only kind of line you can really use to solve your problem.

You have control over M values and can recalculate them if for some reason you don't like the way they were assigned, but it is very difficult to do if you are working with complex branching paths.
0 Kudos