GeoFrame.GeoDataFrame (GeoFrame v0.3.4)

Copy Markdown View Source

A dataframe of attributes paired with a geometry column.

A %GeoDataFrame{} holds an Explorer.DataFrame with the attribute columns only and a GeoFrame.GeoSeries with the geometries, which live in Rust memory. The geometry column is not part of the Explorer dataframe; it has a name (:geometry_column, default "geometry") that is reserved among the attribute names.

Several geometry columns

Like a GeoPandas frame with more than one geometry dtype column, a frame has one active geometry (geometry/1, the one every spatial operation uses) and any number of secondary geometry columns, each a GeoFrame.GeoSeries with its own CRS. put_geometry/3 adds one, set_geometry/3 makes another column the active one, pull/2 returns one by name and geometry_columns/1 lists them (active first). Row operations (take/2, filter_with/2, sort_with/2, join/3, concat_rows/1, explode/2, ...) keep every geometry column aligned; to_crs/2 and set_crs/2 act on the active one, as in GeoPandas. GeoParquet, Feather and Arrow read and write all of them (GeoFrame.read_parquet/2, GeoFrame.write_parquet/3, GeoFrame.write_feather/3, to_arrow/2), and the formats with one geometry per feature (GeoPackage, GeoJSON, FlatGeobuf, Shapefile, PostGIS, to_json/2) raise ArgumentError for such a frame, as GeoPandas to_file raises ValueError. clip/3, overlay/3, sjoin/3, sjoin_nearest/3 and dissolve/2 carry them like GeoPandas (other geometry columns are ordinary columns there): kept with their rows and CRS, suffixed on a name clash, null for rows without a partner, aggregated by dissolve/2 with :first, :last or :count.

Row alignment

Every operation that changes rows computes the row positions once and applies them to both sides (GeoSeries.take/2 and Explorer.DataFrame.slice/2), so attribute and geometry rows can never drift apart. filter_with/2 and sort_with/2 add a temporary row-position column to the attributes, let Explorer do the work, read the resulting positions back, and remove the column again. The temporary column is invisible in the result, and its name is chosen so that it cannot collide with an existing column.

Column order

names/1, to_explorer/2, and the Table.Reader view list the attribute columns in their dataframe order and the geometry column last.

Example

iex> data = Explorer.DataFrame.new(id: [1, 2])
iex> geometry = GeoFrame.GeoSeries.from_wkt!(["POINT (0 0)", "POINT (5 5)"])
iex> gdf = GeoFrame.GeoDataFrame.new(data, geometry)
iex> GeoFrame.GeoDataFrame.names(gdf)
["id", "geometry"]

Summary

Functions

Planar area per row as a series.

Per-row bounds as a dataframe (minx, miny, maxx, maxy).

Returns the frame with its geometry replaced by the centroids.

Stacks frames row-wise, like pandas.concat/GeoDataFrame concatenation.

The CRS of the geometry, or nil.

Rows whose geometry intersects the box, like GeoPandas gdf.cx[xmin:xmax, ymin:ymax]. nil bounds are unbounded; see GeoFrame.GeoSeries.cx/5. Attributes stay aligned.

The attribute dataframe (without geometry).

Drops attribute columns (anything Explorer.DataFrame.discard/2 accepts), and the secondary geometry columns it names. The active geometry is never discarded, and naming it in columns is harmless, like in select/2.

Group-wise union with attribute aggregation; see GeoFrame.Dissolve.dissolve/2.

Keeps the first row of each distinct combination of attribute values, like Explorer.DataFrame.distinct/2; the geometry follows its row.

Drops rows with a null in any of columns (default all attribute columns), like Explorer.DataFrame.drop_nil/2. A null geometry does not count; check it with GeoFrame.GeoSeries.notna/1 with take/2 if needed.

Column dtypes by name; the geometry column maps to :geometry.

Splits multi-part geometries and collections into one row per part, like GeoDataFrame.explode. The attributes of a row are repeated for each of its parts.

