Exemple #1
0
 def test_within_no(self):
     this = Geometry.build_geometry('POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))')
     other = Geometry.build_geometry(
         'POLYGON ((0.5 0, 1.5 0, 1.5 1, 0.5 0))')
     operation = Within()
     result = operation(this, other)
     self.assertFalse(result)
Exemple #2
0
 def test_intersects_yes(self):
     this = Geometry.build_geometry('POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))')
     other = Geometry.build_geometry(
         'POLYGON ((0.5 0, 1.5 0, 1.5 1, 0.5 0))')
     operation = Intersects()
     result = operation(this, other)
     self.assertTrue(result)
Exemple #3
0
 def test_envelope(self):
     this = Geometry.build_geometry(
         'MULTIPOINT (0 0, 1 1, 0 2, 2 2, 3 1, 1 0)')
     operation = Envelope()
     result = operation(this)
     reference = Geometry.build_geometry(
         'POLYGON ((0 0, 3 0, 3 2, 0 2, 0 0))')
     self.assertTrue(result.equals(reference))
Exemple #4
0
 def test_unary(self):
     this = Geometry.build_geometry('POINT (1 1)')
     operation = UnaryOperation(srid=3857)
     result = operation(this)
     reference = Geometry.build_geometry(
         'POINT (111319.4907932723 111325.1428663849)')
     self.assertTrue(reference.almost_equals(result, 7))
     self.assertEqual(result.crs.srid, 3857)
Exemple #5
0
 def test_convex_hull_of_points(self):
     this = Geometry.build_geometry(
         'MULTIPOINT (0 0, 1 1, 0 2, 2 2, 3 1, 1 0)')
     operation = ConvexHull()
     result = operation(this)
     reference = Geometry.build_geometry(
         'POLYGON ((0 0, 0 2, 2 2, 3 1, 1 0, 0 0))')
     self.assertTrue(result.equals(reference))
Exemple #6
0
 def test_intersection(self):
     this = Geometry.build_geometry('POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))')
     other = Geometry.build_geometry(
         'POLYGON ((0.5 0, 1.5 0, 1.5 1, 0.5 0))')
     operation = Intersection()
     result = operation(this, other)
     reference = Geometry.build_geometry(
         'POLYGON ((0.5 0, 1 0, 1 0.5, 0.5 0))')
     self.assertTrue(result.equals(reference))
Exemple #7
0
    def test_difference(self):
        this = Geometry.build_geometry('POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))')
        other = Geometry.build_geometry(
            'POLYGON ((0.5 0, 1.5 0, 1.5 1, 0.5 0))')
        operation = SymmetricDifference()
        result = operation(this, other)

        reference = Geometry.build_geometry(
            'MULTIPOLYGON (((0 0, 0 1, 1 1, 1 0.5, 0.5 0, 0 0)), ((1 0, 1 0.5, 1.5 1, 1.5 0, 1 0)))')
        self.assertTrue(result.equals(reference))
Exemple #8
0
    def test_geojson(self):
        geom1 = Geometry.build_geometry(
            '{ "type": "Point", "coordinates": [ 1.0, 2.0 ] }')
        self.assertTrue(geom1.equals(shapely.geometry.Point(1, 2)))
        self.assertTrue(geom1.crs.equals(SpatialReference(srid=4326)))

        geom2 = Geometry.build_geometry(
            u'{ "type": "Point", "coordinates": [ 1.0, 2.0 ] }')
        self.assertTrue(geom2.equals(shapely.geometry.Point(1, 2)))
        self.assertTrue(geom2.crs.equals(SpatialReference(srid=4326)))
Exemple #9
0
    def test_make_metadata(self):
        geometry = Geometry.build_geometry('POINT (1 1)')
        metadata = Metadata.make_metadata(geometry=geometry)

        self.assertIsInstance(metadata, Metadata)
        self.assertIsNotNone(metadata.geohash)
        self.assertIsNotNone(metadata.bbox)

        metadata2 = metadata.spawn(
            geometry=Geometry.build_geometry('POINT (1 2)'))
        self.assertNotEqual(metadata, metadata2)
