b'Recode from ANSI 1252 to UTF-8 failed with the error: “Invalid argument”.' geopandas python












5















I am trying to read in a shapefile into a GeoDataFrame.



Normally I just do this and it works:



import pandas as pd

import geopandas as gpd
from shapely.geometry import Point

df = gpd.read_file("wild_fires/nbac_2016_r2_20170707_1114.shp")


But this time it gives me the error: b'Recode from ANSI 1252 to UTF-8 failed with the error: "Invalid argument".'



Full error:



---------------------------------------------------------------------------
CPLE_AppDefinedError Traceback (most recent call last)
<ipython-input-14-adcad0275d30> in <module>()
----> 1 df_wildfires_2016 = gpd.read_file("wild_fires/nbac_2016_r2_20170707_1114.shp")

/usr/local/lib/python3.6/site-packages/geopandas/io/file.py in read_file(filename, **kwargs)
19 """
20 bbox = kwargs.pop('bbox', None)
---> 21 with fiona.open(filename, **kwargs) as f:
22 crs = f.crs
23 if bbox is not None:

/usr/local/lib/python3.6/site-packages/fiona/__init__.py in open(path, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt)
163 c = Collection(path, mode, driver=driver, encoding=encoding,
164 layer=layer, vsi=vsi, archive=archive,
--> 165 enabled_drivers=enabled_drivers)
166 elif mode == 'w':
167 if schema:

/usr/local/lib/python3.6/site-packages/fiona/collection.py in __init__(self, path, mode, driver, schema, crs, encoding, layer, vsi, archive, enabled_drivers, crs_wkt, **kwargs)
151 if self.mode == 'r':
152 self.session = Session()
--> 153 self.session.start(self)
154 elif self.mode in ('a', 'w'):
155 self.session = WritingSession()

fiona/ogrext.pyx in fiona.ogrext.Session.start (fiona/ogrext2.c:8432)()

fiona/_err.pyx in fiona._err.GDALErrCtxManager.__exit__ (fiona/_err.c:1861)()

CPLE_AppDefinedError: b'Recode from ANSI 1252 to UTF-8 failed with the error: "Invalid argument".'


I've been trying to figure out why I am getting the error for a while but can't seem to find the answer.



The data was obtained from this webpage I downloaded only the 2016 link: http://cwfis.cfs.nrcan.gc.ca/datamart/download/nbac?token=78e9bd6af67f71204e18cb6fa4e47515



Would anybody be able to help me? Thank you.










share|improve this question

























  • Can you give the full error trace?

    – Mark Ransom
    Nov 13 '17 at 23:47











  • @MarkRansom just added the full error

    – Julien
    Nov 13 '17 at 23:55











  • @Julien so you have done that same process with other data and it works ok? Seems to suggest that the problem is with this dataset (and based on the error, probably had some unrecognized character that failed to convert to UTF-8)

    – DarkCygnus
    Nov 14 '17 at 0:33











  • @DarkCygnus Yes, normally it just works. Is there a way to ignore or bypass this error?

    – Julien
    Nov 14 '17 at 1:39











  • @Julien added an answer, with 2 options you got, that I tested and were able to open without errors :)

    – DarkCygnus
    Nov 14 '17 at 1:42
















5















I am trying to read in a shapefile into a GeoDataFrame.



Normally I just do this and it works:



import pandas as pd

import geopandas as gpd
from shapely.geometry import Point

df = gpd.read_file("wild_fires/nbac_2016_r2_20170707_1114.shp")


But this time it gives me the error: b'Recode from ANSI 1252 to UTF-8 failed with the error: "Invalid argument".'



Full error:



---------------------------------------------------------------------------
CPLE_AppDefinedError Traceback (most recent call last)
<ipython-input-14-adcad0275d30> in <module>()
----> 1 df_wildfires_2016 = gpd.read_file("wild_fires/nbac_2016_r2_20170707_1114.shp")

/usr/local/lib/python3.6/site-packages/geopandas/io/file.py in read_file(filename, **kwargs)
19 """
20 bbox = kwargs.pop('bbox', None)
---> 21 with fiona.open(filename, **kwargs) as f:
22 crs = f.crs
23 if bbox is not None:

/usr/local/lib/python3.6/site-packages/fiona/__init__.py in open(path, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt)
163 c = Collection(path, mode, driver=driver, encoding=encoding,
164 layer=layer, vsi=vsi, archive=archive,
--> 165 enabled_drivers=enabled_drivers)
166 elif mode == 'w':
167 if schema:

/usr/local/lib/python3.6/site-packages/fiona/collection.py in __init__(self, path, mode, driver, schema, crs, encoding, layer, vsi, archive, enabled_drivers, crs_wkt, **kwargs)
151 if self.mode == 'r':
152 self.session = Session()
--> 153 self.session.start(self)
154 elif self.mode in ('a', 'w'):
155 self.session = WritingSession()

fiona/ogrext.pyx in fiona.ogrext.Session.start (fiona/ogrext2.c:8432)()

fiona/_err.pyx in fiona._err.GDALErrCtxManager.__exit__ (fiona/_err.c:1861)()

CPLE_AppDefinedError: b'Recode from ANSI 1252 to UTF-8 failed with the error: "Invalid argument".'


I've been trying to figure out why I am getting the error for a while but can't seem to find the answer.



The data was obtained from this webpage I downloaded only the 2016 link: http://cwfis.cfs.nrcan.gc.ca/datamart/download/nbac?token=78e9bd6af67f71204e18cb6fa4e47515



Would anybody be able to help me? Thank you.










share|improve this question

























  • Can you give the full error trace?

    – Mark Ransom
    Nov 13 '17 at 23:47











  • @MarkRansom just added the full error

    – Julien
    Nov 13 '17 at 23:55











  • @Julien so you have done that same process with other data and it works ok? Seems to suggest that the problem is with this dataset (and based on the error, probably had some unrecognized character that failed to convert to UTF-8)

    – DarkCygnus
    Nov 14 '17 at 0:33











  • @DarkCygnus Yes, normally it just works. Is there a way to ignore or bypass this error?

    – Julien
    Nov 14 '17 at 1:39











  • @Julien added an answer, with 2 options you got, that I tested and were able to open without errors :)

    – DarkCygnus
    Nov 14 '17 at 1:42














5












5








5


1






I am trying to read in a shapefile into a GeoDataFrame.



Normally I just do this and it works:



import pandas as pd

import geopandas as gpd
from shapely.geometry import Point

df = gpd.read_file("wild_fires/nbac_2016_r2_20170707_1114.shp")


But this time it gives me the error: b'Recode from ANSI 1252 to UTF-8 failed with the error: "Invalid argument".'



Full error:



---------------------------------------------------------------------------
CPLE_AppDefinedError Traceback (most recent call last)
<ipython-input-14-adcad0275d30> in <module>()
----> 1 df_wildfires_2016 = gpd.read_file("wild_fires/nbac_2016_r2_20170707_1114.shp")

/usr/local/lib/python3.6/site-packages/geopandas/io/file.py in read_file(filename, **kwargs)
19 """
20 bbox = kwargs.pop('bbox', None)
---> 21 with fiona.open(filename, **kwargs) as f:
22 crs = f.crs
23 if bbox is not None:

/usr/local/lib/python3.6/site-packages/fiona/__init__.py in open(path, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt)
163 c = Collection(path, mode, driver=driver, encoding=encoding,
164 layer=layer, vsi=vsi, archive=archive,
--> 165 enabled_drivers=enabled_drivers)
166 elif mode == 'w':
167 if schema:

/usr/local/lib/python3.6/site-packages/fiona/collection.py in __init__(self, path, mode, driver, schema, crs, encoding, layer, vsi, archive, enabled_drivers, crs_wkt, **kwargs)
151 if self.mode == 'r':
152 self.session = Session()
--> 153 self.session.start(self)
154 elif self.mode in ('a', 'w'):
155 self.session = WritingSession()

fiona/ogrext.pyx in fiona.ogrext.Session.start (fiona/ogrext2.c:8432)()

fiona/_err.pyx in fiona._err.GDALErrCtxManager.__exit__ (fiona/_err.c:1861)()

CPLE_AppDefinedError: b'Recode from ANSI 1252 to UTF-8 failed with the error: "Invalid argument".'


I've been trying to figure out why I am getting the error for a while but can't seem to find the answer.



The data was obtained from this webpage I downloaded only the 2016 link: http://cwfis.cfs.nrcan.gc.ca/datamart/download/nbac?token=78e9bd6af67f71204e18cb6fa4e47515



Would anybody be able to help me? Thank you.










share|improve this question
















I am trying to read in a shapefile into a GeoDataFrame.



Normally I just do this and it works:



import pandas as pd

import geopandas as gpd
from shapely.geometry import Point

df = gpd.read_file("wild_fires/nbac_2016_r2_20170707_1114.shp")


But this time it gives me the error: b'Recode from ANSI 1252 to UTF-8 failed with the error: "Invalid argument".'



Full error:



---------------------------------------------------------------------------
CPLE_AppDefinedError Traceback (most recent call last)
<ipython-input-14-adcad0275d30> in <module>()
----> 1 df_wildfires_2016 = gpd.read_file("wild_fires/nbac_2016_r2_20170707_1114.shp")

/usr/local/lib/python3.6/site-packages/geopandas/io/file.py in read_file(filename, **kwargs)
19 """
20 bbox = kwargs.pop('bbox', None)
---> 21 with fiona.open(filename, **kwargs) as f:
22 crs = f.crs
23 if bbox is not None:

/usr/local/lib/python3.6/site-packages/fiona/__init__.py in open(path, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt)
163 c = Collection(path, mode, driver=driver, encoding=encoding,
164 layer=layer, vsi=vsi, archive=archive,
--> 165 enabled_drivers=enabled_drivers)
166 elif mode == 'w':
167 if schema:

/usr/local/lib/python3.6/site-packages/fiona/collection.py in __init__(self, path, mode, driver, schema, crs, encoding, layer, vsi, archive, enabled_drivers, crs_wkt, **kwargs)
151 if self.mode == 'r':
152 self.session = Session()
--> 153 self.session.start(self)
154 elif self.mode in ('a', 'w'):
155 self.session = WritingSession()

fiona/ogrext.pyx in fiona.ogrext.Session.start (fiona/ogrext2.c:8432)()

fiona/_err.pyx in fiona._err.GDALErrCtxManager.__exit__ (fiona/_err.c:1861)()

CPLE_AppDefinedError: b'Recode from ANSI 1252 to UTF-8 failed with the error: "Invalid argument".'


I've been trying to figure out why I am getting the error for a while but can't seem to find the answer.



The data was obtained from this webpage I downloaded only the 2016 link: http://cwfis.cfs.nrcan.gc.ca/datamart/download/nbac?token=78e9bd6af67f71204e18cb6fa4e47515



Would anybody be able to help me? Thank you.







python shapefile geopandas






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '17 at 23:55







Julien

















asked Nov 11 '17 at 23:23









JulienJulien

335416




335416













  • Can you give the full error trace?

    – Mark Ransom
    Nov 13 '17 at 23:47











  • @MarkRansom just added the full error

    – Julien
    Nov 13 '17 at 23:55











  • @Julien so you have done that same process with other data and it works ok? Seems to suggest that the problem is with this dataset (and based on the error, probably had some unrecognized character that failed to convert to UTF-8)

    – DarkCygnus
    Nov 14 '17 at 0:33











  • @DarkCygnus Yes, normally it just works. Is there a way to ignore or bypass this error?

    – Julien
    Nov 14 '17 at 1:39











  • @Julien added an answer, with 2 options you got, that I tested and were able to open without errors :)

    – DarkCygnus
    Nov 14 '17 at 1:42



















  • Can you give the full error trace?

    – Mark Ransom
    Nov 13 '17 at 23:47











  • @MarkRansom just added the full error

    – Julien
    Nov 13 '17 at 23:55











  • @Julien so you have done that same process with other data and it works ok? Seems to suggest that the problem is with this dataset (and based on the error, probably had some unrecognized character that failed to convert to UTF-8)

    – DarkCygnus
    Nov 14 '17 at 0:33











  • @DarkCygnus Yes, normally it just works. Is there a way to ignore or bypass this error?

    – Julien
    Nov 14 '17 at 1:39











  • @Julien added an answer, with 2 options you got, that I tested and were able to open without errors :)

    – DarkCygnus
    Nov 14 '17 at 1:42

















Can you give the full error trace?

– Mark Ransom
Nov 13 '17 at 23:47





Can you give the full error trace?

– Mark Ransom
Nov 13 '17 at 23:47













@MarkRansom just added the full error

