Example #1
0
    def test_dataframe_to_geodataframe(self):
        df = pd.DataFrame({"A": range(len(self.df)), "location":
                           list(self.df.geometry)}, index=self.df.index)
        gf = df.set_geometry('location', crs=self.df.crs)
        self.assertIsInstance(df, pd.DataFrame)
        self.assertIsInstance(gf, GeoDataFrame)
        assert_geoseries_equal(gf.geometry, self.df.geometry)
        self.assertEqual(gf.geometry.name, 'location')
        self.assert_('geometry' not in gf)

        gf2 = df.set_geometry('location', crs=self.df.crs, drop=True)
        self.assertIsInstance(df, pd.DataFrame)
        self.assertIsInstance(gf2, GeoDataFrame)
        self.assertEqual(gf2.geometry.name, 'geometry')
        self.assert_('geometry' in gf2)
        self.assert_('location' not in gf2)
        self.assert_('location' in df)

        # should be a copy
        df.ix[0, "A"] = 100
        self.assertEqual(gf.ix[0, "A"], 0)
        self.assertEqual(gf2.ix[0, "A"], 0)

        with self.assertRaises(ValueError):
            df.set_geometry('location', inplace=True)
    def test_dataframe_to_geodataframe(self):
        df = pd.DataFrame({"A": range(len(self.df)), "location":
                           list(self.df.geometry)}, index=self.df.index)
        gf = df.set_geometry('location', crs=self.df.crs)
        assert isinstance(df, pd.DataFrame)
        assert isinstance(gf, GeoDataFrame)
        assert_geoseries_equal(gf.geometry, self.df.geometry)
        assert gf.geometry.name == 'location'
        assert 'geometry' not in gf

        gf2 = df.set_geometry('location', crs=self.df.crs, drop=True)
        assert isinstance(df, pd.DataFrame)
        assert isinstance(gf2, GeoDataFrame)
        assert gf2.geometry.name == 'geometry'
        assert 'geometry' in gf2
        assert 'location' not in gf2
        assert 'location' in df

        # should be a copy
        df.ix[0, "A"] = 100
        assert gf.ix[0, "A"] == 0
        assert gf2.ix[0, "A"] == 0

        with pytest.raises(ValueError):
            df.set_geometry('location', inplace=True)
Example #3
0
 def test_buffer_distance_array(self):
     original = GeoSeries([self.p0, self.p0])
     expected = GeoSeries(
         [Polygon(((6, 5), (5, 4), (4, 5), (5, 6), (6, 5))),
          Polygon(((10, 5), (5, 0), (0, 5), (5, 10), (10, 5))),
          ])
     calculated = original.buffer(np.array([1, 5]), resolution=1)
     assert_geoseries_equal(calculated, expected, check_less_precise=True)
Example #4
0
    def test_to_file_with_poly_z(self):
        """Test that 3D geometries are retained in writes (GH #612)."""

        tempfilename = os.path.join(self.tempdir, 'test_3Dpoly.shp')
        poly3d = Polygon([[0, 0, 5], [0, 1, 5], [1, 1, 5], [1, 0, 5]])
        poly2d = Polygon([[0, 0], [0, 1], [1, 1], [1, 0]])
        df = GeoDataFrame({'a': [1, 2]}, geometry=[poly3d, poly2d], crs={})
        df.to_file(tempfilename)
        df_read = GeoDataFrame.from_file(tempfilename)
        assert_geoseries_equal(df.geometry, df_read.geometry)
Example #5
0
    def test_to_file_with_point_z(self):
        """Test that 3D geometries are retained in writes (GH #612)."""

        tempfilename = os.path.join(self.tempdir, 'test_3Dpoint.shp')
        point3d = Point(0, 0, 500)
        point2d = Point(1, 1)
        df = GeoDataFrame({'a': [1, 2]}, geometry=[point3d, point2d], crs={})
        df.to_file(tempfilename)
        df_read = GeoDataFrame.from_file(tempfilename)
        assert_geoseries_equal(df.geometry, df_read.geometry)
