Book Image

Python Geospatial Analysis Cookbook

Book Image

Python Geospatial Analysis Cookbook

Overview of this book

Table of Contents (20 chapters)
Python Geospatial Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Other Geospatial Python Libraries
Mapping Icon Libraries
Index

A polygon centroid must be within a specific distance of a line


Check that each polygon centroid is within a distance tolerance to a LineString. An example use case for such a rule could be for a routing network that defines the snap tolerance in meters from a room centroid to the nearest routing networkline. This line must be located within a certain distance; otherwise, no route can be generated, for example. The following screenshot shows the use of some dummy polygons and LineStrings, indicating the centroids that fall within our set tolerance of 20000 m in red. These are polygons that are spread far apart from Venice to Vienna:

Note

If you're up for some algorithm reading material, this is a nice read by Paul Bourke at http://paulbourke.net/geometry/pointlineplane/.

How to do it...

  1. This code will now automatically find centroids outside your distance tolerance:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    from utils import shp2_geojson_obj
    from utils import create_shply_multigeom
    from utils...