Adding a lot of georeferenced images makes mapbox very slow - mapbox

I have a map for which I have to add a lot of (about 150) images on a map.
I've seen their example Add a raster image to a map layer, which shows that you need to add a source with coordinates, then add a layer to display your image on the map.
I made a loop to add all my images, but it makes my map really laggy when moving on it; see demo here.
I was working with Leaflet before, and it was handling that nicely.
Is Mapbox supposed to work fine with a lot of images loaded, and is there strategies to make it render smoothly?
One attempt that I made is that I was wondering if this was due to a excessive amount of layers; and searched how to add multiple images on a same layer (same question here); but haven't found a way to do it: this does not work:
//add source
map.addSource("imagesSource", {
type: "geojson",
data: {
"type": "FeatureCollection",
"features": [
[
{
"type": "image",
"url": "http://url/image1.png",
"coordinates": [
[
4.3813338557822,
50.842573058675
],
[
4.418685805334,
50.842573058675
],
[
4.418685805334,
50.825893099756
],
[
4.3813338557822,
50.825893099756
]
]
},
{
"type": "image",
"url": "http://url/image2.png",
"coordinates": [
[
4.3981741530879,
50.835614531226
],
[
4.402177428321,
50.835614531226
],
[
4.402177428321,
50.833826839538
],
[
4.3981741530879,
50.833826839538
]
]
},
{
"type": "image",
"url": "http://url/image3.png",
"coordinates": [
[
4.3813338557822,
50.842573058675
],
[
4.418685805334,
50.842573058675
],
[
4.418685805334,
50.825893099756
],
[
4.3813338557822,
50.825893099756
]
]
}
]
]
}
});
//add layer
map.addLayer({
"id": 'imagesLayer',
"source": 'imagesSource',
"type": "raster",
"paint": {"raster-opacity": 0.85}
})
NB There is another example named Add a georeferenced image, which is confusing since this one is for adding a tileset; which is not my case: I want to be able to handle each image individually (toggle a selection, etc).

Related

$geoWithin query fail to retrieve point included in the queried polygon

I'm trying to query a document using its location with two polygons that are quite similar. Both includes the location of the document but one finds it and the other not. I thought that this was related to "big polygons" but I managed to reduce the polygons enough to rule out this possibility. See previous post. Any idea explaining such a difference?
Playground: https://mongoplayground.net/p/sTEtYD3HU8m:
Document:
{
"_id": {
"$oid": "63ef9379e671073bfb963145"
},
"geometry": {
"type": "Point",
"coordinates": [
2.834,
47.264
]
},
"_class": "org.example.springdatamongodbgeowithinissue.model.SamplingGeometry"
}
Is not in search results for this polygon:
{
"geometry": {
"$geoWithin": {
"$geometry": {
"type": "Polygon",
"coordinates": [
[
[
-16.1,
49.12
],
[
-16.1,
46.156
],
[
16.1,
46.156
],
[
16.1,
49.12
],
[
-16.1,
49.12
]
]
]
}
}
}
}
Still the same issue with Earth's curvature. Your area is long enough to take it into account:
zooming in and's clearly outside:
The map: https://jsfiddle.net/blex18/w9g4bzyk/1/
var map = new google.maps.Map(document.body, {zoom:5,center:{lat:47.264,lng:2.834}});
new google.maps.Polygon({geodesic:true,map:map,geodesic:true,
path:[
{lat:49.12,lng:-16.1},
{lat:46.156,lng:-16.1},
{lat:46.156,lng:16.1},
{lat:49.12,lng:16.1},
{lat:49.12,lng:-16.1}]});
new google.maps.Marker({
position: {lat:47.264,lng:2.834},
map,
title: "Here",
});

Mapbox GL style line color based on property text value