– Julien
Nov 13 '17 at 23:55





@MarkRansom just added the full error

– Julien
Nov 13 '17 at 23:55













@Julien so you have done that same process with other data and it works ok? Seems to suggest that the problem is with this dataset (and based on the error, probably had some unrecognized character that failed to convert to UTF-8)

– DarkCygnus
Nov 14 '17 at 0:33





@Julien so you have done that same process with other data and it works ok? Seems to suggest that the problem is with this dataset (and based on the error, probably had some unrecognized character that failed to convert to UTF-8)

– DarkCygnus
Nov 14 '17 at 0:33













@DarkCygnus Yes, normally it just works. Is there a way to ignore or bypass this error?

– Julien
Nov 14 '17 at 1:39





@DarkCygnus Yes, normally it just works. Is there a way to ignore or bypass this error?

– Julien
Nov 14 '17 at 1:39













@Julien added an answer, with 2 options you got, that I tested and were able to open without errors :)

– DarkCygnus
Nov 14 '17 at 1:42





@Julien added an answer, with 2 options you got, that I tested and were able to open without errors :)

– DarkCygnus
Nov 14 '17 at 1:42












3 Answers
3






active

oldest

votes


















4





+50









Seems that your shapefile contains non-UTF characters that causes the Fiona.open() call to fail (geopandas uses Fiona to open files).



What I did that solved this error was to open the Shapefile (with QGis for example), then selecting save as, and specifying the Encoding option as "UTF-8":



enter image description here



After doing this, I got no error when calling df = gpd.read_file("convertedShape.shp").





Another way to do this without having to use QGis or similar, is to read and save your Shapefile again (effectively converting to the desired format). With OGR you can do something like this:



from osgeo import ogr

driver = ogr.GetDriverByName("ESRI Shapefile")
ds = driver.Open("nbac_2016_r2_20170707_1114.shp", 0) #open your shapefile
#get its layer
layer = ds.GetLayer()

#create new shapefile to convert
ds2 = driver.CreateDataSource('convertedShape.shp')
#create a Polygon layer, as the one your Shapefile has
layer2 = ds2.CreateLayer('', None, ogr.wkbPolygon)
#iterate over all features of your original shapefile
for feature in layer:
#and create a new feature on your converted shapefile with those features
layer2.CreateFeature(feature)

ds = layer = ds2 = layer2 = None


This also enabled to successfully open with df = gpd.read_file("convertedShape.shp") after conversion. Hope this helps.






share|improve this answer
























  • thank you! I don't have QGis. I tried pip installing osgeo but it doesn't seem to be working. Any idea how I can download tha library?

    – Julien
    Nov 14 '17 at 2:04













  • @Julien several options are provided here. I think I installed it with apt-get install python-gdal, or with pip install GDAL... most likely the first one, but that Q I linked has several alternatives (easiest if you have conda). Hope my answer was useful :)

    – DarkCygnus
    Nov 14 '17 at 2:50













  • @Julien as a side comment, I suggest you give QGis a try (it is Open), as it usually always comes handy to inspect that shapefiles and rasters are the way we expect (encoding, attributes, etc.) before processing or reading them.

    – DarkCygnus
    Nov 14 '17 at 3:01











  • Thanks for the advice! I think I will install QGis.

    – Julien
    Nov 14 '17 at 3:23











  • @Julien glad it helped :) good luck with your coding.

    – DarkCygnus
    Nov 14 '17 at 3:26



















3














with fiona.open(file, encoding="UTF-8") as f:


worked for me.






