I've been looking at Adding a WMS layer using folium
and https://python-visualization.github.io/folium/modules.html.
I managed to get the example in the above link to work in streamlit but not the WMS I'm trying. I've also tried the WMS in qgis and it works.
I realized I need to specify the coordinate system when connecting to the WMS in the below link. From what I can tell both folium and the wms supports EPSG:900913 = EPSG3857(?). However when adding the wms tile layer all i get is my base map. But the WMS isn't showing.
The WMS can be found at https://resource.sgu.se/dokument/produkter/jordarter-25-100000-wms-beskrivning.pdf
https://resource.sgu.se/service/wms/130/jordarter-25-100-tusen
import streamlit as st
import folium
import streamlit_folium
map_geo = folium.Map(location=[57.8,14.14], zoom_start=13, width=1200)
try:
folium.raster_layers.WmsTileLayer(url ='https://resource.sgu.se/service/wms/130/jordarter-25-100-tusen',
layers = ['jord:SE.GOV.SGU.JORD.TACKNINGSKARTA.25K'],
transparent = False,
control = True,
fmt="image/png",
name = 'SGU',
attr = 'im seeing this',
overlay = True,
show = True,
CRS = 'EPSG:900913',
version = '1.3.0',
).add_to(map_geo)
folium.LayerControl().add_to(map_geo)
except Exception as e:
st.write(e)
streamlit_folium.st_folium(map_geo)
I think it may be due to the fact that the target URL and the layer designation are different. I just don't know if the called layer is the intended layer or not. I got this https://resource.sgu.se/service/wms/130/jordarter-25-100-tusen and layer from the content of the link provided.
import folium
map_geo = folium.Map(location=[57.8,14.14], zoom_start=10, width=1200)
folium.raster_layers.WmsTileLayer(url ='https://maps3.sgu.se/geoserver/jord/ows?',
layers = 'SE.GOV.SGU.JORD.TACKNINGSKARTA.25K',
transparent = False,
control = True,
fmt="image/png",
name = 'SGU',
attr = 'im seeing this',
overlay = True,
show = True,
CRS = 'EPSG:900913',
version = '1.3.0',
).add_to(map_geo)
folium.LayerControl().add_to(map_geo)
map_geo
Related
I'm attempting to create a feature layer in ARC GIS using a shape file but I'm getting the following exception when trying to open the shape file with ShapefileFeatureTable.OpenAsync
{"Geodatabase field exists: fid"}
var shapeFileFeatureTable = ShapefileFeatureTable.OpenAsync(#"...\myshape.shp").Result;
fl = new FeatureLayer(shapeFileFeatureTable)
{
// Set the rendering mode of the feature layer to be dynamic (needed for extrusion to work).
RenderingMode = FeatureRenderingMode.Dynamic,
IsVisible = true,
};
I have read some articles that mentioned how to get image by selenium. For example:
from selenium import webdriver
import requests
driver=webdriver.Firefox()
driver.get("http/https://your website")
img=driver.find_element_by_xpath("xpath leading to your element")#locating element
src=img.get_attribute('src')#fetch the location of image
img=requests.get(src)#fetch image
with open('image.jpg','wb') as writer:#open for writing in binary mode
writer.write(img.content)#write the image
But does this methods have a risk of more bandwidth cost?
Is there any way just like I right click on the image and save as it to local PC?
I have tried use javascript to do that:
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
var img = document.getElementById('someImageId');
context.drawImage(img, 0, 0 );
var theData = context.getImageData(0, 0, img.width, img.height);
and meet cross-origin problem
Uncaught DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.
at <anonymous>:5:23
It's workaround is make another request just like what I do not want in the first line.
Any suggestions?
In order to avoid increasing network footprint you can consider the following approach:
Take the screenshot of the entire page using i.e. get_screenshot_as_png function
Get required element location and size
Extract "interesting" part of the page by cutting anything else but the required element's coordinates
Save the resulting file
Example code which stores the logo from the https://experitest.com/ site to logo.png file:
from selenium import webdriver
from PIL import Image
from io import BytesIO
options = webdriver.ChromeOptions()
options.add_argument("--kiosk")
driver = webdriver.Chrome(chrome_options=options)
driver.get('chrome://settings/')
driver.execute_script('chrome.settingsPrivate.setDefaultZoom(1.0);')
driver.get("https://experitest.com/")
element = driver.find_element_by_xpath("//a[#class='navbar-brand']/img")
location = element.location
size = element.size
png = driver.get_screenshot_as_png()
im = Image.open(BytesIO(png))
left = location['x']
top = location['y']
right = location['x'] + size['width']
bottom = location['y'] + size['height']
im = im.crop((left, top, right, bottom))
im.save('logo.png')
driver.quit()
Assumptions:
You have Pillow library installed (it should be as easy as pip install pillow command)
Your OS DPI scale level is set to 100%
enter image description here
I'm Making an android app.
Well, this is a sample code for face detection provided by google.
Instead of using a jpeg file, I want to use my camera preview .
How should I change the code? It would be very thankful if you help me because I'm struggling with this for 3 hours.
ImageView myImageView = (ImageView) findViewById(R.id.imgview);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable=true;
Bitmap myBitmap = BitmapFactory.decodeResource(
getApplicationContext().getResources(),
R.drawable.test1,
options);
import cv2
import numpy as np
a = cv2.CascadeClassifier('haarcascades/haarcascade_frontalface_default.xml');
cam = cv2.VideoCapture(0);
while(True):
ret,img=cam.read();
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces = a.detectMultiScale(gray,1.3,5)
for(x,y,w,h) in faces :
cv2.rectangle(img, (x,y), (x+w,y+h), (0,0,255), 2)
cv2.imshow("Face", img);
if(cv2.waitKey(1) == ord('q')):
break;
cam.release()
cv2.destroyAllWindows()
I am using mapbox v1.6.1
to show up
var mapboxMap = L.mapbox.map(mapName, 'examples.map-20v6611k',{tileLayer:{noWrap:true},zoomControl:false,zoomAnimation:false,fadeAnimation:false,inertia:false}).setView([23.8, -11], 1);
a choropleth map and
var statesLayer = L.geoJson(localData, {
style: getStyle,
onEachFeature: onEachFeature
}).addTo(mapboxMap);
a normal map with markers
var featureLayer = L.mapbox.featureLayer(mapPlotData).addTo(mapboxMap);
These two layers are not showing up when i export the webpage to pdf using phantomJS
Increasing the timeout doesnt work as well.
I appreciate any help on this!
I am having issues saving images in python via GIMP. I can get the image and apply the effects I want, but when I go to save, it only saves one layer and not everything (NOTE: The background is transparent) and because the background is transparent, I cannot get it to save anything besides the transparent background. The code I am using is posted below:
image_array = gimp.image_list()
i=0
for image in image_array:
img = image_array[i]
layers = img.layers
last_layer = len(layers)-1
try:
disable=pdb.gimp_image_undo_disable(img)
pdb.gimp_layer_add_alpha(layers[0])
drw = pdb.gimp_image_active_drawable(img)
pdb.plug_in_colortoalpha(img,drw,(0,0,0))
drw = pdb.gimp_image_active_drawable(img)
enable = pdb.gimp_image_undo_enable(img)
except:
print "ERROR"
pdb.file_png_save(img, drw, "C:\\Users\\jammer\\Desktop\\test.png",
"test.png",0,9,1,1,1,1,1)
i+=1
I have also tried file_png_save2, but I have a feeling the problem lies in the drw object as I just want to replicate the option of clicking File->Export and saving as PNG without doing that via GUI. I would rather have it save automatically (I have 49 images and each will be named automatically, but first I need to get it to export correctly with one image). as I said before, the code above only exports a transparent background, even changing to a GIF does not resolve the issue. How do I export a file as a PNG while keeping all layers and transparent background?
I found my problem! I was not merging the visible layers and setting that equal to the new layer, which I then used as the "drawable object" when saving the image as a png! I have posted the fixed code below:
image_array = gimp.image_list()
i=0
for image in image_array:
img = image_array[i]
layers = img.layers
last_layer = len(layers)-1
try:
disable=pdb.gimp_image_undo_disable(img)
pdb.gimp_layer_add_alpha(layers[0])
drw = pdb.gimp_image_active_drawable(img)
pdb.plug_in_colortoalpha(img,drw,(0,0,0))
layer = pdb.gimp_image_merge_visible_layers(img, gimpfu.CLIP_TO_IMAGE)#FIXES PROBLEM OF ONLY EXPORTING TRANSPARENCY!
enable = pdb.gimp_image_undo_enable(img)
except:
print "ERROR"
pdb.file_png_save2(img, layer, "C:\\Users\\jammer\\Desktop\\test.png","test.png",1,9,1,1,1,1,1,0,1)
i+=1