I was trying to execute this code:
# Load geojson files
country = gpd.read_file('svn_buffered.geojson')
train_shp = "large_training_aoi.geojson"
test_shp = "large_test_aoi.shp"
train_polyg = gpd.read_file(train_shp)
test_polyg = gpd.read_file(test_shp)
# reproject the polygons
target_crs = CRS.UTM_33N
country = country.to_crs(target_crs.pyproj_crs())
train_polyg = train_polyg.to_crs(target_crs.pyproj_crs())
test_polyg = test_polyg.to_crs(target_crs.pyproj_crs())
fontdict = {'family': 'monospace', 'weight': 'normal', 'size': 11}
fig, ax = plt.subplots(figsize=(20, 20))
test_polyg.plot(ax=ax, facecolor='w', edgecolor='r', alpha=0.5) #test area in red
train_polyg.plot(ax=ax, facecolor='w', edgecolor='g', alpha=0.5) # train area in green
country.plot(ax=ax, facecolor='w', edgecolor='b', alpha=0.5)
ax.set_title('Selected train AOI (in green) and test AOI (in red)');
plt.axis('off')
I tried to use the following syntax:
test_polyg = test_polyg.to_crs(epsg=32632)
and I got the error each time but only for the test data.
ValueError Traceback (most recent call last)
<ipython-input-20-323e17a794e3> in <module>()
11 country = country.to_crs(target_crs.pyproj_crs())
12 train_polyg = train_polyg.to_crs(target_crs.pyproj_crs())
---> 13 test_polyg = test_polyg.to_crs(target_crs.pyproj_crs())
14
15
1 frames
/usr/local/lib/python3.6/dist-packages/geopandas/geoseries.py in to_crs(self, crs, epsg)
420 if self.crs is None:
421 raise ValueError(
--> 422 "Cannot transform naive geometries. "
423 "Please set a crs on the object first."
424 )
ValueError: Cannot transform naive geometries. Please set a crs on the object first.
Any idea on how can I fix it?