Example #6
0
 def test_explode_geoseries(self):
     s = GeoSeries([MultiPoint([(0, 0), (1, 1)]),
                    MultiPoint([(2, 2), (3, 3), (4, 4)])])
     s.index.name = 'test_index_name'
     expected_index_name = ['test_index_name', None]
     index = [(0, 0), (0, 1), (1, 0), (1, 1), (1, 2)]
     expected = GeoSeries([Point(0, 0), Point(1, 1), Point(2, 2),
                           Point(3, 3), Point(4, 4)],
                          index=MultiIndex.from_tuples(
                             index, names=expected_index_name))
     assert_geoseries_equal(expected, s.explode())
Example #7
0
    def test_explode(self):
        s = GeoSeries([MultiPoint([(0,0), (1,1)]),
                      MultiPoint([(2,2), (3,3), (4,4)])])

        index = [(0, 0), (0, 1), (1, 0), (1, 1), (1, 2)]
        expected = GeoSeries([Point(0,0), Point(1,1), Point(2,2), Point(3,3),
                              Point(4,4)], index=MultiIndex.from_tuples(index))

        assert_geoseries_equal(expected, s.explode())

        df = self.gdf1[:2].set_geometry(s)
        assert_geoseries_equal(expected, df.explode())
Example #8
0
    def test_reverse(self):
        with mock.patch('geopy.geocoders.googlev3.GoogleV3.reverse',
                        ReverseMock()) as m:
            g = reverse_geocode(self.points, provider='googlev3', timeout=2)
            self.assertEqual(len(self.points), m.call_count)

        self.assertIsInstance(g, gpd.GeoDataFrame)

        expected = GeoSeries(self.points, crs=from_epsg(4326))
        assert_geoseries_equal(expected, g['geometry'])
        address = pd.Series(['address' + str(x) for x in range(len(self.points))],
                            name='address')
        tm.assert_series_equal(g['address'], address)
Example #9
0
    def test_forward(self):
        with mock.patch('geopy.geocoders.googlev3.GoogleV3.geocode',
                        ForwardMock()) as m:
            g = geocode(self.locations, provider='googlev3', timeout=2)
            self.assertEqual(len(self.locations), m.call_count)

        n = len(self.locations)
        self.assertIsInstance(g, gpd.GeoDataFrame)
        expected = GeoSeries([Point(float(x) + 0.5, float(x)) for x in range(n)],
                             crs=from_epsg(4326))
        assert_geoseries_equal(expected, g['geometry'])
        tm.assert_series_equal(g['address'],
                               pd.Series(self.locations, name='address'))
Example #10
0
    def test_reverse(self):
        with mock.patch('geopy.geocoders.googlev3.GoogleV3.reverse',
                        ReverseMock()) as m:
            g = reverse_geocode(self.points, provider='googlev3', timeout=2)
            assert len(self.points) == m.call_count

        assert isinstance(g, GeoDataFrame)

        expected = GeoSeries(self.points, crs=from_epsg(4326))
        assert_geoseries_equal(expected, g['geometry'])
        address = pd.Series(
            ['address' + str(x) for x in range(len(self.points))],
            name='address')
        assert_series_equal(g['address'], address)
    def test_set_geometry_col(self):
        g = self.df.geometry
        g_simplified = g.simplify(100)
        self.df['simplified_geometry'] = g_simplified
        df2 = self.df.set_geometry('simplified_geometry')

        # Drop is false by default
        assert 'simplified_geometry' in df2
        assert_geoseries_equal(df2.geometry, g_simplified)

        # If True, drops column and renames to geometry
        df3 = self.df.set_geometry('simplified_geometry', drop=True)
        assert 'simplified_geometry' not in df3
        assert_geoseries_equal(df3.geometry, g_simplified)
 def test_explode_geoseries(self):
     s = GeoSeries(
         [MultiPoint([(0, 0), (1, 1)]), MultiPoint([(2, 2), (3, 3), (4, 4)])],
         crs=4326,
     )
     s.index.name = "test_index_name"
     expected_index_name = ["test_index_name", None]
     index = [(0, 0), (0, 1), (1, 0), (1, 1), (1, 2)]
     expected = GeoSeries(
         [Point(0, 0), Point(1, 1), Point(2, 2), Point(3, 3), Point(4, 4)],
         index=MultiIndex.from_tuples(index, names=expected_index_name),
         crs=4326,
     )
     assert_geoseries_equal(expected, s.explode())