Exemple #10
0
    def test_wkb(self):
        geom1 = Geometry.build_geometry(
            '0101000000000000000000F03F0000000000000040')
        self.assertTrue(geom1.equals(shapely.geometry.Point(1, 2)))
        self.assertTrue(geom1.crs.equals(SpatialReference(srid=4326)))

        geom2 = Geometry.build_geometry(
            buffer(
                '\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\x00@'))
        self.assertTrue(geom2.equals(shapely.geometry.Point(1, 2)))
        self.assertTrue(geom2.crs.equals(SpatialReference(srid=4326)))
Exemple #11
0
    def test_literal(self):
        geom1 = Geometry.build_geometry(
            {"type": "Point", "coordinates": [1.0, 2.0]})
        self.assertTrue(geom1.equals(shapely.geometry.Point(1, 2)))
        self.assertTrue(geom1.crs.equals(SpatialReference(srid=4326)))

        geom2 = Geometry.build_geometry(
            {"type": "Point", "coordinates": [1.0, 2.0],
             "crs": {'type': 'name',
                     'properties': {
                         'name': 'EPSG:3857'
                     }}})
        self.assertTrue(geom2.crs.equals(SpatialReference(srid=3857)))
Exemple #12
0
 def test_update_geometry(self):
     feature1 = Feature.build_from_geometry('POINT (1 2)',
                                            properties=dict(x=1, y=2))
     metadata1 = feature1.metadata
     feature1.geometry = Geometry.build_geometry('POINT (3 4)')
     metadata2  = feature1.metadata
     self.assertNotEqual(metadata1, metadata2)
Exemple #13
0
 def test_geometry_types_copy(self):
     for k, v in jsondata.iteritems():
         geometry = Geometry.build_geometry(v, copy=True)
         self.assertDictEqual(
             json.loads(geometry.geojson),
             pydata[k]
         )
Exemple #14
0
    def test_calc_bbox(self):
        geom1 = Geometry.build_geometry('POINT (5 10)')
        bbox1 = calc_bbox(geom1)
        self.assertListEqual(list(bbox1), [5, 10, 5, 10])

        geom2 = shapely.geometry.LineString([(5, 10), (10, 5)])
        bbox2 = calc_bbox(geom2)
        self.assertListEqual(list(bbox2), [5, 5, 10, 10])
Exemple #15
0
    def test_wkt(self):
        # self.assertRaises(NotImplementedError, Geometry)

        geom1 = Geometry.build_geometry('POINT(1 2)')
        self.assertTrue(geom1.equals(shapely.geometry.Point(1, 2)))
        self.assertTrue(geom1.crs.equals(SpatialReference(srid=4326)))

        geom2 = Geometry.build_geometry('POINT(1 2)', srid=3857)
        self.assertTrue(geom2.crs.equals(SpatialReference(srid=3857)))

        geom3 = Geometry.build_geometry('SRID=3857;POINT(1 2)')
        self.assertTrue(geom3.crs.equals(SpatialReference(srid=3857)))

        geom4 = Geometry.build_geometry('SRID=3857;POINT(1 2)', srid=4326)
        self.assertTrue(geom4.equals(shapely.geometry.Point(1, 2)))
        self.assertTrue(geom4.crs.equals(SpatialReference(srid=3857)))

        geom5 = Geometry.build_geometry(
            'GEOMETRYCOLLECTION (POINT (2 2), LINESTRING (0 0, 1 1))')

        self.assertEqual(geom5.geom_type, 'GeometryCollection')
Exemple #16
0
    def test_calc_geohash(self):
        geom1 = Geometry.build_geometry('POINT (126 48)', srid=3857)
        hash0 = calc_geohash(geom1, length=12)
        self.assertEqual(hash0, '')
        hash1 = calc_geohash(geom1, length=12, ignore_crs=True)
        self.assertEqual('yb9954nkkb99', hash1)

        geom2 = shapely.geometry.LineString([(12, 34), (12.0001, 34.0001)])
        hash2 = calc_geohash(geom2, length=12, ignore_crs=True)
        self.assertEqual('sq093jd0', hash2)

        hash2 = calc_geohash(geom2, length=3, ignore_crs=True)
        self.assertEqual('sq0', hash2)
