How to create a polygon from a central point with GeoDjango - django

I want to create a polygon from a point and a radius.
For example, I want to be able to give a point (latitude, longitude) with a given radius (ex. 10km) and calculate the circle and store it as polygon.
The goal is to be able to query my application with points and ask it if the given point is within a given radius of another point.
Maybe I'm doing it wrong, if there is a simplier way to achieve this I'd be glad to ear about it.
Thanks

I do not see why you need a circle. given two points you can use geopy to calculate distances : http://code.google.com/p/geopy/wiki/GettingStarted#Calculating_distances
an almost identical question: Django model property geo distance

Related

PCL: Sphere Filter for Point Cloud

My goal is to remove all points from a point cloud that lie within a certain radius (from the origin).
I've discovered the pcl::CropBox and pcl::CropHull filters, but the former crops a box (obviously...) and the latter needs hull indices.
I guess I could write my own filter by calculating the distance for each point and comparing it to a threshold. But maybe there is already an implementation of this that I'm not noticing?

GeoDjango - distance between a point and a queryset of multipolygons

I'm familiar with Django, but new to GeoDjango and PostGIS.
I have a problem where I want to find the nearest MuliPolygon to a point. The point can be outside or within the MultiPolygon. Nearest means the nearest boundary point.
I know that I can calculate the distance between two points with from django.contrib.gis.db.models.functions import Distance - but I don't want to use the centroid because it is possible the border of a MultiPolygon is closer to one point than the centroid of another.
I have a model Land with a field surface_area which is a MultiPolygon. I have a point object created with from django.contrib.gis.geos import Point. This is the data I'm using to try and build a query.
Any help with best practices would be appreciated.
GeoDjango's distance lookups utilize the corresponding database's distance function.
Since you are using PostgreSQL with PostGIS the corresponding ST_Distance method:
For geometry types returns the minimum 2D Cartesian (planar) distance between two geometries, in projected units (spatial ref units).
Therefore you can use the distance lookups for your calculations.
If you want to implement it a bit differently (for example using the bounding boxes of the polygons) you can refer to this Q&A: How do I get the k nearest neighbors for geodjango?

Removing Points C++

I have N number of points (x_N,y_N,z_N) in a point cloud. The point cloud forms the shape of a spherical shaped object. My problem is that I have points in my cloud that stick out noticeably along the z-axis (This is due to pin object inserted in my object during a scan). I would like to remove these points.
One approach I have taken is finding the change in slope for a set of points in my cloud compared to the immediate next set of points. (for example, I take my first 10 points, compute the change in slope and compare it to the change in slope for the next ten points). But this is not working so well. Any suggestions?
Any help would be greatly appreciated. Any confusion towards my problem, just let me know.
If it's sure to be a sphere like object and points are equally spread (no side has more points than other side), take the average X, Y and Z of all points.
This will be next to the center of the sphere. If that pin is not very thick or very long (if it have few points compared to the total), you can assume this as the center.
Then, measure the distance of each point to the center.
Take off those having distances higher than the average distance.
If you know the radii of the sphere and its center, simply calculate the distance of each point to the center and compare to the radii.
I have an observation and a corresponding suggestion:
First, the observation: You appear to be building a custom solution for a one-off case. This will not work when you scan a different object (with the pin sticking out again).
Now, the suggestion: Use something like meshlab, where you can load up a point cloud, select points and delete them.
Of course, if you're ken on writing code to solve this problem, then this is not helpful.
Find the highest point in z, which is 100% sure to be a pin or apart of one.
Set point to be center of sphere and remove all points within chosen radius
Iterate twice more for other pins

Fit a circle or a spline into a bunch of 3D Points

I have some 3D Points that roughly, but clearly form a segment of a circle. I now have to determine the circle that fits best all the points. I think there has to be some sort of least squares best fit but I cant figure out how to start.
The points are sorted the way they would be situated on the circle. I also have an estimated curvature at each point.
I need the radius and the plane of the circle.
I have to work in c/c++ or use an extern script.
You could use a Principal Component Analysis (PCA) to map your coordinates from three dimensions down to two dimensions.
Compute the PCA and project your data onto the first to principal components. You can then use any 2D algorithm to find the centre of the circle and its radius. Once these have been found/fitted, you can project the centre back into 3D coordinates.
Since your data is noisy, there will still be some data in the third dimension you squeezed out, but bear in mind that the PCA chooses this dimension such as to minimize the amount of data lost, i.e. by maximizing the amount of data that is represented in the first two components, so you should be safe.
A good algorithm for such data fitting is RANSAC (Random sample consensus). You can find a good description in the link so this is just a short outline of the important parts:
In your special case the model would be the 3D circle. To build this up pick three random non-colinear points from your set, compute the hyperplane they are embedded in (cross product), project the random points to the plane and then apply the usual 2D circle fitting. With this you get the circle center, radius and the hyperplane equation. Now it's easy to check the support by each of the remaining points. The support may be expressed as the distance from the circle that consists of two parts: The orthogonal distance from the plane and the distance from the circle boundary inside the plane.
Edit:
The reason because i would prefer RANSAC over ordinary Least-Squares(LS) is its superior stability in the case of heavy outliers. The following image is showing an example comparision of LS vs. RANSAC. While the ideal model line is created by RANSAC the dashed line is created by LS.
The arguably easiest algorithm is called Least-Square Curve Fitting.
You may want to check the math,
or look at similar questions, such as polynomial least squares for image curve fitting
However I'd rather use a library for doing it.

Is it possible to make point vector reycast in pcl?

I have a 3d points world. I have point in it a [x,y,z] and direction (azimuthal angle θ, and polar angle ) I want to get point b [x2,y2,z2] where my ray (sent from my point a into direction) would stop. (only from one point and only for one direction). How to do such thing in pcl, is it possible (I see a ray caster class but it seems to work on whole world not point to point)?
I think that the OctreePointCloudSearch class might help you a little bit more. Have a quick look at the OctreePointCloudSearch::getIntersectedVoxelIndices method: once your point cloud is organized in an octree, it allows you to specify the origin and a direction for the ray to be used for raycasting. In your case, the origin would be the point a and the direction would be obtained from the azimuthal and polar angles (see this)
The function returns the indices to the point within the intersected voxels.
If you google for that class name you can easily find a good number of working examples (this example casts a ray from each point of the cloud toward the camera and checks for occlusions).