You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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'
)
The text was updated successfully, but these errors were encountered:
This indeed seems to be the same issue as #205. While I fixed the error for that issue, I forgot to push it as a new bugfix version to pyshp. I just tried locally with the file you linked to and it worked without issue. Will push the new 2.1.3 to pyshp shortly, in the meanwhile, just install pyshp from GitHub: pip install --upgrade --no-deps --force-reinstall https://github.com/GeospatialPython/pyshp/archive/master.zip.
As an aside, I see in your example code that you are looping through each individual feature of a shapefile, and dumping a FeatureCollection for each individual feature. If this is what you intend, you need to be wrapping your individual feature in list brackets for it to be correct geojson. Something like this:
Thank you for the response. I caught the [feature] issue after recent load into the database. Splitting out the features because of a limit on JSON doc length. Will test the new code. Appreciate your prompt engagement.
Uh oh!
There was an error while loading. Please reload this page.
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:
The text was updated successfully, but these errors were encountered: