Compare commits
5 Commits
6e32eda1c7
...
379abb5e82
Author | SHA1 | Date | |
---|---|---|---|
379abb5e82 | |||
1799faeddd | |||
9749cecef8 | |||
a12ef190fa | |||
89d0611cfc |
@ -5,7 +5,14 @@ Module for rasterizing polygons, with float-precision anti-aliasing on
|
|||||||
See the documentation for float_raster.raster(...) for details.
|
See the documentation for float_raster.raster(...) for details.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .float_raster import *
|
from .float_raster import (
|
||||||
|
raster as raster,
|
||||||
|
find_intersections as find_intersections,
|
||||||
|
create_vertices as create_vertices,
|
||||||
|
clip_vertices_to_window as clip_vertices_to_window,
|
||||||
|
get_raster_parts as get_raster_parts,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
__author__ = 'Jan Petykiewicz'
|
__author__ = 'Jan Petykiewicz'
|
||||||
__version__ = '0.7'
|
__version__ = '0.7'
|
||||||
|
@ -4,6 +4,11 @@ from numpy import logical_and, diff, floor, ceil, ones, zeros, hstack, full_like
|
|||||||
from scipy import sparse
|
from scipy import sparse
|
||||||
|
|
||||||
|
|
||||||
|
class FloatRasterError(Exception):
|
||||||
|
""" Custom exception for float_raster """
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def raster(
|
def raster(
|
||||||
vertices: ArrayLike,
|
vertices: ArrayLike,
|
||||||
grid_x: ArrayLike,
|
grid_x: ArrayLike,
|
||||||
@ -50,15 +55,15 @@ def raster(
|
|||||||
|
|
||||||
|
|
||||||
def find_intersections(
|
def find_intersections(
|
||||||
vertices: NDArray[numpy.float_],
|
vertices: NDArray[numpy.floating],
|
||||||
grid_x: NDArray[numpy.float_],
|
grid_x: NDArray[numpy.floating],
|
||||||
grid_y: NDArray[numpy.float_],
|
grid_y: NDArray[numpy.floating],
|
||||||
) -> tuple[NDArray[numpy.float64], NDArray[numpy.float64], NDArray[numpy.float64]]:
|
) -> tuple[NDArray[numpy.float64], NDArray[numpy.float64], NDArray[numpy.float64]]:
|
||||||
"""
|
"""
|
||||||
Find intersections between a polygon and grid lines
|
Find intersections between a polygon and grid lines
|
||||||
"""
|
"""
|
||||||
if vertices.shape[0] != 2:
|
if vertices.shape[0] != 2:
|
||||||
raise Exception('vertices must be 2xN')
|
raise FloatRasterError('vertices must be 2xN')
|
||||||
|
|
||||||
min_bounds = floor(vertices.min(axis=1))
|
min_bounds = floor(vertices.min(axis=1))
|
||||||
max_bounds = ceil(vertices.max(axis=1))
|
max_bounds = ceil(vertices.max(axis=1))
|
||||||
@ -127,18 +132,18 @@ def find_intersections(
|
|||||||
|
|
||||||
|
|
||||||
def create_vertices(
|
def create_vertices(
|
||||||
vertices: NDArray[numpy.float_],
|
vertices: NDArray[numpy.floating],
|
||||||
grid_x: NDArray[numpy.float_],
|
grid_x: NDArray[numpy.floating],
|
||||||
grid_y: NDArray[numpy.float_],
|
grid_y: NDArray[numpy.floating],
|
||||||
new_vertex_data: tuple[NDArray[numpy.float64], NDArray[numpy.float64], NDArray[numpy.float64]] | None = None
|
new_vertex_data: tuple[NDArray[numpy.float64], NDArray[numpy.float64], NDArray[numpy.float64]] | None = None
|
||||||
) -> sparse.coo_matrix:
|
) -> sparse.coo_matrix:
|
||||||
"""
|
"""
|
||||||
Create additional vertices where a polygon crosses gridlines
|
Create additional vertices where a polygon crosses gridlines
|
||||||
"""
|
"""
|
||||||
if vertices.shape[0] != 2:
|
if vertices.shape[0] != 2:
|
||||||
raise Exception('vertices must be 2xN')
|
raise FloatRasterError('vertices must be 2xN')
|
||||||
if grid_x.size < 1 or grid_y.size < 1:
|
if grid_x.size < 1 or grid_y.size < 1:
|
||||||
raise Exception('Grid must contain at least one line in each direction?')
|
raise FloatRasterError('Grid must contain at least one line in each direction?')
|
||||||
|
|
||||||
num_poly_vertices = vertices.shape[1]
|
num_poly_vertices = vertices.shape[1]
|
||||||
|
|
||||||
@ -235,7 +240,7 @@ def get_raster_parts(
|
|||||||
grid_y = numpy.array(grid_y)
|
grid_y = numpy.array(grid_y)
|
||||||
|
|
||||||
if grid_x.size < 2 or grid_y.size < 2:
|
if grid_x.size < 2 or grid_y.size < 2:
|
||||||
raise Exception('Grid must contain at least one full pixel')
|
raise FloatRasterError('Grid must contain at least one full pixel')
|
||||||
|
|
||||||
num_xy_px = numpy.array([grid_x.size, grid_y.size]) - 1
|
num_xy_px = numpy.array([grid_x.size, grid_y.size]) - 1
|
||||||
|
|
||||||
|
@ -14,6 +14,9 @@ homepage = "https://mpxd.net/code/jan/float_raster"
|
|||||||
repository = "https://mpxd.net/code/jan/float_raster"
|
repository = "https://mpxd.net/code/jan/float_raster"
|
||||||
keywords = [
|
keywords = [
|
||||||
"coverage",
|
"coverage",
|
||||||
|
"raster",
|
||||||
|
"anti-alias",
|
||||||
|
"polygon",
|
||||||
]
|
]
|
||||||
classifiers = [
|
classifiers = [
|
||||||
"Programming Language :: Python :: 3",
|
"Programming Language :: Python :: 3",
|
||||||
@ -36,3 +39,44 @@ dependencies = [
|
|||||||
|
|
||||||
[tool.hatch.version]
|
[tool.hatch.version]
|
||||||
path = "float_raster/__init__.py"
|
path = "float_raster/__init__.py"
|
||||||
|
|
||||||
|
|
||||||
|
[tool.ruff]
|
||||||
|
exclude = [
|
||||||
|
".git",
|
||||||
|
"dist",
|
||||||
|
]
|
||||||
|
line-length = 145
|
||||||
|
indent-width = 4
|
||||||
|
lint.dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
|
||||||
|
lint.select = [
|
||||||
|
"NPY", "E", "F", "W", "B", "ANN", "UP", "SLOT", "SIM", "LOG",
|
||||||
|
"C4", "ISC", "PIE", "PT", "RET", "TCH", "PTH", "INT",
|
||||||
|
"ARG", "PL", "R", "TRY",
|
||||||
|
"G010", "G101", "G201", "G202",
|
||||||
|
"Q002", "Q003", "Q004",
|
||||||
|
]
|
||||||
|
lint.ignore = [
|
||||||
|
#"ANN001", # No annotation
|
||||||
|
"ANN002", # *args
|
||||||
|
"ANN003", # **kwargs
|
||||||
|
"ANN401", # Any
|
||||||
|
"ANN101", # self: Self
|
||||||
|
"SIM108", # single-line if / else assignment
|
||||||
|
"RET504", # x=y+z; return x
|
||||||
|
"PIE790", # unnecessary pass
|
||||||
|
"ISC003", # non-implicit string concatenation
|
||||||
|
"C408", # dict(x=y) instead of {'x': y}
|
||||||
|
"PLR09", # Too many xxx
|
||||||
|
"PLR2004", # magic number
|
||||||
|
"PLC0414", # import x as x
|
||||||
|
"TRY003", # Long exception message
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
[[tool.mypy.overrides]]
|
||||||
|
module = [
|
||||||
|
"scipy",
|
||||||
|
"scipy.sparse",
|
||||||
|
]
|
||||||
|
ignore_missing_imports = true
|
||||||
|
Loading…
Reference in New Issue
Block a user