NumPy Geometry

Working with geometry using numpy.

Maintained by Dan-Patterson

NumPy Geometry and FreeTools


New home base for Free Tools

Developed in ArcGIS Pro <= 3.2.1, python <= 3.9.18 and numpy <= 1.22.

These demo scripts and the toolbox show how numpy and arcpy can play nice together and generate geometries that are normally only available at the ArcGIS Pro Advanced level. The tools are already provided to do this, but less attention is paid to the attributes.

The image to the right reflects the tools as they stand on 2022/02/07.

The /npg folder contains the toolbox and scripts needed to run the tools in ArcGIS Pro.





The basic structure is as follows:

file, folder purpose
npg/npg_tools.tbx the toolbox for ArcGIS Pro (2.8 although may work with 2.7).
npg/tbx_tools.py the main script controlling all tools in the toolbox
npg/npg the scripts folder which contains the modules imported by tbx_tools.

Usually a spatial and/or attribute join enables one to bring the attributes from the input class to the output class.

This can be done after the geometry is created, or I may have done so during script construction (depending on how bored I was).

In some cases, the outputs are only one option of what the Esri tool provides, for example

#6 Polygons to Polylines, is just that... 

a simple conversion of the geometry type, no fancy intersection and overlap stuff...

You get what you pay for, but the widest use is probably the simplest.


Last update : 2022-02-07

Fixed some errors...(I hope).

Last update : 2021-06-04

Rewrites of many functions to optimize array concatenations. npg_clip is still being tested. convex polygons pose no problems, but clipping that results in multipart geometries is still being investigated.

2020-12-20 update

This is not an exhaustive or definitive list of the toolbox functionality... consider it a sampling:

Dissolve Boundaries

Dissolve shared edges in polygon geometry. The polygons do not need to share a common attribute. All shared edges are deleted and holes are removed. Edges that meet at a point are not considered shared since there is no 2D space between the points.

Blog post Dissolve boundaries

Feature Envelope to Polygon

Using the Geo array class, the extent of polyline and polygon features are created from their constituent points.

ArcGIS Pro help Feature envelope to polygon

Convex hulls

Simple convex hull implementation in python, or scipy (feature points > than a threshold)

ArcGIS Pro help Minimum bounding geometry

Feature to Point

For polygon features. Reduces the points to a representative centroid.

ArcGIS Pro help Feature to point

Split Line at Vertices

As it says. I chose to keep the order of the resultant line segments as they were and not remove apparent duplicates for line segments that occur on shared borders. In such cases, the shared segments will have the same points, but their from-to order is reversed. There are cases to be made for keeping them or removing them... however, if they are removed, then they are harder to add back in should one want to recreate polygon geometry from the line segments.

ArcGIS Pro help Split line at vertices

Feature Vertices to Points

Convert polygon features to a centroid. One point is returned for multipart shapes, but this could be altered if someone has a use-case that might be relevant.

ArcGIS Pro help Feature vertices to points

Polygons to Polylines

Really... You are just changing from polygons to polylines. They are still a closed geometry, nothing fancy geometry-wise. Should definitely be Freed from its shackles.

ArcGIS Pro help Feature to polygon

Bounding Circles

Another container that has been around for a long time in a variety of formats and readily implemented in python. Sort-of ported this over from an old toolbox for ArcMap, but redone for the new geom class. Speedy and accurate.

ArcGIS Pro help Minimum area bounding circles

Frequency

Another tool that should be free for such basic functionality.

Create classes from multiple columns

ArcGIS Pro help Frequency