Keeps rows matching a query, like Explorer.DataFrame.filter/2.

Keeps rows for which fun is true, like Explorer.DataFrame.filter_with/2.

Decodes an Arrow IPC stream into a frame; see GeoFrame.GeoSeries.from_arrow/2 for the accepted geometry encodings. All other columns become attributes.

Builds a frame from GeoJSON-like features, like GeoPandas GeoDataFrame.from_features.

GeoPandas GeoDataFrame.from_postgis: alias of GeoFrame.read_postgis/3.

Moves a WKB binary column of df into the geometry. Same options as from_wkt/3.

Moves a WKT string column of df into the geometry.

The geometry series.

Names of the geometry columns: the active one first, then the secondary ones.

Marks the groups of a frame; see GeoFrame.GroupBy.

Applies a function per group and concatenates the results; see GeoFrame.GroupBy.group_map/4.

The names of the grouping columns; see GeoFrame.GroupBy.

The first n rows (default 5); on a grouped frame (group_by/2) the first n rows of each group, in the original row order (as pandas groupby.head).

Joins attributes of right onto the rows of left, like GeoPandas GeoDataFrame.merge.

Planar length (perimeter for polygons) per row as a series.

Adds or replaces attribute columns from a query, like Explorer.DataFrame.mutate/2.

Adds or replaces attribute columns via Explorer.DataFrame.mutate_with/2.

Number of columns, counting the geometry columns.

Number of rows.

Attribute column names followed by the geometry column names (active first).

Pairs an attribute dataframe with a geometry series.

Spatial overlay with another frame; see GeoFrame.Overlay.overlay/3.

An attribute column as a series. The name of a geometry column (active or secondary) returns its GeoFrame.GeoSeries instead.

Adds or replaces the attribute column name with a series, list, or tensor, like Explorer.DataFrame.put/4. Raises ArgumentError for the geometry column's name or a value whose length differs from the row count.

Adds the secondary geometry column name, or replaces the one with that name.

Renames attribute columns via Explorer.DataFrame.rename/2. Raises ArgumentError if a new name equals the geometry column's name.

Renames the active geometry column, like GeoPandas GeoDataFrame.rename_geometry.

A random sample of rows, like Explorer.DataFrame.sample/3: n_or_frac is a row count or a fraction. Options (:replace, :shuffle, :seed) are passed through. On a grouped frame (group_by/2) each group is sampled (n_or_frac per group), as Explorer does; the order of the groups in the result is unspecified.

Selects attribute columns (anything Explorer.DataFrame.select/2 accepts). The active geometry is always kept, and naming it in columns is harmless. A secondary geometry column is kept only when columns names it.

Replaces the CRS metadata without reprojecting; crs is a string, an integer EPSG code or nil. A different existing CRS raises unless allow_override: true. See GeoFrame.GeoSeries.set_crs/3.

Makes another geometry column the active one, like GeoPandas set_geometry.

{rows, columns}, counting the geometry column.

Randomly reorders the rows; opts (:seed) are passed through.

Rows from offset for length rows, with Explorer.DataFrame.slice/3 semantics.

Sorts rows by a query, like Explorer.DataFrame.sort_by/3; opts are passed through.

Sorts rows like Explorer.DataFrame.sort_with/3; opts are passed through.

Aggregates every group into one row, attributes and geometry; see GeoFrame.GroupBy.

The last n rows (default 5); on a grouped frame the last n rows of each group, in the original row order (as pandas groupby.tail).

Selects rows by zero-based position; repeats and reordering are allowed.

Encodes the frame as an Arrow IPC stream (a binary): the attribute columns followed by the geometry columns (the active one first, then the secondary ones, each with its own CRS), whose fields carry GeoArrow extension metadata with the CRS as PROJJSON (and a GeoParquet-style geo entry in the schema metadata). GeoPandas reads it with GeoDataFrame.from_arrow(pyarrow.ipc.open_stream(bytes).read_all()).

