Skip to content

Commit

Permalink
rename GeoJSONResult as Result, keeping an alias
Browse files Browse the repository at this point in the history
  • Loading branch information
njwilson23 committed Oct 13, 2017
1 parent 87097d6 commit 0616b92
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
12 changes: 6 additions & 6 deletions picogeojson/geojson.py
Expand Up @@ -7,7 +7,7 @@
- `fromstring()` and `fromfile()` return namedtuples from GeoJSON input
- `tostring()` returns GeoJSON from a namedtuple
- `result_fromstring()` and `result_fromfile()` return namedtuples wrapped as a
GeoJSONResult so that values of a specific types can be safely extracted
*Result* so that values of a specific types can be safely extracted
Additionally,
Expand Down Expand Up @@ -37,7 +37,7 @@
from .antimeridian import antimeridian_cut
from .bbox import (geom_bbox, geometry_collection_bbox,
feature_bbox, feature_collection_bbox)
from .result import GeoJSONResult
from .result import Result

DEFAULTCRS = {"type": "name",
"properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"}}
Expand Down Expand Up @@ -302,17 +302,17 @@ def fromstring(s, **kw):

@docstring_insert(deserializer_args)
def result_fromfile(f, **kw):
""" Read a JSON file and return a GeoJSONResult.
""" Read a JSON file and return a *Result*.
{} """
d = Deserializer(**kw)
return GeoJSONResult(d.fromfile(f))
return Result(d.fromfile(f))

@docstring_insert(deserializer_args)
def result_fromstring(s, **kw):
""" Read a JSON string and return a GeoJSONResult.
""" Read a JSON string and return a *Result*.
{} """
d = Deserializer(**kw)
return GeoJSONResult(d.fromstring(s))
return Result(d.fromstring(s))

@docstring_insert(serializer_args)
def todict(geom, **kw):
Expand Down
3 changes: 2 additions & 1 deletion picogeojson/result.py
@@ -1,5 +1,5 @@

class GeoJSONResult(object):
class Result(object):

def __init__(self, obj):
self.obj = obj
Expand Down Expand Up @@ -73,3 +73,4 @@ def features(self, geometry_type=None, properties=None):
for feat in obj.features:
objs.append(feat)

GeoJSONResult = Result
30 changes: 15 additions & 15 deletions tests/result_tests.py
Expand Up @@ -3,7 +3,7 @@
MultiPoint, MultiLineString, MultiPolygon,
GeometryCollection, Feature, FeatureCollection,
DEFAULTCRS)
from picogeojson.result import GeoJSONResult
from picogeojson.result import Result

class ResultTests(unittest.TestCase):

Expand Down Expand Up @@ -62,55 +62,55 @@ def setUp(self):
], DEFAULTCRS)

def test_get_points(self):
result = GeoJSONResult(self.geometrycollection)
result = Result(self.geometrycollection)
count = 0
for pt in result.points:
self.assertTrue(isinstance(pt, Point))
count += 1
self.assertEqual(count, 4)

def test_get_linestrings(self):
result = GeoJSONResult(self.geometrycollection)
result = Result(self.geometrycollection)
count = 0
for ls in result.linestrings:
self.assertTrue(isinstance(ls, LineString))
count += 1
self.assertEqual(count, 4)

def test_get_polygons(self):
result = GeoJSONResult(self.geometrycollection)
result = Result(self.geometrycollection)
count = 0
for pg in result.polygons:
self.assertTrue(isinstance(pg, Polygon))
count += 1
self.assertEqual(count, 2)

def test_get_multipoints(self):
result = GeoJSONResult(self.geometrycollection)
result = Result(self.geometrycollection)
count = 0
for mpt in result.multipoints:
self.assertTrue(isinstance(mpt, MultiPoint))
count += 1
self.assertEqual(count, 1)

def test_get_multilinestrings(self):
result = GeoJSONResult(self.geometrycollection)
result = Result(self.geometrycollection)
count = 0
for mls in result.multilinestrings:
self.assertTrue(isinstance(mls, MultiLineString))
count += 1
self.assertEqual(count, 1)

