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_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 _project_point(self, point, src_crs):
return sgeom.Point(*self.transform_point(point.x, point.y, src_crs))
def setDynamicStimPosition(self,flipTime,stateDuration,event):
if self.dynamicStimPositionFuncPtr:
x,y=self.dynamicStimPositionFuncPtr()
if self.nextAreaOfInterest:
p=Point(x,y)
if self.nextAreaOfInterest.contains(p):
self.withinAOIcount+=1
if self.withinAOIcount>=self.WITHIN_AOI_SAMPLE_COUNT_THRESHOLD:
if self.aoiTriggeredID is None:
self.aoiTriggeredTime=event.time
self.aoiTriggeredID=event.event_id
cdist=self.nextAreaOfInterest.centroid.distance(p)
if cdist
Parameters
----------
normals: normals of the current point, before, and after
point: the centerline's point
centerline: Centerline object
poly, poly_no_nuntaks: subcatchment polygons
Returns
-------
(width, MultiLineString)
"""
# How far should the normal vector reach? (make it large)
far_factor = 150.
normal = shpg.LineString([shpg.Point(point + normals[0] * far_factor),
shpg.Point(point + normals[1] * far_factor)])
# First use the external boundaries only
line = normal.intersection(poly_no_nunataks)
if line.type == 'LineString':
pass # Nothing to be done
elif line.type in ['MultiLineString', 'GeometryCollection']:
# Take the one that contains the centerline
oline = None
for l in line:
if l.type != 'LineString':
continue
if l.intersects(centerline.line):
oline = l
break
if oline is None:
def extract_point(feature):
"""
Extract the coordinates from the given GeoJSON :feature: as a shapely.geometry.Point
"""
coords = feature["geometry"]["coordinates"]
return shapely.geometry.Point(coords[0], coords[1])
def snap_point_to_graph(point_x, point_y, G):
edge = get_nearest_edge(point_x, point_y, G)
point = Point((point_x, point_y))
snap = nearest_point_on_line(point, edge)
return (snap.x, snap.y)
with Serafin.Write(args.out_slf, 'fr', args.force) as resout:
output_header = resin.header
resout.write_header(output_header)
pos_B = output_header.var_IDs.index('B')
for time_index, time in enumerate(resin.time):
var = np.empty((output_header.nb_var, output_header.nb_nodes), dtype=output_header.np_float_type)
for i, var_ID in enumerate(output_header.var_IDs):
var[i, :] = resin.read_var_in_frame(time_index, var_ID)
# Replace bottom locally
nmodif = 0
for i in range(output_header.nb_nodes): # iterate over all nodes
x, y = output_header.x[i], output_header.y[i]
pt = geo.Point(x, y)
old_z = var[pos_B, i]
found = False
# Check if it is inside a zone
for j, zone in enumerate(zones):
if zone.contains(pt):
# Current point is inside zone number j and is between polylines a and b
z_int = zone.interpolate(pt)
new_z = zone.operator(z_int, old_z)
var[pos_B, i] = new_z
print("BOTTOM at node {} (zone n°{}) {} to {} (dz={})".format(
i + 1, j, operator_str, new_z, new_z - old_z
))
nmodif += 1