share|improve this answer































    0














    Since you have GDAL installed, I recommend converting the file to UTF-8 using the CLI:



    ogr2ogr output.shp input.shp -lco ENCODING=UTF-8


    Worked like a charm for me. It's much faster than QGIS or Python and can be applied in a cluster environment.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      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: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      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%2fstackoverflow.com%2fquestions%2f47243879%2fbrecode-from-ansi-1252-to-utf-8-failed-with-the-error-invalid-argument-geo%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









      4





      +50









      Seems that your shapefile contains non-UTF characters that causes the Fiona.open() call to fail (geopandas uses Fiona to open files).



      What I did that solved this error was to open the Shapefile (with QGis for example), then selecting save as, and specifying the Encoding option as "UTF-8":



      enter image description here



      After doing this, I got no error when calling df = gpd.read_file("convertedShape.shp").





      Another way to do this without having to use QGis or similar, is to read and save your Shapefile again (effectively converting to the desired format). With OGR you can do something like this:



      from osgeo import ogr

      driver = ogr.GetDriverByName("ESRI Shapefile")
      ds = driver.Open("nbac_2016_r2_20170707_1114.shp", 0) #open your shapefile
      #get its layer
      layer = ds.GetLayer()

      #create new shapefile to convert
      ds2 = driver.CreateDataSource('convertedShape.shp')
      #create a Polygon layer, as the one your Shapefile has
      layer2 = ds2.CreateLayer('', None, ogr.wkbPolygon)
      #iterate over all features of your original shapefile
      for feature in layer:
      #and create a new feature on your converted shapefile with those features
      layer2.CreateFeature(feature)

      ds = layer = ds2 = layer2 = None


      This also enabled to successfully open with df = gpd.read_file("convertedShape.shp") after conversion. Hope this helps.






      share|improve this answer
























      • thank you! I don't have QGis. I tried pip installing osgeo but it doesn't seem to be working. Any idea how I can download tha library?

        – Julien
        Nov 14 '17 at 2:04













      • @Julien several options are provided here. I think I installed it with apt-get install python-gdal, or with pip install GDAL... most likely the first one, but that Q I linked has several alternatives (easiest if you have conda). Hope my answer was useful :)

        – DarkCygnus
        Nov 14 '17 at 2:50













      • @Julien as a side comment, I suggest you give QGis a try (it is Open), as it usually always comes handy to inspect that shapefiles and rasters are the way we expect (encoding, attributes, etc.) before processing or reading them.

        – DarkCygnus
        Nov 14 '17 at 3:01











      • Thanks for the advice! I think I will install QGis.

        – Julien
        Nov 14 '17 at 3:23











      • @Julien glad it helped :) good luck with your coding.

        – DarkCygnus
        Nov 14 '17 at 3:26
















      4





      +50









      Seems that your shapefile contains non-UTF characters that causes the Fiona.open() call to fail (geopandas uses Fiona to open files).



      What I did that solved this error was to open the Shapefile (with QGis for example), then selecting save as, and specifying the Encoding option as "UTF-8":



      enter image description here



      After doing this, I got no error when calling df = gpd.read_file("convertedShape.shp").





      Another way to do this without having to use QGis or similar, is to read and save your Shapefile again (effectively converting to the desired format). With OGR you can do something like this:



      from osgeo import ogr

      driver = ogr.GetDriverByName("ESRI Shapefile")
      ds = driver.Open("nbac_2016_r2_20170707_1114.shp", 0) #open your shapefile
      #get its layer
      layer = ds.GetLayer()

      #create new shapefile to convert
      ds2 = driver.CreateDataSource('convertedShape.shp')
      #create a Polygon layer, as the one your Shapefile has
      layer2 = ds2.CreateLayer('', None, ogr.wkbPolygon)
      #iterate over all features of your original shapefile
      for feature in layer:
      #and create a new feature on your converted shapefile with those features
      layer2.CreateFeature(feature)

      ds = layer = ds2 = layer2 = None


      This also enabled to successfully open with df = gpd.read_file("convertedShape.shp") after conversion. Hope this helps.






      share|improve this answer
























      • thank you! I don't have QGis. I tried pip installing osgeo but it doesn't seem to be working. Any idea how I can download tha library?

        – Julien
        Nov 14 '17 at 2:04













      • @Julien several options are provided here. I think I installed it with apt-get install python-gdal, or with pip install GDAL... most likely the first one, but that Q I linked has several alternatives (easiest if you have conda). Hope my answer was useful :)

        – DarkCygnus
        Nov 14 '17 at 2:50













      • @Julien as a side comment, I suggest you give QGis a try (it is Open), as it usually always comes handy to inspect that shapefiles and rasters are the way we expect (encoding, attributes, etc.) before processing or reading them.

        – DarkCygnus
        Nov 14 '17 at 3:01











      • Thanks for the advice! I think I will install QGis.

        – Julien
        Nov 14 '17 at 3:23











      • @Julien glad it helped :) good luck with your coding.

        – DarkCygnus
        Nov 14 '17 at 3:26














      4





      +50







      4





      +50



      4




      +50





      Seems that your shapefile contains non-UTF characters that causes the Fiona.open() call to fail (geopandas uses Fiona to open files).



      What I did that solved this error was to open the Shapefile (with QGis for example), then selecting save as, and specifying the Encoding option as "UTF-8":



      enter image description here



      After doing this, I got no error when calling df = gpd.read_file("convertedShape.shp").





      Another way to do this without having to use QGis or similar, is to read and save your Shapefile again (effectively converting to the desired format). With OGR you can do something like this:



      from osgeo import ogr

      driver = ogr.GetDriverByName("ESRI Shapefile")
      ds = driver.Open("nbac_2016_r2_20170707_1114.shp", 0) #open your shapefile
      #get its layer
      layer = ds.GetLayer()

      #create new shapefile to convert
      ds2 = driver.CreateDataSource('convertedShape.shp')
      #create a Polygon layer, as the one your Shapefile has
      layer2 = ds2.CreateLayer('', None, ogr.wkbPolygon)
      #iterate over all features of your original shapefile
      for feature in layer:
      #and create a new feature on your converted shapefile with those features
      layer2.CreateFeature(feature)

      ds = layer = ds2 = layer2 = None


      This also enabled to successfully open with df = gpd.read_file("convertedShape.shp") after conversion. Hope this helps.






      share|improve this answer













      Seems that your shapefile contains non-UTF characters that causes the Fiona.open() call to fail (geopandas uses Fiona to open files).



      What I did that solved this error was to open the Shapefile (with QGis for example), then selecting save as, and specifying the Encoding option as "UTF-8":



      enter image description here



      After doing this, I got no error when calling df = gpd.read_file("convertedShape.shp").





      Another way to do this without having to use QGis or similar, is to read and save your Shapefile again (effectively converting to the desired format). With OGR you can do something like this:



      from osgeo import ogr

      driver = ogr.GetDriverByName("ESRI Shapefile")
      ds = driver.Open("nbac_2016_r2_20170707_1114.shp", 0) #open your shapefile
      #get its layer
      layer = ds.GetLayer()

      #create new shapefile to convert
      ds2 = driver.CreateDataSource('convertedShape.shp')
      #create a Polygon layer, as the one your Shapefile has
      layer2 = ds2.CreateLayer('', None, ogr.wkbPolygon)
      #iterate over all features of your original shapefile
      for feature in layer:
      #and create a new feature on your converted shapefile with those features
      layer2.CreateFeature(feature)

      ds = layer = ds2 = layer2 = None


      This also enabled to successfully open with df = gpd.read_file("convertedShape.shp") after conversion. Hope this helps.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 14 '17 at 1:42









      DarkCygnusDarkCygnus

      3,23831936




      3,23831936













      • thank you! I don't have QGis. I tried pip installing osgeo but it doesn't seem to be working. Any idea how I can download tha library?

        – Julien
        Nov 14 '17 at 2:04













      • @Julien several options are provided here. I think I installed it with apt-get install python-gdal, or with pip install GDAL... most likely the first one, but that Q I linked has several alternatives (easiest if you have conda). Hope my answer was useful :)

        – DarkCygnus
        Nov 14 '17 at 2:50













      • @Julien as a side comment, I suggest you give QGis a try (it is Open), as it usually always comes handy to inspect that shapefiles and rasters are the way we expect (encoding, attributes, etc.) before processing or reading them.

        – DarkCygnus
        Nov 14 '17 at 3:01











      • Thanks for the advice! I think I will install QGis.

        – Julien
        Nov 14 '17 at 3:23











      • @Julien glad it helped :) good luck with your coding.

        – DarkCygnus
        Nov 14 '17 at 3:26



















      • thank you! I don't have QGis. I tried pip installing osgeo but it doesn't seem to be working. Any idea how I can download tha library?

        – Julien
        Nov 14 '17 at 2:04













      • @Julien several options are provided here. I think I installed it with apt-get install python-gdal, or with pip install GDAL... most likely the first one, but that Q I linked has several alternatives (easiest if you have conda). Hope my answer was useful :)

        – DarkCygnus
        Nov 14 '17 at 2:50













      • @Julien as a side comment, I suggest you give QGis a try (it is Open), as it usually always comes handy to inspect that shapefiles and rasters are the way we expect (encoding, attributes, etc.) before processing or reading them.

        – DarkCygnus
        Nov 14 '17 at 3:01











      • Thanks for the advice! I think I will install QGis.

        – Julien
        Nov 14 '17 at 3:23











      • @Julien glad it helped :) good luck with your coding.

        – DarkCygnus
        Nov 14 '17 at 3:26

















      thank you! I don't have QGis. I tried pip installing osgeo but it doesn't seem to be working. Any idea how I can download tha library?

      – Julien
      Nov 14 '17 at 2:04







      thank you! I don't have QGis. I tried pip installing osgeo but it doesn't seem to be working. Any idea how I can download tha library?

      – Julien
      Nov 14 '17 at 2:04















      @Julien several options are provided here. I think I installed it with apt-get install python-gdal, or with pip install GDAL... most likely the first one, but that Q I linked has several alternatives (easiest if you have conda). Hope my answer was useful :)

      – DarkCygnus
      Nov 14 '17 at 2:50







      @Julien several options are provided here. I think I installed it with apt-get install python-gdal, or with pip install GDAL... most likely the first one, but that Q I linked has several alternatives (easiest if you have conda). Hope my answer was useful :)

      – DarkCygnus
      Nov 14 '17 at 2:50















      @Julien as a side comment, I suggest you give QGis a try (it is Open), as it usually always comes handy to inspect that shapefiles and rasters are the way we expect (encoding, attributes, etc.) before processing or reading them.

      – DarkCygnus
      Nov 14 '17 at 3:01





      @Julien as a side comment, I suggest you give QGis a try (it is Open), as it usually always comes handy to inspect that shapefiles and rasters are the way we expect (encoding, attributes, etc.) before processing or reading them.

      – DarkCygnus
      Nov 14 '17 at 3:01













      Thanks for the advice! I think I will install QGis.

      – Julien
      Nov 14 '17 at 3:23





      Thanks for the advice! I think I will install QGis.

      – Julien
      Nov 14 '17 at 3:23













      @Julien glad it helped :) good luck with your coding.

      – DarkCygnus
      Nov 14 '17 at 3:26





      @Julien glad it helped :) good luck with your coding.

      – DarkCygnus
      Nov 14 '17 at 3:26













      3














      with fiona.open(file, encoding="UTF-8") as f:


      worked for me.






      share|improve this answer




























        3














        with fiona.open(file, encoding="UTF-8") as f:


        worked for me.






        share|improve this answer


























          3












          3








          3







          with fiona.open(file, encoding="UTF-8") as f:


          worked for me.






          share|improve this answer













          with fiona.open(file, encoding="UTF-8") as f:


          worked for me.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 '18 at 15:47









          VladVlad

          434




          434























              0














              Since you have GDAL installed, I recommend converting the file to UTF-8 using the CLI:



              ogr2ogr output.shp input.shp -lco ENCODING=UTF-8


              Worked like a charm for me. It's much faster than QGIS or Python and can be applied in a cluster environment.






              share|improve this answer




























                0














                Since you have GDAL installed, I recommend converting the file to UTF-8 using the CLI:



                ogr2ogr output.shp input.shp -lco ENCODING=UTF-8


                Worked like a charm for me. It's much faster than QGIS or Python and can be applied in a cluster environment.






                share|improve this answer


























                  0












                  0








                  0







                  Since you have GDAL installed, I recommend converting the file to UTF-8 using the CLI:



                  ogr2ogr output.shp input.shp -lco ENCODING=UTF-8


                  Worked like a charm for me. It's much faster than QGIS or Python and can be applied in a cluster environment.






                  share|improve this answer













                  Since you have GDAL installed, I recommend converting the file to UTF-8 using the CLI:



                  ogr2ogr output.shp input.shp -lco ENCODING=UTF-8


                  Worked like a charm for me. It's much faster than QGIS or Python and can be applied in a cluster environment.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 28 '18 at 2:16









                  Adam EricksonAdam Erickson

                  1,7641320




                  1,7641320






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • 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%2fstackoverflow.com%2fquestions%2f47243879%2fbrecode-from-ansi-1252-to-utf-8-failed-with-the-error-invalid-argument-geo%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

                      Full-time equivalent

                      さくらももこ

                      13 indicted, 8 arrested in Calif. drug cartel investigation