At the moment I am trying to figure out a nice way to split up a polygon that has multiple points inside (in some cases more than 10k) into smaller ones that will have 100 points each (the max number of points within a small polygon will be dynamic, provided by the user, in this example I am using 100).
Please note that the 100 is not written in stone but should be respected (ex 95-105 points should be ok as when we try to balance things, sometimes we can not achieve perfect balance!)
Is there any algorithm that could help me achieve the above request?
The language I am using is javascript and so far I've been using turf.js and my data is in geoJSON format.
I am adding an image to highlight my goal:
In the image you can see that I already have a centroid point of my polygon (I used this point to make a voronoi diagram already and inside this polygon I have multiple point-features.
My goal is to split this polygon to smaller polygons that will hold only 100 points inside them.
(hope that clarifies my goal further)
Related
I have some geoJSON polygons that I render via layers on top of my map. Depending on the shape itself and the zoom level, sometimes the rendered shapes are too small and it doesn't make sense to even show them.
Is there a way to hide shapes that have rendered area less than some number?
So, as Babis.amas suggested, first I calculate the area of the feature with help of turf.area. It gives the value in square meters. Then I convert this value to pixels using the function mentioned here. And then it really depends on the shape type I'm dealing with. If the shape considered to be too small to be rendered, I just don't add it to the layer data feature collection.
I want to get a "sub-Polyline" of a given polyline that is determined by a certain start and end point (in meters).
For example I have a polyline that is 500 meters (build using 30 coordinates (not seperated in same spaces)) and I want to color the line between meter 200 and 300 in a different color. Is it possible using Leaflet functions?
Take a look at the LineStringSelect plugin here: https://github.com/w8r/L.Control.LineStringSelect
With the demo (click in 2 different locations on the polyline):
https://w8r.github.io/L.Control.LineStringSelect
So basically you are asking "If I have a polyline and a distance value, what is the point along the polyline with the desired length-distance to the line's starting point"?
This algorithm has been covered a multitude of times, e.g.:
http://www.postgis.org/docs/ST_Line_Interpolate_Point.html, http://www.postgis.org/docs/ST_Line_Substring.html
http://turfjs.org/docs/#along
https://github.com/IvanSanchez/Leaflet.Polyline.SnakeAnim
The algorithm is always the same: divide the polyline/linestring into segments, measure length of each segment, locate the point, apply direct interpolation in the segment that the point is in.
Keep in mind that geometry in a 2D cartesian plane is different than geometry in the surface of a geoid, particularly when it comes to measuring distances. Do a bit of research on GeographicLib and its methods for manipulating geodesic lines.
To your question «Is it possible using Leaflet functions?», the answer is «no, Leaflet does not implement this algorithm». The easiest way for you should be to read the source code of the mentioned Leaflet plugins in the answers, or use the along() method from the Turf library.
I am working on a data set of coordinate points(many dots in area) either (x,y) or (lat,lon) which fall into multiple categories. What I am trying to do is get polygons of areas from those points which are called concave or non-convex as far as I know, but also those polygons have to be next to each other with no gaps between them.
These are the initial points(example)
This is the approximate result I am aiming for
Real life example would be European geopolitical map, if you had all of the addresses of all countries and wanted to get area of each country as a polygon and end up with a map.
I have come across many questions related to getting polygons from set of points, but were unable to use it in my scenario. If you need any more information please let me know. Thank you for your help.
You could use a Voronoi tesselation of the input space. Instead of having point you have sets of points though. Basically, you take each point in space, and look at the closest point to it. It then gets the same "class" as that point. For smoother outputs you could look at a k majority out of N nearest points. It would mean working with a bitmap image rather than 2D coordinates, but you'd get something workable. You could then use simpler image manipulation tricks (edge detection, binary set operations etc to get just the edges, and then perhaps superimpose those on the image).
As an alternative, you could run a convex hull algorithm on each data set, and then try to fix the overlap areas.
I got some thousand points containing weights.
Many of those points have (more or less) the same coordinate and I want to visualize those points on a leaflet map using absolute coloring of the map. (Same coloring for a point at every zoom level)
I tried using leaflet.heat but it seems to be adding up the values (resulting in everything colored red) and does relative rendering.
It would be ideal if it would use the average or maximum of the provided weights for rendering a heatmap.
Anyone has an idea how this could be done quickly?
An approach would be to use Leaflet-MarkerCluster, use a custom cluster symbolizer, and symbolize each cluster with the symbol corresponding to the point with the highest value of the property.
Another approach would be to use Turf.js to hexbin the data in the client and apply the highest value to the hex.
Another approach would be to use a Voronoi tesselation, and symbolize each area of the tesselation with the desired value, optionally clipping the symbols to prevent symbolizing large empty areas.
What is the neatest (code design) and most per-formant way of getting an array of points for an arc (polyline), for the purpose of animating using Cesium's timer/clock.
Variable inputs include (start/end location), height (highest point) from earth's surface and number of points for drawing.
I'm currently using a polyline collection, so the answer should describe how to generate the points for existing polylines or convert to a different approach.
I would also need the arc (color) to fadeIn or fadeOut to opacity 0.
Multiple arcs may be added or removed from the collection per second. Each arc will have different start and end points
The start and end location should have height 0 (touching the earth).
(For Cesium version b26)
Just to be sure I understand your question, you have a bunch of polylines on a map and you want to get a bunch of data points along the line for use in animating the something along the path. I'll also assume you want geodesic lines/arcs for the polylines rather than the straight lines that are normally drawn on Mercator maps as geodesic lines actually follow the spatially accurate path of the polyline i.e. the same path a plane would take. If this is the case then take a look at this blog post: http://alastaira.wordpress.com/2011/06/27/geodesics-on-bing-maps-v7/ This post describes how to calculate data points along the geodesic path of a polyline.
CesiumJS includes several spline functions that can be used. One of the easier ones to use that an accomplish what you want with just three points is the Catmull-Rom Spline:
http://cesiumjs.org/Cesium/Build/Documentation/CatmullRomSpline.html
You will need to produce a middle point. To do this you can take a mean of the lat/lon coordinates and add a large height. Because of the spline used and the low number of points, it does end up looking a little egg shaped. The benefit to this is that you can ask the spline object for an arbitrary number of points, so the arc can be as smooth as you want. Just don't forget to add the first and last points to the array returned by the spline as those are omitted.
There are other types of splines, but I found the Catmull-Rom spline the easiest to use. You can search the CesiumJS documentation for some of the other included splines.
I've been looking into the same thing (minus the time aspect) and I found Cesium.EllipsoidGeodesic(start, end, ellipsoid), which allows you to get points at fractions of the path. It seems to me that you can choose the fraction based on the distance and calculate regular points using the result.
https://cesiumjs.org/Cesium/Build/Documentation/EllipsoidGeodesic.html
I haven't tried it yet, but it's on my list of things to do.