I have GPS points that show the locations of surface bubbles from a research dive along a transect. Wind, waves, and currents have conspired to add error to these data. I want to create a single best fit line from the points highlighted in blue in the attached picture using ArcGIS 10.3 but I do not know how to do that.
[GIS] Creating best fit line from point data using ArcGIS for Desktop
arcgis-10.3arcgis-desktopgraphregression
Related Solutions
you can follow these steps:
- Generalize line
- Densify using 50m with densify by distance parameter.
- buffer the line with flat option with 10m as distance.
- get the polygon result vertices using Feature vertices tool
If I haven't really understood your question, can you provide a simple drawing to explain the problem clearly.
It looks like what you want is to create a point that is at a polygon corner on the side closest to a line. There are no out of the box solutions in ArcGIS that can do all of this automatically for you. But you can do this with ArcObjects:
Code logic steps:
Begin loop to step through every polygon in your feature class
Select a polygon
Get the XY coordinates of the corners of that polygon. This code looks at the vertices of your polygon and if the angle is > 20 degrees, counts it as a corner.
Create new points using these XY coordinates (use IPoint and IPoint.PutCoords()). If you are dealing with a perfect rectangle/square you will only have 4 points. If it is a complex polygon like some in your picture you may have more.
Loop back through the points you just created and get the two points are closest to any line in your line layer. These are the two corners that are closest to the line layer. They will define which side is the "front" of the house, the side facing the "road". You can either use ESRI's Near(Analysis) for this or this code to do so (IProximityOperator.ReturnDistance() is the method you want).
Get the X and Y coordinates of those two corner points. Use the midpoint formula to get the X and Y coordinates of the midpoint between these two points. Use IPoint.PutCoords() again to create another point. This point will define the "door" of the house.
Get the centroid of your polygon and create a point from that, too
Draw a line between the midpoint you created in step 6 and the centroid you created in step 7
Implement IHitTest on the two corner points that you narrowed down in step 5. You should have the "Left" and "Right" values from your text file loaded into your polygon attribute table. Grab that Left/Right value from your attribute table, then create a case: If the value from your text file is Right, then select the point where IHitTest returns bRightSide as True. This is the point that is to the right of your "door". If the value from your text file is Left, select the point where IHitTest returns bRightSide as False. This is the point that is to the left of your "door". The parameters for IHitTest are as follows: Your query point will be one of the two corner points (not the midpoint from step 6!) and the input geometry is the line you just drew in step 8.
Go back and programatically delete all the points (and the line you just drew) that are not the one you selected in step 9
Go to next polygon and repeat process.
This will give you points that lay on top of the polygon border. If you don't want them on top of the polygon border you can use IConstructPoint to offset them as desired (i.e. you could move the point just to the left or to the right of the midpoint using proportions).
Best Answer
Unfortunately solution by Farid Cher uses regression analysis. It minimises either (X-distance)^2 to line, or (Y-distance)^2, depending on what values were picked for Y axis. It seems that you’d like to minimise distance to line from points.
Complete solution can be found here: https://math.stackexchange.com/questions/839464/how-to-find-a-line-that-minimizes-the-average-squared-perpendicular-distance-fro but it’s to much effort.
Approximate solution can be achieved by using average of XY regression and YX regression lines.
Try this script:
Note, script will work on selection.
On the example shown average distance to Y regression line was 444 m, distance to 'Min line' was 421 m