Geos DataFrame Accessor#

class pgpd.GeosDataFrameAccessor(obj)#

Access Shapely functionality through the “geos” dataframe accessor keyword. The functions defined here simply call the appropriate functions from GeosSeriesAccessor and group the results.

Example

>>> df = pd.DataFrame({
...     'a': list('abcde'),
...     'poly': shapely.box(range(5), 0, range(10,15), 10),
...     'pt': shapely.points(range(5), range(10,15))
... })
>>> df = df.astype({'poly':'geos', 'pt':'geos'})
>>> df
   a                                      poly            pt
0  a  POLYGON ((10 0, 10 10, 0 10, 0 0, 10 0))  POINT (0 10)
1  b  POLYGON ((11 0, 11 10, 1 10, 1 0, 11 0))  POINT (1 11)
2  c  POLYGON ((12 0, 12 10, 2 10, 2 0, 12 0))  POINT (2 12)
3  d  POLYGON ((13 0, 13 10, 3 10, 3 0, 13 0))  POINT (3 13)
4  e  POLYGON ((14 0, 14 10, 4 10, 4 0, 14 0))  POINT (4 14)
>>> df.geos.has_z()
    poly     pt
0  False  False
1  False  False
2  False  False
3  False  False
4  False  False

Serialization#

Serialization & Deserialization functionality.

GeosDataFrameAccessor.to_geos

Transform a geopandas.GeoDataFrame into a regular DataFrame with a geos column.

GeosDataFrameAccessor.to_geopandas

Transform a pandas DataFrame with (at least) a "geos" dtype column to a geopandas.GeoDataFrame.

GeosSeriesAccessor.to_wkt

GeosSeriesAccessor.to_wkb

Geometry#

Methods from Shapely Geometry Properties.

GeosDataFrameAccessor.get_coordinate_dimension

Returns the dimensionality of the coordinates in a geometry (2 or 3).

GeosDataFrameAccessor.get_dimensions

Returns the inherent dimensionality of a geometry.

GeosDataFrameAccessor.get_exterior_ring

Returns the exterior ring of a polygon.

GeosDataFrameAccessor.get_geometry

Returns the nth geometry from a collection of geometries.

GeosDataFrameAccessor.get_interior_ring

Returns the nth interior ring of a polygon.

GeosDataFrameAccessor.get_num_coordinates

Returns the total number of coordinates in a geometry.

GeosDataFrameAccessor.get_num_geometries

Returns number of geometries in a collection.

GeosDataFrameAccessor.get_num_interior_rings

Returns number of internal rings in a polygon

GeosDataFrameAccessor.get_num_points

Returns number of points in a linestring or linearring.

GeosDataFrameAccessor.get_point

Returns the nth point of a linestring or linearring.

GeosDataFrameAccessor.get_precision

Get the precision of a geometry.

GeosDataFrameAccessor.get_srid

Returns the SRID of a geometry.

GeosDataFrameAccessor.get_type_id

Returns the type ID of a geometry.

GeosDataFrameAccessor.get_x

Returns the x-coordinate of a point

GeosDataFrameAccessor.get_y

Returns the y-coordinate of a point

GeosDataFrameAccessor.get_z

Returns the z-coordinate of a point.

GeosDataFrameAccessor.force_2d

Forces the dimensionality of a geometry to 2D.

GeosDataFrameAccessor.force_3d

Forces the dimensionality of a geometry to 3D.

GeosDataFrameAccessor.set_precision

Returns geometry with the precision set to a precision grid size.

GeosDataFrameAccessor.set_srid

Returns a geometry with its SRID set.

Geometry Creation#

Methods from Shapely Geometry Creation.

GeosDataFrameAccessor.destroy_prepared

Destroy the prepared part of a geometry, freeing up memory.

GeosDataFrameAccessor.prepare

Prepare a geometry, improving performance of other operations.

Measurement#

Methods from Shapely Measurement.

GeosDataFrameAccessor.area

Computes the area of a (multi)polygon.

GeosDataFrameAccessor.length

Computes the length of a (multi)linestring or polygon perimeter.

GeosDataFrameAccessor.minimum_bounding_radius

Computes the radius of the minimum bounding circle that encloses an input geometry.

GeosDataFrameAccessor.minimum_clearance

Computes the Minimum Clearance distance.

GeosDataFrameAccessor.total_bounds

Computes the total bounds (extent) of the geometry.

Predicates#

Methods from Shapely Predicates.

GeosDataFrameAccessor.has_z

Returns True if a geometry has a Z coordinate.

