Skip to content

Commit

Permalink
Skip geometries for points that have NaN coords
Browse files Browse the repository at this point in the history
  • Loading branch information
iandees committed Sep 10, 2016
1 parent 4c7f076 commit 3729050
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion esridump/esri2geojson.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from itertools import tee
import math

def esri2geojson(esrijson_feature):
response = dict(type="Feature", geometry=None, properties=None)
Expand Down Expand Up @@ -29,7 +30,7 @@ def convert_esri_point(esri_geometry):
x_coord = esri_geometry.get('x')
y_coord = esri_geometry.get('y')

if x_coord and y_coord:
if x_coord and y_coord and not math.isnan(x_coord) and not math.isnan(y_coord):
return {
"type": "Point",
"coordinates": [x_coord, y_coord]
Expand Down
30 changes: 30 additions & 0 deletions tests/esrijson_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,36 @@ def test_empty_point(self):
}
)

def test_nan_point(self):
self.assertEsriJsonBecomesGeoJson(
{
"geometry": {
"x": float('nan'),
"y": float('nan'),
},
},

{
"type": "Feature",
"properties": None,
"geometry": None
}
)

self.assertEsriJsonBecomesGeoJson(
{
"geometry": {
"points": [float('nan'), float('nan')]
},
},

{
"type": "Feature",
"properties": None,
"geometry": None
}
)


class TestGeoJsonLinestringConversion(TestEsriJsonToGeoJson):
def test_linestring(self):
Expand Down

0 comments on commit 3729050

Please sign in to comment.