Beispiel #1
0
 def test_round2(self):
     expectation = {
         'coordinates': [((1.0, 0.0), (0.71, -0.71), (0.0, -1.0),
                          (-0.71, -0.71), (-1.0, 0.0), (-0.71, 0.71),
                          (0.0, 1.0), (0.71, 0.71), (1.0, 0.0))],
         'type':
         'Polygon'
     }
     rounded = util.round_geom(self.polygon, 2)
     self.assertEqual(rounded, expectation)
Beispiel #2
0
 def test_round2(self):
     expectation = {
         'coordinates':
         ((1.0, 0.0), (0.71, -0.71), (0.0, -1.0), (-0.71, -0.71),
          (-1.0, 0.0), (-0.71, 0.71), (0.0, 1.0), (0.71, 0.71), (1.0, 0.0)),
         'type':
         'LineString'
     }
     rounded = util.round_geom(self.linestring, 2)
     self.assertEqual(rounded, expectation)
Beispiel #3
0
 def test_round1(self):
     expectation = {
         'coordinates':
         [[((1.0, 0.0), (0.7, -0.7), (0.0, -1.0), (-0.7, -0.7), (-1.0, 0.0),
            (-0.7, 0.7), (0.0, 1.0), (0.7, 0.7), (1.0, 0.0))]],
         'type':
         'MultiPolygon'
     }
     rounded = util.round_geom(self.multipolygon, 1)
     self.assertEqual(rounded, expectation)
Beispiel #4
0
 def test_round2(self):
     expectation = {
         'coordinates': (
             (1.0, 0.0),
             (0.71, -0.71),
             (0.0, -1.0),
             (-0.71, -0.71),
             (-1.0, 0.0),
             (-0.71, 0.71),
             (0.0, 1.0),
             (0.71, 0.71),
             (1.0, 0.0)),
         'type': 'LineString'}
     rounded = util.round_geom(self.linestring, 2)
     self.assertEqual(rounded, expectation)
Beispiel #5
0
 def test_round1(self):
     expectation = {
         'coordinates': [[(
             (1.0, 0.0),
             (0.7, -0.7),
             (0.0, -1.0),
             (-0.7, -0.7),
             (-1.0, 0.0),
             (-0.7, 0.7),
             (0.0, 1.0),
             (0.7, 0.7),
             (1.0, 0.0))]],
         'type': 'MultiPolygon'}
     rounded = util.round_geom(self.multipolygon, 1)
     self.assertEqual(rounded, expectation)
Beispiel #6
0
 def test_round2(self):
     expectation = {
         'coordinates': [(
             (1.0, 0.0),
             (0.71, -0.71),
             (0.0, -1.0),
             (-0.71, -0.71),
             (-1.0, 0.0),
             (-0.71, 0.71),
             (0.0, 1.0),
             (0.71, 0.71),
             (1.0, 0.0))],
         'type': 'Polygon'}
     rounded = util.round_geom(self.polygon, 2)
     self.assertEqual(rounded, expectation)
Beispiel #7
0
def translate(text, output_format='json', indent=None, precision=-1):
    if text.startswith('{'):
        geom = json.loads(text)
    elif text.startswith(('G', 'L', 'M', 'P')):
        geom = wkt.loads(text)
    else:
        geom = wkb.loads(a2b_hex(text))
    if output_format == 'wkb':
        output = b2a_hex(wkb.dumps(geom))
    elif output_format == 'wkt':
        kwds = {}
        if precision >= 0:
            kwds['decimals'] = precision
        output = wkt.dumps(geom, **kwds)
    else:
        if precision >= 0:
            geom = util.round_geom(geom, precision)
        output = json.dumps(geom, indent=indent, sort_keys=True)
    return output
Beispiel #8
0
 def test_round1(self):
     expectation = {
         'coordinates': (0.7, -0.7),
         'type': 'Point'}
     rounded = util.round_geom(self.point, 1)
     self.assertEqual(rounded, expectation)
Beispiel #9
0
 def test_round1(self):
     expectation = {'coordinates': (0.7, -0.7), 'type': 'Point'}
     rounded = util.round_geom(self.point, 1)
     self.assertEqual(rounded, expectation)