Reprojects the geometry to target ("EPSG:<code>", "OGC:CRS84" or an integer EPSG code); attributes are untouched. See GeoFrame.GeoSeries.to_crs/2.

Converts to an Explorer.DataFrame with the geometry columns last (active first).

The frame as a GeoJSON-like map, like GeoPandas GeoDataFrame.to_geo_dict. It is to_geo_interface/1 with options, and its defaults differ: no bboxes.

The __geo_interface__ of the frame: a FeatureCollection map (string keys) with id, properties, geometry and bbox per feature, and the collection bbox; missing values are nil. Secondary geometry columns are properties holding GeoJSON geometry maps (GeoPandas keeps the shapely objects there, which Elixir has no equivalent of).

The frame as a GeoJSON FeatureCollection map (RFC 7946).

The frame as a GeoJSON FeatureCollection string, like GeoPandas GeoDataFrame.to_json.

GeoPandas GeoDataFrame.to_postgis: alias of GeoFrame.to_postgis/4.

Every geometry column, the active one and the secondary ones, encoded as WKB in an Explorer.DataFrame; the attribute columns are unchanged and the geometry columns come last (active first). Like GeoPandas GeoDataFrame.to_wkb; null geometries stay nil.

Every geometry column encoded as WKT strings in an Explorer.DataFrame, like GeoPandas GeoDataFrame.to_wkt; see to_wkb/2 for the layout. Takes no options (GeoPandas passes its keyword arguments to shapely, such as rounding_precision, which are not supported).

Removes the groups (all, or the named ones); see GeoFrame.GroupBy.

Types

t()

@type t() :: %GeoFrame.GeoDataFrame{
  data: Explorer.DataFrame.t(),
  geometry: GeoFrame.GeoSeries.t(),
  geometry_column: String.t(),
  secondary_geometries: [{String.t(), GeoFrame.GeoSeries.t()}]
}

Functions

area(geo_data_frame)

@spec area(t()) :: Explorer.Series.t()

Planar area per row as a series.

bounds(geo_data_frame)

@spec bounds(t()) :: Explorer.DataFrame.t()

Per-row bounds as a dataframe (minx, miny, maxx, maxy).

centroid(gdf)

@spec centroid(t()) :: t()

Returns the frame with its geometry replaced by the centroids.

clip(gdf, mask, opts \\ [])

@spec clip(t(), term(), keyword()) :: t()

Clips to a mask; see GeoFrame.Overlay.clip/3.

concat_rows(frames)

@spec concat_rows([t()]) :: t()

Stacks frames row-wise, like pandas.concat/GeoDataFrame concatenation.

Attribute columns follow Explorer.DataFrame.concat_rows/1 (same names and compatible dtypes, else it raises). Every frame must use the same geometry column name and CRS, or ArgumentError is raised. The CRS check runs before any data is copied.

crs(geo_data_frame)

@spec crs(t()) :: String.t() | nil

The CRS of the geometry, or nil.

cx(gdf, xmin, ymin, xmax, ymax)

@spec cx(t(), number() | nil, number() | nil, number() | nil, number() | nil) :: t()

Rows whose geometry intersects the box, like GeoPandas gdf.cx[xmin:xmax, ymin:ymax]. nil bounds are unbounded; see GeoFrame.GeoSeries.cx/5. Attributes stay aligned.

data(geo_data_frame)

@spec data(t()) :: Explorer.DataFrame.t()

The attribute dataframe (without geometry).

discard(gdf, columns)

@spec discard(t(), term()) :: t()

Drops attribute columns (anything Explorer.DataFrame.discard/2 accepts), and the secondary geometry columns it names. The active geometry is never discarded, and naming it in columns is harmless, like in select/2.

dissolve(gdf, opts \\ [])

@spec dissolve(t(), keyword()) :: t()

Group-wise union with attribute aggregation; see GeoFrame.Dissolve.dissolve/2.

distinct(gdf, columns \\ ..)

@spec distinct(t(), term()) :: t()

