How to Identify Coordinate System (CRS) from projection file using Python











up vote
2
down vote

favorite












I am working on many shapefiles (their corresponding projection files are also presented).



Every shapefile has a different Coordinate System, so it becomes difficult to plot these in a generic manner.



How can I identify with Python what is the CRS used in the shapefile?



For example, the ".prj" file for some shapefiles is given below, but I am not able to identify what is the CRS to be used.



GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]

GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]

GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]]

GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]

GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]]









share|improve this question




















  • 1




    Which python library or tools do you use to read your shapefile?
    – YoLecomte
    Nov 27 at 11:21










  • I have tried GeoPandas, Shapely, and Fionna
    – userxxx
    Nov 27 at 11:34















up vote
2
down vote

favorite












I am working on many shapefiles (their corresponding projection files are also presented).



Every shapefile has a different Coordinate System, so it becomes difficult to plot these in a generic manner.



How can I identify with Python what is the CRS used in the shapefile?



For example, the ".prj" file for some shapefiles is given below, but I am not able to identify what is the CRS to be used.



GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]

GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]

GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]]

GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]

GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]]









share|improve this question




















  • 1




    Which python library or tools do you use to read your shapefile?
    – YoLecomte
    Nov 27 at 11:21










  • I have tried GeoPandas, Shapely, and Fionna
    – userxxx
    Nov 27 at 11:34













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I am working on many shapefiles (their corresponding projection files are also presented).



Every shapefile has a different Coordinate System, so it becomes difficult to plot these in a generic manner.



How can I identify with Python what is the CRS used in the shapefile?



For example, the ".prj" file for some shapefiles is given below, but I am not able to identify what is the CRS to be used.



GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]

GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]

GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]]

GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]

GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]]









share|improve this question















I am working on many shapefiles (their corresponding projection files are also presented).



Every shapefile has a different Coordinate System, so it becomes difficult to plot these in a generic manner.



How can I identify with Python what is the CRS used in the shapefile?



For example, the ".prj" file for some shapefiles is given below, but I am not able to identify what is the CRS to be used.



GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]

GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]

GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]]

GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]

GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]]






python coordinate-system shapefile






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 at 11:58









Taras

1,8962622




1,8962622










asked Nov 27 at 11:13









userxxx

1133




1133








  • 1




    Which python library or tools do you use to read your shapefile?
    – YoLecomte
    Nov 27 at 11:21










  • I have tried GeoPandas, Shapely, and Fionna
    – userxxx
    Nov 27 at 11:34














  • 1




    Which python library or tools do you use to read your shapefile?
    – YoLecomte
    Nov 27 at 11:21










  • I have tried GeoPandas, Shapely, and Fionna
    – userxxx
    Nov 27 at 11:34








1




1




Which python library or tools do you use to read your shapefile?
– YoLecomte
Nov 27 at 11:21




Which python library or tools do you use to read your shapefile?
– YoLecomte
Nov 27 at 11:21












I have tried GeoPandas, Shapely, and Fionna
– userxxx
Nov 27 at 11:34




I have tried GeoPandas, Shapely, and Fionna
– userxxx
Nov 27 at 11:34










3 Answers
3






active

oldest

votes

















up vote
3
down vote













For example with fiona:



c = fiona.open('docs/data/test_uk.shp')
crs = c.crs


find it in the docs page 28



If you need the EPSG code there is good inspiration to take here using pyproj






