How can a missing .shx file be created?












5















I am using ArcGIS to view one shapefile.



Only a select number of features are being displayed. The same number are showing in the attribute table even though the database file (.dbf) has a complete list with many more features.



I then tried opening the shapefile in QGIS and it informs me that the file is invalid. Upon inspection of the shapefile, I found that the .shx file is missing.



Can I recreate the missing .shx file so that all the attributes/features can be loaded?










share|improve this question




















  • 1





    If your dBase file contains "many more features" than the .shp, then the shapefile is corrupt, and none of the data can be trusted. The .shx can usually be recostituted from the .shp, but it depends on whether there are any "gaps" in the file data stream.

    – Vince
    Dec 17 '18 at 13:13


















5















I am using ArcGIS to view one shapefile.



Only a select number of features are being displayed. The same number are showing in the attribute table even though the database file (.dbf) has a complete list with many more features.



I then tried opening the shapefile in QGIS and it informs me that the file is invalid. Upon inspection of the shapefile, I found that the .shx file is missing.



Can I recreate the missing .shx file so that all the attributes/features can be loaded?










share|improve this question




















  • 1





    If your dBase file contains "many more features" than the .shp, then the shapefile is corrupt, and none of the data can be trusted. The .shx can usually be recostituted from the .shp, but it depends on whether there are any "gaps" in the file data stream.

    – Vince
    Dec 17 '18 at 13:13
















5












5








5


1






I am using ArcGIS to view one shapefile.



Only a select number of features are being displayed. The same number are showing in the attribute table even though the database file (.dbf) has a complete list with many more features.



I then tried opening the shapefile in QGIS and it informs me that the file is invalid. Upon inspection of the shapefile, I found that the .shx file is missing.



Can I recreate the missing .shx file so that all the attributes/features can be loaded?










share|improve this question
















I am using ArcGIS to view one shapefile.



Only a select number of features are being displayed. The same number are showing in the attribute table even though the database file (.dbf) has a complete list with many more features.



I then tried opening the shapefile in QGIS and it informs me that the file is invalid. Upon inspection of the shapefile, I found that the .shx file is missing.



Can I recreate the missing .shx file so that all the attributes/features can be loaded?







qgis arcgis-desktop shapefile corrupt






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 13:56









nmtoken

7,87742766




7,87742766










asked Dec 17 '18 at 7:43









Ezra RynjahEzra Rynjah

284




284








  • 1





    If your dBase file contains "many more features" than the .shp, then the shapefile is corrupt, and none of the data can be trusted. The .shx can usually be recostituted from the .shp, but it depends on whether there are any "gaps" in the file data stream.

    – Vince
    Dec 17 '18 at 13:13
















  • 1





    If your dBase file contains "many more features" than the .shp, then the shapefile is corrupt, and none of the data can be trusted. The .shx can usually be recostituted from the .shp, but it depends on whether there are any "gaps" in the file data stream.

    – Vince
    Dec 17 '18 at 13:13










1




1





If your dBase file contains "many more features" than the .shp, then the shapefile is corrupt, and none of the data can be trusted. The .shx can usually be recostituted from the .shp, but it depends on whether there are any "gaps" in the file data stream.

– Vince
Dec 17 '18 at 13:13







If your dBase file contains "many more features" than the .shp, then the shapefile is corrupt, and none of the data can be trusted. The .shx can usually be recostituted from the .shp, but it depends on whether there are any "gaps" in the file data stream.

– Vince
Dec 17 '18 at 13:13












2 Answers
2






active

oldest

votes


















12














ESRI provides a guide to repairing corrupted shapefiles which you can find on the ESRI website: https://support.esri.com/en/technical-article/000007161



I can't check on my machine but one of either the Shapefile Repairer Utility or the Shapefile Repair Tool (which are linked at the bottom of that ESRI help page) used to be able to reconstruct a .shx file.



You can also do it in Python. This link suggests this code to recreate a .shx file:



    # Build a new shx index file
#Code by Joel Lawhead http://geospatialpython.com/2011/11/generating-shapefile-shx-files.html
import shapefile
# Explicitly name the shp and dbf file objects
# so pyshp ignores the missing/corrupt shx
myshp = open("myshape.shp", "rb")
mydbf = open("myshape.dbf", "rb")
r = shapefile.Reader(shp=myshp, shx=None, dbf=mydbf)
w = shapefile.Writer(r.shapeType)
# Copy everything from reader object to writer object
w._shapes = r.shapes()
w.records = r.records()
w.fields = list(r.fields)
# saving will generate the shx
w.save("myshape")


Not that code requires the Python Shapefile Library (pyshp) to run.






