Skip to main content
deleted 41 characters in body
Source Link
user2856
  • 69.6k
  • 6
  • 119
  • 203

That example code you link to looks like it's out of date (for an old version of pyshp).

This works (based on bits and pieces from the docs):

shp = r"path/to/shp"  # NOTE no .shp extension

import os.path
from shapefile import (Reader, Writer)

try:  # Py2 (I haven't actually tested on python 2...)
    from StringIO import StringIO as IO
except ImportError:  # Py3
    from io import BytesIO as IO

with IO() as shpio, IO() as dbfio:  # Don't overwrite existing .shp, .dbf
    with Reader(shp) as r, Writer(shp=shpio, dbf=dbfio, shx=os.path.splitext(shp)[0]+'shx=shp+'.shx') as w:
        w.fields = r.fields[1:]  # skip first deletion field
        for rec in r.iterShapeRecords():
            w.record(*rec.record)
            w.shape(rec.shape)

That example code you link to looks like it's out of date (for an old version of pyshp).

This works (based on bits and pieces from the docs):

shp = r"path/to/shp"  # NOTE no .shp extension

import os.path
from shapefile import (Reader, Writer)

try:  # Py2 (I haven't actually tested on python 2...)
    from StringIO import StringIO as IO
except ImportError:  # Py3
    from io import BytesIO as IO

with IO() as shpio, IO() as dbfio:  # Don't overwrite existing .shp, .dbf
    with Reader(shp) as r, Writer(shp=shpio, dbf=dbfio, shx=os.path.splitext(shp)[0]+'.shx') as w:
        w.fields = r.fields[1:]  # skip first deletion field
        for rec in r.iterShapeRecords():
            w.record(*rec.record)
            w.shape(rec.shape)

That example code you link to looks like it's out of date (for an old version of pyshp).

This works (based on bits and pieces from the docs):

shp = r"path/to/shp"  # NOTE no .shp extension

from shapefile import (Reader, Writer)

try:  # Py2 (I haven't actually tested on python 2...)
    from StringIO import StringIO as IO
except ImportError:  # Py3
    from io import BytesIO as IO

with IO() as shpio, IO() as dbfio:  # Don't overwrite existing .shp, .dbf
    with Reader(shp) as r, Writer(shp=shpio, dbf=dbfio, shx=shp+'.shx') as w:
        w.fields = r.fields[1:]  # skip first deletion field
        for rec in r.iterShapeRecords():
            w.record(*rec.record)
            w.shape(rec.shape)
added 41 characters in body
Source Link
user2856
  • 69.6k
  • 6
  • 119
  • 203

That example code you link to looks like it's out of date (for an old version of pyshp).

This works (based on bits and pieces from the docs):

shp = r"path/to/shp"  # NOTE no .shp extension

import os.path
from shapefile import (Reader, Writer)

try:  # Py2 (I haven't actually tested on python 2...)
    from StringIO import StringIO as IO
except ImportError:  # Py3
    from io import BytesIO as IO

with IO() as shpio, IO() as dbfio:  # Don't overwrite existing .shp, .dbf
    with Reader(shp) as r, Writer(shp=shpio, dbf=dbfio, shx=shp+'shx=os.path.splitext(shp)[0]+'.shx') as w:
        w.fields = r.fields[1:]  # skip first deletion field
        for rec in r.iterShapeRecords():
            w.record(*rec.record)
            w.shape(rec.shape)

That example code you link to looks like it's out of date (for an old version of pyshp).

This works (based on bits and pieces from the docs):

shp = r"path/to/shp"  # NOTE no .shp extension

from shapefile import (Reader, Writer)

try:  # Py2 (I haven't actually tested on python 2...)
    from StringIO import StringIO as IO
except ImportError:  # Py3
    from io import BytesIO as IO

with IO() as shpio, IO() as dbfio:  # Don't overwrite existing .shp, .dbf
    with Reader(shp) as r, Writer(shp=shpio, dbf=dbfio, shx=shp+'.shx') as w:
        w.fields = r.fields[1:]  # skip first deletion field
        for rec in r.iterShapeRecords():
            w.record(*rec.record)
            w.shape(rec.shape)

That example code you link to looks like it's out of date (for an old version of pyshp).

This works (based on bits and pieces from the docs):

shp = r"path/to/shp"  # NOTE no .shp extension

import os.path
from shapefile import (Reader, Writer)

try:  # Py2 (I haven't actually tested on python 2...)
    from StringIO import StringIO as IO
except ImportError:  # Py3
    from io import BytesIO as IO

with IO() as shpio, IO() as dbfio:  # Don't overwrite existing .shp, .dbf
    with Reader(shp) as r, Writer(shp=shpio, dbf=dbfio, shx=os.path.splitext(shp)[0]+'.shx') as w:
        w.fields = r.fields[1:]  # skip first deletion field
        for rec in r.iterShapeRecords():
            w.record(*rec.record)
            w.shape(rec.shape)
deleted 3 characters in body
Source Link
user2856
  • 69.6k
  • 6
  • 119
  • 203

That example code you link to looks like it's out of date (for an old version of pyshp).

This works (based on bits and pieces from the docs):

shp = r"path/to/shp"  # NOTE no .shp extension!!!

from shapefile import (Reader, Writer)

try:  # Py2 (I haven't actually tested on python 2...)
    from StringIO import StringIO as IO
except ImportError:  # Py3
    from io import BytesIO as IO

with IO() as shpio, IO() as dbfio:  # Don't overwrite existing .shp, .dbf
    with Reader(shp) as r, Writer(shp=shpio, dbf=dbfio, shx=shp+'.shx') as w:
        w.fields = r.fields[1:]  # skip first deletion field
        for rec in r.iterShapeRecords():
            w.record(*rec.record)
            w.shape(rec.shape)

That example code you link to looks like it's out of date (for an old version of pyshp).

This works (based on bits and pieces from the docs):

shp = r"path/to/shp"  # NOTE no .shp extension!!!

from shapefile import (Reader, Writer)

try:  # Py2 (I haven't actually tested on python 2...)
    from StringIO import StringIO as IO
except ImportError:  # Py3
    from io import BytesIO as IO

with IO() as shpio, IO() as dbfio:  # Don't overwrite existing .shp, .dbf
    with Reader(shp) as r, Writer(shp=shpio, dbf=dbfio, shx=shp+'.shx') as w:
        w.fields = r.fields[1:]  # skip first deletion field
        for rec in r.iterShapeRecords():
            w.record(*rec.record)
            w.shape(rec.shape)

That example code you link to looks like it's out of date (for an old version of pyshp).

This works (based on bits and pieces from the docs):

shp = r"path/to/shp"  # NOTE no .shp extension

from shapefile import (Reader, Writer)

try:  # Py2 (I haven't actually tested on python 2...)
    from StringIO import StringIO as IO
except ImportError:  # Py3
    from io import BytesIO as IO

with IO() as shpio, IO() as dbfio:  # Don't overwrite existing .shp, .dbf
    with Reader(shp) as r, Writer(shp=shpio, dbf=dbfio, shx=shp+'.shx') as w:
        w.fields = r.fields[1:]  # skip first deletion field
        for rec in r.iterShapeRecords():
            w.record(*rec.record)
            w.shape(rec.shape)
added 1 character in body
Source Link
user2856
  • 69.6k
  • 6
  • 119
  • 203
Loading
Source Link
user2856
  • 69.6k
  • 6
  • 119
  • 203
Loading