Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def randomMultiLineString():
return shapely.geometry.MultiLineString([randomLineString() for i in xrange(R.randint(1, 8))])
def test_empty_multilinestring(self):
self.assertTrue(sgeom.MultiLineString([]).is_empty)
except:
pass
done+=1
continue
try:
multiline.append(geometry.LineString(way))
filtered_segs+=len(way)
except:
pass
done+=1
UI.progress_bar(1,100)
if not filter:
return geometry.MultiLineString(multiline)
else:
UI.vprint(2," Number of filtered segs :",filtered_segs)
return (geometry.MultiLineString(multiline),geometry.MultiLineString(multiline_reject))
##############################################################################
try:
routes = skeleton_routes(skeletons, min_length)
except _SignalAlarm, e:
# An alarm signal here means that graph_routes() went overtime.
raise _GraphRoutesOvertime(skeletons)
points += sum(map(len, routes))
lines.extend([simplify_line_vw(route, min_area) for route in routes])
logging.debug('selected %d final points from %d graph route points' % (sum(map(len, lines)), points))
if not lines:
return False
return MultiLineString(lines)
for (key, multiline) in sorted(multilines.items()):
print >> stderr, ', '.join(key), '...'
centerline = multiline_centerline(multiline, **kwargs)
if not centerline:
continue
if output_columns:
properties = dict(zip(output_columns, key))
else:
properties = dict(ref=key[0], highway=key[1])
coords = [[mercator(*point, inverse=True) for point in geom.coords] for geom in centerline.geoms]
geometry = MultiLineString(coords).__geo_interface__
feature = dict(geometry=geometry, properties=properties)
geojson['features'].append(feature)
output = open_file(output_file, 'w')
dump(geojson, output)
ls.coords[0][0],
ls.coords[0][1],
ls.coords[-1][0],
ls.coords[-1][1],
)
)
# If this line segment does not intersect the current polygon of interest,
# we should check any previous polygons to see if it intersects it. We
# could be dealing with invalid ordering in the file, sigh.
if currentpoly.intersection(ls).is_empty:
print(" ls does not intersect currentpoly, looking for match")
found = False
for i, poly in enumerate(polys):
intersect = poly.intersection(ls)
if intersect.is_empty or isinstance(intersect, MultiLineString):
continue
print(
(
" found previous polygon i:%s area: %.1f "
"that intersects"
)
% (i, poly.area)
)
found = True
polys.append(currentpoly)
currentpoly = polys.pop(i)
break
if not found:
print(" setting currentpoly back to CONUS")
polys.append(currentpoly)
currentpoly = copy.deepcopy(CONUS["poly"])
continue
if l.intersects(centerline.line):
oline = l
break
if oline is None:
return np.NaN, shpg.MultiLineString()
line = oline
else:
extext = 'Geometry collection not expected: {}'.format(line.type)
raise RuntimeError(extext)
# Then take the nunataks into account
# Make sure we are always returning a MultiLineString for later
line = line.intersection(poly)
if line.type == 'LineString':
line = shpg.MultiLineString([line])
elif line.type == 'MultiLineString':
pass # nothing to be done
elif line.type == 'GeometryCollection':
oline = []
for l in line:
if l.type != 'LineString':
continue
oline.append(l)
if len(oline) == 0:
return np.NaN, shpg.MultiLineString()
line = shpg.MultiLineString(oline)
else:
extext = 'Geometry collection not expected: {}'.format(line.type)
raise NotImplementedError(extext)
assert line.type == 'MultiLineString'
coords.append(roundxy(x,y))
obj = shapely.geometry.MultiPoint(coords)
elif type==3: # Polyline
bbox=self.__readfmt('<4d', f)
numparts, numpoints=self.__readfmt('1 :
obj=shapely.geometry.Polygon(coords[0],coords[1:])
else:
obj=shapely.geometry.Polygon(coords[0])
start = linestring.coords[i]
test = linestring.coords[i + 1]
if not LineString([start, end]).contains(Point(test)):
coords.append(test)
coords.append(linestring.coords[-1])
return LineString(coords)
net_segments = []
for i, coords in enumerate(nets):
net_segments.append([])
lines = []
for a, b in itertools.combinations(coords, 2):
if Point(a).distance(Point(b)) == 1:
lines.append(LineString([a, b]))
mls = linemerge(MultiLineString(lines))
if not isinstance(mls, MultiLineString):
line = reduce_linestring(mls).coords
net_segments[-1].append(line)
else:
for line in mls:
line = reduce_linestring(line).coords
net_segments[-1].append(line)
for segments, net in zip(net_segments, pcb.netlist.nets):
for seg in segments:
for i, coord in enumerate(seg[1:]):
start = grid_to_pos(*seg[i])
end = grid_to_pos(*coord)
Segment(net, start, end,
pcb.attributes.layers.routing_layers[0])
# for fl1 in mfls:
while len(mfls) > 0:
fl1 = mfls.pop(0)
ol_index = [] # list of index from first overlap
# loop over other main lines and main main line
for fl2 in mfls + [mainfl]:
# calculate overlap, maybe use larger buffer here only to find it
_overlap = fl1.line.intersection(fl2.line.buffer(buffer*2))
# calculate indice of first overlap if overlap length > 0
oix = 9999
if _overlap.length > 0 and fl1 != fl2 and fl2.flows_to != fl1:
if isinstance(_overlap, shpg.MultiLineString):
if _overlap[0].coords[0] == fl1.line.coords[0]:
# if the head of overlap is same as the first line,
# best guess is, that the heads are close topgether!
_ov1 = _overlap[1].coords[1]
else:
_ov1 = _overlap[0].coords[1]
else:
_ov1 = _overlap.coords[1]
for _i, _p in enumerate(fl1.line.coords):
if _p == _ov1:
oix = _i
# low indices are more likely due to an wrong overlap
if oix < 10:
oix = 9999
ol_index.append(oix)