Example #13
0
    def test_forward(self):
        with mock.patch('geopy.geocoders.googlev3.GoogleV3.geocode',
                        ForwardMock()) as m:
            g = geocode(self.locations, provider='googlev3', timeout=2)
            self.assertEqual(len(self.locations), m.call_count)

        n = len(self.locations)
        self.assertIsInstance(g, gpd.GeoDataFrame)
        expected = GeoSeries(
            [Point(float(x) + 0.5, float(x)) for x in range(n)],
            crs=from_epsg(4326))
        assert_geoseries_equal(expected, g['geometry'])
        tm.assert_series_equal(g['address'],
                               pd.Series(self.locations, name='address'))
    def test_set_geometry_col(self):
        g = self.df.geometry
        g_simplified = g.simplify(100)
        self.df['simplified_geometry'] = g_simplified
        df2 = self.df.set_geometry('simplified_geometry')

        # Drop is false by default
        assert 'simplified_geometry' in df2
        assert_geoseries_equal(df2.geometry, g_simplified)

        # If True, drops column and renames to geometry
        df3 = self.df.set_geometry('simplified_geometry', drop=True)
        assert 'simplified_geometry' not in df3
        assert_geoseries_equal(df3.geometry, g_simplified)
Example #15
0
def test_reindex(s, df):
    # GeoSeries reindex
    res = s.reindex([1, 2, 3])
    exp = GeoSeries([Point(1, 1), Point(2, 2), None], index=[1, 2, 3])
    assert_geoseries_equal(res, exp)

    # GeoDataFrame reindex index
    res = df.reindex(index=[1, 2, 3])
    assert_geoseries_equal(res.geometry, exp)

    # GeoDataFrame reindex columns
    res = df.reindex(columns=["value1", "geometry"])
    assert isinstance(res, GeoDataFrame)
    assert isinstance(res.geometry, GeoSeries)
    assert_frame_equal(res, df[["value1", "geometry"]])
Example #16
0
def test_forward(locations, points):
    from geopy.geocoders import Photon

    for provider in ["photon", Photon]:
        with mock.patch("geopy.geocoders.Photon.geocode", ForwardMock()) as m:
            g = geocode(locations, provider=provider, timeout=2)
            assert len(locations) == m.call_count

        n = len(locations)
        assert isinstance(g, GeoDataFrame)
        expected = GeoSeries(
            [Point(float(x) + 0.5, float(x)) for x in range(n)],
            crs="EPSG:4326")
        assert_geoseries_equal(expected, g["geometry"])
        assert_series_equal(g["address"], pd.Series(locations, name="address"))
Example #17
0
 def test_explode_geoseries(self):
     s = GeoSeries(
         [MultiPoint([(0, 0), (1, 1)]), MultiPoint([(2, 2), (3, 3), (4, 4)])],
         crs=4326,
     )
     s.index.name = "test_index_name"
     expected_index_name = ["test_index_name", None]
     index = [(0, 0), (0, 1), (1, 0), (1, 1), (1, 2)]
     expected = GeoSeries(
         [Point(0, 0), Point(1, 1), Point(2, 2), Point(3, 3), Point(4, 4)],
         index=MultiIndex.from_tuples(index, names=expected_index_name),
         crs=4326,
     )
     with pytest.warns(FutureWarning, match="Currently, index_parts defaults"):
         assert_geoseries_equal(expected, s.explode())
