Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def manually_compute_intersections(sources, targets):
records = []
for i, source in sources.geometry.items():
for j, target in targets.geometry.items():
intersection = source.intersection(target)
if not intersection.is_empty:
records.append((i, j, intersection))
expected = (
geopandas.GeoDataFrame.from_records(
records, columns=["source", "target", "geometry"]
)
.set_index(["source", "target"])
.geometry
)
return expected
def manually_compute_intersections(sources, targets):
records = []
for i, source in sources.geometry.items():
for j, target in targets.geometry.items():
intersection = source.intersection(target)
if not intersection.is_empty:
records.append((i, j, intersection))
expected = (
geopandas.GeoDataFrame.from_records(
records, columns=["source", "target", "geometry"]
)
.set_index(["source", "target"])
.geometry
)
return expected
def intersections(sources, targets):
reindexed_sources = get_geometries_with_range_index(sources)
reindexed_targets = get_geometries_with_range_index(targets)
spatially_indexed_sources = IndexedGeometries(reindexed_sources)
records = [
# Flip i, j to j, i so that the index is ["source", "target"]
(sources.index[j], targets.index[i], geometry)
for i, j, geometry in spatially_indexed_sources.enumerate_intersections(
reindexed_targets
)
]
df = GeoDataFrame.from_records(records, columns=["source", "target", "geometry"])
geometries = df.set_index(["source", "target"]).geometry
geometries.sort_index(inplace=True)
return geometries
:param area_cutoff: (optional) if provided, only return intersections with
area greater than ``area_cutoff``
:type area_cutoff: Number or None
"""
reindexed_sources = get_geometries_with_range_index(sources)
reindexed_targets = get_geometries_with_range_index(targets)
spatially_indexed_sources = IndexedGeometries(reindexed_sources)
records = [
# Flip i, j to j, i so that the index is ["source", "target"]
(sources.index[j], targets.index[i], geometry)
for i, j, geometry in spatially_indexed_sources.enumerate_intersections(
reindexed_targets
)
]
df = GeoDataFrame.from_records(records, columns=["source", "target", "geometry"])
geometries = df.set_index(["source", "target"]).geometry
geometries.sort_index(inplace=True)
geometries.crs = sources.crs
if area_cutoff is not None:
geometries = geometries[geometries.area > area_cutoff]
return geometries
nominal intensity category based on the central pressure value.
:param str trackFile: Path to a TCRM-format track file
:returns: `GeoPandas.GeoDataFrame` of tracks
"""
LOGGER.debug(f"Loading track data from {trackFile}")
tracks = track.ncReadTrackData(trackFile)
trackgdf = []
for t in tracks:
segments = []
for n in range(len(t.data) - 1):
segment = LineString([[t.Longitude[n], t.Latitude[n]],[t.Longitude[n+1], t.Latitude[n+1]]])
segments.append(segment)
gdf = gpd.GeoDataFrame.from_records(t.data[:-1])
gdf['geometry'] = segments
gdf['category'] = pd.cut(gdf['CentralPressure'],
bins=[0, 930, 955, 970, 985, 990, 1020],
labels=[5,4,3,2,1,0])
trackgdf.append(gdf)
trackgdf = pd.concat(trackgdf)
return trackgdf