def test_get_multipolygons(self):
result = GeoJSONResult(self.geometrycollection)
result = Result(self.geometrycollection)
count = 0
for mpg in result.multipolygons:
self.assertTrue(isinstance(mpg, MultiPolygon))
count += 1
self.assertEqual(count, 1)

def test_get_point_features(self):
result = GeoJSONResult(self.featurecollection)
result = Result(self.featurecollection)
count = 0
for f in result.features("Point"):
self.assertTrue(isinstance(f, Feature))
Expand All @@ -119,7 +119,7 @@ def test_get_point_features(self):
self.assertEqual(count, 1)

def test_get_linestring_features(self):
result = GeoJSONResult(self.featurecollection)
result = Result(self.featurecollection)
count = 0
for f in result.features("LineString"):
self.assertTrue(isinstance(f, Feature))
Expand All @@ -128,7 +128,7 @@ def test_get_linestring_features(self):
self.assertEqual(count, 1)

def test_get_polygon_features(self):
result = GeoJSONResult(self.featurecollection)
result = Result(self.featurecollection)
count = 0
for f in result.features("Polygon"):
self.assertTrue(isinstance(f, Feature))
Expand All @@ -137,7 +137,7 @@ def test_get_polygon_features(self):
self.assertEqual(count, 1)

def test_get_multipoint_features(self):
result = GeoJSONResult(self.featurecollection)
result = Result(self.featurecollection)
count = 0
for f in result.features("MultiPoint"):
self.assertTrue(isinstance(f, Feature))
Expand All @@ -146,7 +146,7 @@ def test_get_multipoint_features(self):
self.assertEqual(count, 1)

def test_get_multilinestring_features(self):
result = GeoJSONResult(self.featurecollection)
result = Result(self.featurecollection)
count = 0
for f in result.features("MultiLineString"):
self.assertTrue(isinstance(f, Feature))
Expand All @@ -155,7 +155,7 @@ def test_get_multilinestring_features(self):
self.assertEqual(count, 1)

def test_get_multipolygon_features(self):
result = GeoJSONResult(self.featurecollection)
result = Result(self.featurecollection)
count = 0
for f in result.features("MultiPolygon"):
self.assertTrue(isinstance(f, Feature))
Expand All @@ -164,12 +164,12 @@ def test_get_multipolygon_features(self):
self.assertEqual(count, 1)

def test_features_argument_error(self):
result = GeoJSONResult(self.featurecollection)
result = Result(self.featurecollection)
with self.assertRaises(TypeError):
[a for a in result.features({"style": "stout"})]

def test_get_by_attributes(self):
result = GeoJSONResult(self.featurecollection)
result = Result(self.featurecollection)
count = 0
for f in result.features(properties={"style": "stout"}):
count += 1
Expand Down
6 changes: 3 additions & 3 deletions tests/tests.py
Expand Up @@ -17,7 +17,7 @@
from picogeojson import Serializer, Deserializer, merge, burst, DEFAULTCRS
import picogeojson.bbox as bbox
from picogeojson.geojson import fixed_precision
from picogeojson.result import GeoJSONResult
from picogeojson.result import Result

from type_tests import ClosedRingTests, InvalidCoordTests
from result_tests import ResultTests
Expand Down Expand Up @@ -54,7 +54,7 @@ def test_fromdict(self):

def test_shorthand_result(self):
res = pico.result_fromfile(os.path.join(TESTDATA, 'point.json'))
self.assertEqual(type(res), GeoJSONResult)
self.assertEqual(type(res), Result)
for pt in res.points:
self.assertEqual(pt.coordinates, [100.0, 0.0])
return
Expand All @@ -77,7 +77,7 @@ def test_shorthand_string_result(self):
with open(os.path.join(TESTDATA, 'point.json'), 'r') as f:
string = f.read()
res = pico.result_fromstring(string)
self.assertEqual(type(res), GeoJSONResult)
self.assertEqual(type(res), Result)
for pt in res.points:
self.assertEqual(pt.coordinates, [100.0, 0.0])
return
Expand Down

0 comments on commit 0616b92

Please sign in to comment.