I'm trying to style a single GeoJSON source with different line colors based on a feature property using react-map-gl, and I can't find a way to get set the color of lines in a smart way.
Most of all, I would love to apply a function on the dataset to return the color of my own choosing based on a feature property value, but so far I haven't fount anything about it. If you know about it, please point in my direction:)
If I have the following GeoJSON:
{
"type": "FeatureCollection",
"name": "lineData",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "Need": "Urgent" }, "geometry": { "type": "MultiLineString", "coordinates": [ [ [ 10.653823175868171, 59.676506860589157 ], [ 10.652881996887283, 59.675443989456632 ] ] ] } },
{ "type": "Feature", "properties": { "Need": "Starting" }, "geometry": { "type": "MultiLineString", "coordinates": [ [ [ 10.658536710768077, 59.680279341285896 ], [ 10.65787427600862, 59.680222775937636 ] ] ] } },
{ "type": "Feature", "properties": { "Need": "Medium" }, "geometry": { "type": "MultiLineString", "coordinates": [ [ [ 10.653224904719789, 59.67859470385492 ], [ 10.653201052045171, 59.678557551379008 ] ] ] } },
]
}
I would like to be able to style this source data with different line colors based on the property "Need". Say, urgent becomes red, medium becomes yellow, and starting becomes green.
I've read about styling expressions at mapbox, and I believe the "feature-state" is key to solving this, but I cant wrap my head around how to get the color converted from a feature.
If this in the rendering:
<Source id="my-data" type="geojson" data={TheDataFileWithSomeData}>
<Layer {...layerStyleTheLines } />
</Source>
Then I want a layer styling something like this (not working):
const layerStyleTheLines = {
id: 'style_it_to_red',
type: 'line',
paint: {
'line-color': [
[["==", ["feature-state", "Need"], "Urgent"],"red"],
[["==", ["feature-state", "Need"], "Medium"],"yellow"],
[["==", ["feature-state", "Need"], "Starting"],"green"]
],
'line-width': 3,
}
};
Thanks for all your help!
I've read about styling expressions at mapbox, and I believe the "feature-state" is key to solving this, but I cant wrap my head around how to get the color converted from a feature.
You only want feature-state if you're intending to manipulate the feature attributes dynamically, which I don't think you are.
You probably just want regular data-driven styling:
const layerStyleTheLines = {
id: 'style_it_to_red',
type: 'line',
paint: {
'line-color': [
'match', ['get','Need'],
'Urgent', 'red',
'Medium', 'yellow',
'Starting','green',
'black'
],
'line-width': 3,
}
};

Building Smaller Sized Raspberry pi images

Am trying to build small size Raspberry Pi images using packer-builder-arm (https://github.com/mkaczanowski/packer-builder-arm) community plugin.
The resulting images are still 2GB. Anybody suggestion how to reduce the image size. Thanks!
{
"variables": {},
"builders": [
{
"type": "arm",
"file_urls": [
"http://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2020-05-28/2020-05-27-raspios-buster-lite-armhf.zip"
],
"file_checksum_url": "http://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2020-05-28/2020-05-27-raspios-buster-lite-armhf.zip.sha256",
"file_checksum_type": "sha256",
"file_target_extension": "zip",
"image_build_method": "reuse",
"image_path": "custom-raspberry-pi-os.img",
"image_size": "700M",
"image_type": "dos",
"image_partitions": [
{
"name": "boot",
"type": "c",
"start_sector": "8192",
"filesystem": "vfat",
"size": "256M",
"mountpoint": "/boot"
},
{
"name": "root",
"type": "83",
"start_sector": "532480",
"filesystem": "ext4",
"size": "0",
"mountpoint": "/"
}
],
"image_chroot_env": [
"PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin"
],
"qemu_binary_source_path": "/usr/bin/qemu-arm-static",
"qemu_binary_destination_path": "/usr/bin/qemu-arm-static"
}
],
"provisioners": [
{
"type": "shell",
"inline": ["touch /tmp/test"]
}
]
}```
You might want to look into removing the programs you don't need in there. And then do a partition resize using something like resize2fs.

MongoDB: Swap values in array in sub document

I have a database with about 6 million documents where each looks like the following:
{
"_id": ObjectId("5d2327409ac8bc0085f3e733"),
"type": "Feature",
"properties": {
"osm_id": "2956281",
"code": 1500,
"fclass": "building",
"name": null,
"type": "tower"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-0.0154288,
51.4539007
],
[
-0.0153606,
51.4540789
],
[
-0.0150739,
51.4540339
],
[
-0.0151478,
51.4538517
],
[
-0.0154288,
51.4539007
]
]
]
}
}
The values in the coordinates array are pairs of lat/longs, but they're in the wrong order for my requirements so I need to switch them. I have written a script in JavaScript which iterates through the array and switches them but it's very slow as it operates on one document at a time.
Is there any way to do this with a more traditional bulk update call, which presumably would be much faster?

Query to calculate a percentage of a GEO surface in a radius

I am GeoJSON unfortunately still a bloody beginner. Now I have to solve a problem and understand, unfortunately, no piece of systematics.
Can you please help me and explain how I can use MongoDB to evaluate GEO data for the following case.
We have three areas (for example, countries), these have a value (say base area) now I have a catchment area that covers all three countries in part. How do I get the percentage of each country?
Here is a graphic to visualize the problem:
It is needed here e.g. the areas of A (n), B (n) and C (n).
In the database (mongodb#3.2) I have corresponding document with GEO data. Example:
{
"type": "FeatureCollecton",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
13.6868862,
51.063946
],
[
13.6873401,
51.063999
],
[
13.6883277,
51.0640888
],
...
]
]
},
"properties": {
"name": "Land A",
"qkm": 65.866862
}
},
]
}, ...