Keeps the first row of each distinct combination of attribute values, like Explorer.DataFrame.distinct/2; the geometry follows its row.

columns (default all attribute columns) selects the columns compared; the geometry is never compared, and naming it is harmless.

drop_nil(gdf, columns \\ ..)

@spec drop_nil(t(), term()) :: t()

Drops rows with a null in any of columns (default all attribute columns), like Explorer.DataFrame.drop_nil/2. A null geometry does not count; check it with GeoFrame.GeoSeries.notna/1 with take/2 if needed.

dtypes(gdf)

@spec dtypes(t()) :: %{required(String.t()) => atom() | tuple()}

Column dtypes by name; the geometry column maps to :geometry.

estimate_utm_crs(geo_data_frame, opts \\ [])

@spec estimate_utm_crs(t(), keyword()) :: String.t()

The UTM CRS for the geometry's extent. See GeoFrame.GeoSeries.estimate_utm_crs/2.

explode(gdf, opts \\ [])

@spec explode(t(), keyword()) :: t()

Splits multi-part geometries and collections into one row per part, like GeoDataFrame.explode. The attributes of a row are repeated for each of its parts.

GeoSeries.explode/2 explains which geometries have parts: rows whose geometry is null or an empty multi-geometry disappear.

pandas keeps the source row in the index (a MultiIndex of source row and part number when index_parts=True). A frame has no index, so the same information becomes plain columns, placed first:

  • index - the zero-based position of the source row (s64); omitted with ignore_index: true;
  • part - the zero-based number of the part within its source row; only with index_parts: true, whatever ignore_index says.

Options: :index_parts (default false), :ignore_index (default false). Raises ArgumentError if an attribute is already called index or part and the column would be added.

filter(gdf, query)

(macro)

Keeps rows matching a query, like Explorer.DataFrame.filter/2.

Expands to filter_with/2 with Explorer.Query.query/1, so require this module first. The query sees the attribute columns only: the geometry is not a column in it. Use ^ to interpolate Elixir values.

require GeoFrame.GeoDataFrame
limit = 10
GeoFrame.GeoDataFrame.filter(gdf, pop > ^limit)

filter_with(gdf, fun)

@spec filter_with(t(), (Explorer.DataFrame.t() -> Explorer.Series.t())) :: t()

Keeps rows for which fun is true, like Explorer.DataFrame.filter_with/2.

fun receives the attribute dataframe (as a lazy dataframe) and returns a boolean lazy series. The geometry is filtered by the same row positions.

from_arrow(bytes, opts \\ [])

@spec from_arrow(binary(), keyword()) :: {:ok, t()} | {:error, String.t()}

Decodes an Arrow IPC stream into a frame; see GeoFrame.GeoSeries.from_arrow/2 for the accepted geometry encodings. All other columns become attributes.

Options: :columns - attribute columns to keep; :geometry - the geometry column when it cannot be detected; :crs - a CRS used only when the data carries none.

from_arrow!(bytes, opts \\ [])

@spec from_arrow!(binary(), keyword()) :: t()

Like from_arrow/2 but raises ArgumentError on failure.

from_features(features, opts \\ [])

@spec from_features([map()] | map(), keyword()) :: {:ok, t()} | {:error, String.t()}

Builds a frame from GeoJSON-like features, like GeoPandas GeoDataFrame.from_features.

features is a list of feature maps (%{"type" => "Feature", "properties" => .., "geometry" => ..}) or a FeatureCollection map; string or atom keys both work. A bare geometry map counts as one feature. Property types are inferred over all features exactly as GeoFrame.read_geojson/2 does (booleans, s64, f64, otherwise strings; nested values as JSON text; a feature id becomes a leading "id" column when every feature has one). A nil geometry is a null row. Property columns follow their first appearance across the features (as GeoPandas does) when the properties are ordered: a keyword list or a list of {key, value} pairs, or JSON decoded with Jason.decode!(json, objects: :ordered_objects). Plain Elixir maps have no insertion order, so their columns appear sorted by name; use :columns to choose the order explicitly. (The geometry column comes last, as in every GeoDataFrame here, where GeoPandas puts it first.)

