Leaflet Js computing area of GeoJSON multipolygon - leaflet

This is realted to this question:
How to get the area string from a polygon using leaflet.draw
The area calculation works for Polygons, not for multipolygons, any idea on a feature that calculates the area of such GeoJSON Feature?
As a workaround, I can transform the multipolygon into polygons, but it's not an ideal solution.
Many thanks,
VG.

You probably want to use Turf.js for these kind of tasks.

Leaflet.PM supports editing and cutting of MultiPolygons.
Disclaimer: I'm the maintainer.

You can use #turf/area, which can compute area of polygons and multipolygons.

Related

Using leaflet to determine if a line intersects through a polygon

I am trying to work out the best way to determine if a line goes through a polygon, where it is possible that that points on that line do no fall within the polygon as shown in image below.
My data is multiple polygons and I wish to see if a line (lat,long to lat,long) goes through 1 or more of the polygons.
leaflet has a leaflet-pip that does a point in a polygon but I need to test a line... turf.js has lineIntersect but would this work with a line and a polygon (JSON)? Is there something else I can use but haven't found yet?
Just after some advice on the best way or library to achieve this
Thank you.
turf booleanIntersects works nicely.
Example here: https://codesandbox.io/s/ripkk?file=/src/index.js:9634-9641

Using leaflet to determine if a line intersects through a polygon [duplicate]

I am trying to work out the best way to determine if a line goes through a polygon, where it is possible that that points on that line do no fall within the polygon as shown in image below.
My data is multiple polygons and I wish to see if a line (lat,long to lat,long) goes through 1 or more of the polygons.
leaflet has a leaflet-pip that does a point in a polygon but I need to test a line... turf.js has lineIntersect but would this work with a line and a polygon (JSON)? Is there something else I can use but haven't found yet?
Just after some advice on the best way or library to achieve this
Thank you.
turf booleanIntersects works nicely.
Example here: https://codesandbox.io/s/ripkk?file=/src/index.js:9634-9641

Rendering overlapping polygons without holes in multipolygon in Leaflet

Is there a way to render overlapping polygons without holes in multipolygon in Leaflet?
I found Leaflet has an open issue.
codesandbox.io
I am asking because I have a bound polygon that contains inner polygons.
I would need to drag them all together, but it doesn't work in canvas mode. It could work if I can render this as a multipolygon. This is a follow-up question on my previous question.
I'll just copy-paste my response to Leaflet bug #6173 :
I'm reading the OGC's Simple Feature Access specification (again), to remind myself about the formal definitions of Polygons and MultiPolygons. Let me quote page 31:
6.1.14 MultiPolygon
A MultiPolygon is a MultiSurface whose elements are Polygons.
The assertions for MultiPolygons are as follows.
a) The interiors of 2 Polygons that are elements of a MultiPolygon may not intersect.
Heck, it even comes with pretty pictures:
So, MultiPolygons which have overlapping members are not valid MultiPolygons. As such, I think Leaflet has no obligation to handle that invalid case.
See also #3763 (comment) (re: fillRule option for SVG renderer).

Leaflet clustering choropleth regions

I'm fairly new to Leaflet library and I would like to ask if following functionality is somehow already implemented in Leaflet(or maybe in some other library).
I've found the following example which does clustering based on markers on the map and map also contains choropleth areas displayed.
My question is - Is it possible to do clustering based on choropleth data? Like if I have geojson data for some regions and would also have geojson data of subregions for every region. So if I do zooming then those subregions would collapse to big regions or big regions would be divided to small ones?
Big thanks for any advices or links!
No, because clustering algorithms work only on point data.
You might want to just hide the regions and display the "subregions" when zooming in.
If data becomes too dense when zooming out, consider making the union of the polygon geometries to display that instead. A naïve algorithm would be search for the smallest polygon, then search for the smallest neighboring polygon, replace them by their union, repeat. Stop the algorithm when the smallest polygon is larger than a given threshold.

Geoserver - How do I draw a geodesic line that represents the great circle between two points

I'm using Geoserver version 2.1.1, Postgres 9 and PostGIS 2.0
What I want to achieve should (i think!) be quite straight forward. I want to render on a map a line that represents the Great Circle between two cities on the earths surface.
My database contains the city locations represented as geography points defined as latitude and lonfitude pairs.
I have a layer defining an SQL view in Geoserver which retrieves a linestring (st_makeline) from the two coordinates for the specified cities. I'm having to type cast the geographies to geometries to get this to work.
But when I draw the returned line on a map what i get is a straight line and not the curved line that I am expecting.
Can someone tell me how I should be going about this?
Thanks!
PostGIS offers mainly "constructors" of the base geometries point, linestring and polygone, like ST_MakeLine.
And what yo uwant to do depends also on the coordinate reference system you use when displaying your map layers.
Here's a nice trick about great circles or parts of:
https://gis.stackexchange.com/questions/5204/curved-point-to-point-route-maps
Yours, Stefan
P.S. Here's some related stuff:
Drawing circles on a sphere
And here's some math:
http://www.mathworks.ch/matlabcentral/newsreader/view_thread/277881
I had a similar problem in cartodb (which also uses PostGIS); I wanted to get curved lines from straight lines. Maybe this post can help.