0

I want to reproject my ground truth data (land reference map) to UTM.

# Load Reference Data (reference map = ground truth data): labeled vector data in a shapefile (crops in Jendouba)
LULC_filename = "Jendouba.shp"     
land_use_ref= gpd.read_file(str(LULC_filename))


# Convert CRS (WGS 84) to UTM             
# CRS is the Coordinates Reference System
land_use_ref = land_use_ref.to_crs(Jendouba_crs.pyproj_crs()) 

#plot country
land_use_ref.plot()
plt.axis('off');
land_use_ref.crs

which raised the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-87-fe96bab05714> in <module>()
      6 # Convert CRS (WGS 84) to UTM
      7 # CRS is the Coordinates Reference System
----> 8 land_use_ref = land_use_ref.to_crs(Jendouba_crs.pyproj_crs())
      9 
     10 #plot country

4 frames
pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()

/usr/local/lib/python3.6/dist-packages/shapely/ops.py in transform(func, geom)
    222     also satisfy the requirements for `func`.
    223     """
--> 224     if geom.is_empty:
    225         return geom
    226     if geom.type in ('Point', 'LineString', 'LinearRing', 'Polygon'):

AttributeError: 'NoneType' object has no attribute 'is_empty'

I checked the content of the dataframe:

print(land_use_ref.info())

And geometry had a missing value:

class 'geopandas.geodataframe.GeoDataFrame'>
RangeIndex: 249 entries, 0 to 248
Data columns (total 11 columns):
 #   Column      Non-Null Count  Dtype   
---  ------      --------------  -----   
 0   Type        249 non-null    object  
 1   Observatio  100 non-null    object  
 2   Crop_heigh  249 non-null    int64   
 3   Previous_y  7 non-null      object  
 4   Irrigation  28 non-null     object  
 5   Sewing_dat  249 non-null    object  
 6   Soil_type   99 non-null     object  
 7   Soil_col_1  95 non-null     object  
 8   FID222      249 non-null    int64   
 9   Label       249 non-null    int64   
 10  geometry    248 non-null    geometry
dtypes: geometry(1), int64(3), object(7)
memory usage: 21.5+ KB
None

So I tried to drop the row that has this missing value:

polygons_clean = Polygon[Polygon.geometry.type == 'POLYGON']

But I got the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-97-062acdbf0eeb> in <module>()
----> 1 polygons_clean = Polygon[Polygon.geometry.type == 'POLYGON']

AttributeError: type object 'Polygon' has no attribute 'geometry'

This is my dataframe

Edit: I used this: land_use_ref['geometry']=land_use_ref['geometry'].dropna and the problem persists and the weird thing is that the number of non-null samples become 249 (previously 248).

  • What does Jendouba_crs.pyproj_crs() return? – Kadir Şahbaz Jun 9 at 12:27
  • Try this to drop invalid geometries land_use_ref = land_use_ref[land_use_ref.geometry.is_valid] . – Kadir Şahbaz Jun 9 at 12:30
  • Jendouba_crs=CRS.UTM_32N (the projection system that I need to transform my dataframe to) – Rim Sleimi Jun 9 at 12:32
  • Still get the same error: AttributeError: 'NoneType' object has no attribute 'is_empty' – Rim Sleimi Jun 9 at 12:34
  • try to remove .pyproj_crs() part from Jendouba_crs.pyproj_crs(). Just use Jendouba_crs. I didn't hear a method named pyproj_crs(). Is it new? – Kadir Şahbaz Jun 9 at 12:35
0

I was lucky to locate the "None object" in geometry (last row) and thus create a new dataframe from the original one minus the last row:

# Deleting the last row (Wheat) where geometry=None 
land_use_ref.shape    #(249,11)
land_use_ref = land_use_ref[:-1]
land_use_ref.shape    #(248,11)
| improve this answer | |

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.