Options:

  • :crs - the CRS of the geometries, nil by default (GeoPandas default; GeoJSON files read with read_geojson/2 get "OGC:CRS84" instead).
  • :columns - property columns to keep, in that order; an unknown name is an error.
  • :geometry_column - name of the geometry column (default "geometry").

Returns {:error, message} for input that is not valid GeoJSON.

from_features!(features, opts \\ [])

@spec from_features!([map()] | map(), keyword()) :: t()

Like from_features/2 but raises ArgumentError on failure.

from_postgis(conn, sql, opts \\ [])

@spec from_postgis(term(), String.t(), keyword()) :: {:ok, t()} | {:error, String.t()}

GeoPandas GeoDataFrame.from_postgis: alias of GeoFrame.read_postgis/3.

from_wkb(df, column, opts \\ [])

@spec from_wkb(Explorer.DataFrame.t(), String.t(), keyword()) ::
  {:ok, t()} | {:error, String.t()}

Moves a WKB binary column of df into the geometry. Same options as from_wkt/3.

from_wkb!(df, column, opts \\ [])

@spec from_wkb!(Explorer.DataFrame.t(), String.t(), keyword()) :: t()

Like from_wkb/3 but raises ArgumentError on failure.

from_wkt(df, column, opts \\ [])

@spec from_wkt(Explorer.DataFrame.t(), String.t(), keyword()) ::
  {:ok, t()} | {:error, String.t()}

Moves a WKT string column of df into the geometry.

The geometry column keeps the source column's name unless :geometry_column is given. Options: :crs, :geometry_column.

from_wkt!(df, column, opts \\ [])

@spec from_wkt!(Explorer.DataFrame.t(), String.t(), keyword()) :: t()

Like from_wkt/3 but raises ArgumentError on failure.

geometry(geo_data_frame)

@spec geometry(t()) :: GeoFrame.GeoSeries.t()

The geometry series.

geometry_columns(geo_data_frame)

@spec geometry_columns(t()) :: [String.t()]

Names of the geometry columns: the active one first, then the secondary ones.

group_by(gdf, columns)

@spec group_by(t(), term()) :: t()

Marks the groups of a frame; see GeoFrame.GroupBy.

group_map(gdf, by, fun, opts \\ [])

@spec group_map(t(), term(), (t() -> t() | Explorer.DataFrame.t()), keyword()) ::
  t() | Explorer.DataFrame.t()

Applies a function per group and concatenates the results; see GeoFrame.GroupBy.group_map/4.

groups(gdf)

@spec groups(t()) :: [String.t()]

The names of the grouping columns; see GeoFrame.GroupBy.

head(gdf, n \\ 5)

@spec head(t(), non_neg_integer()) :: t()

The first n rows (default 5); on a grouped frame (group_by/2) the first n rows of each group, in the original row order (as pandas groupby.head).

is_geographic(geo_data_frame)

@spec is_geographic(t()) :: boolean() | nil

Whether the CRS is geographic. See GeoFrame.GeoSeries.is_geographic/1.

join(left, right, opts \\ [])

@spec join(t(), Explorer.DataFrame.t() | t(), keyword()) :: t()

Joins attributes of right onto the rows of left, like GeoPandas GeoDataFrame.merge.

right is an Explorer.DataFrame or a GeoFrame.GeoDataFrame; for the latter only the attributes are used and its geometry is dropped (a frame has a single geometry column). The geometry always comes from left: it follows its rows, is repeated for duplicated keys and is nil for rows that exist only on the right (how: :right and :outer).

Options go to Explorer.DataFrame.join/3 (:on, :how, :suffix, ...); :how is one of :inner (default), :left, :right, :outer or :cross. Raises ArgumentError when :on names the geometry column or the result would contain a column with its name.