Example #18
0
def test_reverse(locations, points):
    from geopy.geocoders import Photon

    for provider in ["photon", Photon]:
        with mock.patch("geopy.geocoders.Photon.reverse", ReverseMock()) as m:
            g = reverse_geocode(points, provider=provider, timeout=2)
            assert len(points) == m.call_count

        assert isinstance(g, GeoDataFrame)

        expected = GeoSeries(points, crs="EPSG:4326")
        assert_geoseries_equal(expected, g["geometry"])
        address = pd.Series(["address" + str(x) for x in range(len(points))],
                            name="address")
        assert_series_equal(g["address"], address)
Example #19
0
def test_reverse(locations, points):
    from geopy.geocoders import GeocodeFarm
    for provider in ['geocodefarm', GeocodeFarm]:
        with mock.patch('geopy.geocoders.GeocodeFarm.reverse',
                        ReverseMock()) as m:
            g = reverse_geocode(points, provider=provider, timeout=2)
            assert len(points) == m.call_count

        assert isinstance(g, GeoDataFrame)

        expected = GeoSeries(points, crs=from_epsg(4326))
        assert_geoseries_equal(expected, g['geometry'])
        address = pd.Series(['address' + str(x) for x in range(len(points))],
                            name='address')
        assert_series_equal(g['address'], address)
Example #20
0
def test_forward(locations, points):
    from geopy.geocoders import GeocodeFarm
    for provider in ['geocodefarm', GeocodeFarm]:
        with mock.patch('geopy.geocoders.GeocodeFarm.geocode',
                        ForwardMock()) as m:
            g = geocode(locations, provider=provider, timeout=2)
            assert len(locations) == m.call_count

        n = len(locations)
        assert isinstance(g, GeoDataFrame)
        expected = GeoSeries(
            [Point(float(x) + 0.5, float(x)) for x in range(n)],
            crs=from_epsg(4326))
        assert_geoseries_equal(expected, g['geometry'])
        assert_series_equal(g['address'], pd.Series(locations, name='address'))
Example #21
0
def test_reverse(locations, points):
    from geopy.geocoders import GoogleV3
    for provider in ['googlev3', GoogleV3]:
        with mock.patch('geopy.geocoders.googlev3.GoogleV3.reverse',
                        ReverseMock()) as m:
            g = reverse_geocode(points, provider=provider, timeout=2)
            assert len(points) == m.call_count

        assert isinstance(g, GeoDataFrame)

        expected = GeoSeries(points, crs=from_epsg(4326))
        assert_geoseries_equal(expected, g['geometry'])
        address = pd.Series(
            ['address' + str(x) for x in range(len(points))],
            name='address')
        assert_series_equal(g['address'], address)
Example #22
0
def test_forward(locations, points):
    from geopy.geocoders import GoogleV3
    for provider in ['googlev3', GoogleV3]:
        with mock.patch('geopy.geocoders.googlev3.GoogleV3.geocode',
                        ForwardMock()) as m:
            g = geocode(locations, provider=provider, timeout=2)
            assert len(locations) == m.call_count

        n = len(locations)
        assert isinstance(g, GeoDataFrame)
        expected = GeoSeries(
            [Point(float(x) + 0.5, float(x)) for x in range(n)],
            crs=from_epsg(4326))
        assert_geoseries_equal(expected, g['geometry'])
        assert_series_equal(g['address'],
                            pd.Series(locations, name='address'))
    def test_different_geo_colname(self):
        data = {"A": range(5), "B": range(-5, 0),
                "location": [Point(x, y) for x, y in zip(range(5), range(5))]}
        df = GeoDataFrame(data, crs=self.crs, geometry='location')
        locs = GeoSeries(data['location'], crs=self.crs)
        assert_geoseries_equal(df.geometry, locs)
        assert 'geometry' not in df
        assert df.geometry.name == 'location'
        # internal implementation detail
        assert df._geometry_column_name == 'location'

        geom2 = [Point(x, y) for x, y in zip(range(5, 10), range(5))]
        df2 = df.set_geometry(geom2, crs='dummy_crs')
        assert 'location' in df2
        assert df2.crs == 'dummy_crs'
        assert df2.geometry.crs == 'dummy_crs'
        # reset so it outputs okay
        df2.crs = df.crs
        assert_geoseries_equal(df2.geometry, GeoSeries(geom2, crs=df2.crs))
    def test_different_geo_colname(self):
        data = {"A": range(5), "B": range(-5, 0),
                "location": [Point(x, y) for x, y in zip(range(5), range(5))]}
        df = GeoDataFrame(data, crs=self.crs, geometry='location')
        locs = GeoSeries(data['location'], crs=self.crs)
        assert_geoseries_equal(df.geometry, locs)
        assert 'geometry' not in df
        assert df.geometry.name == 'location'
        # internal implementation detail
        assert df._geometry_column_name == 'location'

        geom2 = [Point(x, y) for x, y in zip(range(5, 10), range(5))]
        df2 = df.set_geometry(geom2, crs='dummy_crs')
        assert 'location' in df2
        assert df2.crs == 'dummy_crs'
        assert df2.geometry.crs == 'dummy_crs'
        # reset so it outputs okay
        df2.crs = df.crs
        assert_geoseries_equal(df2.geometry, GeoSeries(geom2, crs=df2.crs))
