I am using python. Now I have some coordinates (earth plane coordinates) and I want to draw a convex polygon based on these coordinates. Besides, I need to save the polygon into a GeoJSON format and calculate the polygon area.
I heard that scipy.spatial can do this but I have no idea how to do that, besides, how to extract the polygon coordinates and calculate the area on earth?
Thanks
As far as I know, scipy.spatial does not include the functions you need.
GeoPandas would be suitable for this task. See for instance this example for calculating areas of a polynomial. It also allows to convert between different coordinates system and support output to GeoJSON format.
Related
Is there a way to list all the points that lie on the convex hull (it is a 3d mesh) that is computed using the method compute_convex_hull of Open3D. I want to do further processing on the points that specifically lie on the the mesh that is the output of compute_convex_hull. The point cloud input and the output hull are in 3D space. So, any help on achieving this in Open3D? If not, are there any other geometry processing library that can help me achieve this?
I am interested in having my Shapely polygon understand the crossover from a longitude of 179 degrees to -179 degrees. As can be seen with the plot below, this Polygon is understandably viewed as spanning from -179 to +179. Is there anyway around this (to get it to view it as spanning from +179 to -179 and thus having an area of 2? Thank you!
import geopandas
from shapely.geometry import Polygon
p = Polygon([[179,5],[179,6],[-179,6],[-179,5],[179,5]])
p_gs = geopandas.GeoSeries(p,crs= "EPSG:4326")
p_gs.plot()
I see what you mean.
But a map is not a globe.
(After opening the OSM map in QGIS, etc., keep moving to the right. There is only a blank space.)
epsg 4326 i.e. the longitude and latitude coordinate system ends at 180 on both sides. It represents only 180 from the reference point.
Therefore, to do the work you want, you need to select a coordinate system that can represent the part and then draw again.
Choose a coordinate system that allows for meter-based calculations(area or Euclidean distances must use the TM coordinate system) and the reference point represents the desired area.
After that, it seems to be necessary to draw a picture by changing the longitude and latitude to the coordinates that fit the CRS.
I am looking for a solution to find the percentage area covered by a polygon inside another polygon, from geo coordinates using python.
The polygon can be either fully reside inside the other one or a portion of the second polygon.
Is there a solution to this.
Please advice.
Percentage is just area of intersection over area of the (other) polygon:
area(intersection)/area(polygon2).
Basically any of geometry packages should be able to compute this, as they all support area and intersection functions: I think Geopandas, SymPy, Shapely (and others I missed) should be able to do this. There might be differences in supported formats.
You did not specify what Geo coordinates you use though. I think Geopandas and SymPy support only 2D maps (flat map) - meaning you need to use appropriate projection to get exact result, and Shapely works with spherical Earth model.
When I have some points its position is random as drawn below.
I want to dynamically draw lines with some restrictions.
1) No points in selected region.
2) The triangles are at acute angle.
3) Points are in X/Y (2D) plane.
So points are processed & divided therefore...
Can I find advice about any appropriate math solutions or even libraries?
You will want to look up Delaunay triangulation & Voronoi diagram; you can find implementation of these objects in scipy.interpolate; I think these constructs are what you are looking for.
I have a set of points extracted from an image. I need to join these points to from a smooth curve. After drawing the curve on the image, I need to find the tangent to the curve and represent it on the image. I looked at cv2.approxPolyDP but it already requires a curve??
You can build polyline, if order of points is defined. Then it is possible to simplify this polyline with Douglas-Peucker algorithm (if number of points is too large). Then you can construct some kind of spline interpolation to create smooth curve.
If your question is related to the points being extracted in random order, the tool you need is probably the so called 2D alpha-shape. It is a generalization of the convex hull and will let you trace the "outline" of your set of points, and from there perform interpolation.