Known deviations from pandas: :outer lists left-only rows last (pandas sorts them by key) and Polars does not coalesce the key, so :outer yields "k" (nil for right-only rows) plus "k_right"; :inner, :left and :right match pandas row for row. Each row keeps the geometry of its own left row either way.

length(geo_data_frame)

@spec length(t()) :: Explorer.Series.t()

Planar length (perimeter for polygons) per row as a series.

mutate(gdf, mutations)

(macro)

Adds or replaces attribute columns from a query, like Explorer.DataFrame.mutate/2.

Expands to mutate_with/2 with Explorer.Query.query/1. The query sees the attribute columns only. Raises ArgumentError if the result would contain the geometry column's name.

mutate_with(gdf, fun)

@spec mutate_with(t(), (Explorer.DataFrame.t() -> keyword() | map())) :: t()

Adds or replaces attribute columns via Explorer.DataFrame.mutate_with/2.

Raises ArgumentError if the result would contain the geometry column's name.

n_columns(gdf)

@spec n_columns(t()) :: non_neg_integer()

Number of columns, counting the geometry columns.

n_rows(geo_data_frame)

@spec n_rows(t()) :: non_neg_integer()

Number of rows.

names(gdf)

@spec names(t()) :: [String.t()]

Attribute column names followed by the geometry column names (active first).

new(data, geometry, opts \\ [])

Pairs an attribute dataframe with a geometry series.

Options: :geometry_column - the geometry column name (default "geometry").

Raises ArgumentError when row counts differ or data already has a column with the geometry column's name. A data without columns is accepted for any row count.

overlay(df1, df2, opts \\ [])

@spec overlay(t(), t(), keyword()) :: t()

Spatial overlay with another frame; see GeoFrame.Overlay.overlay/3.

pull(gdf, column)

@spec pull(t(), String.t() | atom() | integer()) ::
  Explorer.Series.t() | GeoFrame.GeoSeries.t()

An attribute column as a series. The name of a geometry column (active or secondary) returns its GeoFrame.GeoSeries instead.

put(gdf, name, values)

@spec put(t(), String.t() | atom(), Explorer.Series.t() | list() | Nx.Tensor.t()) ::
  t()

Adds or replaces the attribute column name with a series, list, or tensor, like Explorer.DataFrame.put/4. Raises ArgumentError for the geometry column's name or a value whose length differs from the row count.

put_geometry(gdf, name, series)

@spec put_geometry(t(), String.t() | atom(), GeoFrame.GeoSeries.t()) :: t()

Adds the secondary geometry column name, or replaces the one with that name.

Raises ArgumentError when series does not have one row per frame row or name is an attribute or the active geometry column. A secondary column keeps its own CRS.

rename(gdf, renames)

@spec rename(t(), term()) :: t()

Renames attribute columns via Explorer.DataFrame.rename/2. Raises ArgumentError if a new name equals the geometry column's name.

rename_geometry(gdf, new_name)

@spec rename_geometry(t(), String.t() | atom()) :: t()

Renames the active geometry column, like GeoPandas GeoDataFrame.rename_geometry.

Raises ArgumentError ("Column named <name> already exists") when the frame already has a column with that name, the geometry column itself included.

sample(gdf, n_or_frac, opts \\ [])

@spec sample(t(), number(), keyword()) :: t()

A random sample of rows, like Explorer.DataFrame.sample/3: n_or_frac is a row count or a fraction. Options (:replace, :shuffle, :seed) are passed through. On a grouped frame (group_by/2) each group is sampled (n_or_frac per group), as Explorer does; the order of the groups in the result is unspecified.

select(gdf, columns)

@spec select(t(), term()) :: t()

Selects attribute columns (anything Explorer.DataFrame.select/2 accepts). The active geometry is always kept, and naming it in columns is harmless. A secondary geometry column is kept only when columns names it.

set_crs(gdf, crs, opts \\ [])

@spec set_crs(t(), String.t() | pos_integer() | nil, keyword()) :: t()

