Skip to content

Unexpected error: Unable to find a ring sample point for multiple files #207

Closed
@tmesis

Description

@tmesis

Have an issue similar to #205. When using the __geo_interface__ to convert Shapefiles to GeoJSON, the following exception is encountered: Unexpected error: Unable to find a ring sample point. This happens for a subset of files downloaded from US Census Bureau's TIGER/LINE database. An example is tl_2019_37_cousub.zip (ftp://ftp2.census.gov/geo/tiger/TIGER2019/COUSUB/tl_2019_37_cousub.zip). Not sure if this and #205 arise from same issue.

For reference, my code is thus:

import json
from pathlib import Path
from typing import Dict, Iterator, TextIO, Union

import shapefile


def parse_features(shp: Union[Path, str], shx: Union[Path, str], dbf: Union[Path, str]) -> Iterator[Dict]:
    reader = shapefile.Reader(*map(str, (shp, shx, dbf)))
    fields = reader.fields[1:]
    field_names = [field[0] for field in fields]
    for shape, record in zip(reader.iterShapes(), reader.iterRecords()):
        yield dict(type='Feature', geometry=shape.__geo_interface__, properties=dict(zip(field_names, record)))


def shp_to_json(f: TextIO, shp: Union[Path, str], shx: Union[Path, str], dbf: Union[Path, str]):
    for features in parse_features(shp, shx, dbf):
        f.write(
            json.dumps({'type': 'FeatureCollection', 'features': features}, indent=2) + '\n'
        )

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions