Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_buffer_init(self):
naive_gser = gpd.GeoSeries([self.geom])
gser = gpd.GeoSeries([self.geom], crs=geom_crs)
# test that we cannot init from a shapely geometry without providing
# its crs
self.assertRaises(ValueError, pls.BufferAnalysis, self.landscape_fp,
self.geom, self.buffer_dists)
# test that we cannot init with a landscape that does not have crs and
# transform information, even when providing the `base_mask` arguments
# properly
for base_mask in [self.geom, naive_gser, gser]:
self.assertRaises(ValueError, pls.BufferAnalysis, self.landscape,
base_mask, self.buffer_dists,
{'base_mask_crs': geom_crs})
self.assertRaises(ValueError, pls.BufferAnalysis, self.landscape,
base_mask, self.buffer_dists, {
'base_mask_crs': geom_crs,
'landscape_crs': landscape_crs
def scalar_geo_data_frame_op() -> gpd.GeoDataFrame:
data = {'name': [2000 * 'A'],
'lat': [45],
'lon': [-120]}
df = pd.DataFrame(data, columns=['name', 'lat', 'lon'])
geometry = [Point(xy) for xy in zip(df['lon'], df['lat'])]
return gpd.GeoDataFrame(df, geometry=geometry)
def setup_method(self):
test_file_path = mm.datasets.get_path("bubenec")
self.df_buildings = gpd.read_file(test_file_path, layer="buildings")
self.df_streets = gpd.read_file(test_file_path, layer="streets")
self.df_tessellation = gpd.read_file(test_file_path, layer="tessellation")
self.df_buildings["height"] = np.linspace(10.0, 30.0, 144)
def _get_country_shape(country):
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
area = world[world.name == country]
assert len(area) == 1
area = area.to_crs(epsg=3395) # convert to World Mercator CRS
return area.iloc[0].geometry # get the Polygon
f))
expected = skimage.io.imread(
os.path.join(data_dir, 'rastertile_test_expected', f))
assert np.array_equal(result, expected)
os.remove(os.path.join(data_dir, 'rastertile_test_result', f))
os.rmdir(os.path.join(data_dir, 'rastertile_test_result'))
vector_tiler = VectorTiler(os.path.join(data_dir,
'vectortile_test_result'))
vector_tiler.tile(os.path.join(data_dir, 'geotiff_labels.geojson'),
raster_tiler.tile_bounds)
vector_tiling_result_files = os.listdir(os.path.join(
data_dir, 'vectortile_test_result'))
assert len(vector_tiling_result_files) == len(os.listdir(os.path.join(
data_dir, 'vectortile_test_expected')))
for f in vector_tiling_result_files:
result = gpd.read_file(os.path.join(data_dir,
'vectortile_test_result',
f))
expected = gpd.read_file(os.path.join(data_dir,
'vectortile_test_expected',
f))
if len(result) == 0:
assert len(expected) == 0
else:
result = cascaded_union(result.geometry)
expected = cascaded_union(expected.geometry)
assert result.intersection(expected).area/result.area > 0.99999
os.remove(os.path.join(data_dir, 'vectortile_test_result', f))
os.rmdir(os.path.join(data_dir, 'vectortile_test_result'))
def test_threshold_rules_out_one_but_not_both(self):
# 000
# 00x1
# 00x1
square1 = square_at((0, 0), side_length=3)
square2 = square_at((2, 0), side_length=2)
geometries = geopandas.GeoSeries([square1, square2])
# It's under threshold w.r.t square1 but not square 2
result = resolve_overlaps(geometries, relative_threshold=0.4)
# Expected:
# 000
# 00x1
# 00x1
assert result[0].equals(square1)
assert result[1].equals(square2)
def test_geo_getitem(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')
self.assert_(isinstance(df.geometry, GeoSeries))
df['geometry'] = df["A"]
self.assert_(isinstance(df.geometry, GeoSeries))
self.assertEqual(df.geometry[0], data['location'][0])
# good if this changed in the future
self.assert_(not isinstance(df['geometry'], GeoSeries))
self.assert_(isinstance(df['location'], GeoSeries))
data["geometry"] = [Point(x + 1, y - 1) for x, y in zip(range(5), range(5))]
df = GeoDataFrame(data, crs=self.crs)
self.assert_(isinstance(df.geometry, GeoSeries))
self.assert_(isinstance(df['geometry'], GeoSeries))
# good if this changed in the future
self.assert_(not isinstance(df['location'], GeoSeries))
def test_set_geometry_series(self):
# Test when setting geometry with a Series that
# alignment will occur
#
# Reverse the index order
# Set the Series to be Point(i,i) where i is the index
self.df.index = range(len(self.df)-1, -1, -1)
d = {}
for i in range(len(self.df)):
d[i] = Point(i, i)
g = GeoSeries(d)
# At this point, the DataFrame index is [4,3,2,1,0] and the
# GeoSeries index is [0,1,2,3,4]. Make sure set_geometry aligns
# them to match indexes
df = self.df.set_geometry(g)
for i, r in df.iterrows():
self.assertAlmostEqual(i, r['geometry'].x)
self.assertAlmostEqual(i, r['geometry'].y)
assert isinstance(left.index, type(right.index))
if check_dtype:
assert left.dtype == right.dtype, "dtype: %s != %s" % (left.dtype, right.dtype)
if check_series_type:
assert isinstance(left, GeoSeries)
assert isinstance(left, type(right))
if check_crs:
assert left.crs == right.crs
else:
if not isinstance(left, GeoSeries):
left = GeoSeries(left)
if not isinstance(right, GeoSeries):
right = GeoSeries(right, index=left.index)
assert left.index.equals(right.index), "index: %s != %s" % (left.index, right.index)
if check_geom_type:
assert (left.type == right.type).all(), "type: %s != %s" % (
left.type,
right.type,
)
if check_less_precise:
assert geom_almost_equals(left, right)
else:
assert geom_equals(left, right)
if check_index_type:
assert_isinstance(left.index, type(right.index))
if check_dtype:
assert left.dtype == right.dtype, "dtype: %s != %s" % (left.dtype,
right.dtype)
if check_series_type:
assert isinstance(left, GeoSeries)
assert_isinstance(left, type(right))
if check_crs:
assert(left.crs == right.crs)
else:
if not isinstance(left, GeoSeries):
left = GeoSeries(left)
if not isinstance(right, GeoSeries):
right = GeoSeries(right, index=left.index)
assert left.index.equals(right.index), "index: %s != %s" % (left.index,
right.index)
if check_geom_type:
assert (left.type == right.type).all(), "type: %s != %s" % (left.type,
right.type)
if check_less_precise:
assert geom_almost_equals(left, right)
else:
assert geom_equals(left, right)