Replaces the CRS metadata without reprojecting; crs is a string, an integer EPSG code or nil. A different existing CRS raises unless allow_override: true. See GeoFrame.GeoSeries.set_crs/3.

set_geometry(gdf, column, opts \\ [])

@spec set_geometry(t(), String.t() | atom() | GeoFrame.GeoSeries.t(), keyword()) ::
  t()

Makes another geometry column the active one, like GeoPandas set_geometry.

column is the name of a secondary geometry column, or a GeoFrame.GeoSeries that becomes a new column named by the :geometry_column option (default "geometry", or the active name when that is free). The previous active column stays as a secondary one.

Options: :drop - true removes the previous active geometry column (default false); :geometry_column - the name for a series. Raises ArgumentError for a name that is not a geometry column of the frame.

shape(gdf)

@spec shape(t()) :: {non_neg_integer(), non_neg_integer()}

{rows, columns}, counting the geometry column.

shuffle(gdf, opts \\ [])

@spec shuffle(t(), keyword()) :: t()

Randomly reorders the rows; opts (:seed) are passed through.

sjoin(left, right, opts \\ [])

@spec sjoin(t(), t(), keyword()) :: t()

Spatial join; see GeoFrame.SpatialJoin.sjoin/3.

sjoin_nearest(left, right, opts \\ [])

@spec sjoin_nearest(t(), t(), keyword()) :: t()

Nearest spatial join; see GeoFrame.SpatialJoin.sjoin_nearest/3.

slice(gdf, offset, length)

@spec slice(t(), integer(), non_neg_integer()) :: t()

Rows from offset for length rows, with Explorer.DataFrame.slice/3 semantics.

On a grouped frame (group_by/2) the slice is taken within each group, as Explorer does; the rows come back in their original order.

sort_by(gdf, query, opts \\ [])

(macro)

Sorts rows by a query, like Explorer.DataFrame.sort_by/3; opts are passed through.

Expands to sort_with/3 with Explorer.Query.query/1. The query sees the attribute columns only, and the geometry follows its row.

sort_with(gdf, fun, opts \\ [])

@spec sort_with(t(), (Explorer.DataFrame.t() -> term()), keyword()) :: t()

Sorts rows like Explorer.DataFrame.sort_with/3; opts are passed through.

summarise(gdf, aggregations \\ [], opts \\ [])

@spec summarise(t(), keyword() | map(), keyword()) :: t()

Aggregates every group into one row, attributes and geometry; see GeoFrame.GroupBy.

tail(gdf, n \\ 5)

@spec tail(t(), non_neg_integer()) :: t()

The last n rows (default 5); on a grouped frame the last n rows of each group, in the original row order (as pandas groupby.tail).

take(gdf, indices)

@spec take(t(), [non_neg_integer()]) :: t()

Selects rows by zero-based position; repeats and reordering are allowed.

to_arrow(gdf, opts \\ [])

@spec to_arrow(t(), keyword()) :: binary()

Encodes the frame as an Arrow IPC stream (a binary): the attribute columns followed by the geometry columns (the active one first, then the secondary ones, each with its own CRS), whose fields carry GeoArrow extension metadata with the CRS as PROJJSON (and a GeoParquet-style geo entry in the schema metadata). GeoPandas reads it with GeoDataFrame.from_arrow(pyarrow.ipc.open_stream(bytes).read_all()).

Options: :geometry_encoding - :wkb (default) or :geoarrow; see GeoFrame.GeoSeries.to_arrow/2; :record_batch_size - rows per record batch (positive integer, default 65 536). Failures raise ArgumentError.

to_crs(gdf, target)

@spec to_crs(t(), String.t() | pos_integer()) :: t()

Reprojects the geometry to target ("EPSG:<code>", "OGC:CRS84" or an integer EPSG code); attributes are untouched. See GeoFrame.GeoSeries.to_crs/2.

to_explorer(gdf, opts \\ [])

@spec to_explorer(t(), keyword()) :: Explorer.DataFrame.t()