share|improve this answer































    4














    You could open the Shapefile without the shx in OpenJump and save it as a new Shapefile.
    Then the shx-file will be generated.






    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',
      autoActivateHeartbeat: false,
      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%2f306218%2fhow-can-a-missing-shx-file-be-created%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      12














      ESRI provides a guide to repairing corrupted shapefiles which you can find on the ESRI website: https://support.esri.com/en/technical-article/000007161



      I can't check on my machine but one of either the Shapefile Repairer Utility or the Shapefile Repair Tool (which are linked at the bottom of that ESRI help page) used to be able to reconstruct a .shx file.



      You can also do it in Python. This link suggests this code to recreate a .shx file:



          # Build a new shx index file
      #Code by Joel Lawhead http://geospatialpython.com/2011/11/generating-shapefile-shx-files.html
      import shapefile
      # Explicitly name the shp and dbf file objects
      # so pyshp ignores the missing/corrupt shx
      myshp = open("myshape.shp", "rb")
      mydbf = open("myshape.dbf", "rb")
      r = shapefile.Reader(shp=myshp, shx=None, dbf=mydbf)
      w = shapefile.Writer(r.shapeType)
      # Copy everything from reader object to writer object
      w._shapes = r.shapes()
      w.records = r.records()
      w.fields = list(r.fields)
      # saving will generate the shx
      w.save("myshape")


      Not that code requires the Python Shapefile Library (pyshp) to run.






      share|improve this answer




























        12














        ESRI provides a guide to repairing corrupted shapefiles which you can find on the ESRI website: https://support.esri.com/en/technical-article/000007161



        I can't check on my machine but one of either the Shapefile Repairer Utility or the Shapefile Repair Tool (which are linked at the bottom of that ESRI help page) used to be able to reconstruct a .shx file.



        You can also do it in Python. This link suggests this code to recreate a .shx file:



            # Build a new shx index file
        #Code by Joel Lawhead http://geospatialpython.com/2011/11/generating-shapefile-shx-files.html
        import shapefile
        # Explicitly name the shp and dbf file objects
        # so pyshp ignores the missing/corrupt shx
        myshp = open("myshape.shp", "rb")
        mydbf = open("myshape.dbf", "rb")
        r = shapefile.Reader(shp=myshp, shx=None, dbf=mydbf)
        w = shapefile.Writer(r.shapeType)
        # Copy everything from reader object to writer object
        w._shapes = r.shapes()
        w.records = r.records()
        w.fields = list(r.fields)
        # saving will generate the shx
        w.save("myshape")


        Not that code requires the Python Shapefile Library (pyshp) to run.






        share|improve this answer


























          12












          12








          12







          ESRI provides a guide to repairing corrupted shapefiles which you can find on the ESRI website: https://support.esri.com/en/technical-article/000007161



          I can't check on my machine but one of either the Shapefile Repairer Utility or the Shapefile Repair Tool (which are linked at the bottom of that ESRI help page) used to be able to reconstruct a .shx file.



          You can also do it in Python. This link suggests this code to recreate a .shx file:



              # Build a new shx index file
          #Code by Joel Lawhead http://geospatialpython.com/2011/11/generating-shapefile-shx-files.html
          import shapefile
          # Explicitly name the shp and dbf file objects
          # so pyshp ignores the missing/corrupt shx
          myshp = open("myshape.shp", "rb")
          mydbf = open("myshape.dbf", "rb")
          r = shapefile.Reader(shp=myshp, shx=None, dbf=mydbf)
          w = shapefile.Writer(r.shapeType)
          # Copy everything from reader object to writer object
          w._shapes = r.shapes()
          w.records = r.records()
          w.fields = list(r.fields)
          # saving will generate the shx
          w.save("myshape")


          Not that code requires the Python Shapefile Library (pyshp) to run.






          share|improve this answer













          ESRI provides a guide to repairing corrupted shapefiles which you can find on the ESRI website: https://support.esri.com/en/technical-article/000007161



          I can't check on my machine but one of either the Shapefile Repairer Utility or the Shapefile Repair Tool (which are linked at the bottom of that ESRI help page) used to be able to reconstruct a .shx file.



          You can also do it in Python. This link suggests this code to recreate a .shx file:



              # Build a new shx index file
          #Code by Joel Lawhead http://geospatialpython.com/2011/11/generating-shapefile-shx-files.html
          import shapefile
          # Explicitly name the shp and dbf file objects
          # so pyshp ignores the missing/corrupt shx
          myshp = open("myshape.shp", "rb")
          mydbf = open("myshape.dbf", "rb")
          r = shapefile.Reader(shp=myshp, shx=None, dbf=mydbf)
          w = shapefile.Writer(r.shapeType)
          # Copy everything from reader object to writer object
          w._shapes = r.shapes()
          w.records = r.records()
          w.fields = list(r.fields)
          # saving will generate the shx
          w.save("myshape")


          Not that code requires the Python Shapefile Library (pyshp) to run.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 17 '18 at 8:03









          Ed RollasonEd Rollason

          2,5431127




          2,5431127

























              4














              You could open the Shapefile without the shx in OpenJump and save it as a new Shapefile.
              Then the shx-file will be generated.






              share|improve this answer




























                4














                You could open the Shapefile without the shx in OpenJump and save it as a new Shapefile.
                Then the shx-file will be generated.






                share|improve this answer


























                  4












                  4








                  4







                  You could open the Shapefile without the shx in OpenJump and save it as a new Shapefile.
                  Then the shx-file will be generated.






                  share|improve this answer













                  You could open the Shapefile without the shx in OpenJump and save it as a new Shapefile.
                  Then the shx-file will be generated.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 17 '18 at 8:30









                  markgraeflerlandmarkgraeflerland

                  262320




                  262320






























                      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.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f306218%2fhow-can-a-missing-shx-file-be-created%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

                      Plaza Victoria

                      Puebla de Zaragoza

                      Musa