Skip to content

Commit

Permalink
Refactor ufuncs module into lib module (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Oct 6, 2019
1 parent f583d8e commit 808539d
Show file tree
Hide file tree
Showing 16 changed files with 228 additions and 166 deletions.
6 changes: 3 additions & 3 deletions pygeos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .ufuncs import GEOSException # NOQA
from .ufuncs import Geometry # NOQA
from .ufuncs import geos_version # NOQA
from .lib import GEOSException # NOQA
from .lib import Geometry # NOQA
from .lib import geos_version # NOQA
from .geometry import *
from .creation import *
from .constructive import *
Expand Down
26 changes: 13 additions & 13 deletions pygeos/constructive.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import IntEnum
import numpy as np
from . import Geometry # NOQA
from . import ufuncs
from . import lib


__all__ = [
Expand Down Expand Up @@ -54,7 +54,7 @@ def boundary(geometry, **kwargs):
>>> boundary(Geometry("MULTIPOINT (0 0, 1 2)")) is None
True
"""
return ufuncs.boundary(geometry, **kwargs)
return lib.boundary(geometry, **kwargs)


def buffer(
Expand Down Expand Up @@ -147,7 +147,7 @@ def buffer(
raise TypeError("mitre_limit only accepts scalar values")
if not np.isscalar(single_sided):
raise TypeError("single_sided only accepts scalar values")
return ufuncs.buffer(
return lib.buffer(
geometry,
radius,
np.intc(quadsegs),
Expand Down Expand Up @@ -180,7 +180,7 @@ def centroid(geometry, **kwargs):
>>> centroid(Geometry("MULTIPOINT (0 0, 10 10)"))
<pygeos.Geometry POINT (5 5)>
"""
return ufuncs.centroid(geometry, **kwargs)
return lib.centroid(geometry, **kwargs)


def convex_hull(geometry, **kwargs):
Expand All @@ -197,7 +197,7 @@ def convex_hull(geometry, **kwargs):
>>> convex_hull(Geometry("POLYGON EMPTY"))
<pygeos.Geometry GEOMETRYCOLLECTION EMPTY>
"""
return ufuncs.convex_hull(geometry, **kwargs)
return lib.convex_hull(geometry, **kwargs)


def delaunay_triangles(geometry, tolerance=0.0, only_edges=False, **kwargs):
Expand Down Expand Up @@ -233,7 +233,7 @@ def delaunay_triangles(geometry, tolerance=0.0, only_edges=False, **kwargs):
>>> delaunay_triangles(Geometry("GEOMETRYCOLLECTION EMPTY"))
<pygeos.Geometry GEOMETRYCOLLECTION EMPTY>
"""
return ufuncs.delaunay_triangles(geometry, tolerance, only_edges, **kwargs)
return lib.delaunay_triangles(geometry, tolerance, only_edges, **kwargs)


def envelope(geometry, **kwargs):
Expand All @@ -254,7 +254,7 @@ def envelope(geometry, **kwargs):
>>> envelope(Geometry("GEOMETRYCOLLECTION EMPTY"))
<pygeos.Geometry POINT EMPTY>
"""
return ufuncs.envelope(geometry, **kwargs)
return lib.envelope(geometry, **kwargs)


def extract_unique_points(geometry, **kwargs):
Expand All @@ -280,7 +280,7 @@ def extract_unique_points(geometry, **kwargs):
>>> extract_unique_points(Geometry("LINESTRING EMPTY"))
<pygeos.Geometry MULTIPOINT EMPTY>
"""
return ufuncs.extract_unique_points(geometry, **kwargs)
return lib.extract_unique_points(geometry, **kwargs)


def point_on_surface(geometry, **kwargs):
Expand All @@ -301,7 +301,7 @@ def point_on_surface(geometry, **kwargs):
>>> point_on_surface(Geometry("POLYGON EMPTY"))
<pygeos.Geometry POINT EMPTY>
"""
return ufuncs.point_on_surface(geometry, **kwargs)
return lib.point_on_surface(geometry, **kwargs)


def simplify(geometry, tolerance, preserve_topology=False, **kwargs):
Expand Down Expand Up @@ -331,9 +331,9 @@ def simplify(geometry, tolerance, preserve_topology=False, **kwargs):
<pygeos.Geometry POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))>
"""
if preserve_topology:
return ufuncs.simplify_preserve_topology(geometry, tolerance, **kwargs)
return lib.simplify_preserve_topology(geometry, tolerance, **kwargs)
else:
return ufuncs.simplify(geometry, tolerance, **kwargs)
return lib.simplify(geometry, tolerance, **kwargs)


def snap(geometry, reference, tolerance, **kwargs):
Expand Down Expand Up @@ -362,7 +362,7 @@ def snap(geometry, reference, tolerance, **kwargs):
>>> snap(polygon, Geometry("LINESTRING (8 10, 8 0)"), tolerance=5)
<pygeos.Geometry POLYGON ((0 0, 0 10, 8 10, 8 0, 0 0))>
"""
return ufuncs.snap(geometry, reference, tolerance, **kwargs)
return lib.snap(geometry, reference, tolerance, **kwargs)


def voronoi_polygons(
Expand Down Expand Up @@ -402,4 +402,4 @@ def voronoi_polygons(
>>> voronoi_polygons(Geometry("POINT (2 2)"))
<pygeos.Geometry GEOMETRYCOLLECTION EMPTY>
"""
return ufuncs.voronoi_polygons(geometry, tolerance, extend_to, only_edges, **kwargs)
return lib.voronoi_polygons(geometry, tolerance, extend_to, only_edges, **kwargs)
20 changes: 10 additions & 10 deletions pygeos/creation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from . import ufuncs
from . import lib
from . import Geometry, GeometryType

__all__ = [
Expand Down Expand Up @@ -37,7 +37,7 @@ def points(coords, y=None, z=None):
y : array_like
z : array_like
"""
return _wrap_construct_ufunc(ufuncs.points, coords, y, z)
return _wrap_construct_ufunc(lib.points, coords, y, z)


def linestrings(coords, y=None, z=None):
Expand All @@ -51,7 +51,7 @@ def linestrings(coords, y=None, z=None):
y : array_like
z : array_like
"""
return _wrap_construct_ufunc(ufuncs.linestrings, coords, y, z)
return _wrap_construct_ufunc(lib.linestrings, coords, y, z)


def linearrings(coords, y=None, z=None):
Expand All @@ -68,7 +68,7 @@ def linearrings(coords, y=None, z=None):
y : array_like
z : array_like
"""
return _wrap_construct_ufunc(ufuncs.linearrings, coords, y, z)
return _wrap_construct_ufunc(lib.linearrings, coords, y, z)


def polygons(shells, holes=None):
Expand All @@ -87,12 +87,12 @@ def polygons(shells, holes=None):
shells = linearrings(shells)

if holes is None:
return ufuncs.polygons_without_holes(shells)
return lib.polygons_without_holes(shells)

holes = np.asarray(holes)
if not isinstance(holes, Geometry) and np.issubdtype(holes.dtype, np.number):
holes = linearrings(holes)
return ufuncs.polygons_with_holes(shells, holes)
return lib.polygons_with_holes(shells, holes)


def box(x1, y1, x2, y2):
Expand Down Expand Up @@ -125,7 +125,7 @@ def multipoints(geometries):
geometries.dtype, np.number
):
geometries = points(geometries)
return ufuncs.create_collection(geometries, GeometryType.MULTIPOINT)
return lib.create_collection(geometries, GeometryType.MULTIPOINT)


def multilinestrings(geometries):
Expand All @@ -141,7 +141,7 @@ def multilinestrings(geometries):
geometries.dtype, np.number
):
geometries = linestrings(geometries)
return ufuncs.create_collection(geometries, GeometryType.MULTILINESTRING)
return lib.create_collection(geometries, GeometryType.MULTILINESTRING)


def multipolygons(geometries):
Expand All @@ -157,7 +157,7 @@ def multipolygons(geometries):
geometries.dtype, np.number
):
geometries = polygons(geometries)
return ufuncs.create_collection(geometries, GeometryType.MULTIPOLYGON)
return lib.create_collection(geometries, GeometryType.MULTIPOLYGON)


def geometrycollections(geometries):
Expand All @@ -168,4 +168,4 @@ def geometrycollections(geometries):
geometries : array_like
An array of geometries
"""
return ufuncs.create_collection(geometries, GeometryType.GEOMETRYCOLLECTION)
return lib.create_collection(geometries, GeometryType.GEOMETRYCOLLECTION)
32 changes: 16 additions & 16 deletions pygeos/geometry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import IntEnum
import numpy as np
from . import ufuncs
from . import lib
from . import Geometry # NOQA

__all__ = [
Expand Down Expand Up @@ -68,7 +68,7 @@ def get_type_id(geometry):
>>> get_type_id([Geometry("POINT (1 2)"), Geometry("POINT (1 2)")]).tolist()
[0, 0]
"""
return ufuncs.get_type_id(geometry)
return lib.get_type_id(geometry)


def get_dimensions(geometry):
Expand All @@ -95,7 +95,7 @@ def get_dimensions(geometry):
>>> get_dimensions(None)
-1
"""
return ufuncs.get_dimensions(geometry)
return lib.get_dimensions(geometry)


def get_coordinate_dimensions(geometry):
Expand All @@ -116,7 +116,7 @@ def get_coordinate_dimensions(geometry):
>>> get_coordinate_dimensions(None)
-1
"""
return ufuncs.get_coordinate_dimensions(geometry)
return lib.get_coordinate_dimensions(geometry)


def get_num_coordinates(geometry):
Expand All @@ -139,7 +139,7 @@ def get_num_coordinates(geometry):
>>> get_num_coordinates(None)
-1
"""
return ufuncs.get_num_coordinates(geometry)
return lib.get_num_coordinates(geometry)


def get_srid(geometry):
Expand All @@ -164,7 +164,7 @@ def get_srid(geometry):
>>> get_srid(with_srid)
4326
"""
return ufuncs.get_srid(geometry)
return lib.get_srid(geometry)


def set_srid(geometry, srid):
Expand All @@ -188,7 +188,7 @@ def set_srid(geometry, srid):
>>> get_srid(with_srid)
4326
"""
return ufuncs.set_srid(geometry, np.intc(srid))
return lib.set_srid(geometry, np.intc(srid))


# points
Expand All @@ -213,7 +213,7 @@ def get_x(point):
>>> get_x(Geometry("MULTIPOINT (1 1, 1 2)"))
nan
"""
return ufuncs.get_x(point)
return lib.get_x(point)


def get_y(point):
Expand All @@ -235,7 +235,7 @@ def get_y(point):
>>> get_y(Geometry("MULTIPOINT (1 1, 1 2)"))
nan
"""
return ufuncs.get_y(point)
return lib.get_y(point)


# linestrings
Expand Down Expand Up @@ -270,7 +270,7 @@ def get_point(geometry, index):
>>> get_point(Geometry("POINT (1 1)"), 0) is None
True
"""
return ufuncs.get_point(geometry, np.intc(index))
return lib.get_point(geometry, np.intc(index))


def get_num_points(geometry):
Expand All @@ -295,7 +295,7 @@ def get_num_points(geometry):
>>> get_num_points(Geometry("MULTIPOINT (0 0, 1 1, 2 2, 3 3)"))
0
"""
return ufuncs.get_num_points(geometry)
return lib.get_num_points(geometry)


# polygons
Expand All @@ -319,7 +319,7 @@ def get_exterior_ring(geometry):
>>> get_exterior_ring(Geometry("POINT (1 1)")) is None
True
"""
return ufuncs.get_exterior_ring(geometry)
return lib.get_exterior_ring(geometry)


def get_interior_ring(geometry, index):
Expand All @@ -344,7 +344,7 @@ def get_interior_ring(geometry, index):
>>> get_interior_ring(Geometry("POINT (1 1)"), 0) is None
True
"""
return ufuncs.get_interior_ring(geometry, np.intc(index))
return lib.get_interior_ring(geometry, np.intc(index))


def get_num_interior_rings(geometry):
Expand All @@ -371,7 +371,7 @@ def get_num_interior_rings(geometry):
>>> get_num_interior_rings(Geometry("POINT (1 1)"))
0
"""
return ufuncs.get_num_interior_rings(geometry)
return lib.get_num_interior_rings(geometry)


# collections
Expand Down Expand Up @@ -409,7 +409,7 @@ def get_geometry(geometry, index):
>>> get_geometry(Geometry("POINT (1 1)"), 1) is None
True
"""
return ufuncs.get_geometry(geometry, np.intc(index))
return lib.get_geometry(geometry, np.intc(index))


def get_num_geometries(geometry):
Expand All @@ -433,4 +433,4 @@ def get_num_geometries(geometry):
>>> get_num_geometries(Geometry("POINT (1 1)"))
1
"""
return ufuncs.get_num_geometries(geometry)
return lib.get_num_geometries(geometry)
16 changes: 8 additions & 8 deletions pygeos/linear.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
from . import ufuncs
from . import lib

__all__ = ["interpolate", "line_merge", "project", "shared_paths"]


def interpolate(line, normalize=False):
if normalize:
return ufuncs.interpolate_normalized(line)
return lib.interpolate_normalized(line)
else:
return ufuncs.interpolate(line)
return lib.interpolate(line)


def line_merge(lines):
return ufuncs.line_merge(lines)
return lib.line_merge(lines)


def project(line, other, normalize=False):
if normalize:
return ufuncs.project_normalized(line, other)
return lib.project_normalized(line, other)
else:
return ufuncs.project(line, other)
return lib.project(line, other)


def shared_paths(a, b=None, axis=0):
if b is None:
return ufuncs.shared_paths.reduce(a, axis=axis)
return lib.shared_paths.reduce(a, axis=axis)
else:
return ufuncs.shared_paths(a, b)
return lib.shared_paths(a, b)

0 comments on commit 808539d

Please sign in to comment.