share|improve this answer






























    up vote
    1
    down vote













    Is it not just that simple as below (I know he wanted to know from prj file but I think this is more simple)?



    import arcpy

    arcpy.env.workspace = r"PATH TO FOLDER OR GDB"

    featureclasses = arcpy.ListFeatureClasses()
    for fc in featureclasses:
    desc = arcpy.Describe(fc)
    spatialRef = desc.spatialReference
    print(spatialRef.Name)


    https://www.e-education.psu.edu/geog485/node/115






    share|improve this answer





















    • Thanks for this, but is there any alternate solution which does not use arcpy.
      – userxxx
      Nov 27 at 11:37


















    up vote
    1
    down vote













    A number of Python modules exist to work with CRS or projection files





    • Pypi:ESPSG or Pypi:CRS

    • GitHub: EPSG


    For example, you can use epsg-ident or sridentify (Quickly get the EPSG code from a .prj file or WKT)



    from sridentify import Sridentify
    ident = Sridentify()
    # from file
    ident.from_file('schisto.prj')
    ident.get_epsg()
    31370
    # from WKT
    ident = Sridentify(prj="""GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]])
    ident.get_epsg()
    4326


    But it doesn't always work



    ident =  Sridentify(prj = """GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]""")
    ident.get_epsg()
    # nothing





    share|improve this answer





















      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "79"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f304061%2fhow-to-identify-coordinate-system-crs-from-projection-file-using-python%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      3
      down vote













      For example with fiona:



      c = fiona.open('docs/data/test_uk.shp')
      crs = c.crs


      find it in the docs page 28



      If you need the EPSG code there is good inspiration to take here using pyproj






      share|improve this answer



























        up vote
        3
        down vote













        For example with fiona:



        c = fiona.open('docs/data/test_uk.shp')
        crs = c.crs


        find it in the docs page 28



        If you need the EPSG code there is good inspiration to take here using pyproj






        share|improve this answer

























          up vote
          3
          down vote










          up vote
          3
          down vote









          For example with fiona:



          c = fiona.open('docs/data/test_uk.shp')
          crs = c.crs


          find it in the docs page 28



          If you need the EPSG code there is good inspiration to take here using pyproj






          share|improve this answer














          For example with fiona:



          c = fiona.open('docs/data/test_uk.shp')
          crs = c.crs


          find it in the docs page 28



          If you need the EPSG code there is good inspiration to take here using pyproj







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 27 at 11:52

























          answered Nov 27 at 11:44









          YoLecomte

          1,905218




          1,905218
























              up vote
              1
              down vote













              Is it not just that simple as below (I know he wanted to know from prj file but I think this is more simple)?



              import arcpy

              arcpy.env.workspace = r"PATH TO FOLDER OR GDB"

              featureclasses = arcpy.ListFeatureClasses()
              for fc in featureclasses:
              desc = arcpy.Describe(fc)
              spatialRef = desc.spatialReference
              print(spatialRef.Name)


              https://www.e-education.psu.edu/geog485/node/115






              share|improve this answer





















              • Thanks for this, but is there any alternate solution which does not use arcpy.
                – userxxx
                Nov 27 at 11:37















              up vote
              1
              down vote













              Is it not just that simple as below (I know he wanted to know from prj file but I think this is more simple)?



              import arcpy

              arcpy.env.workspace = r"PATH TO FOLDER OR GDB"

              featureclasses = arcpy.ListFeatureClasses()
              for fc in featureclasses:
              desc = arcpy.Describe(fc)
              spatialRef = desc.spatialReference
              print(spatialRef.Name)


              https://www.e-education.psu.edu/geog485/node/115






              share|improve this answer





















              • Thanks for this, but is there any alternate solution which does not use arcpy.
                – userxxx
                Nov 27 at 11:37













              up vote
              1
              down vote










              up vote
              1
              down vote









              Is it not just that simple as below (I know he wanted to know from prj file but I think this is more simple)?



              import arcpy

              arcpy.env.workspace = r"PATH TO FOLDER OR GDB"

              featureclasses = arcpy.ListFeatureClasses()
              for fc in featureclasses:
              desc = arcpy.Describe(fc)
              spatialRef = desc.spatialReference
              print(spatialRef.Name)


              https://www.e-education.psu.edu/geog485/node/115






              share|improve this answer












              Is it not just that simple as below (I know he wanted to know from prj file but I think this is more simple)?



              import arcpy

              arcpy.env.workspace = r"PATH TO FOLDER OR GDB"

              featureclasses = arcpy.ListFeatureClasses()
              for fc in featureclasses:
              desc = arcpy.Describe(fc)
              spatialRef = desc.spatialReference
              print(spatialRef.Name)


              https://www.e-education.psu.edu/geog485/node/115







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 27 at 11:28









              JuniorPythonNewbie

              3189




              3189












              • Thanks for this, but is there any alternate solution which does not use arcpy.
                – userxxx
                Nov 27 at 11:37


















              • Thanks for this, but is there any alternate solution which does not use arcpy.
                – userxxx
                Nov 27 at 11:37
















              Thanks for this, but is there any alternate solution which does not use arcpy.
              – userxxx
              Nov 27 at 11:37




              Thanks for this, but is there any alternate solution which does not use arcpy.
              – userxxx
              Nov 27 at 11:37










              up vote
              1
              down vote













              A number of Python modules exist to work with CRS or projection files





              • Pypi:ESPSG or Pypi:CRS

              • GitHub: EPSG


              For example, you can use epsg-ident or sridentify (Quickly get the EPSG code from a .prj file or WKT)



              from sridentify import Sridentify
              ident = Sridentify()
              # from file
              ident.from_file('schisto.prj')
              ident.get_epsg()
              31370
              # from WKT
              ident = Sridentify(prj="""GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]])
              ident.get_epsg()
              4326


              But it doesn't always work



              ident =  Sridentify(prj = """GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]""")
              ident.get_epsg()
              # nothing





              share|improve this answer

























                up vote
                1
                down vote













                A number of Python modules exist to work with CRS or projection files





                • Pypi:ESPSG or Pypi:CRS

                • GitHub: EPSG


                For example, you can use epsg-ident or sridentify (Quickly get the EPSG code from a .prj file or WKT)



                from sridentify import Sridentify
                ident = Sridentify()
                # from file
                ident.from_file('schisto.prj')
                ident.get_epsg()
                31370
                # from WKT
                ident = Sridentify(prj="""GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]])
                ident.get_epsg()
                4326


                But it doesn't always work



                ident =  Sridentify(prj = """GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]""")
                ident.get_epsg()
                # nothing





                share|improve this answer























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  A number of Python modules exist to work with CRS or projection files





                  • Pypi:ESPSG or Pypi:CRS

                  • GitHub: EPSG


                  For example, you can use epsg-ident or sridentify (Quickly get the EPSG code from a .prj file or WKT)



                  from sridentify import Sridentify
                  ident = Sridentify()
                  # from file
                  ident.from_file('schisto.prj')
                  ident.get_epsg()
                  31370
                  # from WKT
                  ident = Sridentify(prj="""GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]])
                  ident.get_epsg()
                  4326


                  But it doesn't always work



                  ident =  Sridentify(prj = """GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]""")
                  ident.get_epsg()
                  # nothing





                  share|improve this answer












                  A number of Python modules exist to work with CRS or projection files





                  • Pypi:ESPSG or Pypi:CRS

                  • GitHub: EPSG


                  For example, you can use epsg-ident or sridentify (Quickly get the EPSG code from a .prj file or WKT)



                  from sridentify import Sridentify
                  ident = Sridentify()
                  # from file
                  ident.from_file('schisto.prj')
                  ident.get_epsg()
                  31370
                  # from WKT
                  ident = Sridentify(prj="""GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]])
                  ident.get_epsg()
                  4326


                  But it doesn't always work



                  ident =  Sridentify(prj = """GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]""")
                  ident.get_epsg()
                  # nothing






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 27 at 17:10









                  gene

                  36.5k150109




                  36.5k150109






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f304061%2fhow-to-identify-coordinate-system-crs-from-projection-file-using-python%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Сан-Квентин

                      Алькесар

                      Josef Freinademetz