GeosDataFrameAccessor.is_ccw

Returns True if a linestring or linearring is counterclockwise.

GeosDataFrameAccessor.is_closed

Returns True if a linestring's first and last points are equal.

GeosDataFrameAccessor.is_empty

Returns True if a geometry is an empty point, polygon, etc.

GeosDataFrameAccessor.is_geometry

Returns True if the object is a geometry

GeosDataFrameAccessor.is_missing

Returns True if the object is not a geometry (None)

GeosDataFrameAccessor.is_prepared

Returns True if a Geometry is prepared.

GeosDataFrameAccessor.is_ring

Returns True if a linestring is closed and simple.

GeosDataFrameAccessor.is_simple

Returns True if a Geometry has no anomalous geometric points, such as self-intersections or self tangency.

GeosDataFrameAccessor.is_valid

Returns True if a geometry is well formed.

GeosDataFrameAccessor.is_valid_input

Returns True if the object is a geometry or None

GeosDataFrameAccessor.is_valid_reason

Returns a string stating if a geometry is valid and if not, why.

Constructive Operations#

Methods from Shapely Constructive Operations.

GeosDataFrameAccessor.boundary

Returns the topological boundary of a geometry.

GeosDataFrameAccessor.buffer

Computes the buffer of a geometry for positive and negative buffer distance.

GeosDataFrameAccessor.centroid

Computes the geometric center (center-of-mass) of a geometry.

GeosDataFrameAccessor.clip_by_rect

Returns the portion of a geometry within a rectangle.

GeosDataFrameAccessor.convex_hull

Computes the minimum convex geometry that encloses an input geometry.

GeosDataFrameAccessor.delaunay_triangles

Computes a Delaunay triangulation around the vertices of an input geometry.

GeosDataFrameAccessor.envelope

Computes the minimum bounding box that encloses an input geometry.

GeosDataFrameAccessor.extract_unique_points

Returns all distinct vertices of an input geometry as a multipoint.

GeosDataFrameAccessor.make_valid

Repairs invalid geometries.

GeosDataFrameAccessor.minimum_bounding_circle

Computes the minimum bounding circle that encloses an input geometry.

GeosDataFrameAccessor.minimum_rotated_rectangle

Computes the oriented envelope (minimum rotated rectangle) that encloses an input geometry, such that the resulting rectangle has minimum area.

GeosDataFrameAccessor.normalize

Converts Geometry to normal form (or canonical form).

GeosDataFrameAccessor.offset_curve

Returns a (Multi)LineString at a distance from the object on its right or its left side.

GeosDataFrameAccessor.oriented_envelope

Computes the oriented envelope (minimum rotated rectangle) that encloses an input geometry, such that the resulting rectangle has minimum area.

GeosDataFrameAccessor.point_on_surface

Returns a point that intersects an input geometry.

GeosDataFrameAccessor.reverse

Returns a copy of a Geometry with the order of coordinates reversed.

GeosDataFrameAccessor.simplify

Returns a simplified version of an input geometry using the Douglas-Peucker algorithm.

GeosDataFrameAccessor.snap

Snaps an input geometry to reference geometry's vertices.

GeosDataFrameAccessor.voronoi_polygons

Computes a Voronoi diagram from the vertices of an input geometry.

Linestring Operations#

Methods from Shapely Linestring Operations.

GeosDataFrameAccessor.line_interpolate_point

Returns a point interpolated at given distance on a line.

GeosDataFrameAccessor.line_locate_point

Returns the distance to the line origin of given point.

GeosDataFrameAccessor.line_merge

Returns (Multi)LineStrings formed by combining the lines in a MultiLineString.

Coordinate Operations#

Methods from Shapely Coordinate Operations.

GeosDataFrameAccessor.transform

Returns a copy of a geometry array with a function applied to its coordinates.

GeosDataFrameAccessor.count_coordinates

Counts the number of coordinate pairs in a geometry array.

GeosDataFrameAccessor.set_coordinates

Adapts the coordinates of a geometry array in-place.

Custom#

Custom methods to add more functionality.

GeosDataFrameAccessor.affine

Performs a 2D or 3D affine transformation on all the coordinates.

GeosDataFrameAccessor.rotate

Performs a 2D or 3D rotation on all the coordinates.

GeosDataFrameAccessor.scale

Performs a 2D or 3D scaling on all the coordinates.

GeosDataFrameAccessor.skew

Performs a 2D or 3D skew/shear transformation on all the coordinates.

GeosDataFrameAccessor.translate

Performs a 2D or 3D translation on all the coordinates.