Source code for langchain.document_loaders.geodataframe
from typing import Any, Iterator, List
from langchain.docstore.document import Document
from langchain.document_loaders.base import BaseLoader
[docs]class GeoDataFrameLoader(BaseLoader):
    """Load `geopandas` Dataframe."""
[docs]    def __init__(self, data_frame: Any, page_content_column: str = "geometry"):
        """Initialize with geopandas Dataframe.
        Args:
            data_frame: geopandas DataFrame object.
            page_content_column: Name of the column containing the page content.
              Defaults to "geometry".
        """
        try:
            import geopandas as gpd
        except ImportError:
            raise ImportError(
                "geopandas package not found, please install it with "
                "`pip install geopandas`"
            )
        if not isinstance(data_frame, gpd.GeoDataFrame):
            raise ValueError(
                f"Expected data_frame to be a gpd.GeoDataFrame, got {type(data_frame)}"
            )
        if page_content_column not in data_frame.columns:
            raise ValueError(
                f"Expected data_frame to have a column named {page_content_column}"
            )
        if not isinstance(data_frame[page_content_column].iloc[0], gpd.GeoSeries):
            raise ValueError(
                f"Expected data_frame[{page_content_column}] to be a GeoSeries"
            )
        self.data_frame = data_frame
        self.page_content_column = page_content_column
[docs]    def lazy_load(self) -> Iterator[Document]:
        """Lazy load records from dataframe."""
        # assumes all geometries in GeoSeries are same CRS and Geom Type