ValueError:Cannot render objects with any missing geometries - python

I wrote this code in order to have a map with population in other words i wanted polygan layer but I got an error
here is my code:
import folium
import pandas
data = pandas.read_csv("Volcanoes.txt")
lat=list(data["LAT"])
lon=list(data["LON"])
elev=list(data["ELEV"])
def color_producer(elevation):
if elevation < 1000:
return 'green'
elif 1000<=elevation<3000:
return 'orange'
else:
return 'red'
map=folium.Map(location=[42.304386,-83.066254],zoom_start=6,tiles="Stamen Terrain")
fg=folium.FeatureGroup(name="My Map")
for lt, ln ,el in zip(lat,lon,elev) :
fg.add_child(folium.CircleMarker(location=[lt,ln],radius=6,popup=str(el)+"m",
fill_color=color_producer(el),color='grey',fill_opacity=0.7))
fg.add_child(folium.GeoJson(data=open('world.json','r',encoding='utf-8-sig'),style_function=lambda x:{'fillColor':'yellow' }))
map.add_child(fg)
map.save("Map1.html")
this is my error:
Traceback (most recent call last):
File "C:\Users\Vida\Desktop\Webmapping_real\map1.py", line 28, in <module>
fg.add_child(folium.GeoJson(data=open('world.json','r',encoding='utf-8-sig'),style_function=lambda x:{'fillColor':'yellow' }))
File "C:\Users\Vida\AppData\Local\Programs\Python\Python310\lib\site-packages\folium\features.py", line 499, in __init__
self.data = self.process_data(data)
File "C:\Users\Vida\AppData\Local\Programs\Python\Python310\lib\site-packages\folium\features.py", line 544, in process_data
raise ValueError('Cannot render objects with any missing geometries'
ValueError: Cannot render objects with any missing geometries: <_io.TextIOWrapper name='world.json' mode='r' encoding='utf-8-sig'>
PS C:\Users\Vida\Desktop\Webmapping_real>
would you please help me how to fix it?

Related

ValueError: negative dimensions are not allowed (HOG)

I am implementing the HOG(Histogram of Oriented Gradient) with below code.
import io
from skimage.io import imread, imshow
from skimage.feature import hog
from skimage import exposure
from skimage import io
import matplotlib
img = imread('cr7.jpeg')
io.imshow(img)
MC = True #Fpr color images
#MC = false #for grayscale images
hogfv, hog_image = hog(img, orientations=9,
pixels_per_cell=(32,32),
cells_per_block=(4,4),
visualize = True ,
channel_axis=MC)
hog_image_rescaled = exposure.rescale_intensity(hog_image, in_range=(0,5))
imshow(hog_image_rescaled)
I don't know why i am getting error of dimension.
Traceback (most recent call last):
File "main.py", line 22, in <module>
channel_axis=MC)
File "/Volumes/DATA/Djangoproject/HOG/env/lib/python3.7/site-packages/skimage/_shared/utils.py", line 427, in fixed_func
out = func(*new_args, **kwargs)
File "/Volumes/DATA/Djangoproject/HOG/env/lib/python3.7/site-packages/skimage/_shared/utils.py", line 348, in fixed_func
return func(*args, **kwargs)
File "/Volumes/DATA/Djangoproject/HOG/env/lib/python3.7/site-packages/skimage/feature/_hog.py", line 286, in hog
dtype=float_dtype
ValueError: negative dimensions are not allowed
(base) (env) c100-110#C100-110s-iMac-2 HOG % python main.py
Traceback (most recent call last):
File "main.py", line 18, in <module>
channel_axis=MC)
File "/Volumes/DATA/Djangoproject/HOG/env/lib/python3.7/site-packages/skimage/_shared/utils.py", line 427, in fixed_func
out = func(*new_args, **kwargs)
File "/Volumes/DATA/Djangoproject/HOG/env/lib/python3.7/site-packages/skimage/_shared/utils.py", line 348, in fixed_func
return func(*args, **kwargs)
File "/Volumes/DATA/Djangoproject/HOG/env/lib/python3.7/site-packages/skimage/feature/_hog.py", line 286, in hog
dtype=float_dtype
ValueError: negative dimensions are not allowed
Can anyone help me in finding solution to this error.
The error log says there is a problem in "line 22"
Traceback (most recent call last):
File "main.py", line 22, in <module>
channel_axis=MC)
...
ValueError: negative dimensions are not allowed
channel_axis, it's the "channel axis"! So I guess it expects an integer, rather than a bool value.
It is confirmed in the source code:
channel_axis : int or None, optional
If None, the image is assumed to be a grayscale (single channel) image.
Otherwise, this parameter indicates which axis of the array corresponds
to channels.
I think you were trying to use multichannel, which is deprecated:
multichannel : boolean, optional
If True, the last image dimension is considered as a color channel,
otherwise as spatial. This argument is deprecated: specify channel_axis instead.
By adding following, it is working for my case.
channel_axis=-1

