Repository: rasterio/rasterio

Issue:
CRS.from_string() PROJ string check
https://github.com/mapbox/rasterio/blob/00b5096015a2e1b737c8902abc2b48c6394ff08c/rasterio/crs.py#L362-L363

Sometimes WKT can contain PROJ strings. I am thinking should check if it endswith `]` as well.

Or, change it to:

```python
elif string.endswith("]"): 
    return cls.from_wkt(string, morph_from_esri_dialect=morph_from_esri_dialect)
return cls.from_proj4(string)
```

 Thoughts?


Discussion:
Example:
```python
>>> import pyproj
>>> print(pyproj.CRS("EPSG:3857").to_wkt("WKT1_GDAL", pretty=True))
PROJCS["WGS 84 / Pseudo-Mercator",
    GEOGCS["WGS 84",
        DATUM["WGS_1984",
            SPHEROID["WGS 84",6378137,298.257223563,
                AUTHORITY["EPSG","7030"]],
            AUTHORITY["EPSG","6326"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.0174532925199433,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4326"]],
    PROJECTION["Mercator_1SP"],
    PARAMETER["central_meridian",0],
    PARAMETER["scale_factor",1],
    PARAMETER["false_easting",0],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["Easting",EAST],
    AXIS["Northing",NORTH],
    EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs"],
    AUTHORITY["EPSG","3857"]]

```
Indeed @snowman2 this should be fixed!

Resolving patch:
diff --git a/rasterio/crs.py b/rasterio/crs.py
--- a/rasterio/crs.py
+++ b/rasterio/crs.py
@@ -359,12 +359,11 @@ def from_string(cls, string, morph_from_esri_dialect=False):
             else:
                 return cls.from_dict(**val)
 
-        elif '+' in string and '=' in string:
-            return cls.from_proj4(string)
-
-        else:
+        elif string.strip().endswith("]"):
             return cls.from_wkt(string, morph_from_esri_dialect=morph_from_esri_dialect)
 
+        return cls.from_proj4(string)
+
     @classmethod
     def from_proj4(cls, proj):
         """Make a CRS from a PROJ4 string


Test patch:
diff --git a/tests/test_crs.py b/tests/test_crs.py
--- a/tests/test_crs.py
+++ b/tests/test_crs.py
@@ -510,4 +510,33 @@ def test_equals_different_type(other):
 
 def test_from_user_input_custom_crs_class():
     """Support comparison to foreign objects that provide to_wkt()"""
-    assert CRS.from_user_input(CustomCRS()) == CRS.from_epsg(4326)
\ No newline at end of file
+    assert CRS.from_user_input(CustomCRS()) == CRS.from_epsg(4326)
+
+
+def test_from_string__wkt_with_proj():
+    wkt = (
+        'PROJCS["WGS 84 / Pseudo-Mercator",'
+        'GEOGCS["WGS 84",'
+        '    DATUM["WGS_1984",'
+        '        SPHEROID["WGS 84",6378137,298.257223563,'
+        '            AUTHORITY["EPSG","7030"]],'
+        '        AUTHORITY["EPSG","6326"]],'
+        '    PRIMEM["Greenwich",0,'
+        '        AUTHORITY["EPSG","8901"]],'
+        '    UNIT["degree",0.0174532925199433,'
+        '        AUTHORITY["EPSG","9122"]],'
+        '    AUTHORITY["EPSG","4326"]],'
+        'PROJECTION["Mercator_1SP"],'
+        'PARAMETER["central_meridian",0],'
+        'PARAMETER["scale_factor",1],'
+        'PARAMETER["false_easting",0],'
+        'PARAMETER["false_northing",0],'
+        'UNIT["metre",1,'
+        '    AUTHORITY["EPSG","9001"]],'
+        'AXIS["Easting",EAST],'
+        'AXIS["Northing",NORTH],'
+        'EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0 '
+        '+lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs"],'
+        'AUTHORITY["EPSG","3857"]] '
+    )
+    assert CRS.from_string(wkt).to_epsg() == 3857