def test_set_coords_mixed_dimension(include_z): geoms = np.array([point, point_z], dtype=object) coords = get_coordinates(geoms, include_z=include_z) new_geoms = set_coordinates(geoms, coords * 2) if include_z: # preserve original dimensionality assert not pygeos.has_z(new_geoms[0]) assert pygeos.has_z(new_geoms[1]) else: # all 2D assert not pygeos.has_z(new_geoms).any()
def drop_z(map_: gpd.GeoDataFrame): """Drops z attribute""" if pygeos.has_z(map_.geometry).any(): warnings.warn( "Geometry contains Z co-ordinates. Removed from Map3D (height attribute)" ) map_.geometry = pygeos.apply(map_.geometry, lambda x: x, include_z=False) return map_
def drop_z(map_: gpd.GeoDataFrame): """Drops z attribute""" output = map_.copy() if pygeos.has_z(map_.geometry.array.data).any(): warnings.warn( "Geometry contains Z co-ordinates. Removed from Map3D (height attribute)") output.geometry = pygeos.apply( map_.geometry.array.data, lambda x: x, include_z=False) return output
def map(map_: gpd.GeoDataFrame) -> None: tests = { 'Missing geometries': map_.geometry.is_empty.any(), 'Expecting Polygons': not map_.geom_type.eq("Polygon").all(), 'Unexpected z coordinates': pygeos.has_z(pygeos.io.from_shapely(map_.geometry)).any(), '"height" column missing or not numeric': ('height' not in map_.columns) or (map_['height'].dtype != "float" and map_['height'].dtype != "int"), } _raise(tests) return None
def rays(rays: gpd.GeoSeries) -> None: # errors tests = { 'Missing geometries': rays.is_empty.any(), 'Expecting Linestrings': not rays.geom_type.eq("LineString").all(), 'Missing z coordinates': not pygeos.has_z(pygeos.io.from_shapely(rays)).all(), 'More than 2 points in Linestring': np.not_equal(pygeos.count_coordinates(pygeos.io.from_shapely(rays)), 2 * len(rays)).any(), } _raise(tests) return None
def receiverpoints(points: gpd.GeoDataFrame) -> None: # warnings if 'svid' in points.columns: constellations(points['svid'], supported_constellations) # errors tests = { 'Missing geometries': points.geometry.is_empty.any(), 'Expecting Points': not points.geom_type.eq("Point").all(), 'Missing z coordinates': not pygeos.has_z(pygeos.io.from_shapely(points.geometry)).all(), '"time" column missing or not datetime': (('time' not in points.columns) or (points['time'].dtype != "datetime64[ns]")), } _raise(tests) return None
def transform_geoseries(geometry): target_crs = pyproj.crs.CRS(target) if target_crs == geometry.crs: return geometry cm.check.crs(target_crs) cm.check.crs(geometry.crs) transformer = pyproj.Transformer.from_crs( geometry.crs, target_crs, always_xy=True) if not all(pygeos.has_z(geometry.array.data)): coords = pygeos.get_coordinates( geometry.array.data, include_z=False) new_coords = transformer.transform(coords[:, 0], coords[:, 1]) else: coords = pygeos.get_coordinates( geometry.array.data, include_z=True) new_coords = transformer.transform( coords[:, 0], coords[:, 1], coords[:, 2]) return pygeos.set_coordinates(geometry.array.data.copy(), np.array(new_coords).T)
def has_z(data): if compat.USE_PYGEOS: return pygeos.has_z(data) else: return _unary_op("has_z", data, null_value=False)