Exemple #17
0
 def test_create_from_geojson(self):
     for k, v in pydata.iteritems():
         data = {'type': 'Feature',
                 'geometry': v,
                 'properties':
                     {'type': 'snow'},
                 'crs':
                     {'type': 'name',
                      'properties': {
                          'name': 'EPSG:4326'
                      }}}
         feature = Feature.build_from_geojson(json.dumps(data))
         self.assertTrue(feature.geometry.equals(Geometry.build_geometry(v)))
Exemple #18
0
    def test_transform_multi(self):
        crs1 = SpatialReference(4326)
        crs2 = SpatialReference(3857)

        forward = CoordinateTransform(crs1, crs2)
        backward = CoordinateTransform(crs2, crs1)

        for k, v in jsondata.iteritems():
            geom1 = Geometry.build_geometry(v, copy=True)
            if k == "geometrycollection":
                self.assertRaises(CoordinateTransformationError, forward, geom1)
            else:
                geom2 = forward(geom1)
                geom3 = backward(geom2)
                self.assertTrue(geom1.almost_equals(geom3))
Exemple #19
0
 def test_is_simple(self):
     this = Geometry.build_geometry('LINESTRING (0 0, 1 1, 1 -1, 0 1)')
     operation = IsSimple()
     result = operation(this)
     self.assertFalse(result)
Exemple #20
0
 def test_contains_no(self):
     this = Geometry.build_geometry('LINESTRING (0 0, 1 1)')
     other = Geometry.build_geometry('POINT (1 1)')
     operation = Contains()
     result = operation(this, other)
     self.assertFalse(result)
Exemple #21
0
 def test_equals_no(self):
     this = Geometry.build_geometry('LINESTRING (0 0, 1 1)')
     other = Geometry.build_geometry('LINESTRING (0 0, 1 1.0001)')
     operation = Equals()
     result = operation(this, other)
     self.assertFalse(result)
Exemple #22
0
    def test_crs(self):
        this = Geometry.build_geometry('POINT (1 1)')
        operation = UnaryOperation()

        result = operation(this)
        self.assertIsNotNone(result.crs)
Exemple #23
0
 def test_disjoint_no(self):
     this = Geometry.build_geometry('LINESTRING (0 0, 1 1)')
     other = Geometry.build_geometry('LINESTRING (0 1, 1 0)')
     operation = Crosses()
     result = operation(this, other)
     self.assertTrue(result)
Exemple #24
0
 def test_area_empty(self):
     this = Geometry.build_geometry('POINT (1 1)')
     operation = Area()
     result = operation(this)
     self.assertAlmostEqual(result, 0.0)
Exemple #25
0
 def test_geometry_types_with_crs(self):
     for k, v in jsondata.iteritems():
         geometry = Geometry.build_geometry(v, copy=True, srid=3857)
         self.assertTrue('crs' in geometry.geojson)
Exemple #26
0
 def test_geometry(self):
     geom = shapely.geometry.Point(1, 2)
     geom2 = Geometry.build_geometry(geom)
     self.assertTrue(geom2.crs.equals(SpatialReference(srid=4326)))
Exemple #27
0
 def test_area(self):
     this = Geometry.build_geometry('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
     operation = Area()
     result = operation(this)
     self.assertAlmostEqual(result, 1.0)
Exemple #28
0
 def test_length_zero(self):
     this = Geometry.build_geometry('POINT (1 1)')
     operation = Length()
     result = operation(this)
     self.assertAlmostEqual(result, 0.0)
Exemple #29
0
 def test_area(self):
     this = Geometry.build_geometry('LINESTRING (0 0, 1 0, 1 1, 0 1)')
     operation = Length()
     result = operation(this)
     self.assertAlmostEqual(result, 3.0)
Exemple #30
0
 def test_buffer(self):
     this = Geometry.build_geometry('POINT (1 1)')
     operation = Buffer(distance=1., resolution=50)
     result = operation(this)
     self.assertAlmostEqual(result.area, 3.1415927, delta=0.001)