for loop python error

When i run this function i get the error, int object is not iterable. Here is the function
def WriteData(header, column):
if isinstance(header, str):
worksheet.write_string('A1', header)
elif isinstance(header, list):
worksheet.write_row('A1', header)
else:
worksheet.write_string('A1', 'no header data')
if isinstance(column, str):
worksheet.write_column('A2', column)
elif isinstance(column, list):
for col in range(0,len(column)):
worksheet.write_column('A2',col)
Here how i call the function:
WriteData(header=['Freq', 'Volts', 'VoltsPhase'], column=[frequencies, volts, voltsPhase])
The error is in the for loop for the specific call that i do this is what i am expecting:
for col in range(0,3)
This is correct as far as i know. So where is the error?
Traceback (most recent call last):
File "C:\Src32\PythonScripts\3300_Utilities\Run3300TestProcedure.py", line 415, in <module>
WriteData(header=['Freq', 'Volts', 'VoltsPhase'], column=[frequencies, volts, voltsPhase])
File "C:\Src32\PythonScripts\3300_Utilities\Run3300TestProcedure.py", line 413, in WriteData
worksheet.write_column('A2',col)
File "C:\Program Files (x86)\WinPython-32bit-3.4.4.4Qt5\python-3.4.4\lib\site-packages\xlsxwriter\worksheet.py", line 64, in cell_wrapper
return method(self, *args, **kwargs)
File "C:\Program Files (x86)\WinPython-32bit-3.4.4.4Qt5\python-3.4.4\lib\site-packages\xlsxwriter\worksheet.py", line 1012, in write_column
for token in data:
TypeError: 'int' object is not iterable
This is the correct way to do it:
for col in range(0,len(column)):
worksheet.write_column(1, col, column[col])

using replace for a column of a pandas df TypeError: Cannot compare types 'ndarray(dtype=int64)' and 'str'

How should I fix this?
import pandas as pd
csv_file = 'sample.csv'
count = 1
my_filtered_csv = pd.read_csv(csv_file, usecols=['subDirectory_filePath', 'expression'])
emotion_map = { '0':'6', '1':'3', '2':'4', '3':'5', '4':'2', '5':'1', '6':'0'}
my_filtered_csv['expression'] = my_filtered_csv['expression'].replace(emotion_map)
print(my_filtered_csv)
Error is:
Traceback (most recent call last):
File "/Users/mona/CS585/project/affnet/emotion_map.py", line 11, in <module>
my_filtered_csv['expression'] = my_filtered_csv['expression'].replace(emotion_map)
File "/Users/mona/anaconda/lib/python3.6/site-packages/pandas/core/generic.py", line 3836, in replace
limit=limit, regex=regex)
File "/Users/mona/anaconda/lib/python3.6/site-packages/pandas/core/generic.py", line 3885, in replace
regex=regex)
File "/Users/mona/anaconda/lib/python3.6/site-packages/pandas/core/internals.py", line 3259, in replace_list
masks = [comp(s) for i, s in enumerate(src_list)]
File "/Users/mona/anaconda/lib/python3.6/site-packages/pandas/core/internals.py", line 3259, in <listcomp>
masks = [comp(s) for i, s in enumerate(src_list)]
File "/Users/mona/anaconda/lib/python3.6/site-packages/pandas/core/internals.py", line 3247, in comp
return _maybe_compare(values, getattr(s, 'asm8', s), operator.eq)
File "/Users/mona/anaconda/lib/python3.6/site-packages/pandas/core/internals.py", line 4619, in _maybe_compare
raise TypeError("Cannot compare types %r and %r" % tuple(type_names))
TypeError: Cannot compare types 'ndarray(dtype=int64)' and 'str'
Process finished with exit code 1
A few lines of the csv file looks like:
,subDirectory_filePath,expression
0,689/737db2483489148d783ef278f43f486c0a97e140fc4b6b61b84363ca.jpg,1
1,392/c4db2f9b7e4b422d14b6e038f0cdc3ecee239b55326e9181ee4520f9.jpg,0
2,468/21772b68dc8c2a11678c8739eca33adb6ccc658600e4da2224080603.jpg,0
3,944/06e9ae8d3b240eb68fa60534783eacafce2def60a86042f9b7d59544.jpg,1
4,993/02e06ee5521958b4042dd73abb444220609d96f57b1689abbe87c024.jpg,8
5,979/f675c6a88cdef99a6d8b0261741217a0319387fcf1571a174f99ac81.jpg,6
6,637/94b769d8e880cbbea8eaa1350cb8c094a03d27f9fef44e1f4c0fb2ae.jpg,9
7,997/b81f843f08ce3bb0c48b270dc58d2ab8bf5bea3e2262e50bbcadbec2.jpg,6
8,358/21a32dd1c1ecd57d3e8964621c911df1c0b3348a4ae5203b4a243230.JPG,9
Changing the emotion_map to the following fixed the problem:
emotion_map = { 0:6, 1:3, 2:4, 3:5, 4:2, 5:1, 6:0}
Another possiblity which can also create this error is:
you have already run this code once and the data is already replaced.
To solve this problem, you can go back and load the data set again

