Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "shapely in functional component" in Python

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'shapely' in functional components in Python. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

def test_water_layer(self):
        # water layer should be clipped to the tile bounds expanded by 10%.

        from ModestMaps.Core import Coordinate
        from tilequeue.tile import coord_to_mercator_bounds
        from shapely import wkb

        tile = Coordinate(zoom=15, column=10, row=10)
        bounds = coord_to_mercator_bounds(tile)

        read_row = self._test('water', tile, 1.0)
        clipped_shape = wkb.loads(read_row['__geometry__'])
        # for water layer, the geometry should be 10% larger than the tile
        # bounds.
        x_factor = ((clipped_shape.bounds[2] - clipped_shape.bounds[0]) /
                    (bounds[2] - bounds[0]))
        y_factor = ((clipped_shape.bounds[2] - clipped_shape.bounds[0]) /
                    (bounds[2] - bounds[0]))
        self.assertAlmostEqual(1.1, x_factor)
        self.assertAlmostEqual(1.1, y_factor)
def test_numpy(self):

        from numpy import array, asarray
        from numpy.testing import assert_array_equal

        # Construct from a numpy array
        geom = MultiPoint(array([[0.0, 0.0], [1.0, 2.0]]))
        self.assertIsInstance(geom, MultiPoint)
        self.assertEqual(len(geom.geoms), 2)
        self.assertEqual(dump_coords(geom), [[(0.0, 0.0)], [(1.0, 2.0)]])

        # Geo interface (cont.)
        geom = MultiPoint((Point(1.0, 2.0), Point(3.0, 4.0)))
        assert_array_equal(array(geom), array([[1., 2.], [3., 4.]]))

        # Adapt a Numpy array to a multipoint
        a = array([[1.0, 2.0], [3.0, 4.0]])
        geoma = asMultiPoint(a)
        assert_array_equal(geoma.context, array([[1., 2.], [3., 4.]]))
        self.assertEqual(dump_coords(geoma), [[(1.0, 2.0)], [(3.0, 4.0)]])

        # Now, the inverse
        self.assertEqual(geoma.__array_interface__,
                         geoma.context.__array_interface__)

        pas = asarray(geoma)
        assert_array_equal(pas, array([[1., 2.], [3., 4.]]))
def test_point(self):

        # Test 2D points
        p = Point(1.0, 2.0)
        self.assertEqual(p.x, 1.0)
        self.assertEqual(p.y, 2.0)
        self.assertEqual(p.coords[:], [(1.0, 2.0)])
        self.assertEqual(str(p), p.wkt)
        self.assertFalse(p.has_z)
        with self.assertRaises(DimensionError):
            p.z

        # Check 3D
        p = Point(1.0, 2.0, 3.0)
        self.assertEqual(p.coords[:], [(1.0, 2.0, 3.0)])
        self.assertEqual(str(p), p.wkt)
        self.assertTrue(p.has_z)
        self.assertEqual(p.z, 3.0)

        # From coordinate sequence
        p = Point((3.0, 4.0))
        self.assertEqual(p.coords[:], [(3.0, 4.0)])

        # From another point
        q = Point(p)
        self.assertEqual(q.coords[:], [(3.0, 4.0)])

        # Coordinate access
        self.assertEqual(p.x, 3.0)
        self.assertEqual(p.y, 4.0)
def test_azimuth_west(self):
        assert azimuth(Point(0, 0), Point(-10, 0)) == 270
def test_linstring_m_wkt(self):
        df = pd.DataFrame([
            {'geometry':Point(0,0), 't':datetime(1970,1,1,0,0,1)},
            {'geometry':Point(6,0), 't':datetime(1970,1,1,0,0,2)},
            {'geometry':Point(10,0), 't':datetime(1970,1,1,0,0,3)}
            ]).set_index('t')
        geo_df = GeoDataFrame(df, crs={'init': '31256'})
        traj = Trajectory(1,geo_df)
        result = traj.to_linestringm_wkt()
        expected_result = "LINESTRING M (0.0 0.0 1.0, 6.0 0.0 2.0, 10.0 0.0 3.0)"        
        self.assertEqual(result, expected_result)
