README
DXF Polygon Cleaner
Takes the result table of dxf-polygon-importer and runs cleaning and validation functions on a given file, project and version combination.
The initial version was developed to solve following geometry problems:
Key for yellow numbered test problem sets:
- Overlapping polygons and duplicate labels
- Multiple labels
- Split label ('0', '002')
- C shaped polygon
- C shaped polygon with empty core
- Self-intersecting geometry with duplicate label
- Doughnut geometry
- Doughnut geometry with label only in core (should be in ring)
- '009A' appears as polygon, but is only enclosed by line on the left
- 2 Overlapping polygons
- 3 Overlapping polygons (one that contains both)
- Doughnut with label in core and ring
- Orphaned label
- Non-compact shape type without label
Installation and requirements
npm install dxf-polygon-cleaner
The module requires a PostGIS enabled PostgreSQL database (version 9.3 or higher) and expects a database structure created by the dxf-polygon-importer.
Following environment variables need to be set:
DXF_TOOLS_DB_HOST ... PostgreSQL server host
DXF_TOOLS_DB_PORT ... PostgreSQL server port
DXF_TOOLS_DB_USER ... Database user name
DXF_TOOLS_DB_PASSWORD ... Database user password
DXF_TOOLS_DB_NAME ... Database name
Sensible database connection defaults are applied for typical 'localhost' environments, a database-name is required however.
The module will create a table approved_dxf_features
, for permantly storing a single version of approved features, and 2 temporary views, for accessing the latest versions per feature type, project and filename.
Usage
var Cleaner = require('dxf-polygon-cleaner');
// Cleaner(filename, project, version);
var cleaner = Cleaner('mydrawing.dxf', 'myproject', 1);
cleaner.setup().then(function () {
// data cleaning and/or validation methods
}).then(function () {
return cleaner.teardown();
});
Run tests
Requires a test
database.
$ npm test
API
Cleaner(filename, project, version)
initialize The class takes 3 arguments to identify the feature collection that should be processed: the filename
of the imported dxf file, the project
identifier and the imported version
.
Cleaner.setup()
setup Creates temporary views to make succeeding database queries and operations a little easier.
Cleaner.teardown()
teardown Removes temporary views and ends the database connection pool.
Cleaner.fixDoughnuts()
fixDoughnuts Creates doughnut geometries and removes overlaps of polygons and their completely contained polygons.
Cleaner.deleteEmptyPolygons()
deleteEmptyPolygons Deletes all polygons with an area smaller than 1 [square-unit].
Cleaner.labelPolygons()
labelPolygons Assigns labels as names to enclosing polygons.
Cleaner.fixDoughnutLabels()
fixDoughnutLabels Moves labels from cores to non-labeled rings of doughnut geometries.
Cleaner.flagPolygons()
flagPolygons Adds following validation flags to all polygons:
hasLabel, hasManyLabels, hasSharedLabels
compactness, area
isOverlapping, overlappingPolygons
isValid, validReason
The compactness indicator measures shape form and is calculated by the following formula:
Example values:
- cirlce: 1
- square: ~0.8
- long shaped corridor: ~0.15
Cleaner.flagLabels()
flagLabels Adds following validation flags to all label points:
isInPolygon, isInManyPolygons
Cleaner.approvePolygons(options)
approvePolygons Inserts a copy of the currently processed features into approved_dxf_features
, and deletes any prior existing versions in that table.
{
endPool: true|false end database pool when done
}
Cleaner.getInvalidGeometryDetails()
getInvalidGeometryDetails Return a GeoJSON object with point geometries and meta information of possibly problematic geometries, like self-intersections.
Cleaner.getGeoJson(options)
getGeoJson Return a GeoJSON Feature collection of the currently processed features. It takes and options
object with following properties:
{
approved: true|false return only approved features
endPool: true|false end database pool when done
}
Cleaner.setVersion()
setVersion Finds the most recent version of a project and filename combination and sets the Cleaner._version
property accordingly. Useful when defaulting to the last version.
Cleaner.fullService()
fullService Alias for running common tasks:
- fixDoughnuts
- deleteEmptyPolygons
- labelPolygons
- fixDoughnutLabels
- flagPolygons
- flagLabels
- getGeoJson
Returns GeoJSON.