@@ -176,13 +176,24 @@ def intersection(self, feature):
176176 return FeatureCollection (features , self .crs )
177177
178178 @staticmethod
179- def _read_crs (collection ):
179+ def _process_errors (err_msg , ignore_errors ):
180+ if not ignore_errors :
181+ raise CRSError (err_msg )
180182
181- # if there is no defined CRS in geojson file, we folloe the standard, which says that it must be lat-lon
183+ warning_msg = 'Assuming EPSG:4326 (lat-lon). May cause an error in further reprojection ' \
184+ 'or rasterization if it is not so.'
185+ message = f'{ err_msg } { warning_msg } '
186+ warnings .warn (message , RuntimeWarning )
187+
188+ return CRS_LATLON
189+
190+ @staticmethod
191+ def _read_crs (collection , ignore_errors = True ):
182192 if 'crs' not in collection .keys ():
183- return CRS_LATLON
193+ err_msg = 'CRS is not in collection.'
194+ return FeatureCollection ._process_errors (err_msg , ignore_errors )
184195
185- crs_raw = collection .get ('crs' , CRS_LATLON )
196+ crs_raw = collection .get ('crs' )
186197 crs = CRS ()
187198
188199 try :
@@ -192,18 +203,25 @@ def _read_crs(collection):
192203 if 'type' in crs_raw .keys () and 'properties' in crs_raw .keys ():
193204 if crs_raw ['type' ] == 'name' :
194205 crs = CRS .from_user_input (crs_raw ['properties' ]['name' ])
206+ elif 'init' in crs_raw .keys ():
207+ crs = CRS .from_user_input (crs_raw ['init' ])
208+ else :
209+ err_msg = f'CRS can not be interpreted in dict { crs_raw } .'
210+ return FeatureCollection ._process_errors (err_msg , ignore_errors )
211+ else :
212+ err_msg = f'CRS can not be interpreted in { crs_raw } .'
213+ return FeatureCollection ._process_errors (err_msg , ignore_errors )
214+
195215 # Old rasterio compatibility: a separate check for validity
196216 if not crs .is_valid :
197- message = 'CRS {} is not supported by rasterio,' \
198- 'May cause an error in further reprojection or rasterization' . format ( crs )
199- warnings . warn ( message , RuntimeWarning )
217+ err_msg = 'CRS is not valid.'
218+ return FeatureCollection . _process_errors ( err_msg , ignore_errors )
219+
200220 return crs
201- # Really invalid CRS will throw CRSError
221+ # Really invalid CRS will throw CRSError
202222 except CRSError :
203- message = 'CRS was not imported correctly, assuming EPSG:4326 (lat-lon). ' \
204- 'May cause an error in further reprojection or rasterization if it is not so.'
205- warnings .warn (message , RuntimeWarning )
206- return CRS_LATLON
223+ err_msg = 'CRS was not imported correctly.'
224+ return FeatureCollection ._process_errors (err_msg , ignore_errors )
207225
208226 @classmethod
209227 def read (cls , fp ):
0 commit comments