1
d1= gpd.read_file(aq.shp)
asttom = gpd.read_file(es.shp)
data2 = d1[d1['TYPE'].str.startswith(('01'))]
dslv=data2.dissolve(by='TYPE')

While it reaches the dissolve procedure it causes the error. How to work with it?

  • Have you looked at what data2 returns? The error is telling you that you are dissolving a null. So the select might not be returning anything – Liam G Jun 18 '18 at 13:07
  • Issue is because you are dissolving 'data2' and it must be doing with d1 (a geopandas geodataframe). data2, with 'TYPE' starting with '01', must be created as a geopandas geodataframe. – xunilk Jun 18 '18 at 13:43
1

Issue is because you are dissolving 'data2' and it must be doing with d1 (a geopandas geodataframe). My following example works nicely:

import geopandas as gpd

path = "/home/zeito/pyqgis_data/polygon8.shp"

d1 = gpd.read_file(path)
data = d1['counts']
dslv = d1.dissolve(by='counts')

print dslv

and result, as it expected, is:

Python Console 
Use iface to access QGIS API interface or Type help(iface) for more info
execfile(u'/home/zeito/pyqgis_scripts/using_shapely_geometry.py'.encode('UTF-8'))
                                                 geometry  FID          area  \
counts                                                                         
20      (POLYGON ((425341.4022431545 4428919.808172906 3.0  2.134534e+08   
100     POLYGON ((450747.2094816907 4445981.551269374, 2.0  3.737159e+08   
300     POLYGON ((363445.8816669167 4460178.914137968, 0.0  1.389711e+08   
500     POLYGON ((410566.1276510805 4463034.251804442, 1.0  2.805022e+08   

        class  cno  field     max     min  mult my_string  name  perimeter  \
counts                                                                       
20          2    3      0  2914.0  1364.0     1   my test    34  56801.054   
100         4    2      1  2962.0  1438.0     1   my test    64  76584.033   
300         1    0      1  2738.0  1538.0     1   my test    81  47573.201   
500         3    1      1  2330.0  1351.0     1   my test    27  65657.871   

        values  
counts          
20          33  
100         65  
300         31  
500         43

Original shapefile is:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.