OpenPYXL Python errors on cell values

I have an excel file with a ton of rows, and a column containing HZ, NZ or SZ now is this erroring out, and I have no idea on how to fix it.
region = ws.cell(row=srow, column=3)
if region.value == "HZ":
nregion = "Houston"
elif region.value == "NZ":
nregion = "North"
elif region.value == "SZ":
nregion = "South"
It errors with the following messages:
Traceback (most recent call last):
File "PowerExp.py", line 18, in <module>
wb=load_workbook(filename = wbfile)
File "/usr/local/lib/python2.7/dist-packages/openpyxl/reader/excel.py", line 136, in load_workbook
_load_workbook(wb, archive, filename, use_iterators, keep_vba)
File "/usr/local/lib/python2.7/dist-packages/openpyxl/reader/excel.py", line 171, in _load_workbook
style_table = read_style_table(archive.read(ARC_STYLE))
File "/usr/local/lib/python2.7/dist-packages/openpyxl/reader/style.py", line 42, in read_style_table
font_list = parse_fonts(root, xmlns, color_index)
File "/usr/local/lib/python2.7/dist-packages/openpyxl/reader/style.py", line 160, in parse_fonts
font.size = font_node.find(QName(xmlns, 'sz').text).get('val')
AttributeError: 'NoneType' object has no attribute 'get'
I can't change the value and save the workbook as it is automatically retrieved from the email server and loaded into MySQL.

Python, PIL and libtiff issue

When I do general PIL commands in Python, I get such an error message:
>>> im.save('layer_86_.tiff')
TIFFSetField: layer_86_.tiff: Unknown tag 33922.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\lib\site-packages\PIL\Image.py", line 1685, in save
save_handler(self, fp, filename)
File "C:\Python34\lib\site-packages\PIL\TiffImagePlugin.py", line 1185, in _save
e = Image._getencoder(im.mode, 'libtiff', a, im.encoderconfig)
File "C:\Python34\lib\site-packages\PIL\Image.py", line 430, in _getencoder
return encoder(mode, *args + extra)
RuntimeError: Error setting from dictionary
I've seen at Github and SO similar questions, that date back to many years ago. But in my case this problem still can be reproduced. I've even installed libtiff.dll and put it in the System32 and SysWOW64 folders, but to no avail. So, how can I fix it?
This is another error message, that I see, when I try to rotate an image:
>>> from PIL import Image
>>> Image.MAX_IMAGE_PIXELS = 100000000000
>>> img = Image.open('layer_71_.tiff')
>>> img.rotate(80,expand=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\lib\site-packages\PIL\Image.py", line 1603, in rotate
return self.transform((w, h), AFFINE, matrix, resample)
File "C:\Python34\lib\site-packages\PIL\Image.py", line 1862, in transform
im.__transformer((0, 0)+size, self, method, data, resample, fill)
File "C:\Python34\lib\site-packages\PIL\Image.py", line 1910, in __transformer
image.load()
File "C:\Python34\lib\site-packages\PIL\ImageFile.py", line 245, in load
if not self.map and (not LOAD_TRUNCATED_IMAGES or t == 0) and e < 0:
TypeError: unorderable types: tuple() < int()
So it seems like PIL does not work in many cases.

Categories

Resources