add_sites
site.SiteProblem.add_sites(
candidate_site_df,
candidate_id_col,
required_sites_col=None,
geometry_col='geometry',
vertical_geometry_col='lat',
horizontal_geometry_col='long',
crs=None,
capacity_col=None,
skip_cols=None,
)Add candidate facility sites to the problem and handle spatial alignment.
This method ingests site data from either a standard DataFrame or a GeoDataFrame. If tabular data is provided, it automatically converts coordinates into point geometries. It also ensures the data matches the object’s preferred CRS, attempting to guess the CRS if it’s not provided.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| candidate_site_df | pandas.DataFrame or geopandas.GeoDataFrame or str | The dataset containing potential site locations, or a local or web path to its location. | required |
| candidate_id_col | str | The name of the column containing unique identifiers for each site. | required |
| required_sites_col | str | The name of a boolean or binary column indicating if a site must be included in the final solution. Defaults to None. | None |
| geometry_col | str | The name of the geometry column (used if candidate_site_df is already a GeoDataFrame or is a path to a geodataframe). |
"geometry" |
| vertical_geometry_col | str | The column name for latitude/y-coordinates (used if input is tabular or a path to a tabular file format like .csv). | "lat" |
| horizontal_geometry_col | str | The column name for longitude/x-coordinates (used if input is tabular or a path to a tabular file format like .csv). | "long" |
| crs | str or pyproj.CRS | The coordinate reference system of the input data. If None and the input is tabular, the method will attempt to guess the CRS. | None |
| capacity_col | str | The column name representing the capacity of each site. Defaults to None. | None |
| skip_cols | list of str | A list of column names to ignore during the data loading process. | None |
Returns
| Name | Type | Description |
|---|---|---|
| None |
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | If required columns (ID, capacity, or geometry) are missing from the input data. |
Notes
The method performs the following transformations: 1. Infers data type (spatial vs. tabular). 2. Validates schema based on the data type. 3. If tabular, converts to a geopandas.GeoDataFrame using the specified horizontal and vertical coordinate columns. 4. Matches or converts the dataset to self.preferred_crs.
Updates internal state including self.candidate_sites and self.total_n_sites.