def test_geometry_area_perimeter__polygon():
    geod = Geod(ellps="WGS84")
    assert_almost_equal(
        geod.geometry_area_perimeter(
            Polygon(LineString([Point(1, 2), Point(3, 4), Point(5, 2)]))
        ),
        (-49187690467.58623, 1072185.2103813463),
        decimal=2,
    )
def test_iterops(self):

        coords = ((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0))
        polygon = Polygon(coords)
        points = [Point(0.5, 0.5), Point(2.0, 2.0)]

        # List of the points contained by the polygon
        self.assertTrue(
            all([isinstance(x, Point)
                 for x in iterops.contains(polygon, points, True)]))

        # 'True' is the default value
        self.assertTrue(
            all([isinstance(x, Point)
                 for x in iterops.contains(polygon, points)]))

        # Test a false value
        self.assertTrue(
            all([isinstance(x, Point)
                 for x in iterops.contains(polygon, points, False)]))
def test_feature(self):
        import shapely.geometry
        shape = shapely.geometry.LineString([(0, 0), (1, 1), (1, 0)])
        props = {
            'boundary': 'administrative',
            'admin_level': '2',
        }
        meta = make_test_metadata()
        out_min_zoom = self.boundaries.fn(shape, props, None, meta)
        self.assertEquals(8, out_min_zoom)
def test_parallel_offset_linestring(self):
        line1 = LineString([(0, 0), (10, 0)])
        left = line1.parallel_offset(5, 'left')
        self.assertEqual(left, LineString([(0, 5), (10, 5)]))
        right = line1.parallel_offset(5, 'right')
        self.assertEqual(right, LineString([(10, -5), (0, -5)]))
        right = line1.parallel_offset(-5, 'left')
        self.assertEqual(right, LineString([(10, -5), (0, -5)]))
        left = line1.parallel_offset(-5, 'right')
        self.assertEqual(left, LineString([(0, 5), (10, 5)]))

        # by default, parallel_offset is right-handed
        self.assertEqual(line1.parallel_offset(5), right)

        line2 = LineString([(0, 0), (5, 0), (5, -5)])
        self.assertEqual(line2.parallel_offset(2, 'left', resolution=1),
                         LineString([(0, 2), (5, 2), (7, 0), (7, -5)]))
        self.assertEqual(line2.parallel_offset(2, 'left', join_style=2,
                         resolution=1),
                         LineString([(0, 2), (7, 2), (7, -5)]))
def test_natural_forest_way(self):
        # Way: natural: Forest in POIS
        # note: since #1103, there should be no POIs for natural_forest,
        # only label placements in the landuse layer.
        self.generate_fixtures(dsl.way(202680509, wkt_loads('POLYGON ((-72.8282241701547 41.55614730899158, -72.82812769109321 41.55637606326199, -72.8279667129943 41.55658491930441, -72.82781651467879 41.5568056727527, -72.8276770961467 41.55695819654311, -72.8274087693713 41.5571548838084, -72.82728013062258 41.5572231125046, -72.82711385246348 41.55733550484018, -72.82694748447291 41.55735956968099, -72.82680267604908 41.55735956968099, -72.8266793373606 41.5572752754789, -72.82659336858789 41.55715091780307, -72.8265880685277 41.5569942940115, -72.82660953826299 41.55681367202608, -72.8267328769515 41.55660091790489, -72.82680267604908 41.55641229549799, -72.82690463483389 41.55614327570299, -72.8269947358569 41.5559353593372, -72.8272747407309 41.55583015730019, -72.8275161180478 41.55573389560568, -72.82773072556908 41.55566956421178, -72.82791847346348 41.55568569748268, -72.82811691130981 41.55577395984789, -72.82818132051568 41.55586228931429, -72.82820198176718 41.55594261927978, -72.82820809031109 41.5560308812941, -72.8282241701547 41.55614730899158))'), {u'natural': u'forest', u'name': u'Mine Island', u'way_area': u'29390.7', u'ele': u'134', u'source': u'openstreetmap.org', u'place': u'island'}))  # noqa

        self.assert_no_matching_feature(
            14, 4877, 6109, 'pois',
            {'id': 202680509, 'kind': 'natural_forest'})

        # Label placement forest in landuse
        self.assert_has_feature(
            15, 9755, 12218, 'landuse',
            {'id': 202680509, 'kind': 'natural_forest',
             'label_placement': True})

Is your System Free of Underlying Vulnerabilities?
Find Out Now