Example #25
0
    def test_explode(self):
        s = GeoSeries([
            MultiPoint([(0, 0), (1, 1)]),
            MultiPoint([(2, 2), (3, 3), (4, 4)])
        ])

        index = [(0, 0), (0, 1), (1, 0), (1, 1), (1, 2)]
        expected = GeoSeries(
            [Point(0, 0),
             Point(1, 1),
             Point(2, 2),
             Point(3, 3),
             Point(4, 4)],
            index=MultiIndex.from_tuples(index))

        assert_geoseries_equal(expected, s.explode())

        df = self.gdf1[:2].set_geometry(s)
        assert_geoseries_equal(expected, df.explode())
    def test_set_geometry(self):
        geom = GeoSeries([Point(x, y) for x, y in zip(range(5), range(5))])
        original_geom = self.df.geometry

        df2 = self.df.set_geometry(geom)
        assert self.df is not df2
        assert_geoseries_equal(df2.geometry, geom)
        assert_geoseries_equal(self.df.geometry, original_geom)
        assert_geoseries_equal(self.df['geometry'], self.df.geometry)
        # unknown column
        with pytest.raises(ValueError):
            self.df.set_geometry('nonexistent-column')

        # ndim error
        with pytest.raises(ValueError):
            self.df.set_geometry(self.df)

        # new crs - setting should default to GeoSeries' crs
        gs = GeoSeries(geom, crs="epsg:26018")
        new_df = self.df.set_geometry(gs)
        assert new_df.crs == "epsg:26018"

        # explicit crs overrides self and dataframe
        new_df = self.df.set_geometry(gs, crs="epsg:27159")
        assert new_df.crs == "epsg:27159"
        assert new_df.geometry.crs == "epsg:27159"

        # Series should use dataframe's
        new_df = self.df.set_geometry(geom.values)
        assert new_df.crs == self.df.crs
        assert new_df.geometry.crs == self.df.crs
Example #27
0
    def test_set_geometry(self):
        geom = GeoSeries([Point(x, y) for x, y in zip(range(5), range(5))])
        original_geom = self.df.geometry

        df2 = self.df.set_geometry(geom)
        assert self.df is not df2
        assert_geoseries_equal(df2.geometry, geom)
        assert_geoseries_equal(self.df.geometry, original_geom)
        assert_geoseries_equal(self.df['geometry'], self.df.geometry)
        # unknown column
        with pytest.raises(ValueError):
            self.df.set_geometry('nonexistent-column')

        # ndim error
        with pytest.raises(ValueError):
            self.df.set_geometry(self.df)

        # new crs - setting should default to GeoSeries' crs
        gs = GeoSeries(geom, crs="epsg:26018")
        new_df = self.df.set_geometry(gs)
        assert new_df.crs == "epsg:26018"

        # explicit crs overrides self and dataframe
        new_df = self.df.set_geometry(gs, crs="epsg:27159")
        assert new_df.crs == "epsg:27159"
        assert new_df.geometry.crs == "epsg:27159"

        # Series should use dataframe's
        new_df = self.df.set_geometry(geom.values)
        assert new_df.crs == self.df.crs
        assert new_df.geometry.crs == self.df.crs
def test_assignment(s, df):
    exp = GeoSeries([Point(10, 10), Point(1, 1), Point(2, 2)])

    s2 = s.copy()
    s2[0] = Point(10, 10)
    assert_geoseries_equal(s2, exp)

    s2 = s.copy()
    s2.loc[0] = Point(10, 10)
    assert_geoseries_equal(s2, exp)

    s2 = s.copy()
    s2.iloc[0] = Point(10, 10)
    assert_geoseries_equal(s2, exp)

    df2 = df.copy()
    df2.loc[0, 'geometry'] = Point(10, 10)
    assert_geoseries_equal(df2['geometry'], exp)

    df2 = df.copy()
    df2.iloc[0, 0] = Point(10, 10)
    assert_geoseries_equal(df2['geometry'], exp)
def test_assignment(s, df):
    exp = GeoSeries([Point(10, 10), Point(1, 1), Point(2, 2)])

    s2 = s.copy()
    s2[0] = Point(10, 10)
    assert_geoseries_equal(s2, exp)

    s2 = s.copy()
    s2.loc[0] = Point(10, 10)
    assert_geoseries_equal(s2, exp)

    s2 = s.copy()
    s2.iloc[0] = Point(10, 10)
    assert_geoseries_equal(s2, exp)

    df2 = df.copy()
    df2.loc[0, 'geometry'] = Point(10, 10)
    assert_geoseries_equal(df2['geometry'], exp)

    df2 = df.copy()
    df2.iloc[0, 0] = Point(10, 10)
    assert_geoseries_equal(df2['geometry'], exp)
Example #30
0
 def test_geo_op_empty_result(self):
     l1 = LineString([(0, 0), (1, 1)])
     l2 = LineString([(2, 2), (3, 3)])
     expected = GeoSeries([GeometryCollection()])
     # binary geo resulting in empty geometry
     result = GeoSeries([l1]).intersection(l2)
     assert_geoseries_equal(result, expected)
     # binary geo empty result with right GeoSeries
     result = GeoSeries([l1]).intersection(GeoSeries([l2]))
     assert_geoseries_equal(result, expected)
     # unary geo resulting in emtpy geometry
     result = GeoSeries([GeometryCollection()]).convex_hull
     assert_geoseries_equal(result, expected)
 def test_geo_op_empty_result(self):
     l1 = LineString([(0, 0), (1, 1)])
     l2 = LineString([(2, 2), (3, 3)])
     expected = GeoSeries([GeometryCollection()])
     # binary geo resulting in empty geometry
     result = GeoSeries([l1]).intersection(l2)
     assert_geoseries_equal(result, expected)
     # binary geo empty result with right GeoSeries
     result = GeoSeries([l1]).intersection(GeoSeries([l2]))
     assert_geoseries_equal(result, expected)
     # unary geo resulting in emtpy geometry
     result = GeoSeries([GeometryCollection()]).convex_hull
     assert_geoseries_equal(result, expected)
    def test_geometry_property(self):
        assert_geoseries_equal(self.df.geometry, self.df['geometry'],
                               check_dtype=True, check_index_type=True)

        df = self.df.copy()
        new_geom = [Point(x, y) for x, y in zip(range(len(self.df)),
                                                range(len(self.df)))]
        df.geometry = new_geom

        new_geom = GeoSeries(new_geom, index=df.index, crs=df.crs)
        assert_geoseries_equal(df.geometry, new_geom)
        assert_geoseries_equal(df['geometry'], new_geom)

        # new crs
        gs = GeoSeries(new_geom, crs="epsg:26018")
        df.geometry = gs
        assert df.crs == "epsg:26018"
    def test_geometry_property(self):
        assert_geoseries_equal(self.df.geometry, self.df['geometry'],
                               check_dtype=True, check_index_type=True)

        df = self.df.copy()
        new_geom = [Point(x, y) for x, y in zip(range(len(self.df)),
                                                range(len(self.df)))]
        df.geometry = new_geom

        new_geom = GeoSeries(new_geom, index=df.index, crs=df.crs)
        assert_geoseries_equal(df.geometry, new_geom)
        assert_geoseries_equal(df['geometry'], new_geom)

        # new crs
        gs = GeoSeries(new_geom, crs="epsg:26018")
        df.geometry = gs
        assert df.crs == "epsg:26018"
Example #34
0
    def test_different_geo_colname(self):
        data = {"A": range(5), "B": range(-5, 0),
                "location": [Point(x, y) for x, y in zip(range(5), range(5))]}
        df = GeoDataFrame(data, crs=self.crs, geometry='location')
        locs = GeoSeries(data['location'], crs=self.crs)
        assert_geoseries_equal(df.geometry, locs)
        self.assert_('geometry' not in df)
        self.assertEqual(df.geometry.name, 'location')
        # internal implementation detail
        self.assertEqual(df._geometry_column_name, 'location')

        geom2 = [Point(x, y) for x, y in zip(range(5, 10), range(5))]
        df2 = df.set_geometry(geom2, crs='dummy_crs')
        self.assert_('geometry' in df2)
        self.assert_('location' in df2)
        self.assertEqual(df2.crs, 'dummy_crs')
        self.assertEqual(df2.geometry.crs, 'dummy_crs')
        # reset so it outputs okay
        df2.crs = df.crs
        assert_geoseries_equal(df2.geometry, GeoSeries(geom2, crs=df2.crs))
        # for right now, non-geometry comes back as series
        assert_geoseries_equal(df2['location'], df['location'],
                                  check_series_type=False, check_dtype=False)
Example #35
0
 def test_set_geometry_inplace(self):
     geom = [Point(x, y) for x, y in zip(range(5), range(5))]
     ret = self.df.set_geometry(geom, inplace=True)
     assert ret is None
     geom = GeoSeries(geom, index=self.df.index, crs=self.df.crs)
     assert_geoseries_equal(self.df.geometry, geom)
 def test_convex_hull(self):
     # the convex hull of a square should be the same as the square
     squares = GeoSeries([self.sq for i in range(3)])
     assert_geoseries_equal(squares, squares.convex_hull)
 def test_centroid(self):
     polygon = Polygon([(-1, -1), (1, -1), (1, 1), (-1, 1)])
     point = Point(0, 0)
     polygons = GeoSeries([polygon for i in range(3)])
     points = GeoSeries([point for i in range(3)])
     assert_geoseries_equal(polygons.centroid, points)
def test_fillna():
    # this currently does not work (it seems to fill in the second coordinate
    # of the point
    s2 = GeoSeries([Point(0, 0), None, Point(2, 2)])
    res = s2.fillna(Point(1, 1))
    assert_geoseries_equal(res, s)
def test_dropna():
    # this currently does not work (doesn't drop)
    s2 = GeoSeries([Point(0, 0), None, Point(2, 2)])
    res = s2.dropna()
    exp = s2.loc[[0, 2]]
    assert_geoseries_equal(res, exp)