Converts to an Explorer.DataFrame with the geometry columns last (active first).

Options: :encoding - :wkb (default, binary column) or :wkt (string column). See to_wkb/2 and to_wkt/2.

to_geo_dict(gdf, opts \\ [])

@spec to_geo_dict(t(), keyword()) :: map()

The frame as a GeoJSON-like map, like GeoPandas GeoDataFrame.to_geo_dict. It is to_geo_interface/1 with options, and its defaults differ: no bboxes.

Options: :na - :null (default) keeps missing properties as nil, :drop omits them, :keep leaves values as Explorer yields them (nil, :nan); :show_bbox (default false); :drop_id (default false). Unknown options raise ArgumentError.

to_geo_interface(gdf)

@spec to_geo_interface(t()) :: map()

The __geo_interface__ of the frame: a FeatureCollection map (string keys) with id, properties, geometry and bbox per feature, and the collection bbox; missing values are nil. Secondary geometry columns are properties holding GeoJSON geometry maps (GeoPandas keeps the shapely objects there, which Elixir has no equivalent of).

See to_geo_dict/2 for the variant with options.

to_geojson(gdf)

@spec to_geojson(t()) :: map()

The frame as a GeoJSON FeatureCollection map (RFC 7946).

Each row is a Feature: the geometry (see GeoFrame.GeoSeries.to_geojson/1, nil for null or unrepresentable rows) plus the attribute columns as string-keyed properties. Null attributes are kept as nil. A secondary geometry column becomes a property holding its GeoJSON geometry map (GeoPandas keeps the shapely object there). Property values are the Elixir values Explorer yields (dates, decimals, ...), so they encode with Jason for the common column types.

to_json(gdf, opts \\ [])

@spec to_json(t(), keyword()) :: String.t()

The frame as a GeoJSON FeatureCollection string, like GeoPandas GeoDataFrame.to_json.

Each row is a Feature with a string id (the row position), the attribute columns as properties, the geometry (null for null or unrepresentable rows) and, with show_bbox, its bbox. A frame with secondary geometry columns raises ArgumentError, as GeoPandas raises TypeError (a shape is not JSON serializable). Missing values (nil, NaN) are null. A CRS other than EPSG:4326 adds the crs member as GeoPandas does; see GeoFrame.GeoSeries.to_json/2.

Options: :na - :null (default) keeps missing properties as null, :drop omits them (:keep is rejected: it would emit NaN, which is not JSON); :show_bbox (default false); :drop_id (default false); :to_wgs84 (default false).

to_postgis(gdf, conn, table, opts \\ [])

@spec to_postgis(t(), term(), String.t(), keyword()) :: :ok | {:error, String.t()}

GeoPandas GeoDataFrame.to_postgis: alias of GeoFrame.to_postgis/4.

to_wkb(gdf, opts \\ [])

@spec to_wkb(t(), keyword()) :: Explorer.DataFrame.t()

Every geometry column, the active one and the secondary ones, encoded as WKB in an Explorer.DataFrame; the attribute columns are unchanged and the geometry columns come last (active first). Like GeoPandas GeoDataFrame.to_wkb; null geometries stay nil.

Options: :hex (default false) gives upper-case hexadecimal strings instead of binaries, and :srid (an integer, or true for each column's own EPSG: CRS) gives PostGIS EWKB; see GeoFrame.GeoSeries.to_wkb/2.

to_wkt(gdf, opts \\ [])

@spec to_wkt(t(), keyword()) :: Explorer.DataFrame.t()

Every geometry column encoded as WKT strings in an Explorer.DataFrame, like GeoPandas GeoDataFrame.to_wkt; see to_wkb/2 for the layout. Takes no options (GeoPandas passes its keyword arguments to shapely, such as rounding_precision, which are not supported).

ungroup(gdf, columns \\ ..)

@spec ungroup(t(), term()) :: t()

Removes the groups (all, or the named ones); see GeoFrame.GroupBy.