spatial#
- swmmio.utils.spatial.centroid_and_bbox_from_coords(coords)[source]#
return a bounding box that encapsulates all coordinates :param coords: pd.Series of coordinates :return: boudning list of coordinates
- swmmio.utils.spatial.change_crs(series, in_crs, to_crs)[source]#
Change the projection of a series of coordinates.
- Parameters:
- seriespd.Series, pd.DataFrame, list, or tuple
Series of coordinates to be reprojected.
- in_crsstr
The current coordinate reference system of the series.
- to_crsstr
The target coordinate reference system to reproject the series to.
- Returns:
- pd.Series, pd.DataFrame, list, or tuple
Object with reprojected coordinates.
Examples
>>> from swmmio.examples import jersey >>> proj4_str = '+proj=tmerc +lat_0=36.16666666666666 +lon_0=-94.5 +k=0.9999411764705882 +x_0=850000 +y_0=0 +datum=NAD83 +units=us-ft +no_defs' >>> jersey.crs = proj4_str >>> change_crs(jersey.nodes.dataframe['coords'], proj4_str, "EPSG:4326") Name J3 [(39.236286854940964, -94.64346373821752)] 1 [(39.23851590020802, -94.64756446847099)] 2 [(39.2382157223383, -94.64468629488778)] 3 [(39.23878251491925, -94.64640342340165)] 4 [(39.238353081411915, -94.64603818939938)] 5 [(39.23797714290924, -94.64589184224722)] J2 [(39.23702605103406, -94.64543916929885)] J4 [(39.23633648359375, -94.64190240294558)] J1 [(39.23723558954326, -94.64583338271147)] Name: coords, dtype: object
- swmmio.utils.spatial.coords_series_to_geometry(coords, geomtype='linestring', dtype='geojson')[source]#
Convert a series of coordinates to a series of geometry objects.
- Parameters:
- coordspd.Series
Series of lists of xy coordinates.
- geomtypestr, optional
Geometry type of target (‘linestring’, ‘point’, ‘polygon’). Default is ‘linestring’.
- dtypestr, optional
Format of geometry objects to be created (‘geojson’, ‘shapely’). Default is ‘geojson’.
- Returns:
- pd.Series
Series of geometry objects.
Examples
>>> import swmmio >>> model = swmmio.Model(MODEL_FULL_FEATURES_XY) >>> nodes = model.nodes.dataframe >>> geoms = coords_series_to_geometry(nodes['coords'], geomtype='point') >>> geoms.iloc[0] {"coordinates": [2748073.3060000003, 1117746.087], "type": "Point"}
- swmmio.utils.spatial.read_shapefile(shp_path)[source]#
Read a shapefile into a Pandas dataframe with a ‘coords’ column holding the geometry information. This uses the pyshp package
- swmmio.utils.spatial.write_geojson(df, filename=None, geomtype='linestring', drop_na=True)[source]#
Convert dataframe with coords series to geojson format.
- Parameters:
- dfpd.DataFrame
Target dataframe.
- filenamestr, optional
Path of new file to contain geojson.
- geomtypestr, optional
Geometry type (‘linestring’, ‘point’, ‘polygon’). Default is ‘linestring’.
- drop_nabool, optional
Whether to remove properties with None values. Default is True.
- Returns:
- geojson.FeatureCollection
GeoJSON FeatureCollection.
Examples
>>> from swmmio.examples import philly >>> geoj = write_geojson(philly.links.dataframe, drop_na=True) >>> print(json.dumps(geoj['features'][0]['properties'], indent=2)) { "InletNode": "J1-025", "OutletNode": "J1-026", "Length": 309.456216, "Roughness": 0.014, "InOffset": 0, "OutOffset": 0.0, "InitFlow": 0, "MaxFlow": 0, "Shape": "CIRCULAR", "Geom1": 1.25, "Geom2": 0, "Geom3": 0, "Geom4": 0, "Barrels": 1, "Name": "J1-025.1" } >>> print(json.dumps(geoj['features'][0]['geometry'], indent=2)) { "type": "LineString", "coordinates": [ [ 2746229.223, 1118867.764 ], [ 2746461.473, 1118663.257 ] ] }