def test_indexing(s, df):

    # accessing scalar from the geometry (colunm)
    exp = Point(1, 1)
    assert s[1] == exp
    assert s.loc[1] == exp
    assert s.iloc[1] == exp
    assert df.loc[1, 'geometry'] == exp
    assert df.iloc[1, 0] == exp

    # multiple values
    exp = GeoSeries([Point(2, 2), Point(0, 0)], index=[2, 0])
    assert_geoseries_equal(s.loc[[2, 0]], exp)
    assert_geoseries_equal(s.iloc[[2, 0]], exp)
    assert_geoseries_equal(s.reindex([2, 0]), exp)
    assert_geoseries_equal(df.loc[[2, 0], 'geometry'], exp)
    # TODO here iloc does not return a GeoSeries
    assert_series_equal(df.iloc[[2, 0], 0], exp, check_series_type=False,
                        check_names=False)

    # boolean indexing
    exp = GeoSeries([Point(0, 0), Point(2, 2)], index=[0, 2])
    mask = np.array([True, False, True])
    assert_geoseries_equal(s[mask], exp)
    assert_geoseries_equal(s.loc[mask], exp)
    assert_geoseries_equal(df[mask]['geometry'], exp)
    assert_geoseries_equal(df.loc[mask, 'geometry'], exp)
 def test_set_geometry_inplace(self):
     geom = [Point(x, y) for x, y in zip(range(5), range(5))]
     ret = self.df.set_geometry(geom, inplace=True)
     assert ret is None
     geom = GeoSeries(geom, index=self.df.index, crs=self.df.crs)
     assert_geoseries_equal(self.df.geometry, geom)
def test_dropna():
    # this currently does not work (doesn't drop)
    s2 = GeoSeries([Point(0, 0), None, Point(2, 2)])
    res = s2.dropna()
    exp = s2.loc[[0, 2]]
    assert_geoseries_equal(res, exp)
def test_fillna():
    # this currently does not work (it seems to fill in the second coordinate
    # of the point
    s2 = GeoSeries([Point(0, 0), None, Point(2, 2)])
    res = s2.fillna(Point(1, 1))
    assert_geoseries_equal(res, s)
Example #44
0
def test_dropna():
    s2 = GeoSeries([Point(0, 0), None, Point(2, 2)])
    res = s2.dropna()
    exp = s2.loc[[0, 2]]
    assert_geoseries_equal(res, exp)
Example #45
0
 def test_centroid(self):
     polygon = Polygon([(-1, -1), (1, -1), (1, 1), (-1, 1)])
     point = Point(0, 0)
     polygons = GeoSeries([polygon for i in range(3)])
     points = GeoSeries([point for i in range(3)])
     assert_geoseries_equal(polygons.centroid, points)
def test_indexing(s, df):

    # accessing scalar from the geometry (colunm)
    exp = Point(1, 1)
    assert s[1] == exp
    assert s.loc[1] == exp
    assert s.iloc[1] == exp
    assert df.loc[1, 'geometry'] == exp
    assert df.iloc[1, 0] == exp

    # multiple values
    exp = GeoSeries([Point(2, 2), Point(0, 0)], index=[2, 0])
    assert_geoseries_equal(s.loc[[2, 0]], exp)
    assert_geoseries_equal(s.iloc[[2, 0]], exp)
    assert_geoseries_equal(s.reindex([2, 0]), exp)
    assert_geoseries_equal(df.loc[[2, 0], 'geometry'], exp)
    # TODO here iloc does not return a GeoSeries
    assert_series_equal(df.iloc[[2, 0], 0],
                        exp,
                        check_series_type=False,
                        check_names=False)

    # boolean indexing
    exp = GeoSeries([Point(0, 0), Point(2, 2)], index=[0, 2])
    mask = np.array([True, False, True])
    assert_geoseries_equal(s[mask], exp)
    assert_geoseries_equal(s.loc[mask], exp)
    assert_geoseries_equal(df[mask]['geometry'], exp)
    assert_geoseries_equal(df.loc[mask, 'geometry'], exp)
Example #47
0
 def test_convex_hull(self):
     # the convex hull of a square should be the same as the square
     squares = GeoSeries([self.sq for i in range(3)])
     assert_geoseries_equal(squares, squares.convex_hull)
Example #48
0
def test_fillna(s):
    s2 = GeoSeries([Point(0, 0), None, Point(2, 2)])
    res = s2.fillna(Point(1, 1))
    assert_geoseries_equal(res, s)